Exemplo n.º 1
0
        private void NameIsUniqueForAClass <T>(IObjectSpace objectSpace) where T : IPersistentMemberInfo
        {
            var memberInfo = objectSpace.Create <T>();

            memberInfo.Name = "name";
            var persistentClassInfo = objectSpace.Create <IPersistentClassInfo>();

            memberInfo.Owner = persistentClassInfo;
            memberInfo       = objectSpace.Create <T>();
            memberInfo.Name  = "name";
            memberInfo.Owner = objectSpace.Create <IPersistentClassInfo>();

            objectSpace.CommitChanges();
            var usedProperties = nameof(memberInfo.Name);


            Validator.RuleSet.StateOf <RuleCombinationOfPropertiesIsUnique>(memberInfo, usedProperties)
            .Should()
            .Be(ValidationState.Valid);

            memberInfo.Owner = persistentClassInfo;

            Validator.RuleSet.StateOf <RuleCombinationOfPropertiesIsUnique>(memberInfo, usedProperties)
            .Should()
            .Be(ValidationState.Invalid);
        }
Exemplo n.º 2
0
        void HandleError(XElement element, FailReason failReason, ElementSchema elementSchema, IObjectSpace objectSpace = null)
        {
            objectSpace = objectSpace ?? _objectSpace;
            string innerXml = null;
            string elementXml;
            var    firstOrDefault = element.Ancestors(elementSchema.SerializedObject).FirstOrDefault();

            if (firstOrDefault != null && firstOrDefault != element)
            {
                innerXml   = element.ToString();
                elementXml = firstOrDefault.ToString();
            }
            else
            {
                elementXml = element.ToString();
            }

            if (_errorHandling == ErrorHandling.CreateErrorObjects)
            {
                var errorInfoObject = objectSpace.Create <IIOError>();
                errorInfoObject.Reason     = failReason;
                errorInfoObject.ElementXml = elementXml;
                errorInfoObject.InnerXml   = innerXml;
                objectSpace.CommitChanges();
                throw new UserFriendlyException("Import failed check IOError list for details.");
            }

            if (_errorHandling == ErrorHandling.ThrowException)
            {
                throw new UserFriendlyException(new Exception("ImportFailed", new Exception("Reason=" + failReason + "ELEMENTXML=" + elementXml + " INNERXML=" + innerXml)));
            }
        }
Exemplo n.º 3
0
        public IEnumerable <IPersistentAttributeInfo> Create()
        {
            var persistentAttributeInfos = new List <IPersistentAttributeInfo>();

            if (_persistentClassInfo.TypeAttributes.OfType <IPersistentPersistentAttribute>().FirstOrDefault() == null)
            {
                persistentAttributeInfos.Add(GetPersistentPersistentAttribute(_dbTable.Name));
            }
            if (!(string.IsNullOrEmpty(_navigationPath)) && _persistentClassInfo.TypeAttributes.OfType <IPersistentNavigationItemAttribute>().FirstOrDefault() == null)
            {
                var persistentNavigationItemAttribute = _objectSpace.Create <IPersistentNavigationItemAttribute>();
                var cleanName = _persistentClassInfo.Name.CleanCodeName();
                persistentNavigationItemAttribute.Path   = _navigationPath + "/" + cleanName;
                persistentNavigationItemAttribute.ViewId = cleanName + "_ListView";
                persistentAttributeInfos.Add(persistentNavigationItemAttribute);
            }
            return(persistentAttributeInfos);
        }
Exemplo n.º 4
0
        IPersistentMemberInfo CreatePersistentReferenceMemberInfo(string name, IPersistentClassInfo persistentClassInfo, IPersistentClassInfo persistentReferenceClassInfo, TemplateType templateType)
        {
            var persistentReferenceMemberInfo = _objectSpace.Create <IPersistentReferenceMemberInfo>();

            persistentReferenceMemberInfo.Name = name;
            persistentReferenceMemberInfo.ReferenceClassInfo = persistentReferenceClassInfo;
            if (persistentClassInfo == null)
            {
                persistentClassInfo = _classInfos[ClassGenerator.GetTableName(_dbTable.Name)].PersistentClassInfo;
            }
            persistentClassInfo.OwnMembers.Add(persistentReferenceMemberInfo);
            persistentReferenceMemberInfo.SetDefaultTemplate(templateType);
            if (templateType != TemplateType.XPOneToOnePropertyMember && templateType != TemplateType.XPOneToOneReadOnlyPropertyMember && persistentClassInfo.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.Class && persistentReferenceClassInfo.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.Class)
            {
                CreateCollection(persistentReferenceMemberInfo, persistentClassInfo);
            }
            return(persistentReferenceMemberInfo);
        }
Exemplo n.º 5
0
        public IPersistentClassInfo CreateClassInfo(string name, TemplateType templateType = TemplateType.Class)
        {
            var persistentClassInfo = _objectSpace.Create <IPersistentClassInfo>();

            _persistentAssemblyInfo.PersistentClassInfos.Add(persistentClassInfo);
            persistentClassInfo.SetDefaultTemplate(templateType);
            persistentClassInfo.Name = GetTableName(name);
            persistentClassInfo.PersistentAssemblyInfo = _persistentAssemblyInfo;
            persistentClassInfo.BaseType = typeof(XPLiteObject);
            return(persistentClassInfo);
        }
Exemplo n.º 6
0
        IClassInfoGraphNode CreateClassInfoGraphNode(IObjectSpace objectSpace, IMemberInfo memberInfo, NodeType nodeType)
        {
            var classInfoGraphNode = objectSpace.Create <IClassInfoGraphNode>();

            classInfoGraphNode.Name = memberInfo.Name;
            classInfoGraphNode.SerializationStrategy = GetSerializationStrategy(memberInfo, classInfoGraphNode.SerializationStrategy);
            classInfoGraphNode.TypeName = GetSerializedType(memberInfo).Name;
            classInfoGraphNode.NodeType = nodeType;
            classInfoGraphNode.Key      = IsKey(memberInfo);
            return(classInfoGraphNode);
        }
        private IPersistentAttributeInfo GetBrowsableAttribute()
        {
            var persistentVisibleInDetailViewAttribute = _objectSpace.Create <IPersistentVisibleInDetailViewAttribute>();

            persistentVisibleInDetailViewAttribute.Visible = false;
            return(persistentVisibleInDetailViewAttribute);
        }
Exemplo n.º 8
0
        public void Create()
        {
            Dictionary <string, ClassGeneratorInfo> generatorInfos = new ClassGenerator(_persistentAssemblyInfo, _storageTables).CreateAll().ToDictionary(classGeneratorInfo => classGeneratorInfo.PersistentClassInfo.Name);

            foreach (var classGeneratorInfo in generatorInfos.Where(pair => pair.Value.PersistentClassInfo.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.Class))
            {
                var generatorInfo = classGeneratorInfo.Value;
                new ClassAtrributeGenerator(generatorInfo, _navigationPath).Create().Each(info => generatorInfo.PersistentClassInfo.TypeAttributes.Add(info));
                var memberGeneratorInfos = new MemberGenerator(classGeneratorInfo.Value.DbTable, generatorInfos).Create();
                memberGeneratorInfos.Each(info => new MemberAttributeGenerator(info, generatorInfo).Create());
            }
            var oneToOneMemberInfos = _persistentAssemblyInfo.PersistentClassInfos.SelectMany(info => info.OwnMembers.OfType <IPersistentReferenceMemberInfo>()).Where(info => info.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.XPOneToOnePropertyMember);

            foreach (var oneToOneMemberInfo in oneToOneMemberInfos)
            {
                var codeTemplate = _objectSpace.Create <ICodeTemplate>();
                codeTemplate.TemplateCode = oneToOneMemberInfo.ReferenceClassInfo.OwnMembers.OfType <IPersistentReferenceMemberInfo>().Single(info => info.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.XPOneToOnePropertyMember).Name;
                oneToOneMemberInfo.TemplateInfos.Add(codeTemplate);
            }
            _persistentAssemblyInfo.SupportCompositeKeyPersistentObjects();
            CreateAssemblyAttributes();
        }
Exemplo n.º 9
0
        ISerializationConfiguration GetConfiguration(Type type)
        {
            var configuration = _serializationConfigurationGroup.Configurations.FirstOrDefault(config => config.TypeToSerialize == type);

            if (configuration == null)
            {
                configuration = _objectSpace.Create <ISerializationConfiguration>();
                configuration.SerializationConfigurationGroup = _serializationConfigurationGroup;
                configuration.TypeToSerialize = type;
                new ClassInfoGraphNodeBuilder().Generate(configuration);
            }
            return(configuration);
        }
Exemplo n.º 10
0
        void Generate(IObjectSpace objectSpace, Type typeToSerialize)
        {
            var bussinessObjectType = objectSpace.TypesInfo.FindBussinessObjectType <ISerializationConfiguration>();
            var configuration       = (ISerializationConfiguration)objectSpace.FindObject(bussinessObjectType,
                                                                                          CriteriaOperator.Parse(
                                                                                              $"{nameof(ISerializationConfiguration.SerializationConfigurationGroup)}=? AND {nameof(ISerializationConfiguration.TypeToSerialize)}=?",
                                                                                              _serializationConfigurationGroup, typeToSerialize));

            if (configuration == null)
            {
                var serializationConfiguration = objectSpace.Create <ISerializationConfiguration>();
                serializationConfiguration.SerializationConfigurationGroup = _serializationConfigurationGroup;
                serializationConfiguration.TypeToSerialize = typeToSerialize;
                Generate(serializationConfiguration);
            }
        }