Пример #1
0
        private static void PrintIncludes(CustomSchemaReader reader)
        {
            foreach (Include include in reader.Includes)
            {
                Console.WriteLine("Include: {0}", include.SchemaLocation);
            }

            Console.WriteLine("");
        }
Пример #2
0
        private static void PrintNamespaceTable(CustomSchemaReader reader)
        {
            foreach (KeyValuePair <string, string> pair in reader.NamespaceTable)
            {
                Console.WriteLine("Key: {0}, Value: {1}", pair.Key, pair.Value);
            }

            Console.WriteLine("");
        }
Пример #3
0
        public void UselessTest()
        {
            Console.WriteLine("Test: Parsing an XML Schema\n");

            XmlDocument testDocument = PrepareTest();

            CustomSchemaReader reader = new CustomSchemaReader(testDocument);

            // print namespace declarations
            PrintNamespaceTable(reader);

            // print includes
            PrintIncludes(reader);

            // print items
            PrintItems(reader);
        }
Пример #4
0
        private static void PrintItems(CustomSchemaReader reader)
        {
            foreach (object item in reader.Items)
            {
                if (item is ComplexType)
                {
                    ComplexType ct = (ComplexType)item;

                    Console.WriteLine("Complex Type\n"
                                      + "   Name: " + ct.Name);

                    foreach (object i in ct.Items)
                    {
                        Element element = (Element)i;
                        Console.WriteLine("   Item: " + element.Name);
                    }

                    Console.WriteLine("");
                }

                if (item is Element)
                {
                    Element element = (Element)item;

                    Console.WriteLine("Element\n"
                                      + "   Name: " + element.Name + "\n"
                                      + "   Ref " + "\n"
                                      + "      Prefix:" + element.Ref.Prefix + "\n"
                                      + "      Name: " + element.Ref.Name + "\n"
                                      + "   Type " + "\n"
                                      + "      Prefix:" + element.Type.Prefix + "\n"
                                      + "      Name: " + element.Type.Name + "\n"
                                      + "   MinOccurs: " + element.MinOccurs + "\n"
                                      + "   MaxOccurs: " + element.MaxOccurs
                                      + "\n");
                }
            }

            Console.WriteLine("");
        }
        ///<summary>
        /// The static method imports an XML schema containing Business Information
        /// Entities into an existing BIE library. The method has one input parameter
        /// of type ImporterContext specifying different settings utilized while
        /// importing the XML schema.
        ///</summary>
        ///<param name="context">
        /// The parameter provides the necessary context information required by the
        /// BIE XML schema importer. An example would be the directory location where
        /// all XML schemas to be imported are located, and the repository which contains
        /// the BIE library that all ABIEs should be imported into. Fore more information
        /// plese refer to the documentation of the ImporterContext class.
        /// </param>
        public static void ImportXSD(ImporterContext context)
        {
            #region Import Preparation

            // TODO: ACC, BDT and BIE library should be configurable through the ImporterContext
            InitLibraries(context);

            // Even though the XML schema is stored in the importer context we need to re-read
            // the XML schema. The reason for doing so is that the impoter context pre-read the
            // XML schema using the XML schema reader class from the .net API. However, the XML
            // schema reader dropped information that is required to import the ABIE schema.
            // Instead we want to utilitze the CustomSchemaReader class that requires an XML
            // schema document as an input. Therefore we need to re-read the XML schema file based
            // on the file name and directory location as specified in the importer context.
            XmlDocument bieSchemaDocument = GetBieSchemaDocument(context);

            CustomSchemaReader reader = new CustomSchemaReader(bieSchemaDocument);

            #endregion

            IDictionary <string, string> allElementDefinitions = new Dictionary <string, string>();

            #region Processing Step 1: Cumulate all ABIEs and create them in the BIE library

            foreach (object item in reader.Items)
            {
                if (item is ComplexType)
                {
                    ComplexType abieComplexType = (ComplexType)item;

                    AbieSpec singleAbieSpec = CumulateAbieSpecFromComplexType(abieComplexType);

                    BieLibrary.CreateAbie(singleAbieSpec);
                }

                if (item is Element)
                {
                    Element element = (Element)item;
                    allElementDefinitions.Add(element.Name, element.Type.Name);
                }
            }

            #endregion

            #region Processing Step 2: Update all ABIEs with their ASBIEs

            foreach (object item in reader.Items)
            {
                if (item is ComplexType)
                {
                    ComplexType abieComplexType = (ComplexType)item;

                    string abieName = abieComplexType.Name.Substring(0, abieComplexType.Name.Length - 4);

                    IAbie    abieToBeUpdated = BieLibrary.GetAbieByName(abieName);
                    AbieSpec updatedAbieSpec = AbieSpec.CloneAbie(abieToBeUpdated);

                    updatedAbieSpec.Asbies = new List <AsbieSpec>(CumulateAbiesSpecsFromComplexType(abieComplexType, allElementDefinitions));

                    BieLibrary.UpdateAbie(abieToBeUpdated, updatedAbieSpec);
                }
            }

            #endregion
        }