Exemple #1
0
 public XmlSerializer( Type cls, bool serialize_static_mode ) {
     m_serialize_static_mode = serialize_static_mode;
     if ( serialize_static_mode ) {
         m_static_serializer = new XmlStaticMemberSerializer( cls );
     } else {
         m_serializer = new System.Xml.Serialization.XmlSerializer( cls );
     }
 }
        /// <summary>
        /// パレットツールを読み込みます
        /// </summary>
        public static void init() {
            String path = Utility.getToolPath();
            if ( !Directory.Exists( path ) ) {
                return;
            }

            FileInfo[] files = new DirectoryInfo( path ).GetFiles( "*.txt" );
            foreach ( FileInfo file in files ) {
                String code = "";
                StreamReader sr = null;
                try {
                    sr = new StreamReader( file.FullName );
                    code += sr.ReadToEnd();
                } catch ( Exception ex ) {
                    Logger.write( typeof( PaletteToolServer ) + ".init; ex=" + ex + "\n" );
                } finally {
                    if ( sr != null ) {
                        try {
                            sr.Close();
                        } catch ( Exception ex2 ) {
                            Logger.write( typeof( PaletteToolServer ) + ".init; ex=" + ex2 + "\n" );
                        }
                    }
                }

                Assembly asm = null;
                Vector<String> errors = new Vector<String>();
                try {
                    asm = Utility.compileScript( code, errors );
                } catch ( Exception ex ) {
                    serr.println( "PaletteToolServer#init; ex=" + ex );
                    asm = null;
                }
                if ( asm == null ) {
                    continue;
                }

                if ( asm == null ) {
                    continue;
                }

                foreach ( Type t in asm.GetTypes() ) {
                    if ( t.IsClass && t.IsPublic && !t.IsAbstract && t.GetInterface( typeof( IPaletteTool ).FullName ) != null ) {
                        try {
#if DEBUG
                            AppManager.debugWriteLine( "t.FullName=" + t.FullName );
#endif
                            Object instance = asm.CreateInstance( t.FullName );
                            String dir = Path.Combine( Utility.getApplicationDataPath(), "tool" );
                            String cfg = Path.GetFileNameWithoutExtension( file.FullName ) + ".config";
                            String config = Path.Combine( dir, cfg );
                            if ( fsys.isFileExists( config ) ) {
                                XmlStaticMemberSerializer xsms = new XmlStaticMemberSerializer( instance.GetType() );
                                FileStream fs = null;
                                boolean errorOnDeserialize = false;
                                try {
                                    fs = new FileStream( config, FileMode.Open, FileAccess.Read );
                                    try {
                                        xsms.Deserialize( fs );
                                    } catch ( Exception ex ) {
                                        errorOnDeserialize = true;
                                        serr.println( "PaletteToolServer#init; ex=" + ex );
                                    }
                                } catch ( Exception ex ) {
                                    serr.println( "PaletteToolServer#init; ex=" + ex );
                                } finally {
                                    if ( fs != null ) {
                                        try {
                                            fs.Close();
                                        } catch ( Exception ex2 ) {
                                            serr.println( "PaletteToolServer#init; ex2=" + ex2 );
                                        }
                                    }
                                }
                                if ( errorOnDeserialize ) {
                                    try {
                                        PortUtil.deleteFile( config );
                                    } catch ( Exception ex ) {
                                        serr.println( "PaletteToolServer#init; ex=" + ex );
                                    }
                                }
                            }
                            String id = Path.GetFileNameWithoutExtension( file.FullName );
                            loadedTools.put( id, instance );
                        } catch ( Exception ex ) {
                            serr.println( "PlaetteToolServer#init; ex=" + ex );
                        }
                    }
                }
            }
        }