Example #1
0
        static void Export( Info info )
        {
            Console.WriteLine( "Loading the existing world database..." );
            CanonWorld cw = CanonWorld.FromWorldDatabase( info.worlddb, false, true );
            World w = World.Wrap( new ShadowWorld( cw ) );

            // We have a directory structure, not just an XML file, because we may also need to
            // store binary blobs like images.
            Console.WriteLine( "Saving out world database export..." );
            string baseDir = info.xmlDir;
            if( Directory.Exists( baseDir ) )
            Directory.Delete( baseDir, true );
            Directory.CreateDirectory( baseDir );

            string binDir = Path.Combine( baseDir, "bin" );
            string textDir = Path.Combine( baseDir, "text" );
            string verbDir = Path.Combine( baseDir, "verb" );
            Directory.CreateDirectory( binDir );
            Directory.CreateDirectory( textDir );
            Directory.CreateDirectory( verbDir );

            var objs = w.findObjects( x => true );

            XmlClimoo root = new XmlClimoo();

            foreach( Mob m in objs )
            {
            XmlMob mob = new XmlMob()
            {
                id = m.id,
                parentId = m.parentId,
                pathId = m.pathId,
                locationId = m.locationId,
                ownerId = m.ownerId
            };
            root.mobs.Add( mob );

            foreach( var name in m.attrList )
            {
                string strfn = null, binfn = null;
                var item = m.attrGet( name );
                AttributeSerialized ser = item.serialize();
                if( ser.strvalue != null )
                {
                    strfn = String.Format( "{0}-{1}.txt", m.id, name );
                    File.WriteAllText( Path.Combine( textDir, strfn ), ser.strvalue );
                }
                else if( !item.isNull )
                {
                    binfn = String.Format( "{0}-{1}.bin", m.id, name );
                    File.WriteAllBytes( Path.Combine( binDir, binfn ), ser.binvalue );
                }

                XmlAttr attr = new XmlAttr()
                {
                    mimeType = item.mimetype,
                    name = name,
                    textContentName = strfn,
                    dataContentName = binfn,
                };
                mob.attrs.Add( attr );
            }

            foreach( var name in m.verbList )
            {
                var item = m.verbGet( name );
                string verbfn = "{0}-{1}.cs".FormatI( m.id, item.name );
                File.WriteAllText( Path.Combine( verbDir, verbfn ), item.code );
                XmlVerb verb = new XmlVerb()
                {
                    name = item.name,
                    codeName = verbfn
                };
                mob.verbs.Add( verb );
            }
            }

            XmlPersistence.Save<XmlClimoo>( Path.Combine( baseDir, "mobs.xml" ), root );

            // This holds everything not in MooCore.
            XmlClimooWeb web = new XmlClimooWeb();

            Console.WriteLine("Exporting web core database...");

            string screenDir = Path.Combine( baseDir, "screen" );
            Directory.CreateDirectory( screenDir );

            var token = info.coredb.token();
            foreach( var r in info.coredb.@select( token, new DBScreen(), new string[] { } ) )
            {
            var scrfn = String.Format( "{0}.html", r.name );
            File.WriteAllText( Path.Combine( screenDir, scrfn ), r.text );

            web.screens.Add( new XmlScreen()
            {
                name = r.name,
                textName = scrfn
            } );
            }
            web.users.AddRange(
            from r in info.coredb.@select( token, new DBUser(), new string[] { } )
            select new XmlUser() {
                login = r.login,
                name = r.name,
                objectId = r.@object,
                openId = r.openId,
                password = r.password
            });

            XmlPersistence.Save<XmlClimooWeb>( Path.Combine( baseDir, "web.xml" ), web );
        }
Example #2
0
        static void Export( Info info )
        {
            Console.WriteLine( "Loading the existing world database..." );
            CanonWorld cw = CanonWorld.FromWorldDatabase( info.worlddb, false, true );
            World w = World.Wrap( new ShadowWorld( cw ) );

            // We have a directory structure, not just an XML file, because we may also need to
            // store binary blobs like images.
            Console.WriteLine( "Saving out world database export..." );
            string baseDir = info.xmlDir;
            if( Directory.Exists( baseDir ) )
            Directory.Delete( baseDir, true );
            Directory.CreateDirectory( baseDir );

            string binDir = Path.Combine( baseDir, "bin" );
            string textDir = Path.Combine( baseDir, "text" );
            string verbDir = Path.Combine( baseDir, "verb" );
            Directory.CreateDirectory( binDir );
            Directory.CreateDirectory( textDir );
            Directory.CreateDirectory( verbDir );

            var objs = w.findObjects( x => true );

            XmlClimoo root = new XmlClimoo();

            foreach( Mob m in objs )
            {
            XmlMob mob = new XmlMob()
            {
                id = m.id,
                parentId = m.parentId,
                pathId = m.pathId,
                locationId = m.locationId,
                ownerId = m.ownerId
            };
            root.mobs.Add( mob );

            foreach( var name in m.attrList )
            {
                string strfn = null, binfn = null;
                var item = m.attrGet( name );
                AttributeSerialized ser = item.serialize();
                if( ser.strvalue != null )
                {
                    strfn = String.Format( "{0}-{1}.txt", m.id, name );
                    File.WriteAllText( Path.Combine( textDir, strfn ), ser.strvalue );
                }
                else if( !item.isNull )
                {
                    binfn = String.Format( "{0}-{1}.bin", m.id, name );
                    File.WriteAllBytes( Path.Combine( binDir, binfn ), ser.binvalue );
                }

                XmlAttr attr = new XmlAttr()
                {
                    mimeType = item.mimetype,
                    name = name,
                    textContentName = strfn,
                    dataContentName = binfn,
                };
                mob.attrs.Add( attr );
            }

            foreach( var name in m.verbList )
            {
                var item = m.verbGet( name );
                string verbfn = "{0}-{1}.coral".FormatI( m.id, item.name );
                File.WriteAllText( Path.Combine( verbDir, verbfn ), item.code );
                XmlVerb verb = new XmlVerb()
                {
                    name = item.name,
                    codeName = verbfn
                };
                mob.verbs.Add( verb );
            }
            }

            XmlPersistence.Save<XmlClimoo>( Path.Combine( baseDir, "mobs.xml" ), root );
        }