Ejemplo n.º 1
0
        public CqrsDataModelBuilder SetCurrentNamespace(string namespaceName)
        {
            var currentProject = GetOrCreateNamespaceModel(CurrentProjectModel, namespaceName);

            CurrentNamespaceModel = currentProject;
            return(this);
        }
        private MarkdownTemplateModel InitNamespaceTemplateModel(NamespaceModel item)
        {
            var @namespace = InitBaseTemplateModel(item);

            @namespace.Classes =
                _models
                .Values
                .Where(model => item.Classes.FirstOrDefault(s => model.FullName == s) != null)
                .ToList();
            @namespace.Interfaces =
                _models
                .Values
                .Where(model => item.Interfaces.FirstOrDefault(s => model.FullName == s) != null)
                .ToList();
            @namespace.Structs =
                _models
                .Values
                .Where(model => item.Structs.FirstOrDefault(s => model.FullName == s) != null)
                .ToList();
            @namespace.Enums =
                _models
                .Values
                .Where(model => item.Enums.FirstOrDefault(s => model.FullName == s) != null)
                .ToList();
            @namespace.Delegates = _models
                                   .Values
                                   .Where(model => item.Delegates.FirstOrDefault(s => model.FullName == s) != null)
                                   .ToList();
            @namespace.Attributes = _models
                                    .Values
                                    .Where(model => item.Attributes.FirstOrDefault(s => model.FullName == s) != null)
                                    .ToList();
            @namespace.FilePath = $"{@namespace.Name.Replace('.', '/')}/{@namespace.Name}.md";
            return(@namespace);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds the specified assembly name.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <returns></returns>
        public NamespaceModel Build(string assemblyName)
        {
            var alternateName = GetAlternateName(assemblyName);
            var nm            = new NamespaceModel {
                Name = assemblyName,
            };
            var exclude = this.GetType().Assembly;

            var xml          = LoadXml(assemblyName);
            var NSIgnoreList = ConfigurationManager.AppSettings["site:NamespacesIgnoreList"].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            DocumentationAssemblies.Where(a => a != exclude &&
                                          (a.GetName().Name.Equals(alternateName, StringComparison.InvariantCultureIgnoreCase) || a.GetName().Name.Equals(assemblyName, StringComparison.InvariantCultureIgnoreCase))
                                          ).ForEach(a => {
                a.GetTypes()
                .Where(t => ((t.IsInNamespace(alternateName) || t.IsInNamespace(assemblyName)) || (t.IsInChildNamespace(alternateName) || t.IsInChildNamespace(assemblyName))) && !NSIgnoreList.Contains(t.Namespace))
                .Select(t => t.Namespace)
                .Distinct()
                .ForEach(ns => {
                    if (string.IsNullOrWhiteSpace(nm.AssemblyVersion))
                    {
                        nm.AssemblyVersion = a.GetName().Version.ToString();
                    }
                    var processedNS = ProcessNamespace(ns, xml);
                    if (processedNS != null && processedNS.Classes.Count > 0)
                    {
                        nm.Namespaces.Add(processedNS);
                    }
                });
            });
            return(nm);
        }
        public void OpenNamespaceTestCase()
        {
            string         namespaceCode = "ExampleNamespaceCode";
            NamespaceModel selectedModel = null;

            GivenShowEmptyPage()
            .And("Open settings.",
                 viewModel => viewModel.UiServices.GetUiService <IUiSettings>().OpenSettingsAsync(null))
            .AndWait(Timeouts.Second.One)
            .When("Open namespace.", () =>
            {
                var page      = CheckTypeAndGetPage <ContextPage>();
                var list      = page.FindChildByName <ListBox>("listNamespaces");
                selectedModel = page
                                .CheckTypeAndDataContext <ContextViewModel>()
                                .Context
                                .Namespaces
                                .First(n => n.Code.EqualsOrdinalIgnoreCase(namespaceCode));
                list.SelectedItem = selectedModel;
            })
            .ThenWait(Timeouts.Second.One)
            .And("Check page.", () =>
            {
                NamespaceModel namespaceModel = CheckTypeAndGetPage <NamespacePage>()
                                                .CheckTypeAndDataContext <NamespaceViewModel>()
                                                .Namespace;

                Assert.AreEqual(selectedModel, namespaceModel, "Expected another namespaceModel");
            })
            .RunTestWindow(Timeouts.Minute.One);
        }
Ejemplo n.º 5
0
 public static NamespaceBase NamespaceBase(NamespaceModel namespaceModel)
 {
     return(new NamespaceBase()
     {
         Name = namespaceModel.Name,
         Types = namespaceModel.Types?.Select(GetOrAdd).ToList()
     });
 }
Ejemplo n.º 6
0
        private IEnumerable <CodeNamespace> GenerateCode()
        {
            var hierarchy = NamespaceHierarchyItem.Build(Namespaces.Values.GroupBy(x => x.Name).SelectMany(x => x))
                            .MarkAmbiguousNamespaceTypes();

            return(hierarchy.Flatten()
                   .Select(nhi => NamespaceModel.Generate(nhi.FullName, nhi.Models)));
        }
Ejemplo n.º 7
0
        public NamespaceModel ToModel()
        {
            NamespaceModel namespaceModel = new NamespaceModel();

            namespaceModel.NamespaceName = NamespaceName;
            namespaceModel.Types         = Types.Select(model => model.ToModel());
            return(namespaceModel);
        }
Ejemplo n.º 8
0
        public NamespaceViewModel(NamespaceModel namespaceModel, TreeNodeViewModel parent)
            : base(namespaceModel.Name, parent)
        {
            NamespaceModel = namespaceModel;

            if (NamespaceModel.Namespaces?.Count > 0 || NamespaceModel?.Types.Count > 0)
            {
                AddDummyChild();
            }
        }
Ejemplo n.º 9
0
        private async Task GenerateNamespace(NamespaceModel @namespace, DirectoryInfo di)
        {
            foreach (var type in @namespace.Types)
            {
                await GenerateCodeFile(type, di);
            }

            foreach (var ns in @namespace.Namespaces)
            {
                await GenerateNamespace(ns, di.CreateSubdirectory(ns.Name));
            }
        }
        internal static NamespaceModel MapToNamespaceModel(this SettingNamespace settingNamespace, string namespacesPath, GrViewModelBase viewModel)
        {
            var result = new NamespaceModel
            {
                NamespacePath = namespacesPath,
                Namespace     = settingNamespace,
                Settings      = new ObservableCollection <SettingModel>(),
            };

            viewModel.BindModel(result);
            return(result);
        }
Ejemplo n.º 11
0
        public static string GetUniqueTypeName(this NamespaceModel model, string name)
        {
            var n = name;
            var i = 2;

            while (model.Types.ContainsKey(n) && !(model.Types[n] is SimpleModel))
            {
                n = name + i;
                i++;
            }

            return(n);
        }
Ejemplo n.º 12
0
        private void PropertyModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            NamespaceModel namespaceModel = sender as NamespaceModel;

            if (namespaceModel.Selected)
            {
                _iswixNamespaces.Add(namespaceModel.Prefix, namespaceModel.Uri);
            }
            else
            {
                _iswixNamespaces.Remove(namespaceModel.Prefix);
            }
        }
Ejemplo n.º 13
0
        public BaseNamespaceModel MapDown(NamespaceModel model, Type namespaceModelType)
        {
            object       namespaceModel          = Activator.CreateInstance(namespaceModelType);
            PropertyInfo nameProperty            = namespaceModelType.GetProperty("Name");
            PropertyInfo namespaceModelsProperty = namespaceModelType.GetProperty("Types",
                                                                                  BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            nameProperty?.SetValue(namespaceModel, model.Name);
            namespaceModelsProperty?.SetValue(namespaceModel,
                                              HelperClass.ConvertList(namespaceModelsProperty.PropertyType.GetGenericArguments()[0],
                                                                      model.Types.Select(t => new TypeModelMapper().MapDown(t, namespaceModelsProperty.PropertyType.GetGenericArguments()[0])).ToList()));

            return((BaseNamespaceModel)namespaceModel);
        }
Ejemplo n.º 14
0
        public override void GenerateModule(Module module, NamespaceModel @namespace, ITypeModelRegistry registry)
        {
            if (GetTypes(module).Any())
            {
                var @class = @namespace.AddClass($"{module.Name}DbContext");

                foreach (var aggregate in module.GetTypes <Aggregate>())
                {
                    @class.AddProperty($"{aggregate.Name}Set", SystemTypes.DbSet(registry.Resolve(Layer, aggregate)));
                }

                registry.Register(Layer, module, @class);
            }
        }
        public void SetValueTestCase()
        {
            string         namespaceCode = "SubExampleNamespaceCode";
            string         settingCode   = "SettingInt";
            string         invalidValue  = "1234";
            NamespaceModel selectedModel = null;
            ValueTask <List <Setting> > openSettingsTask = default;

            GivenShowEmptyPage()
            .And("Open settings.",
                 viewModel => openSettingsTask = viewModel.UiServices.GetUiService <IUiSettings>().OpenSettingsAsync(null))
            .AndWait(Timeouts.Second.One)
            .And("Open namespace.", () =>
            {
                var page      = CheckTypeAndGetPage <ContextPage>();
                var list      = page.FindChildByName <ListBox>("listNamespaces");
                selectedModel = page
                                .CheckTypeAndDataContext <ContextViewModel>()
                                .Context
                                .Namespaces
                                .First(n => n.Code.EqualsOrdinalIgnoreCase(namespaceCode));
                list.SelectedItem = selectedModel;
            })
            .AndWait(Timeouts.Second.One)
            .And("Set value", () =>
            {
                var settingModel   = selectedModel.Settings.First(s => s.Code.EqualsOrdinalIgnoreCase(settingCode));
                settingModel.Value = invalidValue;
            })
            .AndWait(Timeouts.Second.One)
            .And("Close Namespace page.",
                 () => CheckTypeAndGetPage <NamespacePage>().FindChildByName <Button>("btnOk").OnClick())
            .AndWait(Timeouts.Second.One)
            .WhenAsync("Close Context page.", async() =>
            {
                CheckTypeAndGetPage <ContextPage>().FindChildByName <Button>("btnOk").OnClick();
                return(await openSettingsTask);
            })
            .Then("Check result", settings =>
            {
                Setting setting = settings.Single();

                Assert.AreEqual(settingCode, setting.Code, "Expected another code.");
                var expectedSetting = GetAdapter <SettingsAdapter>().GetSetting(setting.FullCode);
                Assert.AreEqual(expectedSetting.Value, setting.Value, "Expected another value.");
            })
            .RunTestWindow(Timeouts.Minute.One);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Processes the namespace.
        /// </summary>
        /// <param name="namespace">The namespace.</param>
        /// <param name="xml">The XML.</param>
        /// <returns></returns>
        private NamespaceModel ProcessNamespace(string @namespace, XmlDocument xml)
        {
            var nm = new NamespaceModel {
                Name = @namespace
            };

            DocumentationAssemblies.ForEach(a => {
                var classes = new List <ClassModel>();
                a.GetTypes().Where(t => t.IsPublic && t.IsClass && t.IsInNamespace(@namespace)).ForEach(t => {
                    var pclass = ProcessType(t, xml);
                    nm.Classes.Add(pclass);
                });
            });

            return(nm);
        }
Ejemplo n.º 17
0
        public NamespaceModel MapUp(BaseNamespaceModel model)
        {
            NamespaceModel namespaceModel = new NamespaceModel();

            namespaceModel.Name = model.Name;
            Type         type          = model.GetType();
            PropertyInfo typesProperty = type.GetProperty("Types",
                                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            List <BaseTypeModel> types = (List <BaseTypeModel>)HelperClass.ConvertList(typeof(BaseTypeModel), (IList)typesProperty?.GetValue(model));

            if (types != null)
            {
                namespaceModel.Types = types.Select(n => TypeModelMapper.EmitType(n)).ToList();
            }
            return(namespaceModel);
        }
        public void SetInvalidValueTestCase()
        {
            string namespaceCode     = "SubExampleNamespaceCode";
            string settingCode       = "SettingInt";
            string invalidValue      = "Hey!";
            var    settingValueError = new SettingValueError
            {
                ErrorMessage    = "Error Errrorroororororor",
                SettingFullCode = $"ExampleNamespaceCode.{namespaceCode}.{settingCode}"
            };
            NamespaceModel selectedModel = null;

            GivenShowEmptyPage()
            .And("Open settings.",
                 viewModel => viewModel.UiServices.GetUiService <IUiSettings>().OpenSettingsAsync(new List <SettingValueError> {
                settingValueError
            }))
            .AndWait(Timeouts.Second.Two)
            .And("Open namespace.", () =>
            {
                var page      = CheckTypeAndGetPage <ContextPage>();
                var list      = page.FindChildByName <ListBox>("listNamespaces");
                selectedModel = page
                                .CheckTypeAndDataContext <ContextViewModel>()
                                .Context
                                .Namespaces
                                .First(n => n.Code.EqualsOrdinalIgnoreCase(namespaceCode));
                list.SelectedItem = selectedModel;
            })
            .AndWait(Timeouts.Second.One)
            .When("Set value", () =>
            {
                var settingModel   = selectedModel.Settings.First(s => s.Code.EqualsOrdinalIgnoreCase(settingCode));
                settingModel.Value = invalidValue;
            })
            .ThenWait(Timeouts.Second.One)
            .And("Check notification", () =>
            {
                var viewModel = CheckTypeAndGetPageSubFrame <NotificationWindowPage>().CheckTypeAndDataContext <NotificationWindowViewModel>();

                Assert.AreEqual(NotificationTypes.Warning, viewModel.Type, "Expected another notification type.");
                Assert.AreEqual($"- {settingValueError.ErrorMessage}", viewModel.Message, "Expected another notification message.");
            })
            .RunTestWindow(Timeouts.Minute.One);
        }
Ejemplo n.º 19
0
        private NamespaceModel CreateNamespaceModel(Uri source, XmlQualifiedName qualifiedName)
        {
            NamespaceModel namespaceModel = null;

            if (!qualifiedName.IsEmpty && qualifiedName.Namespace != XmlSchema.Namespace)
            {
                var key = new NamespaceKey(source, qualifiedName.Namespace);
                if (!Namespaces.TryGetValue(key, out namespaceModel))
                {
                    var namespaceName = BuildNamespace(source, qualifiedName.Namespace);
                    namespaceModel = new NamespaceModel(key, _configuration)
                    {
                        Name = namespaceName
                    };
                    Namespaces.Add(key, namespaceModel);
                }
            }
            return(namespaceModel);
        }
Ejemplo n.º 20
0
        private void PrepareModule(Module module, NamespaceModel @namespace, IEnumerable <ILayerCodeGenerator> generators)
        {
            foreach (var generator in generators)
            {
                foreach (var type in generator.GetTypes(module))
                {
                    var name = generator.GetTypeName(type);
                    if (name != null)
                    {
                        var model = generator.PrepareType(@namespace, type);
                        Register(generator.Layer, type, model.WithDescription(type.Description));
                    }
                }
            }

            module.Modules.ForEach(m =>
            {
                PrepareModule(m, @namespace.AddNamespace(m.Name), generators);
            });
        }
Ejemplo n.º 21
0
        public void LoadData()
        {
            ObservableCollection <NamespaceModel> namespaces = new ObservableCollection <NamespaceModel>();

            _iswixNamespaces = new WiXNamespaces();

            foreach (var iswixNamespace in _iswixNamespaces.PossibleNamespaces)
            {
                NamespaceModel namespaceModel = new NamespaceModel();
                if (_documentManager.Document.NameSpaces().ContainsKey(iswixNamespace.Key))
                {
                    namespaceModel.Selected = true;
                }
                namespaceModel.Prefix           = iswixNamespace.Key;
                namespaceModel.Uri              = iswixNamespace.Value;
                namespaceModel.PropertyChanged += PropertyModel_PropertyChanged;
                namespaces.Add(namespaceModel);
            }
            Namespaces = namespaces;
        }
Ejemplo n.º 22
0
        private TypeModel CreateTypeModel(Uri source, XmlSchemaGroup group, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List <DocumentationModel> docs)
        {
            var name = "I" + _configuration.NamingProvider.GroupTypeNameFromQualifiedName(qualifiedName);

            if (namespaceModel != null)
            {
                name = namespaceModel.GetUniqueTypeName(name);
            }

            var interfaceModel = new InterfaceModel(_configuration)
            {
                Name          = name,
                Namespace     = namespaceModel,
                XmlSchemaName = qualifiedName
            };

            interfaceModel.Documentation.AddRange(docs);

            if (namespaceModel != null)
            {
                namespaceModel.Types[name] = interfaceModel;
            }

            if (!qualifiedName.IsEmpty)
            {
                var key = BuildKey(group, qualifiedName);
                Types[key] = interfaceModel;
            }

            var particle   = group.Particle;
            var items      = GetElements(particle);
            var properties = CreatePropertiesForElements(source, interfaceModel, particle, items.Where(i => !(i.XmlParticle is XmlSchemaGroupRef)));

            interfaceModel.Properties.AddRange(properties);
            var interfaces = items.Select(i => i.XmlParticle).OfType <XmlSchemaGroupRef>()
                             .Select(i => (InterfaceModel)CreateTypeModel(CodeUtilities.CreateUri(i.SourceUri), Groups[i.RefName], i.RefName));

            interfaceModel.AddInterfaces(interfaces);

            return(interfaceModel);
        }
        internal static IReadOnlyCollection <MessageModel> SetupNamespaceList(XmlNodeList namespaces, ref int count)
        {
            var messageModels = new List <MessageModel>(namespaces.Count);

            foreach (XmlNode @namespace in namespaces)
            {
                var namespaceModel = new NamespaceModel
                {
                    Name = XmlNodeHelper.GetNodeAttributeValue(@namespace, "Name")
                };

                // Get the list of messages
                messageModels.AddRange(MessageModelHelper.BuildListOfMessages(@namespace, namespaceModel, ref count));

                var list = XmlNodeHelper.NodeListHelper(@namespace, ref count);

                messageModels.AddRange(list);
            }

            return(messageModels);
        }
Ejemplo n.º 24
0
        private void GenerateModule(Module module, NamespaceModel model, IEnumerable <ILayerCodeGenerator> generators)
        {
            foreach (var generator in generators)
            {
                generator.GenerateModule(module, model, this);

                foreach (var type in generator.GetTypes(module))
                {
                    var resolved = Resolve(generator.Layer, type, generator.GetTypeName(type));
                    if (resolved != null)
                    {
                        generator.GenerateType(type, resolved, this);
                    }
                }
            }

            module.Modules.ForEach(m =>
            {
                GenerateModule(m, model.AddNamespace(m.Name), generators);
            });
        }
Ejemplo n.º 25
0
        public void CircuralReferenceTest()
        {
            reflector.Reflect(path);
            IMapper _mapper = Mapper.Initialize();

            AssemblyModel assemblyModel = reflector.AssemblyModel;
            AssemblyDto   assemblyDto   = _mapper.Map <AssemblyDto>(assemblyModel);

            NamespaceModel circuralNamespaceModel = assemblyModel.Namespaces[1].Namespaces[0];
            NamespaceDto   circuralNamespaceDto   = assemblyDto.Namespaces[1].Namespaces[0];

            TypeModel typeModel_A     = circuralNamespaceModel.Types[0];
            TypeModel typemodel_A_ref = circuralNamespaceModel.Types[1].Fields[0].TypeModel;

            TypeModel typeModel_B = circuralNamespaceModel.Types[1];

            TypeDto typeDto_A     = circuralNamespaceDto.Types[0];
            TypeDto typeDto_A_ref = circuralNamespaceDto.Types[1].Fields[0].TypeModel;

            TypeDto typeDto_B = circuralNamespaceDto.Types[1];


            Assert.AreEqual(typeModel_A.Name, typemodel_A_ref.Name);
            Assert.AreSame(typeModel_A, typemodel_A_ref);

            Assert.AreNotEqual(typeModel_A.Name, typeModel_B.Name);
            Assert.AreNotSame(typeModel_A, typeModel_B);



            Assert.AreEqual(typeDto_A.Name, typeDto_A_ref.Name);
            Assert.AreSame(typeDto_A, typeDto_A_ref);

            Assert.AreNotEqual(typeDto_A.Name, typeDto_B.Name);
            Assert.AreNotSame(typeDto_A, typeDto_B);
        }
        public void TestIfReflectorReturnsAppropriateNamespace()
        {
            string    path      = @"..\..\..\ExampleDll\obj\Debug\netstandard2.0\ExampleDll.dll";
            Reflector reflector = new Reflector();

            reflector.GetAssemblyModel(path);
            Assert.AreEqual(17, reflector.Beans.Count);
            Assert.AreEqual(1, reflector.AssemblyModel.Namespaces.Count);
            NamespaceModel testedNamespace = reflector.AssemblyModel.Namespaces.Find(n => n.Name == "ExampleDll.Home");

            Assert.AreEqual(3, testedNamespace.Namespaces.Count);

            NamespaceModel testedNamespace2 = testedNamespace
                                              .Namespaces
                                              .Find(n => n.Name == "ExampleDll.Home.NestedNamespace")
                                              .Namespaces
                                              .Find(n => n.Name == "ExampleDll.Home.NestedNamespace.InnerNestedNamespace");

            TypeModel testedClass = testedNamespace2
                                    .Types
                                    .Find(t => t.Name == "ClassImplementingInterfaces");

            Assert.AreEqual(2, testedClass.Interfaces.Count);
        }
Ejemplo n.º 27
0
        private TypeModel CreateTypeModel(XmlSchemaSimpleType simpleType, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List <DocumentationModel> docs)
        {
            var restrictions = new List <RestrictionModel>();

            if (simpleType.Content is XmlSchemaSimpleTypeRestriction typeRestriction)
            {
                var enumFacets = typeRestriction.Facets.OfType <XmlSchemaEnumerationFacet>().ToList();
                // If there's a pattern restriction mixed into the enumeration values, we'll generate a string to play it safe.
                var isEnum = enumFacets.Count > 0 && !typeRestriction.Facets.OfType <XmlSchemaPatternFacet>().Any();
                if (isEnum)
                {
                    // we got an enum
                    var name = _configuration.NamingProvider.EnumTypeNameFromQualifiedName(qualifiedName);
                    if (namespaceModel != null)
                    {
                        name = namespaceModel.GetUniqueTypeName(name);
                    }

                    var enumModel = new EnumModel(_configuration)
                    {
                        Name          = name,
                        Namespace     = namespaceModel,
                        XmlSchemaName = qualifiedName,
                        XmlSchemaType = simpleType,
                        IsAnonymous   = string.IsNullOrEmpty(simpleType.QualifiedName.Name),
                    };

                    enumModel.Documentation.AddRange(docs);

                    foreach (var facet in enumFacets.DistinctBy(f => f.Value))
                    {
                        var value = new EnumValueModel
                        {
                            Name  = _configuration.NamingProvider.EnumMemberNameFromValue(enumModel.Name, facet.Value),
                            Value = facet.Value
                        };

                        var valueDocs = GetDocumentation(facet);
                        value.Documentation.AddRange(valueDocs);

                        var deprecated = facet.Annotation != null && facet.Annotation.Items.OfType <XmlSchemaAppInfo>()
                                         .Any(a => a.Markup.Any(m => m.Name == "annox:annotate" && m.HasChildNodes && m.FirstChild.Name == "jl:Deprecated"));
                        value.IsDeprecated = deprecated;

                        enumModel.Values.Add(value);
                    }

                    enumModel.Values = EnsureEnumValuesUnique(enumModel.Values);
                    if (namespaceModel != null)
                    {
                        namespaceModel.Types[enumModel.Name] = enumModel;
                    }

                    if (!qualifiedName.IsEmpty)
                    {
                        var key = BuildKey(simpleType, qualifiedName);
                        Types[key] = enumModel;
                    }

                    return(enumModel);
                }

                restrictions = GetRestrictions(typeRestriction.Facets.Cast <XmlSchemaFacet>(), simpleType).Where(r => r != null).Sanitize().ToList();
            }

            var simpleModelName = _configuration.NamingProvider.SimpleTypeNameFromQualifiedName(qualifiedName);

            if (namespaceModel != null)
            {
                simpleModelName = namespaceModel.GetUniqueTypeName(simpleModelName);
            }

            var simpleModel = new SimpleModel(_configuration)
            {
                Name          = simpleModelName,
                Namespace     = namespaceModel,
                XmlSchemaName = qualifiedName,
                XmlSchemaType = simpleType,
                ValueType     = simpleType.Datatype.GetEffectiveType(_configuration, restrictions),
            };

            simpleModel.Documentation.AddRange(docs);
            simpleModel.Restrictions.AddRange(restrictions);

            if (namespaceModel != null)
            {
                namespaceModel.Types[simpleModel.Name] = simpleModel;
            }

            if (!qualifiedName.IsEmpty)
            {
                var key = BuildKey(simpleType, qualifiedName);
                Types[key] = simpleModel;
            }

            return(simpleModel);
        }
Ejemplo n.º 28
0
        private TypeModel CreateTypeModel(Uri source, XmlSchemaAttributeGroup attributeGroup, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List <DocumentationModel> docs)
        {
            var name = "I" + _configuration.NamingProvider.AttributeGroupTypeNameFromQualifiedName(qualifiedName);

            if (namespaceModel != null)
            {
                name = namespaceModel.GetUniqueTypeName(name);
            }

            var interfaceModel = new InterfaceModel(_configuration)
            {
                Name          = name,
                Namespace     = namespaceModel,
                XmlSchemaName = qualifiedName
            };

            interfaceModel.Documentation.AddRange(docs);

            if (namespaceModel != null)
            {
                namespaceModel.Types[name] = interfaceModel;
            }

            if (!qualifiedName.IsEmpty)
            {
                var key = BuildKey(attributeGroup, qualifiedName);
                Types[key] = interfaceModel;
            }

            var items      = attributeGroup.Attributes;
            var properties = CreatePropertiesForAttributes(source, interfaceModel, items.OfType <XmlSchemaAttribute>());

            interfaceModel.Properties.AddRange(properties);
            var interfaces = items.OfType <XmlSchemaAttributeGroupRef>()
                             .Select(a => (InterfaceModel)CreateTypeModel(CodeUtilities.CreateUri(a.SourceUri), AttributeGroups[a.RefName], a.RefName));

            interfaceModel.AddInterfaces(interfaces);

            return(interfaceModel);
        }
Ejemplo n.º 29
0
        private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List <DocumentationModel> docs)
        {
            var name = _configuration.NamingProvider.ComplexTypeNameFromQualifiedName(qualifiedName);

            if (namespaceModel != null)
            {
                name = namespaceModel.GetUniqueTypeName(name);
            }

            var classModel = new ClassModel(_configuration)
            {
                Name           = name,
                Namespace      = namespaceModel,
                XmlSchemaName  = qualifiedName,
                XmlSchemaType  = complexType,
                IsAbstract     = complexType.IsAbstract,
                IsAnonymous    = string.IsNullOrEmpty(complexType.QualifiedName.Name),
                IsMixed        = complexType.IsMixed,
                IsSubstitution = complexType.Parent is XmlSchemaElement && !((XmlSchemaElement)complexType.Parent).SubstitutionGroup.IsEmpty
            };

            classModel.Documentation.AddRange(docs);

            if (namespaceModel != null)
            {
                namespaceModel.Types[classModel.Name] = classModel;
            }

            if (!qualifiedName.IsEmpty)
            {
                var key = BuildKey(complexType, qualifiedName);
                Types[key] = classModel;
            }

            if (complexType.BaseXmlSchemaType != null && complexType.BaseXmlSchemaType.QualifiedName != AnyType)
            {
                var baseModel = CreateTypeModel(source, complexType.BaseXmlSchemaType, complexType.BaseXmlSchemaType.QualifiedName);
                classModel.BaseClass = baseModel;
                if (baseModel is ClassModel baseClassModel)
                {
                    baseClassModel.DerivedTypes.Add(classModel);
                }
            }

            XmlSchemaParticle particle = null;

            if (classModel.BaseClass != null)
            {
                if (complexType.ContentModel.Content is XmlSchemaComplexContentExtension complexContent)
                {
                    particle = complexContent.Particle;
                }

                // If it's a restriction, do not duplicate elements on the derived class, they're already in the base class.
                // See https://msdn.microsoft.com/en-us/library/f3z3wh0y.aspx
            }
            else
            {
                particle = complexType.Particle ?? complexType.ContentTypeParticle;
            }

            var items = GetElements(particle, complexType).ToList();

            if (_configuration.GenerateInterfaces)
            {
                var interfaces = items.Select(i => i.XmlParticle).OfType <XmlSchemaGroupRef>()
                                 .Select(i => (InterfaceModel)CreateTypeModel(CodeUtilities.CreateUri(i.SourceUri), Groups[i.RefName], i.RefName)).ToList();

                classModel.AddInterfaces(interfaces);
            }

            var properties = CreatePropertiesForElements(source, classModel, particle, items);

            classModel.Properties.AddRange(properties);

            XmlSchemaObjectCollection attributes = null;

            if (classModel.BaseClass != null)
            {
                if (complexType.ContentModel.Content is XmlSchemaComplexContentExtension complexContent)
                {
                    attributes = complexContent.Attributes;
                }
                else if (complexType.ContentModel.Content is XmlSchemaSimpleContentExtension simpleContent)
                {
                    attributes = simpleContent.Attributes;
                }

                // If it's a restriction, do not duplicate attributes on the derived class, they're already in the base class.
                // See https://msdn.microsoft.com/en-us/library/f3z3wh0y.aspx
            }
            else
            {
                attributes = complexType.Attributes;
            }

            if (attributes != null)
            {
                var attributeProperties = CreatePropertiesForAttributes(source, classModel, attributes.Cast <XmlSchemaObject>());
                classModel.Properties.AddRange(attributeProperties);

                if (_configuration.GenerateInterfaces)
                {
                    var attributeInterfaces = attributes.OfType <XmlSchemaAttributeGroupRef>()
                                              .Select(i => (InterfaceModel)CreateTypeModel(CodeUtilities.CreateUri(i.SourceUri), AttributeGroups[i.RefName], i.RefName));
                    classModel.AddInterfaces(attributeInterfaces);
                }
            }

            if (complexType.AnyAttribute != null)
            {
                var property = new PropertyModel(_configuration)
                {
                    OwningType = classModel,
                    Name       = "AnyAttribute",
                    Type       = new SimpleModel(_configuration)
                    {
                        ValueType = typeof(XmlAttribute), UseDataTypeAttribute = false
                    },
                    IsAttribute  = true,
                    IsCollection = true,
                    IsAny        = true
                };

                var attributeDocs = GetDocumentation(complexType.AnyAttribute);
                property.Documentation.AddRange(attributeDocs);

                classModel.Properties.Add(property);
            }

            return(classModel);
        }
Ejemplo n.º 30
0
        private TypeModel CreateTypeModel(Uri source, XmlSchemaSimpleType simpleType, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List <DocumentationModel> docs)
        {
            var restrictions = new List <RestrictionModel>();

            if (simpleType.Content is XmlSchemaSimpleTypeRestriction typeRestriction)
            {
                var enumFacets = typeRestriction.Facets.OfType <XmlSchemaEnumerationFacet>().ToList();
                var isEnum     = (enumFacets.Count == typeRestriction.Facets.Count && enumFacets.Count != 0) ||
                                 (EnumTypes.Contains(typeRestriction.BaseTypeName.Name) && enumFacets.Any());
                if (isEnum)
                {
                    // we got an enum
                    var name = ToTitleCase(qualifiedName.Name);
                    if (namespaceModel != null)
                    {
                        name = namespaceModel.GetUniqueTypeName(name);
                    }

                    var enumModel = new EnumModel(_configuration)
                    {
                        Name          = name,
                        Namespace     = namespaceModel,
                        XmlSchemaName = qualifiedName,
                        XmlSchemaType = simpleType,
                    };

                    enumModel.Documentation.AddRange(docs);

                    foreach (var facet in enumFacets.DistinctBy(f => f.Value))
                    {
                        var value = new EnumValueModel
                        {
                            Name  = _configuration.NamingProvider.EnumMemberNameFromValue(enumModel.Name, facet.Value),
                            Value = facet.Value
                        };

                        var valueDocs = GetDocumentation(facet);
                        value.Documentation.AddRange(valueDocs);

                        var deprecated = facet.Annotation != null && facet.Annotation.Items.OfType <XmlSchemaAppInfo>()
                                         .Any(a => a.Markup.Any(m => m.Name == "annox:annotate" && m.HasChildNodes && m.FirstChild.Name == "jl:Deprecated"));
                        value.IsDeprecated = deprecated;

                        enumModel.Values.Add(value);
                    }

                    if (namespaceModel != null)
                    {
                        namespaceModel.Types[enumModel.Name] = enumModel;
                    }

                    if (!qualifiedName.IsEmpty)
                    {
                        Types[qualifiedName] = enumModel;
                    }

                    return(enumModel);
                }

                restrictions = GetRestrictions(typeRestriction.Facets.Cast <XmlSchemaFacet>(), simpleType).Where(r => r != null).Sanitize().ToList();
            }

            var simpleModelName = ToTitleCase(qualifiedName.Name);

            if (namespaceModel != null)
            {
                simpleModelName = namespaceModel.GetUniqueTypeName(simpleModelName);
            }

            var simpleModel = new SimpleModel(_configuration)
            {
                Name          = simpleModelName,
                Namespace     = namespaceModel,
                XmlSchemaName = qualifiedName,
                XmlSchemaType = simpleType,
                ValueType     = simpleType.Datatype.GetEffectiveType(_configuration),
            };

            simpleModel.Documentation.AddRange(docs);
            simpleModel.Restrictions.AddRange(restrictions);

            if (namespaceModel != null)
            {
                namespaceModel.Types[simpleModel.Name] = simpleModel;
            }

            if (!qualifiedName.IsEmpty)
            {
                Types[qualifiedName] = simpleModel;
            }

            return(simpleModel);
        }