Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
        public static SifDataObject WriteParseAndReturn(SifDataObject o,
                                                        SifVersion version)
        {
            SifDataObject returnVal = null;

            try
            {
                //  Write the object to System.out
                Console.WriteLine("Writing object : " + o.ObjectTag
                                  + " using SifVersion: " + version.ToString());
                SifWriter echo = new SifWriter(Console.Out);
                echo.Write(o, version);
                o.SetChanged(false);
                echo.Write(o);

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

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


                //  Write the parsed object to System.out
                returnVal.SetChanged(true);
                Console.WriteLine("Read object : " + returnVal.ObjectTag);
                echo.Write(returnVal, version);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Assert.Fail("Exception: " + e.Message);
            }

            return(returnVal);
        }
        public static SifDataObject WriteParseAndReturn( SifDataObject o,
			SifVersion version )
        {
            SifDataObject returnVal = null;

            try
            {
                //  Write the object to System.out
                Console.WriteLine( "Writing object : " + o.ObjectTag
                           + " using SifVersion: " + version.ToString() );
                SifWriter echo = new SifWriter( Console.Out );
                echo.Write( o, version );
                o.SetChanged( false );
                echo.Write( o );

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

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

                //  Write the parsed object to System.out
                returnVal.SetChanged( true );
                Console.WriteLine( "Read object : " + returnVal.ObjectTag );
                echo.Write( returnVal, version  );
            }
            catch (Exception e)
            {
                Console.WriteLine( e );
                Assert.Fail( "Exception: " + e.Message );
            }

            return returnVal;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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("Validation failed on " + tmpFileName );
                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;
        }