예제 #1
0
        /// <summary>  Gets the DB object associated with the specified version of SIF (or
        /// creates a new object if none currently exists).
        /// </summary>
        /// <param name="version">The SIF version (e.g. "1.0r1")
        /// </param>
        public static DB getDB(SifVersion version)
        {
            DB db = (DB)fDBs[version.ToString()];

            if (db == null)
            {
                db = new DB(version, version.Xmlns, "Edustructures MetaData");
                fDBs[version.ToString()] = db;
            }
            return(db);
        }
예제 #2
0
 private void assertSIFVersion(SifVersion assertVersion, int major, int minor, int revision, String tag)
 {
     Assert.AreEqual(major, assertVersion.Major, "Major");
     Assert.AreEqual(minor, assertVersion.Minor, "Minor");
     Assert.AreEqual(revision, assertVersion.Revision, "Revision");
     Assert.AreEqual(tag, assertVersion.ToString(), "Tag");
 }
예제 #3
0
        private XmlDocument getDocument(string localPackage,
                                        SifVersion version)
        {
            string path = Path.Combine(fsrcLocation, "autogen." + localPackage + ".xml");

            XmlDocument doc = packageFiles[path] as XmlDocument;

            if (doc == null)
            {
                doc = new XmlDocument();
                if (File.Exists(path))
                {
                    doc.Load(path);
                }
                else
                {
                    // TODO: generate a more concise xml string, based on version
                    string xml = "<adk package=\"" + localPackage + "\" version=\"" +
                                 version.ToString() + "\" namespace=\"" + version.Xmlns + "\"/>";
                    doc.PreserveWhitespace = false;
                    doc.LoadXml(xml);
                }
                packageFiles[path] = doc;
            }
            return(doc);
        }
 protected static void ThrowParseException(Exception ex,
                                           String elementDefName,
                                           SifVersion version)
 {
     throw new AdkParsingException
               ("Unable to parse element or attribute '" + elementDefName + "' :" +
               (ex == null ? "" : ex.Message) + " (SIF " + version.ToString() + ")", null, ex);
 }
예제 #5
0
        private void testSIFPingWithZISVersion(InMemoryProtocolHandler handler, SifVersion testVersion)
        {
            SIF_SystemControl ssc;

            Zone.Properties.ZisVersion = testVersion.ToString();
            Zone.SifPing();
            ssc = (SIF_SystemControl)handler.readMsg();

            Assert.AreEqual(testVersion, ssc.SifVersion, "SifVersion");
            Assert.AreEqual(testVersion.Xmlns, ssc.GetXmlns(), "SifVersion->Xmlns");
        }
예제 #6
0
        public bool Validate(SifElement se, SifVersion testedVerson)
        {
            // Before we can validate with the schema, we need to ensure that the
            // data object is wrapped in a SIF_Message elements, because the SIF
            // Schema makes that assumption
            SifMessagePayload smp = MakeSIFMessagePayload(se);

            String tmpFileName = se.ElementDef.Name + ".SchemaValidator."
                                 + testedVerson.ToString() + ".adk";

            // 2) Write the message out to a file
            WriteObject(testedVerson, tmpFileName, smp);

            return(Validate(tmpFileName));
        }
예제 #7
0
        public virtual void addAlias(SifVersion version,
                                     string tag,
                                     int sequence)
        {
            if (fAliases == null)
            {
                fAliases = new Hashtable();
            }
            Alias a = (Alias)fAliases[version.ToString()];

            if (a != null)
            {
                throw new MergeException(Tag + " alias already defined for " + version);
            }

            a          = new Alias();
            a.tag      = tag;
            a.sequence = sequence;
            string verStr = version.Major + version.Minor.ToString() +
                            (version.Revision == 0 ? "" : "r" + version.Revision);

            fAliases[verStr] = a;
        }
예제 #8
0
        private bool RunSingleTest(
            SifVersion parseVersion,
            SifVersion writeVersion,
            string fileName,
            TextWriter output,
            SchemaValidator sv)
        {
            sv.Clear();

            if (VERBOSE)
            {
                output.Write("Running test on " + fileName + "\r\n");
            }

            // 1) Read the object into memory
            SifElement se = null;

            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output
                .WriteLine("Error parsing file " + fileName + "\r\n  - "
                           + adke);
                output.WriteLine();
                return(false);
            }
            catch (Exception re)
            {
                output.WriteLine("Error parsing file " + fileName + "\r\n  - " + re);
                output.WriteLine();
                return(false);
            }

//            if (VERBOSE)
//            {
//                SifWriter writer = new SifWriter(output);
//                writer.Write(se,parseVersion);
//                output.Flush();
//            }

            // Before we can validate with the schema, we need to ensure that the
            // data object is wrapped in a SIF_Message elements, because the SIF
            // Schema makes that assumption
            SifMessagePayload smp = SchemaValidator.MakeSIFMessagePayload(se);

            String tmpFileName = fileName + "." + writeVersion.ToString() + ".adk";

            // 2) Write the message out to a file
            SchemaValidator.WriteObject(writeVersion, tmpFileName, smp);

            // 3) Validate the file
            bool validated = sv.Validate(tmpFileName);

            // 4) If validation failed, write the object out for tracing purposes
            if (!validated)
            {
                if (VERBOSE)
                {
                    SifWriter outWriter = new SifWriter(output);
                    outWriter.Write(se, writeVersion);
                    outWriter.Flush();
                }
                output.WriteLine("Errors reading/writing " + fileName);
                sv.PrintProblems(output);
                return(false);
            }

            // 5) Read the object again into memory
            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output.WriteLine("Error parsing file " + fileName + ": "
                                 + adke.Message);
                return(false);
            }
            catch (Exception re)
            {
                output.Write("Error parsing file " + fileName + ": "
                             + re.Message + "\r\n");
                return(false);
            }

            return(validated);
        }
 protected static void ThrowParseException(String errorMessage,
                                           SifVersion version)
 {
     throw new AdkParsingException(errorMessage + " (SIF " + version.ToString() + ")", null);
 }
예제 #10
0
        public static T WriteParseAndReturn<T>(T o, SifVersion version, SchemaValidator validator, bool echoOut)
            where T : SifElement
        {
            T returnVal;

            if ( o is SifMessagePayload )
            {
                o.SifVersion = version;
            }


            SifWriter echo = null;
            if ( echoOut )
            {
                //   Write the object to System.out
                Console.WriteLine( "Writing object : " + o.ElementDef.Name + " using SIFVersion: " + version.ToString() );

                echo = new SifWriter( Console.Out );
                echo.Write( o, version );
            }

            //  Write the object to a file
            Console.WriteLine( "Writing to file... test.xml" );

            using ( Stream fos = File.Open( "test.xml", FileMode.Create, FileAccess.Write ) )
            {
                SifWriter writer = new SifWriter( fos );
                writer.Write( o, version  );
                writer.Flush();
                writer.Close();
                fos.Close();
            }


            if ( validator != null )
            {
                Validate( "test.xml", validator );
            }

            //  Parse the object from the file
            Console.WriteLine( "Parsing from file..." );
            SifParser p = SifParser.NewInstance();
            using ( Stream fis = File.OpenRead( "test.xml" ) )
            {
                returnVal = (T) p.Parse( fis, null );
                fis.Close();
            }


            //  Write the parsed object to System.out
            returnVal.SetChanged( true );
            Console.WriteLine( "Read object : " + returnVal.ElementDef.Name );
            if ( echoOut )
            {
                echo.Write( returnVal, version );
                echo.Flush();
            }
             
            return returnVal;
        }
예제 #11
0
        public static SifElement WriteParseAndReturn( 
            SifElement o,
            SifVersion version,
            SchemaValidator validator, 
            Boolean echoOut )
        {
            SifElement returnVal;

            if ( o is SifMessagePayload )
            {
                o.SifVersion = version;
            }

            SifWriter echo = null;

            if ( echoOut )
            {
                //   Write the object to System.out
                Console.WriteLine( "Writing object : " + o.ElementDef.Name
                                   + " using SIFVersion: " + version.ToString() );

                echo = new SifWriter( Console.Out );
                echo.Write( o, version );
                echo.Flush();
                Console.Out.Flush();
                
            }

            //  Write the object to a file
            Console.WriteLine( "Writing to file... test.xml" );
            using (Stream fos = new FileStream("test.xml", FileMode.Create))
            {
                SifWriter writer = new SifWriter( new StreamWriter( fos, Encoding.UTF8 ) );
                o.SetChanged( true );
                writer.Write( o, version );
                writer.Flush();
                writer.Close();
                fos.Close();
            }

            if ( validator != null )
            {
                Validate( "test.xml", validator );
            }

            //  Parse the object from the file
            Console.WriteLine( "Parsing from file..." );
            SifParser p = SifParser.NewInstance();

            FileStream fr = new FileStream( "test.xml", FileMode.Open );

            StreamReader inStream = new StreamReader( fr, Encoding.UTF8 );


            returnVal = p.Parse( inStream, null, 0, version );

            inStream.Close();
            fr.Close();
            //  Write the parsed object to System.out
            returnVal.SetChanged( true );
            Console.WriteLine( "Read object : " + returnVal.ElementDef.Name );
            if ( echoOut )
            {
                echo.Write( returnVal, version );
                echo.Flush();
            }


            return returnVal;
        }
예제 #12
0
// BEGIN EXTRA METHODS (C:/GitHub/rafidzal/OpenADK-java/adk-generator/../adk-generator/datadef/core/sif20/SIF_Version.txt.cs)


        /**
         * Creates a SIF_Version object with the specified SIFVersion
         * @param version
         */
        public SIF_Version(SifVersion version) : this(version.ToString())
        {
        }
예제 #13
0
 public SifFormatter GetFormatter(SifVersion version)
 {
     if (version.Major == 2)
     {
         return SIF_2X_FORMATTER;
     }
     else if (version.Major == 1)
     {
         return SIF_1X_FORMATTER;
     }
     else
     {
         throw new AdkException("Formatter not defined for SIFVersion: " + version.ToString(), null);
     }
 }