Example #1
0
 public DB( SifVersion version,
            String namespace_Renamed,
            string schemaTagName )
 {
     InitBlock();
     fVersion = version;
     fNamespace = namespace_Renamed;
     fSchemaName = schemaTagName;
 }
 /// <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;
 }
Example #3
0
 /// <summary>  Constructor
 /// </summary>
 /// <param name="id">Sequence number of this object
 /// </param>
 /// <param name="name">Element name (e.g. "StudentPersonal", "OtherId", etc.)
 /// </param>
 /// <param name="localPackage">Package name (e.g. "common", "student", "food", etc.)
 /// </param>
 /// <param name="version">Version of SIF this object is being defined for
 /// 
 /// </param>
 public ObjectDef( int id,
                   string name,
                   string srcLocation,
                   string localPackage,
                   SifVersion version )
     : base(name)
 {
     this.SourceLocation = srcLocation;
     this.LocalPackage = localPackage;
     //this.LatestVersion =
 }
        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;
        }
Example #5
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;
        }
Example #6
0
        /// <summary>  Gets a SifVersion instance</summary>
        /// <remarks>
        /// <para>
        /// This method always returns the same version instance for the given version
        /// numbers. If the version number match on official version supported by the ADK,
        /// that version instance is returned. Otherwise, a new SIFVersion instance is
        /// created and returned. The sam SifVersion instance will always be returned for 
        /// the same paramters
        /// </para>
        /// </remarks>
        /// <returns> A SifVersion instance to encapsulate the version information
        /// provided to this method. If the <i>major</i>, <i>minor</i>, and
        /// <i>revision</i> numbers match one of the versions supported by the
        /// Adk (e.g. SifVersion.SIF10r1, SifVersion.SIF10r2, etc.), that object
        /// is returned. Otherwise, a new instance is created. Thus, you are
        /// guaranteed to always receive the same SifVersion instance or a given
        /// version number supported by the Adk.
        /// </returns>
        private static SifVersion GetInstance(int major,
                                               int minor,
                                               int revision)
        {
            // Check for versions explicitly supported by the ADK first
            if (major == 2)
            {
                if (minor == 0)
                {
                    if (revision == 0)
                    {
                        return SIF20;
                    }
                    else if (revision == 1)
                    {
                        return SIF20r1;
                    }
                }
                if (minor == 1 && revision == 0)
                {
                    return SIF21;
                }

            }
            else if (major == 1)
            {
                if (minor == 5 && revision == 1)
                {
                    return SIF15r1;
                }
                else if (minor == 1 && revision == 0)
                {
                    return SIF11;
                }
            }

            // No explicit support found. Return a newly-fabricated instance
            // to support this version of SIF
            String tag = ToString(major, minor, revision, '.');

            SifVersion ver;
            if (sVersions == null)
            {
                sVersions = new Dictionary<string, SifVersion>();
            }
            if (!sVersions.TryGetValue(tag, out ver))
            {
                ver = new SifVersion(major, minor, revision);
                sVersions[tag] = ver;
            }
            return ver;
        }
        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;
        }
 private void AddUndefinedObject( ObjectDef def,
                                  SifVersion version )
 {
     XmlDocument doc = getDocument( def.LocalPackage, version );
     DefinitionFile.WriteObjectToDom( def, doc );
 }
 private void AddUndefinedEnum( EnumDef def,
                                SifVersion version )
 {
     XmlDocument doc = getDocument( def.LocalPackage, version );
     DefinitionFile.WriteEnumToDom( def, doc );
 }
Example #10
0
        protected internal virtual void onRoot( XmlElement node )
        {
            fLocalPackage = getAttr( node, "package" );
            String ver = getAttr( node, "version" );
            fNamespace = getAttr( node, "namespace" );

            if ( fLocalPackage == null || ver == null || fNamespace == null ) {
                throw new ParseException
                    ( "<adk> must specify the package=, version=, and namespace= attributes" );
            }

            fVersion = SifVersion.Parse( ver );
            fPackage = "Edustructures.SifWorks." + fLocalPackage;

            Console.Out.WriteLine( "    Package=" + fPackage );
            Console.Out.WriteLine( "    Version=" + ver + " (" + this.fVersion + ")" );
            Console.Out.WriteLine( "    Namespace=" + fNamespace );

            fDB = MetaDataSchema.getDB( fVersion );
        }
        private void RunVersioningTests(SifVersion dataVersion, SifVersion schemaVersion, bool ignoreEnumerationErrors)
        {
            // Tests assume that the schema files are embedded in the test assembly
            DirectoryInfo workingDirectory = new DirectoryInfo(Environment.CurrentDirectory);
            Type rootNamespaceType = typeof ( UsAdkTest );

            String schemaVersionStr = getShortenedVersion(schemaVersion);
            String schemaResourcePath = rootNamespaceType.Namespace + ".schemas." + schemaVersionStr;
            AssemblyResourceResolver asr = new AssemblyResourceResolver(rootNamespaceType.Assembly, schemaResourcePath );

            SchemaValidator sv = null;

            using( Stream rootSchema = rootNamespaceType.Assembly.GetManifestResourceStream( schemaResourcePath + ".SIF_Message.xsd" ))
            using( TextReader textReader = new StreamReader( rootSchema ) )
            {
                sv = SchemaValidator.NewInstance( textReader, asr );
                textReader.Close();
                rootSchema.Close();
            }

            sv.IgnoreEnumerationErrors = ignoreEnumerationErrors;

            String dataVersionStr = getShortenedVersion(dataVersion);
            // Warning, slight hack. Move up two directories to the project root directory (assumes the project directory is still there)
            workingDirectory = workingDirectory.Parent.Parent;
            DirectoryInfo dataDir = new DirectoryInfo(workingDirectory.FullName + "\\data\\" + dataVersionStr);

            int errorCount = RunDirectoryTest(dataVersion, schemaVersion, dataDir, Console.Out, sv);

            Assert.AreEqual(0, errorCount, "Tests Failed. See System.out for details");
        }
        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;
        }
        private int RunDirectoryTest(SifVersion parseVersion, SifVersion writeVersion, DirectoryInfo dir, TextWriter output, SchemaValidator sv)
        {
            int errorCount = 0;
            foreach (DirectoryInfo childDir in dir.GetDirectories())
            {
                errorCount += RunDirectoryTest(parseVersion, writeVersion, childDir, output, sv);
            }

            foreach (FileInfo fileInfo in dir.GetFiles("*.xml"))
            {
                if (!RunSingleTest(parseVersion, writeVersion, fileInfo.FullName, output, sv))
                {
                    errorCount++;
                }
            }
            output.Flush();
            return errorCount;
        }
 private String getShortenedVersion(SifVersion version)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("SIF");
     builder.Append(version.Major);
     builder.Append(version.Minor);
     if (version.Revision > 0)
     {
         builder.Append('r');
         builder.Append(version.Revision);
     }
     return builder.ToString();
 }
Example #15
0
 public ISchemaDefinition GetSchemaDefinition( SifVersion version )
 {
     return getDB( version );
 }