Exemple #1
0
        private void AddOrUpdateCRMEntity()
        {
            IOrganizationService serviceProxy = GetCRMClientServiceProxy();

            if (serviceProxy == null)
            {
                throw new Exception("Unable to found CRM client service proxy");
            }
            try
            {
                ORM <SimpleFlowStructure> orm = new ORM <SimpleFlowStructure>();
                //Check current type of entity present in data base or not
                SimpleFlowStructure simpleFlowStructure = orm.Fetch(new WhereCondition[]
                {
                    new FieldWhereCondition("data_type_name", QueryMatchType.Equals, CRMEntityName),
                    new FieldWhereCondition("data_type_name_space", QueryMatchType.Equals, GetCrmEntityNamespace())
                }).FirstOrDefault();

                if (simpleFlowStructure == null)
                {
                    EnsureCrmEntityFolderExists();
                    simpleFlowStructure = new SimpleFlowStructure();
                    simpleFlowStructure.DataTypeNameSpace = GetCrmEntityNamespace();
                    simpleFlowStructure.EntityFolderID    = GetCrmEntityFolderId();
                    simpleFlowStructure.StorageOption     = StorageOption.NotDatabaseStored;
                    simpleFlowStructure.SuperClass        = null;
                    simpleFlowStructure.TemplateForType   = @"DecisionsFramework.Utilities.CodeGeneration.Templates.StringMappedDataStructure.vm";
                }
                simpleFlowStructure.DataTypeName = CRMEntityName;

                AddOrUpdateCRMEntityWithDataStructure(serviceProxy, CRMEntityName, simpleFlowStructure);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }
Exemple #2
0
        private void RegenerateDataStructureOfSelectedEntity(AbstractUserContext userContext, string entityId)
        {
            try
            {
                ORM <CRM2011Entity> crmEntityORM = new ORM <CRM2011Entity>();
                CRM2011Entity       crmEntity    = crmEntityORM.Fetch(entityId);
                if (crmEntity != null)
                {
                    log.Info(string.Format("started regenerating data structure of {0} entity", crmEntity.CRMEntityName));
                    ORM <SimpleFlowStructure> simpleFlowStructureORM = new ORM <SimpleFlowStructure>();
                    SimpleFlowStructure       simpleFlowStructure    = simpleFlowStructureORM.Fetch(new WhereCondition[]
                    {
                        new FieldWhereCondition("data_type_name", QueryMatchType.Equals, crmEntity.CRMEntityName),
                        new FieldWhereCondition("data_type_name_space", QueryMatchType.Equals, crmEntity.GetCrmEntityNamespace())
                    }).FirstOrDefault();
                    if (simpleFlowStructure != null)
                    {
                        IOrganizationService serviceProxy = GetCRMClientServiceProxy();
                        if (serviceProxy == null)
                        {
                            throw new BusinessRuleException("Unable to found CRM service client proxy");
                        }

                        simpleFlowStructure.Children = null;
                        AddOrUpdateCRMEntityWithDataStructure(serviceProxy, crmEntity.CRMEntityName, simpleFlowStructure);
                        // Make sure the updated CRMEntityFields are stored:
                        crmEntityORM.Store(this, true, false);
                    }
                    log.Info(string.Format("completed regenerating data structure of {0} entity", crmEntity.CRMEntityName));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }
Exemple #3
0
        private void AddOrUpdateCRMEntityWithDataStructure(IOrganizationService serviceProxy, string crmEntityName, SimpleFlowStructure simpleFlowStructure)
        {
            RetrieveEntityResponse crmEntity = GetEntityInformationFromCRMClient(serviceProxy, crmEntityName);

            if (crmEntity != null)
            {
                log.Info("CRM entity fetched successfully from server");
                List <AttributeMetadata>         entityAttributes = crmEntity.EntityMetadata.Attributes.Where(t => t.IsValidForCreate == true).ToList();
                List <CRMEntityField>            entityFields;
                List <DefinedDataTypeDataMember> memberList;

                GetEntityFieldsFromCRMEntityAttributes(entityAttributes, crmEntityName, out entityFields, out memberList);

                simpleFlowStructure.Children = memberList.ToArray();
                CRMEntityFields = entityFields.ToArray();
                string displayName;
                if (crmEntity.EntityMetadata.DisplayName.LocalizedLabels != null && crmEntity.EntityMetadata.DisplayName.LocalizedLabels.Count > 0)
                {
                    displayName = crmEntity.EntityMetadata.DisplayName.LocalizedLabels[0].Label;
                }
                else
                {
                    displayName = crmEntity.EntityMetadata.LogicalName;
                }
                CRMEntityDisplayName = displayName;
                DataStructureService.Instance.AddDataStructure(UserContextHolder.GetRootUserContext(), simpleFlowStructure);
                log.Info(string.Format("Entity with name {0} added successfully to the database", crmEntityName));
            }
        }