Beispiel #1
0
        public void AddStep(ICrmEntity plugin, CrmPluginStep step)
        {
            if (step == null)
            {
                throw new ArgumentNullException("step");
            }

            if (plugin == null)
            {
                throw new ArgumentNullException("plugin");
            }

            if (plugin is CrmPlugin crmPlugin)
            {
                if (!crmPlugin.Steps.ContainsKey(step.StepId))
                {
                    crmPlugin.AddStep(step);
                    return;
                }
            }

            //if (plugin is CrmServiceEndpoint crmServiceEndpoint)
            //{
            //    if (!crmServiceEndpoint.Steps.ContainsKey(step.StepId))
            //    {
            //        crmServiceEndpoint.AddStep(step);
            //        return;
            //    }
            //}

            ValidateEntity(step);

            m_stepList.Add(step.StepId, step);
        }
        /// <summary>
        /// Sets the properties of the entity.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <param name="fields">
        /// The fields.
        /// </param>
        protected virtual void SetProperties(ICrmEntity entity, AdaptedResultList fields)
        {
            if (entity != null && fields != null)
            {
                foreach (XCrmField field in this.EntitySettings.Fields)
                {
                    string value = this.GetValue(field, fields);
                    if (value == null)
                    {
                        Log.Warn(
                            "'Create crm {0}' action: the {1} field requires some more settings defined.".FormatWith(
                                this.EntitySettings.EntityName, field.Name),
                            this);
                        continue;
                    }

                    string previouse     = this.GetPropertyValue(entity, field.Name);
                    bool   allowedToEdit = fields.IsTrueStatement(field.EditMode);
                    if (allowedToEdit)
                    {
                        if (this.EntitySettings.OverwriteNotEmptyField || string.IsNullOrEmpty(previouse))
                        {
                            this.SetProperty(
                                field.Name,
                                field.AttributeType,
                                value,
                                entity,
                                field.EntityReference,
                                this.EntitySettings.EntityName,
                                this.EntitySettings.PrimaryKey);
                        }
                    }

                    if (string.Compare(value, previouse, true) != 0 || this.isCreated)
                    {
                        bool isUpdated = allowedToEdit &&
                                         (this.EntitySettings.OverwriteNotEmptyField || string.IsNullOrEmpty(previouse));
                        if (isUpdated)
                        {
                            this.AuditUpdatedField(this.GetValueSource(field, fields), field.Name, value);
                        }
                        else
                        {
                            this.AuditSkippedField(this.GetValueSource(field, fields), field.Name, value);
                        }
                    }
                }

                if (this.IsAuditEnabled)
                {
                    string audit = this.DumpAuditInfomration(this.GetPropertyValue(entity, this.EntitySettings.Audit));
                    if (!string.IsNullOrEmpty(audit))
                    {
                        this.SetProperty(this.EntitySettings.Audit, this.EntitySettings.AuditAttributeType, audit, entity);
                    }
                }
            }
        }
        /// <summary>
        /// Sets the system CRM properties.
        /// </summary>
        /// <param name="guid">
        /// The GUID.
        /// </param>
        /// <param name="entity">
        /// The entity.
        /// </param>
        protected void SetSystemCrmProperties(Guid guid, ICrmEntity entity)
        {
            Assert.ArgumentNotNull(entity, "entity");

            if (this.systemProperties.Count > 0 && (!this.CanBeOverwritten || this.EntitySettings.OverwriteNotEmptyField))
            {
                var args = new SetSystemCrmPropertyArgs(entity, this.systemProperties, guid);
                //CorePipeline.Run("setSystemCrmProperty", args);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SetCustomCrmPropertyArgs"/> class.
        /// </summary>
        /// <param name="formId">
        /// The form id.
        /// </param>
        /// <param name="fields">
        /// The fields.
        /// </param>
        /// <param name="entity">
        /// The entity.
        /// </param>
        public SetCustomCrmPropertyArgs(ID formId, AdaptedResultList fields, ICrmEntity entity)
        {
            Assert.ArgumentNotNull(formId, "formId");
            Assert.ArgumentNotNull(fields, "fields");
            Assert.ArgumentNotNull(entity, "entity");

            this.FormID    = formId;
            this.Fields    = fields;
            this.CrmEntity = entity;
        }
        public SetSystemCrmPropertyArgs(ICrmEntity entity, IEnumerable <ICrmAttribute> systemProperties, Guid entityID)
        {
            Assert.ArgumentNotNull(entity, "entity");
            Assert.ArgumentNotNullOrEmpty(entity.LogicalName, "entity.LogicalName");
            Assert.ArgumentNotNull(systemProperties, "systemProperties");
            Assert.ArgumentNotNull(entityID, "entityID");

            Entity           = entity;
            SystemProperties = systemProperties;
            EntityId         = entityID;
        }
        protected void SetCustomCrmProperties(ID formId, AdaptedResultList fields, ICrmEntity entity)
        {
            Assert.ArgumentNotNull(formId, "guid");
            Assert.ArgumentNotNull(entity, "entity");
            var args = new SetCustomCrmPropertyArgs(formId, fields, entity)
            {
                CanBeOverwritten       = this.CanBeOverwritten,
                OverwriteNotEmptyField = this.EntitySettings != null ? this.EntitySettings.OverwriteNotEmptyField : false
            };

            CorePipeline.Run("setCustomCrmProperty", args);
        }
        protected string GetPropertyValue(ICrmEntity entry, string name)
        {
            if (!string.IsNullOrEmpty(name) && entry != null)
            {
                var property = entry.Attributes[name];
                if (property != null)
                {
                    return(property.GetStringifiedValue());
                }
            }

            return(string.Empty);
        }
Beispiel #8
0
        public override void Update(ICrmEntity crmEntity)
        {
            CrmEntityAdapter adapter = crmEntity as CrmEntityAdapter;

            if (adapter != null)
            {
                KeyValuePair <string, object>[] attributes = adapter.AttributeCollectionAdapter.StripSystem();
                this._organizationService.Update(adapter.Adaptee);
                adapter.AttributeCollectionAdapter.AddRange(attributes);
                if (adapter.IsStateChanged || adapter.IsStatusChanged)
                {
                    this.UpdateStateStatus(adapter.LogicalName, adapter.Id, adapter.State, adapter.Status);
                }
            }
        }
        /// <summary>
        /// Updates the specified CRM entity.
        /// </summary>
        /// <param name="crmEntity">The CRM entity.</param>
        public override void Update(ICrmEntity crmEntity)
        {
            var entityAdapter = crmEntity as CrmEntityAdapter;

            if (entityAdapter == null)
            {
                return;
            }

            this.crmService.Update(entityAdapter.Adaptee);

            if (entityAdapter.IsStateChanged || entityAdapter.IsStatusChanged)
            {
                this.UpdateStateStatus(entityAdapter.LogicalName, entityAdapter.Id, entityAdapter.State, entityAdapter.Status);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Shows the lookup.
        /// </summary>
        /// <param name="field">The field.</param>
        private void ShowLookup(XCrmField field)
        {
            this.LookupBorder.Style["display"] = "block";

            if (field.LookupValue != null)
            {
                try
                {
                    ICrmEntity entity = this.EntityRepository.GetEntity(field.EntityReference, field.LookupValue.PrimaryKey, field.CrmValue, false, null);
                    if (entity != null)
                    {
                        this.LookupValue.Value = entity.Attributes[field.LookupValue.PrimaryField].GetStringifiedValue();
                    }
                }
                catch { }
            }
        }
Beispiel #11
0
        public override Guid Insert(ICrmEntity crmEntity)
        {
            CrmEntityAdapter adapter = crmEntity as CrmEntityAdapter;

            if (adapter == null)
            {
                return(Guid.Empty);
            }
            KeyValuePair <string, object>[] attributes = adapter.AttributeCollectionAdapter.StripSystem();
            Guid id = adapter.Id = this._organizationService.Create(adapter.Adaptee);

            adapter.AttributeCollectionAdapter.AddRange(attributes);
            if (adapter.IsStateChanged || adapter.IsStatusChanged)
            {
                this.UpdateStateStatus(adapter.LogicalName, id, adapter.State, adapter.Status);
            }
            return(id);
        }
Beispiel #12
0
        /// <summary>
        /// Updates the specified CRM entity.
        /// </summary>
        /// <param name="crmEntity">The CRM entity.</param>
        public override void Update(ICrmEntity crmEntity)
        {
            var entityAdapter = crmEntity as CrmEntityAdapter;

            if (entityAdapter == null)
            {
                return;
            }

            var systemProperties = entityAdapter.AttributeCollectionAdapter.StripSystem();

            this.organizationServiceCache.GetOrganizationService().Update(entityAdapter.Adaptee);

            entityAdapter.AttributeCollectionAdapter.AddRange(systemProperties);

            if (entityAdapter.IsStateChanged || entityAdapter.IsStatusChanged)
            {
                this.UpdateStateStatus(entityAdapter.LogicalName, entityAdapter.Id, entityAdapter.State, entityAdapter.Status);
            }
        }
        /// <summary>
        /// Creates the specified CRM entity.
        /// </summary>
        /// <param name="crmEntity">The CRM entity.</param>
        public override Guid Insert(ICrmEntity crmEntity)
        {
            var entityAdapter = crmEntity as CrmEntityAdapter;

            if (entityAdapter == null)
            {
                return(Guid.Empty);
            }

            var createdEntity = this.crmService.Create(entityAdapter.Adaptee);

            entityAdapter.Id = createdEntity;

            if (entityAdapter.IsStateChanged || entityAdapter.IsStatusChanged)
            {
                this.UpdateStateStatus(entityAdapter.LogicalName, entityAdapter.Id, entityAdapter.State, entityAdapter.Status);
            }

            return(createdEntity);
        }
Beispiel #14
0
        /// <summary>
        /// Creates the specified CRM entity.
        /// </summary>
        /// <param name="crmEntity">The CRM entity.</param>
        public override Guid Insert(ICrmEntity crmEntity)
        {
            var entityAdapter = crmEntity as CrmEntityAdapter;

            if (entityAdapter == null)
            {
                return(Guid.Empty);
            }

            var systemProperties = entityAdapter.AttributeCollectionAdapter.StripSystem();

            var createdEntity = entityAdapter.Id = this.organizationServiceCache.GetOrganizationService().Create(entityAdapter.Adaptee);

            entityAdapter.AttributeCollectionAdapter.AddRange(systemProperties);

            if (entityAdapter.IsStateChanged || entityAdapter.IsStatusChanged)
            {
                this.UpdateStateStatus(entityAdapter.LogicalName, createdEntity, entityAdapter.State, entityAdapter.Status);
            }

            return(createdEntity);
        }
Beispiel #15
0
        public static void SetProperty(this ICrmEntity entity, string name, CrmAttributeType attributeType, string value, params string[] data)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (value == null)
            {
                Log.Warn("'Create crm {0}' action: the {1} crm field cannot contain the null value.".FormatWith(entity.LogicalName, name), entity);
            }

            var crmAttribute = entity.Attributes[name];

            if (crmAttribute != null)
            {
                crmAttribute.SetValue(value, data);
            }
            else
            {
                entity.Attributes.Create(name, attributeType, value, data);
            }
        }
Beispiel #16
0
 /// <summary>
 /// Updates the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 public virtual void Update(ICrmEntity entity)
 {
     Assert.ArgumentNotNull(entity, "entity");
     this.EntityRepository.Update(entity);
 }
Beispiel #17
0
 /// <summary>
 /// Creates the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns></returns>
 public virtual Guid Create(ICrmEntity entity)
 {
     Assert.ArgumentNotNull(entity, "entity");
     return(this.EntityRepository.Insert(entity));
 }
Beispiel #18
0
 /// <summary>
 /// Updates the specified CRM entity.
 /// </summary>
 /// <param name="crmEntity">The CRM entity.</param>
 public abstract void Update(ICrmEntity crmEntity);
Beispiel #19
0
 /// <summary>
 /// Creates the specified CRM entity.
 /// </summary>
 /// <param name="crmEntity">The CRM entity.</param>
 /// <returns>Inserted entity key</returns>
 public abstract Guid Insert(ICrmEntity crmEntity);
        /// <summary>
        /// Sets the property of the entity.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="propertyType">
        /// The property Type.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        protected void SetProperty(
            string name, CRMSecurityProvider.Sources.Attribute.CrmAttributeType propertyType, string value, ICrmEntity entity, params string[] data)
        {
            Assert.ArgumentNotNull(entity, "entity");

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (value == null)
            {
                string entityName = this.EntitySettings != null ? this.EntitySettings.EntityName : string.Empty;
                Log.Warn("'Create crm {0}' action: the {1} crm field cannot contain the null value.".FormatWith(entityName, name), this);
            }

            var property = entity.Attributes[name];

            if (property != null)
            {
                property.SetValue(value, data);

                //        if (this.IsSystemProperty(name))
                //        {
                //          var arr=entity.Attributes.ToArray();
                //          List<ICrmAttribute> list = (entity.Attributes  ?? new Property[] { }).ToList();
                //          list.RemoveAll(p => p.Name == name);
                //          entity.Properties = list.ToArray();
                //          this.systemProperties.Add(property);
                //        }
            }
            else
            {
                entity.Attributes.Create(name, propertyType, value, data);

                //        Property newProperty = PropertyFactory.Instance.CreateProperty(name, propertyType, value, data);
                //        newProperty.Name = name;
                //        if (!this.IsSystemProperty(name) || this.IsChangeStatusWithoutState(name))
                //        {
                //          entity.Properties = (entity.Properties ?? new Property[] { }).Union(new[] { newProperty }).ToArray();
                //        }
                //        else
                //        {
                //          this.systemProperties.Add(newProperty);
                //        }
            }
        }
        public override void Execute(ID formId, AdaptedResultList adaptedFields, ActionCallContext actionCallContext = null, params object[] data)
        {
            Assert.ArgumentNotNull(formId, "formId");
            Assert.ArgumentNotNull(adaptedFields, "fields");

            this.Result = adaptedFields;

            this.formId = formId;
            Guid undoEntityCreation = Guid.Empty;

            try
            {
                if (this.EntitySettings != null && (this.PrimaryField != null || !this.CanBeOverwritten))
                {
                    ICrmEntity entity = null;

                    if (this.CanBeOverwritten)
                    {
                        string keyValue = this.GetValue(this.PrimaryField, adaptedFields);

                        if (string.IsNullOrEmpty(keyValue))
                        {
                            throw new ArgumentException(this.KeyFieldUndefinedMessage);
                        }

                        entity = this.Get(this.EntityName, this.EntitySettings.PrimaryFieldName, keyValue, this.EntitySettings.SupportStateCode, this.GetColumns());
                    }

                    Guid entityId;
                    if (entity == null)
                    {
                        entity         = this.EntityRepository.NewEntity(this.EntityName);
                        this.isCreated = true;
                        this.InitEntityState(entity);
                        this.SetProperties(entity, adaptedFields);
                        this.SetCustomCrmProperties(this.formId, adaptedFields, entity);

                        undoEntityCreation = this.Create(entity);
                        entityId           = undoEntityCreation;

                        actionCallContext.Parameters.Add(this.UniqueKey, new FormsCrmEntity {
                            Name = this.EntitySettings.EntityName, ID = entityId
                        });

                        if (Guid.Empty == undoEntityCreation)
                        {
                            throw new InvalidOperationException(this.CannotBeCreatedMessage);
                        }
                        return;
                    }

                    entityId = new Guid(this.GetPropertyValue(entity, this.EntitySettings.PrimaryKey));

                    this.SetProperties(entity, adaptedFields);
                    this.SetCustomCrmProperties(this.formId, adaptedFields, entity);
                    this.Update(entity);

                    actionCallContext.Parameters.Add(this.UniqueKey, new FormsCrmEntity {
                        Name = this.EntitySettings.EntityName, ID = entityId
                    });
                }
                else
                {
                    Log.Warn(
                        "'The Create CRM {0}' action is not customized.".FormatWith(
                            this.EntitySettings != null ? this.EntitySettings.EntityName : "entity"),
                        this);
                }
            }
            catch (SoapException ex)
            {
                var exception = new Exception(ex.GetFormatedMessage(), ex);

                this.UndoAction(undoEntityCreation);
                throw exception;
            }
            catch (Exception)
            {
                this.UndoAction(undoEntityCreation);
                throw;
            }
        }
        /// <summary>
        /// Inits the state of the entity.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        protected void InitEntityState(ICrmEntity entity)
        {
            Assert.ArgumentNotNull(entity, "entity");

            entity.LogicalName = this.EntitySettings != null ? this.EntitySettings.EntityName : string.Empty;
        }
        /// <summary>
        /// Sets the property of the entity.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="propertyType">
        /// The property Type.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        protected void SetProperty(string name, CrmAttributeType attributeType, string value, ICrmEntity entity, params string[] data)
        {
            Assert.ArgumentNotNull(entity, "entity");

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (value == null)
            {
                string entityName = this.EntitySettings != null ? this.EntitySettings.EntityName : string.Empty;
                Log.Warn("'Create crm {0}' action: the {1} crm field cannot contain the null value.".FormatWith(entityName, name), this);
                return;
            }
            var crmAttribute = entity.Attributes[name];

            if (crmAttribute != null)
            {
                crmAttribute.SetValue(value, data);
            }
            else
            {
                entity.Attributes.Create(name, attributeType, value, data);
            }
        }