/// <summary>
        /// 转换辅助类。 mapping暂未使用
        /// </summary>
        /// <param name="type"></param>
        /// <param name="dataAdapter"></param>
        /// <param name="mapping"></param>
        /// <returns></returns>
        private static object ConvertDataToObject(Type type, BeeDataAdapter dataAdapter, Dictionary <string, string> mapping)
        {
            ThrowExceptionUtil.ArgumentNotNull(type, "type");
            ThrowExceptionUtil.ArgumentNotNull(dataAdapter, "dataAdapter");

            object result = ReflectionUtil.CreateInstance(type);

            if (result != null)
            {
                IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(type);

                foreach (string key in dataAdapter.Keys)
                {
                    string value = dataAdapter[key] as string;
                    if (value != null && value.Length == 0)
                    {
                        /// 空字符串并且目标类型不是字符型则不转换
                        PropertySchema schema = entityProxy[key];
                        if (schema != null && schema.PropertyType != typeof(string))
                        {
                            continue;
                        }
                    }

                    entityProxy.SetPropertyValue(result, key, dataAdapter[key]);
                }
            }

            return(result);
        }
Exemple #2
0
 /// <summary>
 /// An internal scalar field.
 /// </summary>
 public SchemaScalarField(PropertySchema propertySchema)
 {
     //		internal FluidTrade.Sandbox.WorkingOrder.AskPrice askPrice;
     this.Attributes = MemberAttributes.Assembly;
     this.Type       = new CodeTypeReference(propertySchema.Type);
     this.Name       = CommonConversion.ToCamelCase(propertySchema.Name);
 }
Exemple #3
0
        public IndexSpecification <T> Add(string propertyName, IndexType indexType)
        {
            EntityProxy <T> proxy  = EntityProxyManager.Instance.GetEntityProxy <T>();
            PropertySchema  schema = proxy.GetProperty(propertyName);

            if (schema == null)
            {
                return(this);
            }

            bool containFlag = false;

            foreach (IndexMeta item in IndexedProperties)
            {
                if (string.Compare(item.PropertyName, schema.Name, false) == 0)
                {
                    containFlag = true;
                    break;
                }
            }

            if (!containFlag)
            {
                IndexedProperties.Add(new IndexMeta()
                {
                    PropertyName = schema.Name, IndexType = indexType, PropertyType = schema.PropertyType
                });
            }

            return(this);
        }
Exemple #4
0
        private object DetermineActualValue(ServerObject obj, PropertySchema propertySchema)
        {
            object val = obj.Data.GetValue(propertySchema.Property.Name);

            if (val == null)
            {
                if (propertySchema.CanBeNull)
                {
                    val = DBNull.Value;
                }
                else
                {
                    throw new ObjectServerException(String.Format(CultureInfo.CurrentCulture, "{0}.{1} has no value", obj.ServerObjectType.FullName, propertySchema.Property.Name));
                }
            }
            else
            {
                if (propertySchema.CanBeNull && val.Equals(propertySchema.NullValue))
                {
                    val = DBNull.Value;
                }
            }

            return(val);
        }
        private static LoanFieldFormat?GetFormat(PropertySchema propertySchema)
        {
            if (propertySchema.Format.EnumValue.HasValue)
            {
                return(propertySchema.Format);
            }
            switch (propertySchema.Type.EnumValue)
            {
            case PropertySchemaType.Bool:
                return(LoanFieldFormat.YN);

            case PropertySchemaType.DateTime:
                return(LoanFieldFormat.DATETIME);

            case PropertySchemaType.Date:
                return(LoanFieldFormat.DATE);

            case PropertySchemaType.Int:
                return(LoanFieldFormat.INTEGER);

            case PropertySchemaType.String:
            case PropertySchemaType.Uuid:
                return(LoanFieldFormat.STRING);

            default:
                return(null);
            }
        }
 /// <summary>
 /// An internal vector field.
 /// </summary>
 public SchemaVectorField(PropertySchema propertySchema)
 {
     //		internal System.Collections.Generic.IEnumerable<Sandbox.WorkingOrder.WorkingOrder> workingOrderList;
     this.Attributes = MemberAttributes.Assembly;
     this.Type       = new CodeTypeReference(string.Format("{0}[]", propertySchema.Type));
     this.Name       = CommonConversion.ToCamelCase(propertySchema.Name);
 }
        /// <summary>
        /// Creates a property for from the XML Schema definition.
        /// </summary>
        public SchemaProperty(PropertySchema propertySchema)
        {
            //		/// <summary>
            //		/// Price
            //		/// <summary>
            //		public decimal Price
            //		{
            //			get
            //			{
            //				return this.price;
            //			}
            //			set
            //			{
            //
            //			}
            this.Comments.Add(new CodeCommentStatement("<summary>", true));
            this.Comments.Add(new CodeCommentStatement(propertySchema.Name, true));
            this.Comments.Add(new CodeCommentStatement("</summary>", true));
            this.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            this.Type       = propertySchema.MaxOccurs == 1 ?
                              new CodeTypeReference(propertySchema.Type) :
                              new CodeTypeReference(string.Format("System.Collections.Generic.IEnumerable<{0}>", propertySchema.Type));
            this.Name = propertySchema.Name;

            this.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(propertySchema.Name))));
            this.SetStatements.Add(new CodeSnippetStatement());

            //		}
        }
Exemple #8
0
 public void InitializeContext()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.patternModel = this.store.ElementFactory.CreateElement <PatternModelSchema>();
         this.property     = patternModel.Create <PatternSchema>().Create <PropertySchema>();
     });
 }
 public void InitializeContext()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
         this.property = patternModel.Create<PatternSchema>().Create<PropertySchema>();
     });
 }
 public virtual void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.elementOwner = this.store.ElementFactory.CreateElement<ElementSchema>();
         this.element = this.store.ElementFactory.CreateElement<PropertySchema>();
         this.elementOwner.Properties.Add(this.element);
     });
     validationContext = new ValidationContext(ValidationCategories.Save, this.element);
 }
Exemple #11
0
        public PropertyRepo(PropertySchema propertySchema, TypeRepo typeRepo = null)
        {
            PropertySchema = propertySchema;
            TypeRepo       = typeRepo;

            if (typeRepo?.Serializer.PublicOnly == true && PropertySchema.IsPrivate)
            {
                PropertySchema.IsLoadable = false;
            }
        }
 public void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         var patternModel = this.store.ElementFactory.CreateElement <PatternModelSchema>();
         var pattern      = patternModel.Create <PatternSchema>();
         this.property    = pattern.Create <PropertySchema>();
     });
     validationContext = new ValidationContext(ValidationCategories.Save, this.property);
 }
Exemple #13
0
        /// <summary>
        /// 获取子表结构
        /// </summary>
        /// <param name="Schema"></param>
        /// <param name="Field"></param>
        /// <returns></returns>
        private BizObjectSchema GetChildSchema(BizObjectSchema schema, FieldSchema field)
        {
            PropertySchema property = schema.GetProperty(field.Name);

            if (property != null && property.ChildSchema != null)
            {
                return(property.ChildSchema);
            }
            return(this.Engine.BizObjectManager.GetPublishedSchema(field.ChildSchemaCode));
        }
 public virtual void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.elementOwner = this.store.ElementFactory.CreateElement <ElementSchema>();
         this.element      = this.store.ElementFactory.CreateElement <PropertySchema>();
         this.elementOwner.Properties.Add(this.element);
     });
     validationContext = new ValidationContext(ValidationCategories.Save, this.element);
 }
            public void InitializeContext()
            {
                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
                    var pattern = patternModel.Create<PatternSchema>();
                    this.property = pattern.Create<PropertySchema>();
                });

                this.descriptor = new DefaultValuePropertyDescriptor("DefaultValue", property, typeof(string), new Attribute[0]);
            }
 public void InitializeContext()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
         this.propertySchema = (PropertySchema)patternModel.CreatePatternSchema().CreatePropertySchema();
         this.propertySchema.Type = typeof(string).FullName;
         this.propertySchema.DefaultValue.Value = "Foo";
         this.propertySchema.DefaultValue.ValueProvider = new ValueProviderBindingSettings { TypeId = "Bar" };
     });
 }
Exemple #17
0
            public void WhenPropertyAddedToElement_ThenPropertyUsageIsGeneral()
            {
                PropertySchema newProperty = null;

                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    newProperty = this.patternModel.Pattern.Create <PropertySchema>();
                });

                Assert.True(newProperty.PropertyUsage == Runtime.PropertyUsages.General);
            }
            public void InitializeContext()
            {
                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    var patternModel = this.store.ElementFactory.CreateElement <PatternModelSchema>();
                    var pattern      = patternModel.Create <PatternSchema>();
                    this.property    = pattern.Create <PropertySchema>();
                });

                this.descriptor = new DefaultValuePropertyDescriptor("DefaultValue", property, typeof(string), new Attribute[0]);
            }
            public void WhenSameNamedElementAddedToDifferentOwner_ThenValidateNameIsUniqueSucceeds()
            {
                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    ElementSchema elementOwner2 = this.store.ElementFactory.CreateElement <ElementSchema>();
                    PropertySchema element2     = this.store.ElementFactory.CreateElement <PropertySchema>();
                    element2.Name = this.element.Name;
                    elementOwner2.Properties.Add(element2);
                });
                this.element.ValidateNameIsUnique(validationContext);

                Assert.True(validationContext.CurrentViolations.Count == 0);
            }
Exemple #20
0
 public void InitializeContext()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         var patternModel         = this.store.ElementFactory.CreateElement <PatternModelSchema>();
         this.propertySchema      = (PropertySchema)patternModel.CreatePatternSchema().CreatePropertySchema();
         this.propertySchema.Type = typeof(string).FullName;
         this.propertySchema.DefaultValue.Value         = "Foo";
         this.propertySchema.DefaultValue.ValueProvider = new ValueProviderBindingSettings {
             TypeId = "Bar"
         };
     });
 }
        internal static string DetermineColumnName(IQueryBuilder query, string propertyName)
        {
            string[] properties = propertyName.Split('.');
            string   table      = String.Empty;
            string   column     = String.Empty;

            TypeSchema schema = SchemaCache.Current.GetSchema(query.QueriedType);

            for (int i = 0; i < properties.Length; i++)
            {
                if (i == properties.Length - 1)
                {
                    PropertySchema propertySchema = schema.FindPropertySchema(properties[i]);

                    if (propertySchema != null)
                    {
                        column = String.Format(CultureInfo.CurrentCulture, query.Context.ColumnFormat, propertySchema.ColumnName);
                    }
                    else
                    {
                        ParentSchema parentSchema = schema.FindParentSchema(properties[i]);

                        if (parentSchema != null)
                        {
                            column = String.Format(CultureInfo.CurrentCulture, query.Context.ColumnFormat, parentSchema.ColumnName);
                        }
                        else
                        {
                            throw new ObjectServerException(String.Format(CultureInfo.CurrentCulture, "Could not locate schema for {0}.{1}", schema.Type.FullName, properties[i]));
                        }
                    }

                    table = String.Format(CultureInfo.CurrentCulture, query.Context.TableFormat, schema.TableName);
                }
                else
                {
                    ParentSchema parentSchema = schema.FindParentSchema(properties[i]);

                    if (parentSchema == null)
                    {
                        throw new ObjectServerException(String.Format(CultureInfo.CurrentCulture, "Could not locate schema for {0}.{1}", schema.Type.FullName, properties[i]));
                    }

                    schema = SchemaCache.Current.GetSchema(parentSchema.Property.PropertyType);

                    query.AddParentJoin(parentSchema);
                }
            }

            return(String.Format(CultureInfo.CurrentCulture, query.Context.TableColumnFormat, table, column));
        }
            public void WhenSameNamedElementAddedToSameOwner_ThenValidateNameIsUniqueFails()
            {
                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    PropertySchema element2 = this.store.ElementFactory.CreateElement <PropertySchema>();
                    element2.Name           = this.element.Name;
                    this.elementOwner.Properties.Add(element2);
                });
                this.element.ValidateNameIsUnique(validationContext);

                Assert.True(validationContext.CurrentViolations.Count == 1);
                Assert.True(validationContext.ValidationSubjects.IndexOf(this.element) == 0);
                Assert.True(validationContext.CurrentViolations[0].Code == Properties.Resources.Validate_PropertyNameIsNotUniqueCode);
            }
            public void WhenAddingNewProperty_ThenNamePropertyIsBrowsableAndNotReadOnly()
            {
                PropertySchema property = null;

                this.PatternModel.Store.TransactionManager.DoWithinTransaction(() =>
                {
                    property = this.PatternModel.Create <PropertySchema>();
                });

                var descriptor = TypedDescriptor.GetProperty(property, prop => prop.Name);

                Assert.False(property.IsInheritedFromBase);
                Assert.True(descriptor.IsBrowsable);
                Assert.False(descriptor.IsReadOnly);
            }
        private PropertySchema FillPropertySchema(DataRow Fields)
        {
            PropertySchema propsch = new PropertySchema();

            propsch.Id   = (int)Fields[PropertySchemaNames.Id];
            propsch.Name = Fields[PropertySchemaNames.Name].ToString();
            propsch.IsSummaryProperty = (bool)Fields[PropertySchemaNames.IsSummaryProp];

            IEnumerable <AttributeSchema> attrschs = _attrschlist.Values.Where(attr => attr.PropertySchema.Id == propsch.Id);

            foreach (AttributeSchema a in attrschs)
            {
                propsch.AttributeSchemas.Add(a.Id, a);
            }

            return(propsch);
        }
Exemple #25
0
        private static BeeDataAdapter GetHeaderItem(PropertySchema propertySchema)
        {
            ModelPropertyAttribute modelPropertyAttribute
                = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();

            BeeDataAdapter dataAdapter = new BeeDataAdapter();
            string         descriptionInfo;

            if (modelPropertyAttribute != null)
            {
                if (!modelPropertyAttribute.Visible)
                {
                    return(null);
                }
                descriptionInfo = modelPropertyAttribute.Description;
                if (string.IsNullOrEmpty(descriptionInfo))
                {
                    descriptionInfo = propertySchema.Name;
                }

                dataAdapter.Add("description", descriptionInfo);
                dataAdapter.Add("name", propertySchema.Name);

                if (modelPropertyAttribute.ColumnWidth != 0)
                {
                    dataAdapter.Add("width", modelPropertyAttribute.ColumnWidth.ToString());
                }

                if (!string.IsNullOrEmpty(modelPropertyAttribute.Align))
                {
                    dataAdapter.Add("align", modelPropertyAttribute.Align);
                }

                if (modelPropertyAttribute.OrderableFlag)
                {
                    dataAdapter.Add("orderField", propertySchema.Name);
                }
            }
            else
            {
                dataAdapter.Add("description", propertySchema.Name);
                dataAdapter.Add("Name", propertySchema.Name);
            }

            return(dataAdapter);
        }
Exemple #26
0
        private BeeDataAdapter GetSearchItem(PropertySchema propertySchema)
        {
            BeeDataAdapter         dataAdapter = null;
            ModelPropertyAttribute modelPropertyAttribute
                = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();

            if (modelPropertyAttribute != null)
            {
                if (!modelPropertyAttribute.Visible)
                {
                    return(null);
                }

                if (!modelPropertyAttribute.Queryable)
                {
                    return(null);
                }

                dataAdapter = new BeeDataAdapter();

                string descriptionInfo = modelPropertyAttribute.Description;
                if (string.IsNullOrEmpty(descriptionInfo))
                {
                    descriptionInfo = propertySchema.Name;
                }

                dataAdapter.Add("name", propertySchema.Name);
                dataAdapter.Add("Type", propertySchema.PropertyType);
                dataAdapter.Add("QueryType", modelPropertyAttribute.QueryType);
                dataAdapter.Add("Description", descriptionInfo);

                if (!string.IsNullOrEmpty(modelPropertyAttribute.MappingName))
                {
                    dataAdapter.Add("MappingName", modelPropertyAttribute.MappingName);
                }

                if (propertySchema.PropertyType.IsEnum && !dataAdapter.ContainsKey("MappingName"))
                {
                    dataAdapter.Add("MappingName", propertySchema.PropertyType.ToString());
                }
            }

            return(dataAdapter);
        }
Exemple #27
0
        public IPropertySchema AddSchema([Required] string name, [Required] string nspace)
        {
            IPropertySchema result = null;

            if (GetSchema(name, nspace) == null)
            {
                if (_schemas == null)
                {
                    _schemas = new List <IPropertySchema>();
                }
                result = new PropertySchema(this, name, nspace);
                _schemas.Add(result);
                SetDirty();
                RegisterEvents(result);
                ChildCreated?.Invoke(result);
            }

            return(result);
        }
            public virtual void InitializeContext()
            {
                var store = new DslTestStore <PatternModelDomainModel>();

                var serviceProvider = Mock.Get(store.ServiceProvider);

                serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns(
                    Mock.Of <IPatternManager>(p => p.InstalledToolkits == new List <IInstalledToolkitInfo>()));

                store.TransactionManager.DoWithinTransaction(() =>
                {
                    this.PatternModel   = store.ElementFactory.CreateElement <PatternModelSchema>();
                    var pattern         = this.PatternModel.Create <PatternSchema>();
                    pattern.PatternLink = "patternmanager://foo";

                    var uriService = Mock.Of <IUriReferenceService>(
                        u => u.ResolveUri <IInstanceBase>(It.IsAny <Uri>()) == Mock.Of <IProduct>(p =>
                                                                                                  p.ToolkitInfo.Identifier == "ToolkitId"));

                    pattern.UriService = uriService;

                    this.Property = pattern.Create <PropertySchema>();
                });
            }
Exemple #29
0
        private static IHtmlContent EditorDataProperty(IHtmlHelper helper, object record, PropertySchema propertySchema)
        {
            IProperty property = propertySchema.Property as IProperty;

            if (property.GetContainingForeignKeys().Any())
            {
                // editing and creating this property should be handled by the INavigation entity property, rather than the raw key
                return(new StringHtmlContent(string.Empty));
            }
            object propertyValue = record == null ? null : property.GetGetter().GetClrValue(record);

            if (property.IsPrimaryKey())
            {
                // primary key shouldn't be edited
                return(helper.Hidden(property.Name, propertyValue));
            }
            return(GeneratorUtils.LoadView(helper, "Edit", propertyValue, propertySchema) ??
                   helper.TextBox(property.Name, propertyValue));
        }
Exemple #30
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Deserializes an element from the specified context.
 /// </summary>
 /// <param name="ctx">
 ///  Serialization context.
 /// </param>
 /// <returns>
 ///  An object.
 /// </returns>
 ///-------------------------------------------------------------------------------------------------
 protected override object Deserialize(SerializationContext ctx)
 {
     ctx.Schema = this.PropertySchema;
     return(PropertySchema.Deserialize(ctx));
 }
Exemple #31
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Serializes the specified data.
 /// </summary>
 /// <param name="data">
 ///  The data.
 /// </param>
 /// <returns>
 ///  A string.
 /// </returns>
 ///-------------------------------------------------------------------------------------------------
 protected override object Serialize(object data)
 {
     return(PropertySchema.Serialize(data));
 }
 private static List <FieldOption> GetOptions(PropertySchema propertySchema)
 {
     return(propertySchema.AllowedValues?.Where(o => !string.IsNullOrEmpty(o.Text) || !string.IsNullOrEmpty(o.Value)).Select(o => o.Value == "true" || o.Value == "false" ? new FieldOption(o.Value == "true" ? "Y" : "N", o.Text) : o).Distinct().ToList());
 }
 public void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
         var pattern = patternModel.Create<PatternSchema>();
         this.property = pattern.Create<PropertySchema>();
     });
     validationContext = new ValidationContext(ValidationCategories.Save, this.property);
 }
Exemple #34
0
 public static IHtmlContent EditorProperty(IHtmlHelper helper, object record, PropertySchema property)
 {
     return((property.Property is INavigation) ?
            EditorNavigationProperty(helper, record, property) :
            EditorDataProperty(helper, record, property));
 }
Exemple #35
0
        private static IHtmlContent EditorNavigationProperty(IHtmlHelper helper, object record, PropertySchema propertySchema)
        {
            INavigation property      = propertySchema.Property as INavigation;
            object      propertyValue = record == null ? null : property.GetGetter().GetClrValue(record);

            var lookupType = property.IsDependentToPrincipal()
                ? property.ForeignKey.PrincipalEntityType
                : property.ForeignKey.DeclaringEntityType;
            IQueryable <object> lookupData = Reflection.GetDbSetForType(new FormicDbContext(), lookupType);

            var primaryKeyGetter = EFUtils.GetPrimaryKeyProperty(lookupType).GetGetter();
            var items            = (from result in lookupData
                                    let value = primaryKeyGetter.GetClrValue(result).ToString()
                                                select new SelectListItem
            {
                Text = result.ToString(),
                Value = value,
                Selected = value.Equals(propertyValue)
            })
                                   .ToList();

            return(GeneratorUtils.LoadView(helper, "Edit", items, propertySchema) ??
                   GeneratorUtils.LoadView(helper, "EditTemplates/Navigation",
                                           propertyValue: items,
                                           propertyLabel: propertySchema.Description,
                                           propertyName: property.ForeignKey.Properties[0].Name));
        }
 public DefaultValuePropertyDescriptor(string propertyName, PropertySchema schema, Type propertyType, Attribute[] attrs)
     : base(propertyName, attrs.Add(new DefaultValueAttribute(propertyType.GetDefaultValueString())).ToArray())
 {
     this.schema = schema;
     this.propertyType = TypeDescriptor.GetProvider(propertyType).GetRuntimeType(propertyType);
 }