private static int?FindDefaultValidValueId(List <XmlCustomPropertyValidValue> validValues)
        {
            if (validValues == null)
            {
                return(null);
            }

            var orderedValidValues = validValues.OrderBy(v => I18NHelper.Int32ParseInvariant(v.OrderIndex)).ToList();

            for (var i = 0; i < orderedValidValues.Count; i++)
            {
                var validValue = orderedValidValues.ElementAt(i);
                if (validValue?.Selected == "1")
                {
                    int?vvId = null;
                    if (!string.IsNullOrWhiteSpace(validValue.LookupListItemId))
                    {
                        int intValue;
                        if (int.TryParse(validValue.LookupListItemId, out intValue))
                        {
                            vvId = intValue;
                        }
                    }
                    return(vvId);
                }
            }

            return(null);
        }
        public static PropertyType ConvertToPropertyType(this SqlProjectMetaRepository.PropertyTypeVersion pv)
        {
            // Property XmlInfo is not supposed to be null, see bug 4819
            var propertyFromXml = pv.PrimitiveType == PropertyPrimitiveType.Choice
                ? XmlModelSerializer.DeserializeCustomProperties(pv.XmlInfo).CustomProperties[0]
                : null;

            return(new PropertyType
            {
                Id = pv.PropertyTypeId,
                Name = pv.Name,
                VersionId = pv.VersionId,
                InstancePropertyTypeId = pv.InstancePropertyTypeId,
                PrimitiveType = pv.PrimitiveType,
                IsRichText = pv.PrimitiveType == PropertyPrimitiveType.Text ? pv.RichText : null,
                IsRequired = pv.Required,
                IsValidated = pv.PrimitiveType == PropertyPrimitiveType.Number ||
                              pv.PrimitiveType == PropertyPrimitiveType.Date ||
                              pv.PrimitiveType == PropertyPrimitiveType.Choice
                                    ? pv.Validate : null,
                IsMultipleAllowed = pv.PrimitiveType == PropertyPrimitiveType.Text ||
                                    pv.PrimitiveType == PropertyPrimitiveType.Choice
                                    ? pv.AllowMultiple : null,
                StringDefaultValue = pv.PrimitiveType == PropertyPrimitiveType.Text ? pv.StringDefaultValue : null,
                DateDefaultValue = pv.PrimitiveType == PropertyPrimitiveType.Date ? pv.DateDefaultValue : null,
                DecimalDefaultValue = pv.PrimitiveType == PropertyPrimitiveType.Number
                                      ? PropertyHelper.ToDecimal(pv.DecimalDefaultValue) : null,
                UserGroupDefaultValue = pv.PrimitiveType == PropertyPrimitiveType.User
                                      ? PropertyHelper.ParseUserGroups(pv.UserDefaultValue) : null,
                MinDate = pv.PrimitiveType == PropertyPrimitiveType.Date && pv.Validate.GetValueOrDefault() ? pv.MinDate : null,
                MaxDate = pv.PrimitiveType == PropertyPrimitiveType.Date && pv.Validate.GetValueOrDefault() ? pv.MaxDate : null,
                MinNumber = pv.PrimitiveType == PropertyPrimitiveType.Number && pv.Validate.GetValueOrDefault()
                                      ? PropertyHelper.ToDecimal(pv.MinNumber) : null,
                MaxNumber = pv.PrimitiveType == PropertyPrimitiveType.Number && pv.Validate.GetValueOrDefault()
                                      ? PropertyHelper.ToDecimal(pv.MaxNumber) : null,
                DecimalPlaces = pv.PrimitiveType == PropertyPrimitiveType.Number ? pv.DecimalPlaces : null,
                ValidValues = pv.PrimitiveType == PropertyPrimitiveType.Choice
                                      ? propertyFromXml?.ValidValues.OrderBy(v => I18NHelper.Int32ParseInvariant(v.OrderIndex))
                              .Select(v =>
                {
                    int?vvId = null;
                    if (!string.IsNullOrWhiteSpace(v.LookupListItemId))
                    {
                        int intValue;
                        if (int.TryParse(v.LookupListItemId, out intValue))
                        {
                            vvId = intValue;
                        }
                    }
                    return new ValidValue {
                        Id = vvId, Value = v.Value
                    };
                }).ToList()
                                      : null,
                DefaultValidValueId = pv.PrimitiveType == PropertyPrimitiveType.Choice
                                      ? FindDefaultValidValueId(propertyFromXml.ValidValues) // TODO
                                      : null,
            });
        }
        private Dictionary <int, List <WorkflowPropertyType> > ToItemTypePropertyTypesDictionary(IEnumerable <SqlPropertyType> sqlPropertyTypes)
        {
            var dictionary = new Dictionary <int, List <WorkflowPropertyType> >();

            foreach (var sqlPropertyType in sqlPropertyTypes)
            {
                WorkflowPropertyType workflowProperty;
                switch (sqlPropertyType.PrimitiveType)
                {
                case PropertyPrimitiveType.Text:
                {
                    workflowProperty = new TextPropertyType
                    {
                        AllowMultiple          = sqlPropertyType.AllowMultiple,
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = GetInstancePropertyTypeId(sqlPropertyType.InstancePropertyTypeId, sqlPropertyType.Predefined),
                        Name               = sqlPropertyType.Name,
                        PropertyTypeId     = sqlPropertyType.PropertyTypeId,
                        PrimitiveType      = sqlPropertyType.PrimitiveType,
                        IsRequired         = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        StringDefaultValue = sqlPropertyType.StringDefaultValue,
                        VersionId          = sqlPropertyType.VersionId,
                        Predefined         = sqlPropertyType.Predefined,

                        DefaultValue = sqlPropertyType.StringDefaultValue,
                        IsValidate   = sqlPropertyType.Validate.GetValueOrDefault(false),
                        IsRichText   = sqlPropertyType.IsRichText
                    };
                    break;
                }

                case PropertyPrimitiveType.Number:
                {
                    workflowProperty = new NumberPropertyType
                    {
                        AllowMultiple          = sqlPropertyType.AllowMultiple,
                        DefaultValue           = PropertyHelper.ToDecimal((byte[])sqlPropertyType.DecimalDefaultValue),
                        DecimalPlaces          = sqlPropertyType.DecimalPlaces.GetValueOrDefault(0),
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        Name           = sqlPropertyType.Name,
                        PropertyTypeId = sqlPropertyType.PropertyTypeId,
                        Range          = new Range <decimal>
                        {
                            End   = PropertyHelper.ToDecimal((byte[])sqlPropertyType.NumberRange_End).GetValueOrDefault(0),
                            Start = PropertyHelper.ToDecimal((byte[])sqlPropertyType.NumberRange_Start).GetValueOrDefault(0)
                        },
                        PrimitiveType = sqlPropertyType.PrimitiveType,
                        IsRequired    = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        IsValidate    = sqlPropertyType.Validate.GetValueOrDefault(false),
                        VersionId     = sqlPropertyType.VersionId,
                        Predefined    = sqlPropertyType.Predefined
                    };
                    break;
                }

                case PropertyPrimitiveType.Date:
                {
                    workflowProperty = new DatePropertyType
                    {
                        AllowMultiple          = sqlPropertyType.AllowMultiple,
                        DefaultValue           = sqlPropertyType.DateDefaultValue,
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        Name           = sqlPropertyType.Name,
                        PropertyTypeId = sqlPropertyType.PropertyTypeId,
                        Range          = new Range <DateTime?>
                        {
                            End   = sqlPropertyType.DateRange_End,
                            Start = sqlPropertyType.DateRange_Start
                        },
                        PrimitiveType = sqlPropertyType.PrimitiveType,
                        IsRequired    = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        IsValidate    = sqlPropertyType.Validate.GetValueOrDefault(false),
                        VersionId     = sqlPropertyType.VersionId,
                        Predefined    = sqlPropertyType.Predefined
                    };
                    break;
                }

                case PropertyPrimitiveType.User:
                    workflowProperty = new UserPropertyType()
                    {
                        DefaultLabels          = sqlPropertyType.UserDefaultLabel,
                        DefaultValues          = sqlPropertyType.UserDefaultValue,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        Name           = sqlPropertyType.Name,
                        PropertyTypeId = sqlPropertyType.PropertyTypeId,
                        PrimitiveType  = sqlPropertyType.PrimitiveType,
                        IsRequired     = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        VersionId      = sqlPropertyType.VersionId,
                        Predefined     = sqlPropertyType.Predefined
                    };
                    break;

                case PropertyPrimitiveType.Choice:
                {
                    workflowProperty = new ChoicePropertyType
                    {
                        AllowMultiple = sqlPropertyType.AllowMultiple,
                        // DefaultValue = PropertyHelper.ToDecimal((byte[])sqlPropertyType.DecimalDefaultValue),
                        ValidValues = XmlModelSerializer.DeserializeCustomProperties(sqlPropertyType.CustomProperty).CustomProperties[0]?.ValidValues
                                      .OrderBy(v => I18NHelper.Int32ParseInvariant(v.OrderIndex))
                                      .Select(v =>
                            {
                                int?vvId = null;
                                if (!string.IsNullOrWhiteSpace(v.LookupListItemId))
                                {
                                    int intValue;
                                    if (int.TryParse(v.LookupListItemId, out intValue))
                                    {
                                        vvId = intValue;
                                    }
                                }
                                int?vvSid = null;
                                if (!string.IsNullOrWhiteSpace(v.StandardLookupListItemId))
                                {
                                    int intValue;
                                    if (int.TryParse(v.StandardLookupListItemId, out intValue))
                                    {
                                        vvSid = intValue;
                                    }
                                }
                                return(new ValidValue {
                                    Id = vvId, Value = v.Value, Sid = vvSid
                                });
                            }).ToList(),
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        Name           = sqlPropertyType.Name,
                        PropertyTypeId = sqlPropertyType.PropertyTypeId,
                        PrimitiveType  = sqlPropertyType.PrimitiveType,
                        IsRequired     = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        IsValidate     = sqlPropertyType.Validate.GetValueOrDefault(false),
                        VersionId      = sqlPropertyType.VersionId,
                        Predefined     = sqlPropertyType.Predefined
                    };
                    break;
                }

                // TODO: add other DPropertyTypes
                default:
                {
                    workflowProperty = new WorkflowPropertyType
                    {
                        AllowMultiple          = sqlPropertyType.AllowMultiple,
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        IsRichText             = sqlPropertyType.IsRichText,
                        Name               = sqlPropertyType.Name,
                        PropertyTypeId     = sqlPropertyType.PropertyTypeId,
                        PrimitiveType      = sqlPropertyType.PrimitiveType,
                        IsRequired         = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        StringDefaultValue = sqlPropertyType.StringDefaultValue,
                        VersionId          = sqlPropertyType.VersionId,
                        Predefined         = sqlPropertyType.Predefined
                    };
                    break;
                }
                }

                if (dictionary.ContainsKey(sqlPropertyType.ItemTypeId))
                {
                    dictionary[sqlPropertyType.ItemTypeId].Add(workflowProperty);
                }
                else
                {
                    dictionary.Add(sqlPropertyType.ItemTypeId, new List <WorkflowPropertyType> {
                        workflowProperty
                    });
                }
            }
            return(dictionary);
        }
Example #4
0
 public static int ConfigValue(string configValue, int defaultValue)
 {
     return(ConfigurationManager.AppSettings[configValue] != null ? I18NHelper.Int32ParseInvariant(ConfigurationManager.AppSettings[configValue]) : defaultValue);
 }
Example #5
0
        private static int GetConfigValue(string configKey, int defaultValue)
        {
            string configValue = ConfigurationManager.AppSettings[configKey];

            return(configValue != null?I18NHelper.Int32ParseInvariant(configValue) : defaultValue);
        }