コード例 #1
0
ファイル: Program.cs プロジェクト: modeco80/cvm2-server-cs
 static void LoadAllControllers()
 {
     string[] controllers = Directory.GetFiles("controllers/", "*.dll");
     foreach (string controller in controllers)
     {
         Logger.Log("Attempting to load controller " + controller);
         IVirtualMachineController vm = LoadController(controller);
         if (vm == null)
         {
             continue; // error loading that plugin; skip list add
         }
         vms.Add(vm.Id, vm);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: modeco80/cvm2-server-cs
        // Loads a controller plugin.
        public static IVirtualMachineController LoadController(string ControllerAssemblyPath)
        {
            Assembly ControllerAssembly;
            IVirtualMachineController vm = null;

            try
            {
                ControllerAssembly = Assembly.LoadFrom(ControllerAssemblyPath);
            }
            catch (Exception ex)
            {
                Logger.Log($"Error loading controller {ControllerAssemblyPath}", Logger.Severity.Error);
                Logger.Log($"Exception message: {ex.Message}", Logger.Severity.Error);
                return(null);
            }

            foreach (Type AssemblyType in ControllerAssembly.GetTypes())
            {
                if (typeof(IVirtualMachineController).GetTypeInfo().IsAssignableFrom(AssemblyType.GetTypeInfo()))
                {
                    object ControllerInstance = Activator.CreateInstance(AssemblyType);
                    try
                    {
                        vm = (IVirtualMachineController)ControllerInstance;
                        Logger.Log("VM Controller \"" + vm.DescribingName + "\" loaded successfully!");
                    }
                    catch (Exception ex)
                    {
                        Logger.Log($"Error loading controller {ControllerAssemblyPath}", Logger.Severity.Error);
                        Logger.Log($"Exception message: {ex.Message}", Logger.Severity.Error);
                        return(null);
                    }
                    return(vm);
                }
            }

            // Return a nullref if there is an error.
            return(null);
        }
コード例 #3
0
 public VirtualMachine(IVirtualMachineController vmc, string id)
 {
     this.id  = id;
     this.vmc = vmc;
     this.vmc.DisplayUpdate += this.OnDisplayUpdate;
 }