Exemplo n.º 1
0
        public static void ReloadPlugins()
        {
            lock (loadedPlugins.SyncRoot) {
                foreach (Assembly a in loadedPlugins)
                {
                    UnregisterAssembly(a);
                    // AssemblyDisposer.ClearAssembly(a); See in scripts
                }
                loadedPlugins.Clear();
            }

            DirectoryInfo pluginsDir = new DirectoryInfo(PluginsDirectory);

            FileInfo[] libs = pluginsDir.GetFiles("*.dll", SearchOption.AllDirectories);

            RuntimeObjectsLoader rol = new RuntimeObjectsLoader();

            rol.Report.Name = "Plugins " + GetCurrentTimeString();
            reports.Add(rol.Report);

            // Load assemblies
            foreach (FileInfo f in libs)
            {
                try {
                    Assembly a = Assembly.LoadFile(f.FullName);
                    rol.AssemblyList.Add(a);
                }
                catch (Exception e) {
                    Trace.WriteLine("Error loading plugin " + f.Name + ". Exception:\n" + e.ToString(), "Runtime");
                }
            }

            // Run analyzation
            rol.Run();

            // Add processed assemblies to list
            foreach (Assembly a in rol.Report.LoadedAssemblies)
            {
                loadedPlugins.Add(a);
            }

            if (rol.Report.AnalyzerErrors.Count > 0)
            {
                ReportViewer.Show(rol.Report);
            }
        }
Exemplo n.º 2
0
        internal static void RegisterPhoenix()
        {
            RuntimeObjectsLoader rol = new RuntimeObjectsLoader();

            rol.AssemblyList.Add(typeof(Core).Assembly);
            rol.Report.Name = "Phoenix " + GetCurrentTimeString();
            reports.Add(rol.Report);
            rol.Run();

            if (rol.Report.AnalyzerErrors.Count > 0)
            {
                using (ReportViewerDialog viewer = new ReportViewerDialog(reports)) {
                    viewer.SelectedReport = rol.Report;
                    viewer.ShowDialog();
                }
            }
        }
Exemplo n.º 3
0
        private static void CompileScriptsInternal(object param)
        {
            Trace.WriteLine("Scripts compilation started.", "Runtime");

            try {
                RuntimeObjectsLoader rol = new RuntimeObjectsLoader();
                rol.Report.Name = "Scripts " + GetCurrentTimeString();
                rol.Report.Output.Add("Scripts directory: " + ScriptsDirectory);

                reports.Add(rol.Report);

                // Read file list
                DirectoryInfo   scriptsDir = new DirectoryInfo(RuntimeCore.ScriptsDirectory);
                List <FileInfo> fileList   = new List <FileInfo>(64);
                fileList.AddRange(scriptsDir.GetFiles("*.cs", SearchOption.AllDirectories));
                fileList.AddRange(scriptsDir.GetFiles("*.vb", SearchOption.AllDirectories));
                fileList.AddRange(scriptsDir.GetFiles("*.boo", SearchOption.AllDirectories));
                fileList.AddRange(scriptsDir.GetFiles("*.resx", SearchOption.AllDirectories));

                for (int i = 0; i < fileList.Count; i++)
                {
                    rol.FileList.Add(fileList[i].FullName);
                }

                rol.Report.Output.Add(rol.FileList.Count.ToString() + " files found.");
                rol.Report.Output.Add("");

                // Create reference list
                // - Phoenix.dll
                rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(typeof(Core).Assembly).FullName);
                // - PhoenixShared.dll
                rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(typeof(RuntimeAttribute).Assembly).FullName);
                // - MulLib.dll
                rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(typeof(MulLib.Ultima).Assembly).FullName);
                // - MagicLibrary.dll
                rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(typeof(Crownwood.Magic.Menus.PopupMenu).Assembly).FullName);

                lock (loadedPlugins.SyncRoot) {
                    foreach (Assembly a in loadedPlugins)
                    {
                        rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(a).FullName);
                    }
                }

                // Unregister old scripts
                lock (scriptAssemblies.SyncRoot) {
                    // First unregister registered script assemblies
                    foreach (Assembly a in scriptAssemblies)
                    {
                        Debug.WriteLine("Unregistering assembly " + a.GetName().Name, "Runtime");
                        UnregisterAssembly(a);
                        // AssemblyDisposer.ClearAssembly(a);
                        // Caused problems that static classes was initialized after this was called and
                        // they registered some things when assembly should be unregistred.
                    }
                    scriptAssemblies.Clear();
                }

                // Compile and register

                bool silent = (bool)param;
                if (!silent)
                {
                    ReportViewer.Show(rol.Report);
                }

                rol.Run();

                if (silent && rol.Report.HasErrors)
                {
                    ReportViewer.Show(rol.Report);
                }

                // Add processed assemblies to list
                foreach (Assembly a in rol.Report.LoadedAssemblies)
                {
                    scriptAssemblies.Add(a);
                }
            }
            catch (Exception e) {
                string msg = "Unhandled exception during scripts compilation. Exception:\n" + e.ToString();
                Trace.WriteLine(msg, "Runtime");
                System.Windows.Forms.MessageBox.Show(msg, "Runtime Error");
            }
            finally {
                Trace.WriteLine("Scipts compilation finished.", "Runtime");
            }
        }
Exemplo n.º 4
0
        private static void CompileScriptsInternal(object param)
        {
            Trace.WriteLine("Scripts compilation started.", "Runtime");

            try {
                RuntimeObjectsLoader rol = new RuntimeObjectsLoader();
                rol.Report.Name = "Scripts " + GetCurrentTimeString();
                rol.Report.Output.Add("Scripts directory: " + ScriptsDirectory);

                reports.Add(rol.Report);

                // Read file list
                DirectoryInfo scriptsDir = new DirectoryInfo(RuntimeCore.ScriptsDirectory);
                List<FileInfo> fileList = new List<FileInfo>(64);
                fileList.AddRange(scriptsDir.GetFiles("*.cs", SearchOption.AllDirectories));
                fileList.AddRange(scriptsDir.GetFiles("*.vb", SearchOption.AllDirectories));
                fileList.AddRange(scriptsDir.GetFiles("*.boo", SearchOption.AllDirectories));
                fileList.AddRange(scriptsDir.GetFiles("*.resx", SearchOption.AllDirectories));

                for (int i = 0; i < fileList.Count; i++) {
                    rol.FileList.Add(fileList[i].FullName);
                }

                rol.Report.Output.Add(rol.FileList.Count.ToString() + " files found.");
                rol.Report.Output.Add("");

                // Create reference list
                // - Phoenix.dll
                rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(typeof(Core).Assembly).FullName);
                // - PhoenixShared.dll
                rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(typeof(RuntimeAttribute).Assembly).FullName);
                // - MulLib.dll
                rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(typeof(MulLib.Ultima).Assembly).FullName);
                // - MagicLibrary.dll
                rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(typeof(Crownwood.Magic.Menus.PopupMenu).Assembly).FullName);

                lock (loadedPlugins.SyncRoot) {
                    foreach (Assembly a in loadedPlugins) {
                        rol.ReferenceList.Add(Helper.GetAssemblyFileInfo(a).FullName);
                    }
                }

                // Unregister old scripts
                lock (scriptAssemblies.SyncRoot) {
                    // First unregister registered script assemblies
                    foreach (Assembly a in scriptAssemblies) {
                        Debug.WriteLine("Unregistering assembly " + a.GetName().Name, "Runtime");
                        UnregisterAssembly(a);
                        // AssemblyDisposer.ClearAssembly(a);
                        // Caused problems that static classes was initialized after this was called and
                        // they registered some things when assembly should be unregistred.
                    }
                    scriptAssemblies.Clear();
                }

                // Compile and register

                bool silent = (bool)param;
                if (!silent)
                    ReportViewer.Show(rol.Report);

                rol.Run();

                if (silent && rol.Report.HasErrors)
                    ReportViewer.Show(rol.Report);

                // Add processed assemblies to list
                foreach (Assembly a in rol.Report.LoadedAssemblies) {
                    scriptAssemblies.Add(a);
                }
            }
            catch (Exception e) {
                string msg = "Unhandled exception during scripts compilation. Exception:\n" + e.ToString();
                Trace.WriteLine(msg, "Runtime");
                System.Windows.Forms.MessageBox.Show(msg, "Runtime Error");
            }
            finally {
                Trace.WriteLine("Scipts compilation finished.", "Runtime");
            }
        }
Exemplo n.º 5
0
        internal static void RegisterPhoenix()
        {
            RuntimeObjectsLoader rol = new RuntimeObjectsLoader();
            rol.AssemblyList.Add(typeof(Core).Assembly);
            rol.Report.Name = "Phoenix " + GetCurrentTimeString();
            reports.Add(rol.Report);
            rol.Run();

            if (rol.Report.AnalyzerErrors.Count > 0) {
                using (ReportViewerDialog viewer = new ReportViewerDialog(reports)) {
                    viewer.SelectedReport = rol.Report;
                    viewer.ShowDialog();
                }
            }
        }
Exemplo n.º 6
0
        public static void ReloadPlugins()
        {
            lock (loadedPlugins.SyncRoot) {
                foreach (Assembly a in loadedPlugins) {
                    UnregisterAssembly(a);
                    // AssemblyDisposer.ClearAssembly(a); See in scripts
                }
                loadedPlugins.Clear();
            }

            DirectoryInfo pluginsDir = new DirectoryInfo(PluginsDirectory);
            FileInfo[] libs = pluginsDir.GetFiles("*.dll", SearchOption.AllDirectories);

            RuntimeObjectsLoader rol = new RuntimeObjectsLoader();
            rol.Report.Name = "Plugins " + GetCurrentTimeString();
            reports.Add(rol.Report);

            // Load assemblies
            foreach (FileInfo f in libs) {
                try {
                    Assembly a = Assembly.LoadFile(f.FullName);
                    rol.AssemblyList.Add(a);
                }
                catch (Exception e) {
                    Trace.WriteLine("Error loading plugin " + f.Name + ". Exception:\n" + e.ToString(), "Runtime");
                }
            }

            // Run analyzation
            rol.Run();

            // Add processed assemblies to list
            foreach (Assembly a in rol.Report.LoadedAssemblies) {
                loadedPlugins.Add(a);
            }

            if (rol.Report.AnalyzerErrors.Count > 0) {
                ReportViewer.Show(rol.Report);
            }
        }