Пример #1
0
        private void AssertHouse(DomainProperty property)
        {
            AssertPropertyObject(property, "Hourse", "AdminPersonHourse");
            var ps = DomainProperty.GetProperties(property.PropertyType).ToArray();

            AssertPropertyValue(ps[0], "Address", typeof(string));
        }
Пример #2
0
 ////////////////////////////////////////////////////////////////////////////////////////////////
 /*--------------------------------------------------------------------------------------------*/
 public PropertyMapping(DomainProperty pDom, ApiProperty pApi,
                        CustomDir pCustom = CustomDir.Neither)
 {
     Domain = pDom;
     Api    = pApi;
     Custom = pCustom;
 }
Пример #3
0
        /// <summary>
        /// 创建基础值集合的值字段
        /// </summary>
        /// <param name="ownerType"></param>
        /// <param name="propertyType"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static GeneratedField CreatePrimitiveValue(Type ownerType, ValueListField field)
        {
            var            valueType = field.ValueType;
            DomainProperty property  = null;
            DbFieldType    fieldType = DbFieldType.Common;

            if (valueType == typeof(string))
            {
                var maxLength = field.Tip.GetMaxLength();
                if (maxLength < 300)
                {
                    //如果value的字符串类型长度小于300,那么就可以参与索引
                    fieldType = DbFieldType.NonclusteredIndex;
                }
                property = new StringProperty(ownerType, PrimitiveValueName, maxLength, field.Tip.IsASCIIString());
            }
            else
            {
                fieldType = DbFieldType.NonclusteredIndex;
                property  = new CustomProperty(ownerType, valueType, PrimitiveValueName);
            }

            var attr = new PropertyRepositoryAttribute()
            {
                Property = property
            };

            return(new GeneratedField(attr, PrimitiveValueName, GeneratedFieldType.PrimitiveValue, fieldType));
        }
Пример #4
0
        /// <summary>
        /// 常用于根据某一项数据的值,判断对象是否已经存在
        /// 例如:在注册和修改账户对象时时,账户的的名称属性是不能重复的,
        /// 该方法仅用于判断字符串类型的属性
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="property"></param>
        /// <param name="findByValue">该方法是用仓储根据属性的值加载对象,请指定QueryLevel.HoldSingle锁,来避免并发冲突</param>
        /// <returns></returns>
        private static bool IsPropertyRepeated <T>(T obj, DomainProperty property, out string value) where T : class, IAggregateRoot
        {
            value = null;
            if (!obj.IsPropertyDirty(property))
            {
                return(false);
            }
            string propertyValue = obj.GetPropertyValue <string>(property.Name);

            if (string.IsNullOrEmpty(propertyValue))
            {
                return(false);
            }

            var exp    = _getPropertyNameCondition(property.Name);
            var target = DataContext.Current.QuerySingle <T>(exp, (data) =>
            {
                data.Add(property.Name, propertyValue);
            }, QueryLevel.HoldSingle);

            value = propertyValue;
            if (target.IsEmpty())
            {
                return(false);                   //如果没有找到,那么没有重复
            }
            if (target.Equals(obj))
            {
                return(false);                    //如果找到了但是跟obj一样,那么也不算重复
            }
            return(true);
        }
Пример #5
0
        static BookPoster()
        {
            TitleProperty           = DomainProperty.Register <string, BookPoster>("Title");
            ProviderCompanyProperty = DomainProperty.Register <string, BookPoster>("ProviderCompany");

            Empty = new BookPosterEmpty();
        }
            static Bookmark()
            {
                PageIndexProperty   = DomainProperty.Register <int, Bookmark>("PageIndex", 0);
                DescriptionProperty = DomainProperty.Register <string, Bookmark>("Description");

                Empty = new BookmarkEmpty();
            }
            static BookCover()
            {
                TitleProperty  = DomainProperty.Register <string, BookCover>("Title");
                NumberProperty = DomainProperty.Register <string, BookCover>("Number");

                Empty = new BookCoverEmpty();
            }
Пример #8
0
        static BookReader()
        {
            NameProperty = DomainProperty.Register <string, BookReader>("Name");
            SexProperty  = DomainProperty.Register <Sex, BookReader>("Sex", Sex.Male);

            Empty = new BookReaderEmpty();
        }
        private LinkedElementCollection <ClrAttribute> MapAttributesToClrAttributes(LinkedElementCollection <Attribute> attributes, Store store)
        {
            using (Transaction transaction = store.TransactionManager.BeginTransaction("Map attributes to ClrAttributes"))
            {
                var fakeProperty = new DomainProperty(store);
                var result       = fakeProperty.Attributes;

                foreach (var attribute in attributes)
                {
                    var clrAttribute = new ClrAttribute(store);
                    clrAttribute.Name = attribute.Name;

                    foreach (var attributeParameter in attribute.Parameters)
                    {
                        var clrAttributeParameter = new ClaAttributeParameter(store);
                        clrAttributeParameter.Name  = attributeParameter.Name;
                        clrAttributeParameter.Value = attributeParameter.Value;

                        clrAttribute.Parameters.Add(clrAttributeParameter);
                    }

                    result.Add(clrAttribute);
                }

                transaction.Commit();
                return(result);
            }
        }
Пример #10
0
        private void onPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            PropertyViewEntity propertyViewEntity = sender as PropertyViewEntity;

            if (propertyViewEntity == null)
            {
                return;
            }

            switch (args.PropertyName)
            {
            case "IsSelected": {
                if (propertyViewEntity.IsSelected)
                {
                    DomainProperty property = export.DomainObject.PropertyHeader.Properties.FirstOrDefault(p => p.NameIndex.Name == propertyViewEntity.Name &&
                                                                                                           p.ArrayIndex == propertyViewEntity.ArrayIndex);

                    if (property == null)
                    {
                        return;
                    }

                    messenger.Send(new PropertySelectedMessage {
                            Property = property
                        });
                }

                break;
            }

            default: {
                break;
            }
            }
        }
 static BookCategory()
 {
     NameProperty     = DomainProperty.Register <string, BookCategory>("Name");
     PhotoProperty    = DomainProperty.Register <BookCover, BookCategory>("Photo", (owner) => BookCover.Empty);
     BookmarkProperty = DomainProperty.Register <Bookmark, BookCategory>("Bookmark", (owner) => Bookmark.Empty);
     CommentsProperty = DomainProperty.RegisterCollection <Bookmark, BookCategory>("Comments");
     Empty            = new BookCategoryEmpty();
 }
Пример #12
0
        public static string GetEditorTypeName(DomainProperty p)
        {
            string n = p.Type.PropertyGridEditor.Namespace;

            n += "." + p.Type.PropertyGridEditor.Name;

            return(n);
        }
Пример #13
0
 public static IEnumerable <DomainProperty> GetProperties(Type objectType)
 {
     if (!objectType.IsDerived())
     {
         return(DomainProperty.GetProperties(objectType));
     }
     return(_getPropertiesByDerived(objectType));
 }
Пример #14
0
 public static string PropertyTypeDecl(DomainProperty property)
 {
     if (property.Length == 0)
     {
         return(TypeLookup(property.TypeName));
     }
     return($"Array<{TypeLookup(property.TypeName)}>");
 }
Пример #15
0
        static Author()
        {
            NameProperty   = DomainProperty.Register <string, Author>("Name");
            SexProperty    = DomainProperty.Register <Sex, Author>("Sex", Sex.Male);
            PersonProperty = DomainProperty.Register <Person, Author>("Person");

            Empty = new AuthorEmpty();
        }
Пример #16
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public ClassSchema()
        {
            Names        = new NameProvider("Class", "Classes", "c");
            GetAccess    = Access.All;
            CreateAccess = Access.All;
            DeleteAccess = Access.CreatorUserAndApp;
            IsAbstract   = false;
            CustomCreate = true;

            ////

            Name           = new DomainProperty <string>("Name", "c_na");
            Name.IsElastic = true;

            NameKey             = new DomainProperty <string>("NameKey", "c_nk");
            NameKey.ToLowerCase = true;
            NameKey.IsIndexed   = true;
            Name.ExactIndexVia  = NameKey;

            Disamb            = new DomainProperty <string>("Disamb", "c_di");
            Disamb.IsNullable = true;
            Disamb.IsElastic  = true;

            Note            = new DomainProperty <string>("Note", "c_no");
            Note.IsNullable = true;

            ////

            FabName = new ApiProperty <string>("Name");
            FabName.SetOpenAccess();
            FabName.LenMin       = 1;
            FabName.LenMax       = 128;
            FabName.ValidRegex   = ApiProperty.ValidTitleRegex;
            FabName.TraversalHas = Matching.None;

            FabDisamb = new ApiProperty <string>("Disamb");
            FabDisamb.SetOpenAccess();
            FabDisamb.IsNullable   = true;
            FabDisamb.LenMin       = 1;
            FabDisamb.LenMax       = 128;
            FabDisamb.ValidRegex   = ApiProperty.ValidTitleRegex;
            FabDisamb.TraversalHas = Matching.None;

            FabNote = new ApiProperty <string>("Note");
            FabNote.SetOpenAccess();
            FabNote.IsNullable   = true;
            FabNote.LenMin       = 1;
            FabNote.LenMax       = 256;
            FabNote.TraversalHas = Matching.None;

            ////

            FabNameMap = new PropertyMapping <string, string>(Name, FabName, CustomDir.ApiToDomain);
            FabNameMap.ApiToDomainNote = "Set Domain.NameKey = Api.Name.ToLower()";

            FabDisambMap = new PropertyMapping <string, string>(Disamb, FabDisamb);
            FabNoteMap   = new PropertyMapping <string, string>(Note, FabNote);
        }
        private object FindObject(RemotableAttribute tip, DTObject arg)
        {
            var idProperty = DomainProperty.GetProperty(tip.ObjectType, EntityObject.IdPropertyName);
            var id         = DataUtil.ToValue(arg.GetValue("id"), idProperty.PropertyType);

            var repository = Repository.Create(tip.ObjectType);

            return(repository.Find(id, QueryLevel.None));
        }
Пример #18
0
        public void Add(DomainProperty domProp)
        {
            if (DomainProperties.ContainsKey(domProp.Identifier))
            {
                throw new ArgumentException(string.Format("Domain property identifier already exist: {0}", domProp.Identifier));
            }

            DomainProperties.Add(domProp.Identifier, domProp);
        }
Пример #19
0
 static BookAddress()
 {
     NameProperty       = DomainProperty.Register <string, BookAddress>("Name");
     CategoryProperty   = DomainProperty.Register <BookCategory, BookAddress>("Category", (owner) => BookCategory.Empty);
     CategoriesProperty = DomainProperty.RegisterCollection <BookCategory, BookAddress>("Categories");
     PhotoProperty      = DomainProperty.Register <BookCover, BookAddress>("Photo", (owner) => BookCover.Empty);
     PhotosProperty     = DomainProperty.RegisterCollection <BookCover, BookAddress>("Photos");
     Empty = new BookAddressEmpty();
 }
Пример #20
0
 /// <summary>
 /// Interception de la génération d'un nom unique si le nom proposé n'est pas encore utilisé,
 /// on le prend sinon on rajoute un suffixe.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="baseName">The name for the element.</param>
 /// <param name="siblingNames">Names that can be added to the base name.</param>
 protected override void SetUniqueNameCore(ModelElement element, string baseName,
                                           IDictionary <string, ModelElement> siblingNames)
 {
     if (!siblingNames.ContainsKey(baseName))
     {
         DomainProperty.SetValue(element, baseName);
         return;
     }
     base.SetUniqueNameCore(element, baseName, siblingNames);
 }
Пример #21
0
        protected override object LoadData(DomainProperty property)
        {
            var tip = property.RepositoryTip;

            if (tip != null && tip.Lazy)
            {
                return(this.Table.ReadPropertyValue(this.Owner, tip, null, this.OriginalData));
            }
            return(null);
        }
Пример #22
0
        /// <summary>
        /// 验证属性值是否重复
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <param name="property"></param>
        public static void CheckPropertyRepeated <T>(T obj, DomainProperty property, ValidationResult result) where T : class, IAggregateRoot
        {
            object propertyValue = null;

            if (IsPropertyRepeated(obj, property, out propertyValue))
            {
                var code = _getProppertyRepeatedErrorCode(property);
                result.AddError(code, string.Format(Strings.PropertyValueRepeated, property.Name, propertyValue));
                return;
            }
        }
Пример #23
0
        private bool ContainsPropertyInInvolved(DomainProperty p)
        {
            foreach (DomainProperty refP in this.InvolvedProperties)
            {
                if (p.Name == refP.Name && p.Type.Name == refP.Type.Name && p.Type.Namespace == refP.Type.Namespace)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #24
0
        private bool HasProperty(List <DomainProperty> properties, DomainProperty p)
        {
            foreach (DomainProperty refP in properties)
            {
                if (p.Name == refP.Name && p.Type.Name == refP.Type.Name && p.Type.Namespace == refP.Type.Namespace)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #25
0
        protected override object LoadData(DomainProperty property)
        {
            var tip = property.RepositoryTip;

            //if (tip != null && tip.Lazy)
            if (tip != null)
            {
                var level = IsLoadByMirroring() ? QueryLevel.Mirroring : QueryLevel.None;
                return(this.Table.ReadPropertyValue(this.Owner, tip, null, this.OriginalData, level));
            }
            return(null);
        }
Пример #26
0
 public static string PropertyTypeDecl(DomainProperty property)
 {
     if (property.Domain.IsEnumeration(property.TypeName))
     {
         return($"{TypeLookup(property.TypeName)}?");
     }
     if (property.Length == 0)
     {
         return(TypeLookup(property.TypeName));
     }
     return($"[{TypeLookup(property.TypeName)}]");
 }
        protected void UseDefines(DTObject arg, Action <AggregateRootDefine, object> action)
        {
            var typeName = arg.GetValue <string>("typeName");
            var defines  = RemoteType.GetDefines(typeName);

            foreach (var define in defines)
            {
                var idProperty = DomainProperty.GetProperty(define.MetadataType, EntityObject.IdPropertyName);
                var id         = DataUtil.ToValue(arg.GetValue(EntityObject.IdPropertyName), idProperty.PropertyType);
                action((AggregateRootDefine)define, id);
            }
        }
Пример #28
0
        private DomainProperty GetProperty(DomainClass domainClass, DomainProperty referenceProperty)
        {
            foreach (DomainProperty p in domainClass.Properties)
            {
                if (p.Name == referenceProperty.Name && p.Type == referenceProperty.Type)
                {
                    return(p);
                }
            }

            return(null);
        }
Пример #29
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public InstanceSchema()
        {
            Names        = new NameProvider("Instance", "Instances", "i");
            GetAccess    = Access.All;
            CreateAccess = Access.All;
            DeleteAccess = Access.CreatorUserAndApp;
            IsAbstract   = false;
            CustomCreate = true;

            ////

            Name            = new DomainProperty <string>("Name", "i_na");
            Name.IsNullable = true;
            Name.IsElastic  = true;

            Disamb            = new DomainProperty <string>("Disamb", "i_di");
            Disamb.IsNullable = true;
            Disamb.IsElastic  = true;

            Note            = new DomainProperty <string>("Note", "i_no");
            Note.IsNullable = true;

            ////

            FabName = new ApiProperty <string>("Name");
            FabName.SetOpenAccess();
            FabName.IsNullable   = true;
            FabName.LenMin       = 1;
            FabName.LenMax       = 128;
            FabName.ValidRegex   = ApiProperty.ValidTitleRegex;
            FabName.TraversalHas = Matching.None;

            FabDisamb = new ApiProperty <string>("Disamb");
            FabDisamb.SetOpenAccess();
            FabDisamb.IsNullable   = true;
            FabDisamb.LenMin       = 1;
            FabDisamb.LenMax       = 128;
            FabDisamb.ValidRegex   = ApiProperty.ValidTitleRegex;
            FabDisamb.TraversalHas = Matching.None;

            FabNote = new ApiProperty <string>("Note");
            FabNote.SetOpenAccess();
            FabNote.IsNullable   = true;
            FabNote.LenMin       = 1;
            FabNote.LenMax       = 256;
            FabNote.TraversalHas = Matching.None;

            ////

            FabNameMap   = new PropertyMapping <string, string>(Name, FabName);
            FabDisambMap = new PropertyMapping <string, string>(Disamb, FabDisamb);
            FabNoteMap   = new PropertyMapping <string, string>(Note, FabNote);
        }
Пример #30
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public AppSchema()
        {
            Names        = new NameProvider("App", "Apps", "p");
            GetAccess    = Access.All;
            CreateAccess = Access.Internal;
            DeleteAccess = Access.Internal;
            IsAbstract   = false;

            ////

            Name           = new DomainProperty <string>("Name", "p_na");
            Name.IsUnique  = true;
            Name.IsElastic = true;

            NameKey = new DomainProperty <string>("NameKey", "p_nk");
            NameKey.EnforceUnique = true;
            NameKey.ToLowerCase   = true;
            NameKey.IsIndexed     = true;
            Name.ExactIndexVia    = NameKey;

            Secret = new DomainProperty <string>("Secret", "p_se");

            OauthDomains            = new DomainProperty <string>("OauthDomains", "p_od");
            OauthDomains.IsNullable = true;

            ////

            FabName              = new ApiProperty <string>("Name");
            FabName.GetAccess    = Access.All;
            FabName.IsUnique     = true;
            FabName.LenMin       = 3;
            FabName.LenMax       = 64;
            FabName.ValidRegex   = ApiProperty.ValidTitleRegex;
            FabName.TraversalHas = Matching.None;

            FabSecret            = new ApiProperty <string>("Secret");
            FabSecret.LenMin     = 32;
            FabSecret.LenMax     = 32;
            FabSecret.ValidRegex = ApiProperty.ValidCodeRegex;

            FabOauthDomains                  = new ApiProperty <string>("OauthDomains");
            FabOauthDomains.IsNullable       = true;
            FabOauthDomains.CustomValidation = true;

            ////

            FabNameMap = new PropertyMapping <string, string>(Name, FabName, CustomDir.ApiToDomain);
            FabNameMap.ApiToDomainNote = "Set Domain.NameKey = Api.Name.ToLower()";

            FabSecretMap = new PropertyMapping <string, string>(Secret, FabSecret);

            FabOauthDomainsMap = new PropertyMapping <string, string>(OauthDomains, FabOauthDomains);
        }
        private bool ContainsPropertyInInvolved(DomainProperty p)
        {
            foreach (DomainProperty refP in this.InvolvedProperties)
                if (p.Name == refP.Name && p.Type.Name == refP.Type.Name && p.Type.Namespace == refP.Type.Namespace)
                    return true;

            return false;
        }
        /// <summary>
        /// Applies the optimization.
        /// </summary>
        /// <param name="metaModel"></param>
        /// <param name="modelContext"></param>
        public override void ApplyOptimization(bool bApplyForTempModel)
        {
            MetaModel metaModel;
            LibraryModelContext modelContext;
            if (bApplyForTempModel)
            {
                metaModel = this.TargetModel;
                modelContext = this.TargetModel.ModelContexts[0] as LibraryModelContext;
            }
            else
            {
                metaModel = this.MetaModel;
                modelContext = this.ModelContext;
            }

            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction("Apply optimization"))
            {
                DomainClass bClass = null;
                if (!IsInheritance)
                {
                    // create new base class to host the properties
                    bClass = new DomainClass(metaModel.Store);
                    modelContext.Classes.Add(bClass);
                    bClass.InheritanceModifier = InheritanceModifier.Abstract;

                    bClass.Name = GetUniqueNameForBaseClass();

                    // create inheritance rs to domain classes
                    foreach (DomainClass s in this.InvolvedClasses)
                    {
                        DomainClass domainClass;
                        if (bApplyForTempModel)
                            domainClass = bClass.Store.ElementDirectory.FindElement(this.InvolvedClassesTargetMapping[s.Id]) as DomainClass;
                        else
                            domainClass = s;
                        if (domainClass == null)
                            throw new ArgumentNullException("DomainClass not found: Target Mappping error.. ");

                        new DomainClassReferencesBaseClass(domainClass, bClass);
                    }
                }
                else
                {
                    if (CreateIntermediate)
                    {
                        // create class
                        using (Transaction tD = this.MetaModel.Store.TransactionManager.BeginTransaction("Create intermediate Base class"))
                        {
                            DomainClass intermediateBaseClass = new DomainClass(metaModel.Store);
                            modelContext.Classes.Add(intermediateBaseClass);

                            intermediateBaseClass.InheritanceModifier = InheritanceModifier.Abstract;
                            intermediateBaseClass.Name = GetUniqueNameForBaseClass();

                            bClass = intermediateBaseClass;
                            tD.Commit();
                        }

                        // create inheritance rs to domain classes
                        foreach (DomainClass s in this.InvolvedClasses)
                        {
                            if (s == this.BaseClass)
                                continue;

                            DomainClass domainClass;
                            if (bApplyForTempModel)
                                domainClass = bClass.Store.ElementDirectory.FindElement(this.InvolvedClassesTargetMapping[s.Id]) as DomainClass;
                            else
                                domainClass = s;
                            if (domainClass == null)
                                throw new ArgumentNullException("DomainClass not found: Target Mappping error.. ");


                            using (Transaction t2 = this.MetaModel.Store.TransactionManager.BeginTransaction("Base class"))
                            {
                                domainClass.BaseClass = null;
                                t2.Commit();
                            }

                            using (Transaction t3 = this.MetaModel.Store.TransactionManager.BeginTransaction("Add inh class"))
                            {
                                new DomainClassReferencesBaseClass(domainClass, bClass);
                                t3.Commit();
                            }
                        }

                        // create inheritance from intermediate base class to base class
                        DomainClass curBaseClass;
                        if (bApplyForTempModel)
                            curBaseClass = metaModel.Store.ElementDirectory.FindElement(this.InvolvedClassesTargetMapping[this.BaseClass.Id]) as DomainClass;
                        else
                            curBaseClass = this.BaseClass;
                        new DomainClassReferencesBaseClass(bClass, curBaseClass);

                        
                    }
                    else
                    {
                        // get base class
                        if (bApplyForTempModel)
                            bClass = metaModel.Store.ElementDirectory.FindElement(this.InvolvedClassesTargetMapping[this.BaseClass.Id]) as DomainClass;
                        else
                            bClass = this.BaseClass;
                    }
                }

                if (bClass == null)
                    throw new ArgumentNullException("Couldn't retrieve base class");

                // remove properties from domain classes
                List<DomainProperty> toDelete = new List<DomainProperty>();
                foreach (DomainClass d in this.InvolvedClasses)
                {
                    if (d == this.BaseClass)
                        continue;

                    DomainClass domainClass;
                    if (bApplyForTempModel)
                        domainClass = bClass.Store.ElementDirectory.FindElement(this.InvolvedClassesTargetMapping[d.Id]) as DomainClass;
                    else
                        domainClass = d;
                    
                    if (domainClass == null)
                        throw new ArgumentNullException("DomainClass not found: Target Mappping error.. ");

                    for (int i = domainClass.Properties.Count - 1; i >= 0; i--)
                        if (ContainsPropertyInInvolved(domainClass.Properties[i]))
                            toDelete.Add(domainClass.Properties[i]);
                }

                foreach (DomainProperty p in toDelete)
                    if( !p.IsDeleted && !p.IsDeleting )
                        p.Delete();

                // add properties on bClass
                foreach (DomainProperty p in this.InvolvedProperties)
                {
                    DomainProperty domainProperty = new DomainProperty(bClass.Store);
                    domainProperty.Name = p.Name;
                    domainProperty.Type = p.Type;
                    domainProperty.IsElementName = p.IsElementName;

                    bClass.Properties.Add(domainProperty);
                }


                t.Commit();
            }
        }
Пример #33
0
        public DomainPropertyCollection GetEmptyProperties(SessionIdentifier sessionId, ObjectIdentifier parentId)
        {
            DomainObjectConfig obj = m_inquiry.AObject[parentId.Code];
            DomainPropertyCollection result = new DomainPropertyCollection();

            foreach (DomainPropertyConfig prop in obj.Property)
            {
                DomainProperty newProperty = new DomainProperty(sessionId, parentId, prop.Code, prop.DefaultValue);
                result.Add(newProperty);
            }

            return result;
        }
Пример #34
0
        private DomainPropertyCollection LoadProperties(SessionIdentifier sessionId, ObjectIdentifier objectId)
        {
            string objCode = objectId.Code;

            DomainObjectConfig objConfig = m_inquiry.AObject[objCode];
            DomainObjectBroker broker = GetObjectBroker(objCode);

            long[] idList = new long[] { objectId.Id };

            DbCommonCommand command = broker.LoadItemsCommand;
            command["ID"].Value = idList;

            DomainPropertyCollection result = null;
            using (IDbCommonDataReader reader = command.ExecuteReader(sessionId))
            {
                if (!reader.Read())
                {
                    reader.Close();
                    throw new DomainException(String.Format("Объект {0} не найден в БД", objectId));
                }

                result = new DomainPropertyCollection();
                foreach (DomainPropertyConfig prop in objConfig.Property)
                {
                    object value = reader.GetValue(reader.GetOrdinal(prop.Code), prop.DataType);
                    DomainProperty newProperty = new DomainProperty(sessionId, objectId, prop.Code, value);
                    result.Add(newProperty);
                }
                reader.Close();
            }

            return result;
        }
        /// <summary>
        /// Adds a new element view model for the given element.
        /// </summary>
        /// <param name="element">Element.</param>
        public void AddProperty(DomainProperty element)
        {
            if (element == null)
                return;

            // verify that node hasnt been added yet
            foreach (DomainPropertyViewModel viewModel in this.propertiesVM)
                if (viewModel.DomainProperty.Id == element.Id)
                    return;

            DomainPropertyViewModel vm = new DomainPropertyViewModel(this.ViewModelStore, element, this);
            this.propertiesVM.Add(vm);

            OnPropertyChanged("HasDomainProperties");
            OnPropertyChanged("PropertiesDescription");
        }
        /// <summary>
        /// Deletes the element view model that is hosting the given element.
        /// </summary>
        /// <param name="node">Element.</param>
        public void DeleteProperty(DomainProperty element)
        {
            if (element == null)
                return;

            for (int i = this.propertiesVM.Count - 1; i >= 0; i--)
                if (this.propertiesVM[i].DomainProperty.Id == element.Id)
                {
                    this.propertiesVM[i].Dispose();
                    this.propertiesVM.RemoveAt(i);
                }
            
            OnPropertyChanged("HasDomainProperties");
            OnPropertyChanged("PropertiesDescription");
        }
        private bool HasProperty(List<DomainProperty> properties, DomainProperty p)
        {
            foreach (DomainProperty refP in properties)
                if (p.Name == refP.Name && p.Type.Name == refP.Type.Name && p.Type.Namespace == refP.Type.Namespace)
                    return true;

            return false;
        }
Пример #38
0
 private DomainProperty CloneProperty(DomainProperty property, SessionIdentifier newSession)
 {
     return new DomainProperty(newSession, property.m_parentId, property.Code, property.Value);
 }
        /// <summary>
        /// Creates the temp model.
        /// </summary>
        /// <returns></returns>
        public override void CreateTempModel(MetaModel m, bool bIsTarget)
        {
            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                // add properties to domain classes
                foreach (DomainClass key in this.InvolvedClasses)
                {
                    if (key == BaseClass)
                        continue;

                    DomainClass d;
                    if( !bIsTarget )
                        d = m.Store.ElementDirectory.FindElement(this.InvolvedClassesMapping[key.Id]) as DomainClass;
                    else
                        d = m.Store.ElementDirectory.FindElement(this.InvolvedClassesTargetMapping[key.Id]) as DomainClass;
                    if (d == null)
                        throw new ArgumentNullException("DomainClass not found: Mappping error.. ");

                    // create properties
                    foreach (DomainProperty p in this.InvolvedProperties)
                    {
                        DomainProperty domainProperty = new DomainProperty(m.Store);
                        domainProperty.Name = p.Name;
                        domainProperty.Type = p.Type;

                        d.Properties.Add(domainProperty);
                    }
                }

                t.Commit();
            }
        }
        private DomainProperty GetProperty(DomainClass domainClass, DomainProperty referenceProperty)
        {
            foreach (DomainProperty p in domainClass.Properties)
                if (p.Name == referenceProperty.Name && p.Type == referenceProperty.Type)
                    return p;

            return null;
        }