コード例 #1
0
        internal bool IsAssignableTo(StoreFieldType storeType)
        {
            switch (this.ValueType)
            {
            case DefaultValueType.DateTime:
            case DefaultValueType.DateTimeNow:
                return(storeType.IsDateTime || storeType.IsString);

            case DefaultValueType.String:
                if (!storeType.IsString)
                {
                    return(false);
                }
                return(this.Value == null || storeType.MaximumLength >= this.Value.ToString().Length);

            case DefaultValueType.RandomString:
                return(storeType.IsString && storeType.MaximumLength >= _randomStringSettings.Length);

            case DefaultValueType.Integer:
                return(storeType.IsNumeric || storeType.IsString);

            case DefaultValueType.Decimal:
                return(storeType.IsDecimal);

            case DefaultValueType.Boolean:
                return(storeType.IsBoolean || storeType.IsString);

            case DefaultValueType.Guid:
            case DefaultValueType.NewGuid:
                return(storeType.IsGuid || storeType.IsString);
            }

            throw new ArgumentException("Unknown store type");
        }
コード例 #2
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 /// <param name="id">Permanent unique id for this field. This should never change.</param>
 /// <param name="name">Name (programmatic) of field </param>
 /// <param name="storeType">Type to use when storing field</param>
 /// <param name="instanceType">Type to use when field is exposed to .NET</param>
 /// <param name="inherited">True when this field is inherited from a super interface.</param>
 public DataFieldDescriptor(Guid id, string name, StoreFieldType storeType, Type instanceType, bool inherited)
 {
     _id                       = id;
     _name                     = NameValidation.ValidateName(name);
     this.StoreType            = storeType;
     this.InstanceType         = instanceType;
     this.FormRenderingProfile = new DataFieldFormRenderingProfile();
     this.TreeOrderingProfile  = new DataFieldTreeOrderingProfile();
     this.Inherited            = inherited;
     this.IsReadOnly           = false;
 }
コード例 #3
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 /// <param name="id">Permanent unique id for this field. This should never change.</param>
 /// <param name="name">Name (programmatic) of field </param>
 /// <param name="storeType">Type to use when storing field</param>
 /// <param name="instanceType">Type to use when field is exposed to .NET</param>
 /// <param name="inherited">True when this field is inherited from a super interface.</param>
 public DataFieldDescriptor(Guid id, string name, StoreFieldType storeType, Type instanceType, bool inherited)
 {
     _id = id;
     _name = NameValidation.ValidateName(name);
     this.StoreType = storeType;
     this.InstanceType = instanceType;
     this.FormRenderingProfile = new DataFieldFormRenderingProfile();
     this.TreeOrderingProfile = new DataFieldTreeOrderingProfile();
     this.Inherited = inherited;
     this.IsReadOnly = false;
 }
コード例 #4
0
        internal static string MapStoreTypeToSqlDataType(StoreFieldType storeType)
        {
            string result = string.Format(" [{0}]", GetStoreTypeToSqlDataTypeMapping(storeType));

            switch (storeType.PhysicalStoreType)
            {
                case PhysicalStoreFieldType.String:
                    return string.Format("{0}({1})", result, storeType.MaximumLength);
                case PhysicalStoreFieldType.LargeString:
                    return string.Format("{0}({1})", result, "max");
                case PhysicalStoreFieldType.Decimal:
                    return string.Format("{0}({1},{2})", result, storeType.NumericPrecision, storeType.NumericScale);
                default:
                    return result;
            }
        }
コード例 #5
0
        /// <summary>
        /// Evaluate if one field type can safely change to another type.
        /// </summary>
        /// <param name="newStoreFieldType">New store field type</param>
        /// <returns>True is conversion is allowed.</returns>
        public bool IsConvertibleTo(StoreFieldType newStoreFieldType)
        {
            if (this.PhysicalStoreType == newStoreFieldType.PhysicalStoreType)
            {
                return(true);
            }
            if (this.IsNumeric && newStoreFieldType.IsDecimal)
            {
                return(true);
            }

            // String and LargeString are convertable to each other
            if ((PhysicalStoreType == PhysicalStoreFieldType.String && newStoreFieldType.PhysicalStoreType == PhysicalStoreFieldType.LargeString) ||
                (newStoreFieldType.PhysicalStoreType == PhysicalStoreFieldType.String && PhysicalStoreType == PhysicalStoreFieldType.LargeString))
            {
                return(true);
            }

            return(false);
        }
コード例 #6
0
 internal static SqlDbType GetStoreTypeToSqlDataTypeMapping(StoreFieldType storeType)
 {
     switch (storeType.PhysicalStoreType)
     {
         case PhysicalStoreFieldType.Integer:
             return SqlDbType.Int;
         case PhysicalStoreFieldType.Long:
             return SqlDbType.BigInt;
         case PhysicalStoreFieldType.String:
             return SqlDbType.NVarChar;
         case PhysicalStoreFieldType.LargeString:
             return SqlDbType.NVarChar;
         case PhysicalStoreFieldType.DateTime:
             return SqlDbType.DateTime;
         case PhysicalStoreFieldType.Decimal:
             return SqlDbType.Decimal;
         case PhysicalStoreFieldType.Boolean:
             return SqlDbType.Bit;
         case PhysicalStoreFieldType.Guid:
             return SqlDbType.UniqueIdentifier;
         default:
             throw new ArgumentException("Unknown store type on field");
     }
 }
コード例 #7
0
        private string GetDefaultValueText(StoreFieldType storeFieldType)
        {
            Verify.ArgumentNotNull(storeFieldType, "storeFieldType");

            switch (storeFieldType.PhysicalStoreType)
            {
                case PhysicalStoreFieldType.String:
                case PhysicalStoreFieldType.LargeString:
                    return "N''";
                case PhysicalStoreFieldType.Guid:
                    return "'00000000-0000-0000-0000-000000000000'";
                case PhysicalStoreFieldType.Integer:
                case PhysicalStoreFieldType.Long:
                case PhysicalStoreFieldType.Decimal:
                    return "0";
                case PhysicalStoreFieldType.Boolean:
                    return "0";
                case PhysicalStoreFieldType.DateTime:
                    return "getdate()";
            }

            throw new NotImplementedException("Supplied StoreFieldType contains an unsupported PhysicalStoreType '{0}'."
                                              .FormatWith(storeFieldType.PhysicalStoreType));
        }
コード例 #8
0
        /// <summary>
        /// Deserialize a <see cref="DataFieldDescriptor"/>.
        /// </summary>
        /// <param name="element">Deserialized DataFieldDescriptor</param>
        /// <returns></returns>
        public static DataFieldDescriptor FromXml(XElement element)
        {
            if (element.Name != "DataFieldDescriptor")
            {
                throw new ArgumentException("The xml is not correctly formatted");
            }

            Guid       id         = (Guid)element.GetRequiredAttribute("id");
            string     name       = element.GetRequiredAttributeValue("name");
            bool       isNullable = (bool)element.GetRequiredAttribute("isNullable");
            int        position   = (int)element.GetRequiredAttribute("position");
            bool       inherited  = (bool)element.GetRequiredAttribute("inherited");
            XAttribute groupByPriorityAttribute = element.Attribute("groupByPriority");
            XAttribute instanceTypeAttribute    = element.GetRequiredAttribute("instanceType");
            XAttribute storeTypeAttribute       = element.GetRequiredAttribute("storeType");
            XAttribute isReadOnlyAttribute      = element.Attribute("isReadOnly");
            XAttribute newInstanceDefaultFieldValueAttribute = element.Attribute("newInstanceDefaultFieldValue");


            bool isReadOnly      = isReadOnlyAttribute != null && (bool)isReadOnlyAttribute;
            int  groupByPriority = groupByPriorityAttribute != null ? (int)groupByPriorityAttribute : 0;

            XAttribute defaultValueAttribute = element.Attribute("defaultValue");
            XAttribute foreignKeyReferenceTypeNameAttribute = element.Attribute("foreignKeyReferenceTypeName");
            XElement   formRenderingProfileElement          = element.Element("FormRenderingProfile");
            XElement   treeOrderingProfileElement           = element.Element("TreeOrderingProfile");
            XElement   validationFunctionMarkupsElement     = element.Element("ValidationFunctionMarkups");
            XElement   dataUrlProfileElement = element.Element("DataUrlProfile");
            XElement   searchProfileElement  = element.Element(nameof(SearchProfile));



            Type           instanceType = TypeManager.GetType(instanceTypeAttribute.Value);
            StoreFieldType storeType    = StoreFieldType.Deserialize(storeTypeAttribute.Value);

            var dataFieldDescriptor = new DataFieldDescriptor(id, name, storeType, instanceType, inherited)
            {
                IsNullable      = isNullable,
                Position        = position,
                GroupByPriority = groupByPriority,
                IsReadOnly      = isReadOnly
            };

            if (newInstanceDefaultFieldValueAttribute != null)
            {
                dataFieldDescriptor.NewInstanceDefaultFieldValue = newInstanceDefaultFieldValueAttribute.Value;
            }

            if (defaultValueAttribute != null)
            {
                DefaultValue defaultValue = DefaultValue.Deserialize(defaultValueAttribute.Value);
                dataFieldDescriptor.DefaultValue = defaultValue;
            }

            if (foreignKeyReferenceTypeNameAttribute != null)
            {
                string typeName = foreignKeyReferenceTypeNameAttribute.Value;

                typeName = TypeManager.FixLegasyTypeName(typeName);

                dataFieldDescriptor.ForeignKeyReferenceTypeName = typeName;
            }

            if (formRenderingProfileElement != null)
            {
                XAttribute labelAttribute                = formRenderingProfileElement.Attribute("label");
                XAttribute helpTextAttribute             = formRenderingProfileElement.Attribute("helpText");
                XAttribute widgetFunctionMarkupAttribute = formRenderingProfileElement.Attribute("widgetFunctionMarkup");

                var dataFieldFormRenderingProfile = new DataFieldFormRenderingProfile();

                if (labelAttribute != null)
                {
                    dataFieldFormRenderingProfile.Label = labelAttribute.Value;
                }

                if (helpTextAttribute != null)
                {
                    dataFieldFormRenderingProfile.HelpText = helpTextAttribute.Value;
                }

                if (widgetFunctionMarkupAttribute != null)
                {
                    dataFieldFormRenderingProfile.WidgetFunctionMarkup = widgetFunctionMarkupAttribute.Value;
                }

                dataFieldDescriptor.FormRenderingProfile = dataFieldFormRenderingProfile;
            }

            if (dataUrlProfileElement != null)
            {
                int order     = (int)dataUrlProfileElement.GetRequiredAttribute("Order");
                var formatStr = (string)dataUrlProfileElement.Attribute("Format");
                DataUrlSegmentFormat?format = null;

                if (formatStr != null)
                {
                    format = (DataUrlSegmentFormat)Enum.Parse(typeof(DataUrlSegmentFormat), formatStr);
                }

                dataFieldDescriptor.DataUrlProfile = new DataUrlProfile {
                    Order = order, Format = format
                };
            }

            if (searchProfileElement != null)
            {
                Func <string, bool> getAttr = fieldName => (bool)searchProfileElement.GetRequiredAttribute(CamelCase(fieldName));

                dataFieldDescriptor.SearchProfile = new SearchProfile
                {
                    IndexText     = getAttr(nameof(DynamicTypes.SearchProfile.IndexText)),
                    EnablePreview = getAttr(nameof(DynamicTypes.SearchProfile.EnablePreview)),
                    IsFacet       = getAttr(nameof(DynamicTypes.SearchProfile.IsFacet))
                };
            }

            if (treeOrderingProfileElement != null)
            {
                int? orderPriority   = (int?)treeOrderingProfileElement.Attribute("orderPriority");
                bool orderDescending = (bool)treeOrderingProfileElement.Attribute("orderDescending");

                dataFieldDescriptor.TreeOrderingProfile = new DataFieldTreeOrderingProfile
                {
                    OrderPriority   = orderPriority,
                    OrderDescending = orderDescending
                };
            }

            dataFieldDescriptor.ValidationFunctionMarkup = new List <string>();
            if (validationFunctionMarkupsElement != null)
            {
                foreach (XElement validationFunctionMarkupElement in validationFunctionMarkupsElement.Elements("ValidationFunctionMarkup"))
                {
                    string markup = validationFunctionMarkupElement.GetRequiredAttributeValue("markup");

                    dataFieldDescriptor.ValidationFunctionMarkup.Add(markup);
                }
            }

            return(dataFieldDescriptor);
        }
コード例 #9
0
ファイル: StoreFieldType.cs プロジェクト: DBailey635/C1-CMS
        /// <summary>
        /// Evaluate if one field type can safely change to another type.
        /// </summary>
        /// <param name="newStoreFieldType">New store field type</param>
        /// <returns>True is conversion is allowed.</returns>
        public bool IsConvertibleTo(StoreFieldType newStoreFieldType)
        {
            if (this.PhysicalStoreType == newStoreFieldType.PhysicalStoreType) return true;
            if (this.IsNumeric && newStoreFieldType.IsDecimal) return true;

            // String and LargeString are convertable to each other
            if ((PhysicalStoreType == PhysicalStoreFieldType.String && newStoreFieldType.PhysicalStoreType == PhysicalStoreFieldType.LargeString)
                || (newStoreFieldType.PhysicalStoreType == PhysicalStoreFieldType.String && PhysicalStoreType == PhysicalStoreFieldType.LargeString))
            {
                return true;
            }

            return false;
        }
コード例 #10
0
ファイル: DefaultValue.cs プロジェクト: DBailey635/C1-CMS
        internal bool IsAssignableTo(StoreFieldType storeType)
        {
            switch (this.ValueType)
            {
                case DefaultValueType.DateTime:
                case DefaultValueType.DateTimeNow:
                    return storeType.IsDateTime || storeType.IsString;
                case DefaultValueType.String:
                    if (!storeType.IsString) return false;
                    return this.Value == null || storeType.MaximumLength >= this.Value.ToString().Length;
                case DefaultValueType.RandomString:
                    return storeType.IsString && storeType.MaximumLength >= _randomStringSettings.Length;
                case DefaultValueType.Integer:
                    return storeType.IsNumeric || storeType.IsString;
                case DefaultValueType.Decimal:
                    return storeType.IsDecimal;
                case DefaultValueType.Boolean:
                    return storeType.IsBoolean || storeType.IsString;
                case DefaultValueType.Guid:
                case DefaultValueType.NewGuid:
                    return storeType.IsGuid || storeType.IsString;
            }

            throw new ArgumentException("Unknown store type");
        }