Ejemplo n.º 1
0
        // Save application's configuration
        public void Save(GlyphDatabases dbs)
        {
            lock ( sync )
            {
                // make sure directory exists
                Directory.CreateDirectory(Path.GetDirectoryName(configFileName));

                // open file
                FileStream fs = new FileStream(configFileName, FileMode.Create);
                // create XML writer
                XmlTextWriter xmlOut = new XmlTextWriter(fs, Encoding.UTF8);

                // use indenting for readability
                xmlOut.Formatting = Formatting.Indented;

                // start document
                xmlOut.WriteStartDocument( );
                xmlOut.WriteComment("Glyph Recognition Studio configuration file");

                // main node
                xmlOut.WriteStartElement(mainTag);

                // save configuration options
                xmlOut.WriteStartElement(optionsTag);
                SaveOptions(xmlOut);
                xmlOut.WriteEndElement( );

                // save glyph databases
                xmlOut.WriteStartElement(glyphDatabasesTag);
                dbs.Save(xmlOut);
                xmlOut.WriteEndElement( );

                xmlOut.WriteEndElement( ); // end of main node
                // close file
                xmlOut.Close( );
            }
        }
Ejemplo n.º 2
0
        // Save application's configuration
        public void Save( GlyphDatabases dbs )
        {
            lock ( sync )
            {
                // make sure directory exists
                Directory.CreateDirectory( Path.GetDirectoryName( configFileName ) );

                // open file
                FileStream fs = new FileStream( configFileName, FileMode.Create );
                // create XML writer
                XmlTextWriter xmlOut = new XmlTextWriter( fs, Encoding.UTF8 );

                // use indenting for readability
                xmlOut.Formatting = Formatting.Indented;

                // start document
                xmlOut.WriteStartDocument( );
                xmlOut.WriteComment( "Glyph Recognition Studio configuration file" );

                // main node
                xmlOut.WriteStartElement( mainTag );

                // save configuration options
                xmlOut.WriteStartElement( optionsTag );
                SaveOptions( xmlOut );
                xmlOut.WriteEndElement( );

                // save glyph databases
                xmlOut.WriteStartElement( glyphDatabasesTag );
                dbs.Save( xmlOut );
                xmlOut.WriteEndElement( );

                xmlOut.WriteEndElement( ); // end of main node
                // close file
                xmlOut.Close( );
            }
        }
Ejemplo n.º 3
0
        // Load application's configration
        public bool Load( GlyphDatabases dbs )
        {
            isSuccessfullyLoaded = false;

            lock ( sync )
            {
                // check file existance
                if ( File.Exists( configFileName ) )
                {
                    FileStream fs = null;
                    XmlTextReader xmlIn = null;

                    try
                    {
                        // open file
                        fs = new FileStream( configFileName, FileMode.Open );
                        // create XML reader
                        xmlIn = new XmlTextReader( fs );

                        xmlIn.WhitespaceHandling = WhitespaceHandling.None;
                        xmlIn.MoveToContent( );

                        // check main node
                        if ( xmlIn.Name != mainTag )
                            throw new ApplicationException( );

                        // move to next node
                        xmlIn.Read( );

                        while ( true )
                        {
                            // ignore anything if it is not under main tag
                            while ( ( xmlIn.Depth > 1 ) || (
                                    ( xmlIn.Depth == 1 ) && ( xmlIn.NodeType != XmlNodeType.Element ) ) )
                            {
                                xmlIn.Read( );
                            }

                            // break if end element is reached
                            if ( xmlIn.Depth == 0 )
                                break;

                            int tagStartLineNummber = xmlIn.LineNumber;

                            switch ( xmlIn.Name )
                            {
                                case glyphDatabasesTag:
                                    dbs.Load( xmlIn );
                                    break;

                                case optionsTag:
                                    LoadOptions( xmlIn );
                                    break;
                            }

                            // read to the next node, if loader did not move any further
                            if ( xmlIn.LineNumber == tagStartLineNummber )
                            {
                                xmlIn.Read( );
                            }
                        }

                        isSuccessfullyLoaded = true;
                        // ignore the rest
                    }
                    catch
                    {
                    }
                    finally
                    {
                        if ( xmlIn != null )
                            xmlIn.Close( );
                    }
                }
            }

            return isSuccessfullyLoaded;
        }
Ejemplo n.º 4
0
        // Load application's configration
        public bool Load(GlyphDatabases dbs)
        {
            isSuccessfullyLoaded = false;

            lock ( sync )
            {
                // check file existance
                if (File.Exists(configFileName))
                {
                    FileStream    fs    = null;
                    XmlTextReader xmlIn = null;

                    try
                    {
                        // open file
                        fs = new FileStream(configFileName, FileMode.Open);
                        // create XML reader
                        xmlIn = new XmlTextReader(fs);

                        xmlIn.WhitespaceHandling = WhitespaceHandling.None;
                        xmlIn.MoveToContent( );

                        // check main node
                        if (xmlIn.Name != mainTag)
                        {
                            throw new ApplicationException( );
                        }

                        // move to next node
                        xmlIn.Read( );

                        while (true)
                        {
                            // ignore anything if it is not under main tag
                            while ((xmlIn.Depth > 1) || (
                                       (xmlIn.Depth == 1) && (xmlIn.NodeType != XmlNodeType.Element)))
                            {
                                xmlIn.Read( );
                            }

                            // break if end element is reached
                            if (xmlIn.Depth == 0)
                            {
                                break;
                            }

                            int tagStartLineNummber = xmlIn.LineNumber;

                            switch (xmlIn.Name)
                            {
                            case glyphDatabasesTag:
                                dbs.Load(xmlIn);
                                break;

                            case optionsTag:
                                LoadOptions(xmlIn);
                                break;
                            }

                            // read to the next node, if loader did not move any further
                            if (xmlIn.LineNumber == tagStartLineNummber)
                            {
                                xmlIn.Read( );
                            }
                        }

                        isSuccessfullyLoaded = true;
                        // ignore the rest
                    }
                    catch
                    {
                    }
                    finally
                    {
                        if (xmlIn != null)
                        {
                            xmlIn.Close( );
                        }
                    }
                }
            }

            return(isSuccessfullyLoaded);
        }