Exemplo n.º 1
0
 internal static void Main(string[] args)
 {
     Module[] modules = ModuleLoader.LoadModule(ModuleLoader.SelectModules.New, true);
     Console.WriteLine("\nPress any key to REALOAD and START again modules...\n");
     Console.ReadKey(true);
     ModuleLoader.ReloadModule(ref modules, true);
     Console.WriteLine("\nPress any key to STOP and REMOVE modules...\n");
     Console.ReadKey(true);
     ModuleLoader.RemoveModule(ref modules);
     Console.WriteLine("\nPress any key to exit...");
     Console.ReadKey(true);
 }
Exemplo n.º 2
0
        private static void _fileWatcher_Changed(object sender, ModuleEventArgs e)
        {
            Console.WriteLine("Changed someting: {0}", e.ChangeType);
            e.Target._fileInfo.Refresh();
            if (e.ChangeType == WatcherChangeTypes.Changed && e.Target.LastWriteTime != e.Target._fileInfo.LastWriteTime)
            {
                Console.WriteLine("DONE");
                e.Target.Reload(true, e.Target.ConstructorParameters);
            }
            else if (e.ChangeType == WatcherChangeTypes.Created)
            {
                ModuleLoader.LoadModule(e.FullPath, true);
            }
            else if (e.ChangeType == WatcherChangeTypes.Renamed)
            {
                if (e.Name.EndsWith(".module.dll"))
                {
                    e.Target.NotifyNameChanged(e.FullPath);
                }
                else
                {
                    Console.WriteLine("Invalid path format given \"{0}\". File name should end with \".module.dll\"!\n\tFilename is changed back to {1}.", e.Name, e.Target._fileInfo.Name);
                    _moduleWatcher.EnableRaisingEvents = false;
                    File.Move(e.FullPath, e.Target.Path);
                    _moduleWatcher.EnableRaisingEvents = true;
                }
            }
            // ELSE DO NOTHING - e.ChangeType == WatcherChangeTypes.Deleted
            // We'd not like to delete the module because it is possible that the user doesn't wants to. In cases, the file name could changle with the new version so we should keep it now.
            // TODO: Later we will implement to reload the module in a similar case like describer in the prvious sentence.

            /*
             * else if (e.ChangeType == WatcherChangeTypes.Deleted)
             * {
             *  //TODO
             * }
             */
        }