Beispiel #1
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="data">The data.</param>
        public override void SetValue(string value, params string[] data)
        {
            if (this.Adaptee is StateProperty)
            {
                ((StateProperty)this.Adaptee).Value = value;
                return;
            }

            if (this.Adaptee is StringProperty)
            {
                ((StringProperty)this.Adaptee).Value = value;
                return;
            }

            if (this.Adaptee is UniqueIdentifierProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var identifier = new UniqueIdentifier {
                        Value = idValue.Guid
                    };
                    ((UniqueIdentifierProperty)this.Adaptee).Value = identifier;
                }

                return;
            }

            if (this.Adaptee is StatusProperty)
            {
                int intValue;
                if (int.TryParse(value, out intValue))
                {
                    var status = new Status {
                        Value = intValue
                    };
                    ((StatusProperty)this.Adaptee).Value = status;
                }

                return;
            }

            if (this.Adaptee is PicklistProperty)
            {
                string   picklistValue = value;
                Picklist list          = null;
                int      intValue;

                if (!string.IsNullOrEmpty(picklistValue) && int.TryParse(picklistValue, out intValue))
                {
                    list = new Picklist {
                        Value = intValue
                    };
                }
                else
                {
                    picklistValue = null;
                }

                if (string.IsNullOrEmpty(picklistValue))
                {
                    list = new Picklist
                    {
                        IsNull          = true,
                        IsNullSpecified = true
                    };
                }

                ((PicklistProperty)this.Adaptee).Value = list;
                return;
            }

            if (this.Adaptee is OwnerProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var owner = new Owner {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((OwnerProperty)this.Adaptee).Value = owner;
                }

                return;
            }

            if (this.Adaptee is LookupProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var lookup = new Lookup {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((LookupProperty)this.Adaptee).Value = lookup;
                }

                return;
            }

            if (this.Adaptee is KeyProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var key = new Key {
                        Value = idValue.Guid
                    };
                    ((KeyProperty)this.Adaptee).Value = key;
                }

                return;
            }

            if (this.Adaptee is EntityNameReferenceProperty)
            {
                var reference = new EntityNameReference {
                    Value = value
                };
                ((EntityNameReferenceProperty)this.Adaptee).Value = reference;
                return;
            }

            if (this.Adaptee is DynamicEntityArrayProperty)
            {
                var dynamycProperty = (DynamicEntityArrayProperty)this.Adaptee;

                dynamycProperty.Value = new[]
                {
                    new DynamicEntity
                    {
                        Name       = "activityparty",
                        Properties = new[]
                        {
                            new LookupProperty
                            {
                                Name  = "partyid",
                                Value = new Lookup
                                {
                                    Value = new Guid(value),
                                    type  = data[0]
                                }
                            }
                        }
                    }
                };
            }

            if (this.Adaptee is CustomerProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var customer = new Customer {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((CustomerProperty)this.Adaptee).Value = customer;
                }

                return;
            }

            if (this.Adaptee is CrmNumberProperty)
            {
                int intValue;
                if (int.TryParse(value, out intValue))
                {
                    var number = new CrmNumber {
                        Value = intValue
                    };
                    ((CrmNumberProperty)this.Adaptee).Value = number;
                }

                return;
            }

            if (this.Adaptee is CrmMoneyProperty)
            {
                decimal decimalValue;
                if (decimal.TryParse(value, out decimalValue))
                {
                    var money = new CrmMoney {
                        Value = decimalValue
                    };
                    ((CrmMoneyProperty)this.Adaptee).Value = money;
                }

                return;
            }

            if (this.Adaptee is CrmFloatProperty)
            {
                float decimalValue;
                if (float.TryParse(value, out decimalValue))
                {
                    var crmFloat = new CrmFloat {
                        Value = decimalValue
                    };
                    ((CrmFloatProperty)this.Adaptee).Value = crmFloat;
                }

                return;
            }

            if (this.Adaptee is CrmDecimalProperty)
            {
                decimal decimalValue;
                if (decimal.TryParse(value, out decimalValue))
                {
                    var crmDecimal = new CrmDecimal {
                        Value = decimalValue
                    };
                    ((CrmDecimalProperty)this.Adaptee).Value = crmDecimal;
                }

                return;
            }

            if (this.Adaptee is CrmDateTimeProperty)
            {
                DateTime parsedValue;
                if (value.TryParseDateTime(out parsedValue))
                {
                    ((CrmDateTimeProperty)this.Adaptee).Value = new CrmDateTime {
                        Value = parsedValue.ToCrmDateTimeString()
                    };
                }
            }

            if (this.Adaptee is CrmBooleanProperty)
            {
                var boolValue = MainUtil.GetBool(value, false);
                var crmBool   = new CrmBoolean {
                    Value = boolValue
                };
                ((CrmBooleanProperty)this.Adaptee).Value = crmBool;
            }
        }
        public virtual void SetPropertyValue(Property property, string value, params string[] data)
        {
            Assert.ArgumentNotNull(property, "property");

            if (property is StateProperty)
            {
                ((StateProperty)property).Value = value;
                return;
            }

            if (property is StringProperty)
            {
                ((StringProperty)property).Value = value;
                return;
            }

            if (property is UniqueIdentifierProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var identifier = new UniqueIdentifier {
                        Value = idValue.Guid
                    };
                    ((UniqueIdentifierProperty)property).Value = identifier;
                }
                return;
            }

            if (property is StatusProperty)
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    var status = new Status {
                        Value = intValue
                    };
                    ((StatusProperty)property).Value = status;
                }

                return;
            }

            if (property is PicklistProperty)
            {
                string   picklistValue = value;
                Picklist list          = null;
                int      intValue      = 0;

                if (!string.IsNullOrEmpty(picklistValue) && int.TryParse(picklistValue, out intValue))
                {
                    list = new Picklist {
                        Value = intValue
                    };
                }
                else
                {
                    picklistValue = null;
                }

                if (string.IsNullOrEmpty(picklistValue))
                {
                    list = new Picklist
                    {
                        IsNull          = true,
                        IsNullSpecified = true
                    };
                }

                ((PicklistProperty)property).Value = list;
                return;
            }

            if (property is OwnerProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var owner = new Owner {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((OwnerProperty)property).Value = owner;
                }
                return;
            }

            if (property is LookupProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var lookup = new Lookup {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((LookupProperty)property).Value = lookup;
                }
                return;
            }

            if (property is KeyProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var key = new CrmCampaignIntegration.Services.Key {
                        Value = idValue.Guid
                    };
                    ((KeyProperty)property).Value = key;
                }
                return;
            }

            if (property is EntityNameReferenceProperty)
            {
                var reference = new EntityNameReference {
                    Value = value
                };
                ((EntityNameReferenceProperty)property).Value = reference;
                return;
            }

            if (property is DynamicEntityArrayProperty)
            {
                var dynamycProperty = (DynamicEntityArrayProperty)property;

                dynamycProperty.Value = new[]
                {
                    new DynamicEntity {
                        Name       = "activityparty",
                        Properties = new []
                        {
                            new LookupProperty
                            {
                                Name  = "partyid",
                                Value = new Lookup
                                {
                                    Value = new Guid(value),
                                    type  = data[0]
                                }
                            }
                        }
                    }
                };
            }

            if (property is CustomerProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var customer = new Customer {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((CustomerProperty)property).Value = customer;
                }
                return;
            }

            if (property is CrmNumberProperty)
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    var number = new CrmCampaignIntegration.Services.CrmNumber {
                        Value = intValue
                    };
                    ((CrmNumberProperty)property).Value = number;
                }
                return;
            }

            if (property is CrmMoneyProperty)
            {
                decimal decimalValue = 0;
                if (decimal.TryParse(value, out decimalValue))
                {
                    var money = new CrmMoney {
                        Value = decimalValue
                    };
                    ((CrmMoneyProperty)property).Value = money;
                }
                return;
            }

            if (property is CrmFloatProperty)
            {
                float decimalValue = 0;
                if (float.TryParse(value, out decimalValue))
                {
                    var crmFloat = new CrmCampaignIntegration.Services.CrmFloat {
                        Value = decimalValue
                    };
                    ((CrmFloatProperty)property).Value = crmFloat;
                }
                return;
            }

            if (property is CrmDecimalProperty)
            {
                decimal decimalValue = 0;
                if (decimal.TryParse(value, out decimalValue))
                {
                    var crmDecimal = new CrmDecimal {
                        Value = decimalValue
                    };
                    ((CrmDecimalProperty)property).Value = crmDecimal;
                }
                return;
            }

            if (property is CrmDateTimeProperty)
            {
                var dateTime = Sitecore.CrmCampaignIntegrations.Core.Utility.DateUtil.ToCrmDateTime(value);
                if (dateTime != null)
                {
                    var crmDateTime = new CrmCampaignIntegration.Services.CrmDateTime {
                        Value = dateTime.Value
                    };
                    ((CrmDateTimeProperty)property).Value = crmDateTime;
                }
            }

            if (property is CrmBooleanProperty)
            {
                var boolValue = MainUtil.GetBool(value, false);
                var crmBool   = new CrmCampaignIntegration.Services.CrmBoolean {
                    Value = boolValue
                };
                ((CrmBooleanProperty)property).Value = crmBool;
                return;
            }
        }