using EnVisage.Code.BLL; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EnVisage.Code.Integration { public class CrmHelper { private static string HelperClass = "EnVisage.Code.Integration.CrmAccess"; public static CrmAccess GetCrm() { IntegrationManager man = new IntegrationManager(new EnVisageEntities()); var model = man.getCrmModel(); string CrmAccessStringType = model.CrmAccessClass; if (String.IsNullOrEmpty(CrmAccessStringType)) { return null; } else { System.Type crmAccessType = System.Type.GetType(CrmAccessStringType); if (crmAccessType == null) { throw (new NullReferenceException("crmAccessType"+ CrmAccessStringType + " can not be found")); } System.Type tp = System.Type.GetType(HelperClass); if (!tp.IsAssignableFrom(crmAccessType)) { throw (new ArgumentException("crmAccessType("+ CrmAccessStringType + ") does not inherit from "+ HelperClass)); } CrmAccess crm = (CrmAccess) Activator.CreateInstance(crmAccessType); return (crm); } } } }