protected QueryCondition PropCompare(
     MetadataProperty prop,
     CompareOp op,
     object value)
 {
     return(this.Compare(prop.Name, op, value));
 }
Exemple #2
0
        internal void LoadFromXml(XmlNode node)
        {
            string attr = XmlUtils.GetAttr(node, "ref-select-case");

            this.FSelector = attr.Length == 0 ? (MetadataProperty)null : this.Property.Class.Properties.Need(attr);
            if (this.FSelector == null)
            {
                MetadataAssociationRef assRef = new MetadataAssociationRef(this, this.Refs.Count);
                assRef.LoadFromXml(node);
                this.Refs.Add(assRef);
            }
            else
            {
                foreach (XmlNode selectNode in node.SelectNodes("case"))
                {
                    MetadataAssociationRef assRef = new MetadataAssociationRef(this, this.Refs.Count);
                    assRef.LoadFromXml(selectNode);
                    if (this.Refs.FindBySelectorValue((object)assRef.SelectorValue) == null)
                    {
                        ;
                    }
                    this.Refs.Add(assRef);
                }
                if (this.Refs.Count == 0)
                {
                    throw new MetadataException("Не заданы варианты связи.");
                }
                this.FSelector.SetAssociation(this);
            }
        }
Exemple #3
0
 public DataProperty(DataObject obj, MetadataProperty metadata)
 {
     this.Object    = obj;
     this.Metadata  = metadata;
     this.FValue    = DataProperty.NotAssigned;
     this.FModified = false;
 }
 private static void AddOriginalValue(
     MetadataProperty property,
     ListDictionary properties,
     IDataReader originalValuesReader)
 {
     properties.Add((object)property.Name, originalValuesReader.GetValue(originalValuesReader.GetOrdinal(property.DataField)));
 }
        internal void LoadFromXml(XmlNode node)
        {
            MetadataClass metadataClass1 = this.Association.Class;

            try
            {
                MetadataClass metadataClass2 = metadataClass1.Metadata.Classes.Need(XmlUtils.NeedAttr(node, "ref-class"));
                this.FRefProperty           = metadataClass2.Properties.Find(XmlUtils.GetAttr(node, "ref-property")) ?? metadataClass2.IDProperty;
                this.FSelectorValue         = node.Name == "case" ? XmlUtils.NeedAttr(node, "value") : string.Empty;
                this.FAssociationObjectView = XmlUtils.GetAttr(node, "association-object-view", "default");
                if (this.Association.Property.IsAggregation)
                {
                    this.FAggregationRoleMemberName = XmlUtils.GetAttr(node, "role-prog-id", this.Association.Class.IdentName);
                    this.FAggregationBuiltIn        = XmlUtils.GetBoolAttr(node, "is-built-in");
                    this.FAggregationType           = (AggregationType)XmlUtils.GetEnumAttr(node, "aggregation-type", MetadataAssociationRef.FAggregationTypeNames, 0);
                    this.FAggregationObjectView     = XmlUtils.GetAttr(node, "aggregation-object-view", "default");
                    metadataClass2.Childs.Ensure(this);
                }
                metadataClass2.ExternalRefs.Add(this);
            }
            catch (Exception ex)
            {
                throw new MetadataException(string.Format("Ошибка загрузки свойства {0}", (object)this.Association.Property.Name), ex);
            }
        }
        public bool TryFindMember(
            string memberName,
            out MetadataProperty property,
            out MetadataChildRef childRef)
        {
            property = this.Properties.Find(memberName);
            if (property != null)
            {
                childRef = (MetadataChildRef)null;
                return(true);
            }
            MetadataClass byIdentName = this.Metadata.Classes.FindByIdentName(memberName);

            if (byIdentName != null)
            {
                childRef = this.Childs.Find(byIdentName);
                if (childRef != null)
                {
                    return(true);
                }
            }
            else
            {
                childRef = (MetadataChildRef)null;
            }
            return(false);
        }
 protected QueryCondition PropBetween(
     MetadataProperty prop,
     object minValue,
     object maxValue)
 {
     return(this.Between(prop.Name, minValue, maxValue));
 }
Exemple #8
0
 private void AppendField(
     SqlUtils.NavigationStep step,
     MetadataProperty prop,
     StringBuilder sb)
 {
     sb.AppendFormat("[{0}].[{1}]", step != null ? (object)step.TargetAlias : (object)this.Alias, (object)prop.DataField);
 }
        private void LoadPropertiesFromXml(XmlNode node)
        {
            foreach (XmlNode selectNode in node.SelectNodes("property"))
            {
                string name = XmlUtils.NeedAttr(selectNode, "name");
                if (this.Properties.Find(name) != null)
                {
                    throw new MetadataException(string.Format("Свойство {0} уже определено.", (object)name));
                }
                MetadataProperty property = new MetadataProperty(this, name, this.Properties.Count);
                property.LoadFromXml(selectNode);
                this.AllProperties.Add(property);
                if (!property.IsExtension)
                {
                    this.Properties.Add(property);
                    switch (property.Purpose)
                    {
                    case MetadataPropertyPurpose.Id:
                        this.FIdProperty = property;
                        break;

                    case MetadataPropertyPurpose.Association:
                    case MetadataPropertyPurpose.Aggregation:
                        MetadataAssociation ass = new MetadataAssociation(property);
                        this.Associations.Add(ass);
                        if (property.Purpose == MetadataPropertyPurpose.Aggregation)
                        {
                            this.Owners.Add(ass);
                            break;
                        }
                        break;
                    }
                }
            }
        }
 internal int SavePropertyValue(
     MetadataProperty metadataProperty,
     ref object value,
     ref object exValue)
 {
     return(this.EnsurePropertyInstance(metadataProperty).SaveValueToDb(ref value, ref exValue));
 }
 public void NeedMember(
     string memberName,
     out MetadataProperty property,
     out MetadataChildRef childRef)
 {
     if (!this.TryFindMember(memberName, out property, out childRef))
     {
         throw new DataException(string.Format("\"{0}\" не является ни свойством, ни дочерним классом.", (object)memberName));
     }
 }
        public bool IsPropertyAssigned(MetadataProperty propertyMetadata)
        {
            if (this.FProperties == null)
            {
                return(false);
            }
            DataProperty fproperty = this.FProperties[propertyMetadata.Index];

            return(fproperty != null && fproperty.IsAssigned);
        }
 private static void GenerateProperties(MetadataClass cls, StringBuilder sb)
 {
     for (int index = 0; index < cls.Properties.Count; ++index)
     {
         MetadataProperty property = cls.Properties[index];
         if (!property.IsSelector && !property.IsId)
         {
             CodeGenerator.GenerateProperty(property, sb);
         }
     }
 }
Exemple #14
0
            public SqlUtils.NavigationStep EnsureRootStep(string path)
            {
                SqlUtils.NavigationStep navigationStep1 = !string.IsNullOrEmpty(path) ? this.FindRootStep(path) : throw new ArgumentNullException(nameof(path));
                if (navigationStep1 != null)
                {
                    return(navigationStep1);
                }
                string        predecessorPath;
                string        identifier;
                MetadataClass refClass1;
                bool          isExternalRef;

                SqlUtils.Navigation.ParseLastPartOfPath(this.Class.Metadata.Classes, path, out predecessorPath, out identifier, out refClass1, out isExternalRef);
                SqlUtils.NavigationStep predecessor = !string.IsNullOrEmpty(predecessorPath) ? this.EnsureRootStep(predecessorPath) : (SqlUtils.NavigationStep)null;
                MetadataClass           refClass2   = predecessor != null ? predecessor.TargetClass : this.Class;

                SqlUtils.NavigationStep navigationStep2;
                if (isExternalRef)
                {
                    MetadataProperty metadataProperty = refClass1.Properties.Need(identifier);
                    if (!metadataProperty.IsLink)
                    {
                        throw new Exception(string.Format("Свойство \"{0}.{1}\" не является отношением.", (object)refClass1.Name, (object)identifier));
                    }
                    navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.ExternalAssociationNavigationStep(this, predecessor, path, metadataProperty.Association.Refs.Need(refClass2));
                }
                else
                {
                    MetadataProperty property;
                    MetadataChildRef childRef;
                    refClass2.NeedMember(identifier, out property, out childRef);
                    if (property != null)
                    {
                        if (!property.IsLink)
                        {
                            throw new DataException(string.Format("\"{0}\" не является ассоциацией или дочерним объектом.", (object)identifier));
                        }
                        MetadataAssociationRefList refs = property.Association.Refs;
                        if (refClass1 == null && refs.Count != 1)
                        {
                            throw new DataException(string.Format("\"{0}\" является ассоциацией с вариантами связи. В тексте запроса такое поле следует указывать в форме \"имя-свойства:имя-связанного-класса\" (например, \"Subject:Person\").", (object)identifier));
                        }
                        navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.AssociationNavigationStep(this, predecessor, path, refClass1 == null ? refs[0] : refs.Need(refClass1));
                    }
                    else
                    {
                        navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.ChildNavigationStep(this, predecessor, path, childRef);
                    }
                }
                navigationStep2.TargetAlias = this.CreateUniqueAlias(navigationStep2.TargetClass.DataTable);
                this.RootSteps.Add(navigationStep2);
                return(navigationStep2);
            }
Exemple #15
0
 public void EnsureDataProperty(MetadataProperty propertyMetadata)
 {
     if (!propertyMetadata.IsData)
     {
         throw new System.Data.DataException(string.Format("DataLoadPlan.AddData: Свойство {0}.{1}, добавляемое в план загрузки простых типов, являться ассоциацией. Используйте метод AddLink.", (object)propertyMetadata.Class.QTypeName, (object)propertyMetadata.Name));
     }
     if (this.Data.Contains(propertyMetadata))
     {
         return;
     }
     this.Data.Add(propertyMetadata);
 }
        private static void GenerateProperty(MetadataProperty prop, StringBuilder sb)
        {
            string valueType;
            string propertyType;

            prop.GetMemberTypes(out valueType, out propertyType);
            string memberName = prop.MemberName;

            CodeGenerator.GenerateDoc("\t", "summary", prop.Caption, sb);
            sb.AppendFormat("\tpublic {0} {1}Property {{ get {{ return ({0})base[Meta.{1}]; }} }}\n", (object)propertyType, (object)memberName);
            CodeGenerator.GenerateDoc("\t", "summary", prop.Caption, sb);
            sb.AppendFormat("\tpublic {0} {1} {{\n\tget {{ return {1}Property.Value; }}\n\tset {{ {1}Property.Value = value; }}\n\t}}\n", (object)valueType, (object)memberName);
        }
        internal void DropCache()
        {
            MetadataProperty property = this.ChildRef.AggregationRef.Association.Property;

            for (int index = this.FItems.Count - 1; index >= 0; --index)
            {
                if (!((DataObject)this.FItems[index]).IsPropertyModified(property))
                {
                    this.FItems.RemoveAt(index);
                }
            }
            this.FIsComplete = false;
        }
 private static void CopyPropsToMasterObject(
     DataObject obj,
     DataObject masterObj,
     IList <MetadataProperty> metaProps)
 {
     for (int index = 0; index < metaProps.Count; ++index)
     {
         MetadataProperty metaProp = metaProps[index];
         if (!metaProp.IsId && !metaProp.IsSelector)
         {
             masterObj[metaProp].Assign(obj[metaProp]);
         }
     }
 }
        internal void LoadPropertyValue(
            MetadataProperty propertyMetadata,
            object value,
            object exValue,
            LoadContext loadContext)
        {
            DataProperty dataProperty = this.EnsurePropertyInstance(propertyMetadata);

            if (dataProperty.IsModified)
            {
                return;
            }
            dataProperty.LoadValueFromDb(value, exValue, loadContext);
        }
 public void GenerateConditionBuilder(MetadataClass cls, StringBuilder sb)
 {
     CodeGenerator.ApplyTemplate(cls, sb, "\npublic class {Type}ConditionBuilder: QueryCondition\n{\n\tpublic readonly {Type}Meta Meta;\n\tpublic {Type}ConditionBuilder({Type}Meta meta): base() { Meta = meta; }\n");
     for (int index = 0; index < cls.Properties.Count; ++index)
     {
         MetadataProperty property = cls.Properties[index];
         if (!property.IsSelector && !property.IsId)
         {
             string valueType;
             property.GetMemberTypes(out valueType, out string _);
             sb.AppendFormat("\tpublic {0} {1}IsNull {{ get {{ return ({0})base.PropIsNull({2}); }}}}\n\tpublic {0} {1}IsNotNull {{ get {{ return ({0})base.PropIsNotNull({2}); }}}}\n\tpublic {0} {1}Is({3} value) {{ return ({0})base.PropIs({2}, value); }}\n\tpublic {0} {1}(CompareOp op, {3} value) {{ return ({0})base.PropCompare({2}, op, value); }}\n\tpublic {0} {1}Like(string value) {{ return ({0})base.PropLike({2}, value); }}\n\tpublic {0} {1}In(params {3}[] value) {{ return ({0})base.PropIn({2}, value); }}\n\tpublic {0} {1}Between({3} minValue, {3} maxValue) {{ return ({0})base.PropBetween({2}, minValue, maxValue); }}\n", (object)(cls.TypeName + "ConditionBuilder"), (object)property.MemberName, (object)("Meta." + property.MemberName), (object)valueType);
         }
     }
     sb.AppendFormat("\tnew public {0} Begin {{ get {{ return ({0})base.Begin; }}}}\n\tnew public {0} End {{ get {{ return ({0})base.End; }}}}\n\tnew public {0} And {{ get {{ return ({0})base.And; }}}}\n\tnew public {0} Or {{ get {{ return ({0})base.Or; }}}}\n\tnew public {0} Not {{ get {{ return ({0})base.Not; }}}}\n}}\n", (object)(cls.TypeName + "ConditionBuilder"));
 }
 private static void CopyPropsToParams(
     DataObject obj,
     IList <MetadataProperty> metaProps,
     object[] values,
     ref int index)
 {
     for (int index1 = 0; index1 < metaProps.Count; ++index1)
     {
         MetadataProperty metaProp = metaProps[index1];
         if (!metaProp.IsId && !metaProp.IsSelector)
         {
             StorageCommitPlan.CopyPropToParam(obj, metaProp, values, ref index);
         }
     }
 }
        private static void GetPropValues(
            DataObject obj,
            MetadataProperty metaProp,
            out MetadataProperty prop1,
            out object value1,
            out MetadataProperty prop2,
            out object value2)
        {
            value1 = (object)null;
            value2 = (object)null;
            int num = obj.SavePropertyValue(metaProp, ref value1, ref value2);

            prop1 = metaProp;
            prop2 = num > 1 ? metaProp.Association.Selector : (MetadataProperty)null;
        }
Exemple #23
0
 internal ObjectListLoaderByIds(
     ObjectLoader objectLoader,
     MetadataProperty inProperty,
     DataId[] ids)
     : base(objectLoader)
 {
     this.FIds = new Hashtable();
     if (ids != null)
     {
         for (int index = 0; index < ids.Length; ++index)
         {
             this.FIds[(object)ids[index]] = (object)null;
         }
     }
     this.InProperty = inProperty;
 }
Exemple #24
0
        internal ObjectListLoaderByIds EnsureObjectListLoaderByIds(
            ObjectLoader objectLoader,
            MetadataProperty inProperty)
        {
            for (int index = 0; index < this.ObjectListLoaders.Count; ++index)
            {
                if (this.ObjectListLoaders[index] is ObjectListLoaderByIds objectListLoader && objectListLoader.ObjectLoader == objectLoader && objectListLoader.InProperty == inProperty)
                {
                    return(objectListLoader);
                }
            }
            ObjectListLoaderByIds objectListLoaderByIds = new ObjectListLoaderByIds(objectLoader, inProperty, (DataId[])null);

            this.ObjectListLoaders.Add((ObjectListLoader)objectListLoaderByIds);
            return(objectListLoaderByIds);
        }
        private static void CopyPropToParam(
            DataObject obj,
            MetadataProperty metaProp,
            object[] values,
            ref int index)
        {
            object obj1    = (object)null;
            object exValue = (object)null;
            int    num     = obj.SavePropertyValue(metaProp, ref obj1, ref exValue);

            values[index++] = obj1 ?? (object)DBNull.Value;
            if (num <= 1)
            {
                return;
            }
            values[index++] = exValue ?? (object)DBNull.Value;
        }
        protected internal DataProperty CreatePropertyInstance(
            MetadataProperty propertyMetadata)
        {
            switch (propertyMetadata.Purpose)
            {
            case MetadataPropertyPurpose.Data:
                DataType dataType = propertyMetadata.DataType & DataType.BaseMask;
                switch (dataType)
                {
                case DataType.Boolean:
                    return((DataProperty) new BooleanProperty(this, propertyMetadata));

                case DataType.Integer:
                    return((DataProperty) new IntegerProperty(this, propertyMetadata));

                case DataType.Float:
                    return((DataProperty) new DoubleProperty(this, propertyMetadata));

                case DataType.Currency:
                    return((DataProperty) new CurrencyProperty(this, propertyMetadata));

                case DataType.DateTime:
                    return((DataProperty) new DateTimeProperty(this, propertyMetadata));

                case DataType.String:
                    return((DataProperty) new StringProperty(this, propertyMetadata));

                case DataType.Memo:
                    return((DataProperty) new StringProperty(this, propertyMetadata));

                case DataType.Binary:
                    return((DataProperty) new BinaryProperty(this, propertyMetadata));

                default:
                    throw new DataException(string.Format("Некорректный тип данных {0} свойства {1} объекта {2}", (object)dataType, (object)propertyMetadata.Name, (object)this.FStorage.Class.Name));
                }

            case MetadataPropertyPurpose.Association:
            case MetadataPropertyPurpose.Aggregation:
                MetadataAssociationRefList refs = propertyMetadata.Association.Refs;
                return(propertyMetadata.Association.Selector == null ? (DataProperty)this.Session[refs[0].RefClass].CreateLinkPropertyInstance(this, propertyMetadata) : (DataProperty) new LinkProperty(this, propertyMetadata));

            default:
                throw new System.Data.DataException("Попытка создания объекта доступа к свойству ID.");
            }
        }
        private DataProperty EnsurePropertyInstance(MetadataProperty propertyMetadata)
        {
            this.CheckNotUntypedNull();
            DataProperty[] dataPropertyArray = this.FProperties;
            if (dataPropertyArray == null)
            {
                dataPropertyArray = new DataProperty[this.Class.Properties.Count];
                this.FProperties  = dataPropertyArray;
            }
            DataProperty propertyInstance = dataPropertyArray[propertyMetadata.Index];

            if (propertyInstance == null)
            {
                propertyInstance = this.CreatePropertyInstance(propertyMetadata);
                dataPropertyArray[propertyMetadata.Index] = propertyInstance;
            }
            return(propertyInstance);
        }
 public void GenerateMeta(MetadataClass cls, StringBuilder sb)
 {
     CodeGenerator.ApplyTemplate(cls, sb, "\npublic class {Type}Meta\n{\n\tprivate MetadataClass FClass;\n");
     for (int index = 0; index < cls.Properties.Count; ++index)
     {
         MetadataProperty property = cls.Properties[index];
         if (!property.IsSelector && !property.IsId)
         {
             sb.AppendFormat("\tprivate MetadataProperty F{0};\n\tpublic MetadataProperty {0} {{ get {{ if(F{0} == null) {{ F{0} = FClass.Properties.Need(\"{1}\"); }} return F{0}; }} }}\n", (object)property.MemberName, (object)property.Name);
         }
     }
     for (int index = 0; index < cls.Childs.Count; ++index)
     {
         sb.AppendFormat("\tprivate MetadataChildRef F{0};\n\tpublic MetadataChildRef {0} {{ get {{ if(F{0} == null) {{ F{0} = FClass.Childs.Need(\"{1}\"); }} return F{0}; }} }}\n", (object)cls.Childs[index].MemberName, (object)cls.Childs[index].ChildClass.Name);
     }
     CodeGenerator.ApplyTemplate(cls, sb, "\tpublic {Type}Meta(MetadataClass cls) { FClass = cls; }\n");
     sb.Append("}\n");
 }
 private static void MetaPropToSql(
     MetadataProperty metaProp,
     StringBuilder sql,
     string divider,
     string format,
     ref int paramIndex,
     DataType[] paramTypes)
 {
     if (divider != null && sql != null)
     {
         sql.Append(divider);
     }
     sql?.Append(string.Format(format, (object)metaProp.DataField));
     if (paramTypes != null)
     {
         paramTypes[paramIndex] = metaProp.DataType;
     }
     ++paramIndex;
 }
 private void CheckComplete()
 {
     if (this.FIsComplete)
     {
         return;
     }
     if (this.Object.IsNull)
     {
         this.FIsComplete = true;
     }
     else
     {
         DataStorage storage       = this.Object.Storage;
         DataSession masterSession = this.Session.MasterSession;
         if (masterSession != null)
         {
             DataObjectChildList childs      = masterSession[storage.Class][this.Object.Id].GetChilds(this.ChildRef);
             DataStorage         dataStorage = this.Session[this.ChildRef.ChildClass];
             MetadataProperty    property    = this.ChildRef.AggregationRef.Association.Property;
             for (int index = 0; index < childs.Count; ++index)
             {
                 DataObject untypedValue = (DataObject)dataStorage[childs[index].Id][property].UntypedValue;
             }
             this.FIsComplete = true;
         }
         else if (storage.IsChildListCompleted(this.ChildRef))
         {
             this.FIsComplete = true;
         }
         else
         {
             this.Session.TraceUnplannedChildrenLoading(this.ChildRef);
             LoadPlan plan = new LoadPlan(storage.Class);
             plan.EnsureChildRef(this.ChildRef, new LoadPlan(this.ChildRef.ChildClass));
             storage.Session.LoadData(plan, (DataObjectList)null, new DataId[1]
             {
                 this.Object.Id
             }, (string)null);
         }
     }
 }