Exemplo n.º 1
0
        private static Model ReadModel(MetaDataStore store, string packageFolder, FileInfo modelFile)
        {
            XmlDocument modelXml = new XmlDocument();

            try
            {
                modelXml.Load(modelFile.FullName);
            }
            catch (Exception ex)
            {
                // Notify a structural model descriptor error
                store.Messages.Add(new DiagnosticMessage(string.Format("Package '{0}': Ignoring model '{1}' due to error by XML loading.",
                                                                       packageFolder, modelFile.Name), DiagnosticMessageType.Warning));
                store.Messages.Add(new DiagnosticMessage(string.Format("Package '{0}': XML loading of model '{1}' exception: '{2}'.",
                                                                       packageFolder, modelFile.Name, ex.Message), DiagnosticMessageType.Debug));
                return(null);
            }
            XmlElement root = modelXml["AxModelInfo"];

            if (root == null)
            {
                // Notify an model descriptor structural error
                store.Messages.Add(new DiagnosticMessage(string.Format("Package '{0}': Ignoring model '{1}' due to XML does not contain " +
                                                                       "the 'AxModelInfo' element.", packageFolder, modelFile.Name), DiagnosticMessageType.Error));
                return(null);
            }
            XmlElement e = root["Name"];

            if (e == null)
            {
                // Notify an model descriptor structural error
                store.Messages.Add(new DiagnosticMessage(string.Format("Package '{0}': Ignoring model '{1}' due to XML does not contain " +
                                                                       "the 'Name' element as part of 'AxModelInfo' element.", packageFolder, modelFile.Name), DiagnosticMessageType.Error));
                return(null);
            }

            Model m = new Model(e.InnerText);

            m.OriginLocation     = packageFolder + "\\" + m.Name;
            m.DescriptorFilename = modelFile.FullName;

            e = root["DisplayName"];
            if (e != null)
            {
                m.DisplayName = e.InnerText;
            }
            e = root["Description"];
            if (e != null)
            {
                m.Description = e.InnerText;
            }
            e = root["Id"];
            if (e != null && long.TryParse(e.InnerText, out long id))
            {
                m.Id = id;
            }
            e = root["Customization"];
            if (e != null)
            {
                m.Customization = e.InnerText;
            }
            e = root["Layer"];
            if (e != null)
            {
                m.Layer = new Layer(int.Parse(e.InnerText));
            }
            e = root["Locked"];
            if (e != null)
            {
                m.Locked = e.InnerText;
            }
            e = root["ModelModule"];
            if (e != null)
            {
                m.ModelModule = e.InnerText;
            }
            e = root["Publisher"];
            if (e != null)
            {
                m.Publisher = e.InnerText;
            }
            e = root["VersionBuild"];
            if (e != null)
            {
                m.VersionBuild = e.InnerText;
            }
            e = root["VersionMajor"];
            if (e != null)
            {
                m.VersionMajor = e.InnerText;
            }
            e = root["VersionMinor"];
            if (e != null)
            {
                m.VersionMinor = e.InnerText;
            }
            e = root["VersionRevision"];
            if (e != null)
            {
                m.VersionRevision = e.InnerText;
            }

            // Lists
            e = root["ModuleReferences"];
            if (e != null && e.HasChildNodes)
            {
                foreach (XmlNode nodeReference in e.ChildNodes)
                {
                    ModuleReference r = new ModuleReference {
                        Name = nodeReference.InnerText
                    };
                    m.ModuleReferences.Add(r);
                }
            }

            // TODO: Handle following elements which are lists: AppliedUpdates, InternalsVisibleTo

            return(m);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a demo data metadata store without accessing any file.
        /// </summary>
        /// <param name="numPackages">Specifies the maximum number of packages contained in the metadata.</param>
        /// <param name="withErrors">Specifies whether errors should be contained in the data.</param>
        /// <returns>Demo 'metadata store' data type.</returns>
        public static MetaDataStore GetModelStore(int numPackages, bool withErrors)
        {
            MetaDataStore store = new MetaDataStore();

            Package p1 = new Package("System Base");

            p1.Models.Add(new Model("ModelBase1")
            {
                DisplayName = "Model Base-1", Layer = new Layer("SYS")
            });
            p1.Models.Add(new Model("ModelBase2")
            {
                DisplayName = "Model Base-2", Layer = new Layer("SYS")
            });
            store.Packages.Add(p1);

            if (numPackages >= 2)
            {
                Package p2 = new Package("System Foundation");
                p2.Models.Add(new Model("ModelFound1")
                {
                    DisplayName = "Model Foundation-1", Layer = new Layer("SYS")
                });
                p2.Models.Add(new Model("ModelFound2")
                {
                    DisplayName = "Model Foundation-2", Layer = new Layer("SYP")
                });
                store.Packages.Add(p2);
                ModuleReference ref2 = new ModuleReference {
                    Name = p1.AssemblyName, ReferencedPackage = p1
                };
                p2.Models[0].ModuleReferences.Add(ref2);
                p2.Models[1].ModuleReferences.Add(ref2);
                if (withErrors)
                {
                    ref2 = new ModuleReference {
                        Name = "Some AssemblyName", ReferencedPackage = null
                    };
                    p2.Models[0].ModuleReferences.Add(ref2);
                    store.Messages.Add(new DiagnosticMessage("Referencing a unknown module: " + ref2.Name, DiagnosticMessageType.Error));
                }
            }

            if (numPackages >= 3)
            {
                Package p3 = new Package("System Suite");
                p3.Models.Add(new Model("ModelSuite1")
                {
                    DisplayName = "Model Suite-1"
                });
                p3.Models.Add(new Model("ModelSuite2")
                {
                    DisplayName = "Model Suite-2"
                });
                p3.Models.Add(new Model("ModelSuite3")
                {
                    DisplayName = "Model Suite-3"
                });
                p3.Models.Add(new Model("ModelSuite4")
                {
                    DisplayName = "Model Suite-4"
                });
                store.Packages.Add(p3);
                ModuleReference ref3 = new ModuleReference {
                    Name = p1.AssemblyName, ReferencedPackage = p1
                };
                p3.Models[0].ModuleReferences.Add(ref3);
                p3.Models[1].ModuleReferences.Add(ref3);
                p3.Models[2].ModuleReferences.Add(ref3);
                p3.Models[3].ModuleReferences.Add(ref3);
                Package pck2 = store.Packages[1];
                ref3 = new ModuleReference {
                    Name = pck2.AssemblyName, ReferencedPackage = pck2
                };
                p3.Models[0].ModuleReferences.Add(ref3);
                p3.Models[2].ModuleReferences.Add(ref3);
            }

            if (withErrors)
            {
                store.Messages.Add(new DiagnosticMessage("Demo error message", DiagnosticMessageType.Error));
                store.Messages.Add(new DiagnosticMessage("Demo information message", DiagnosticMessageType.Information));
                store.Messages.Add(new DiagnosticMessage("Demo debug message", DiagnosticMessageType.Debug));
                store.Messages.Add(new DiagnosticMessage("Demo warning message", DiagnosticMessageType.Warning));
            }

            return(store);
        }