示例#1
0
        private void SaveModule()
        {
            if (string.IsNullOrWhiteSpace(ModuleName))
            {
                return;
            }
            bool doSave = true;

            if (Modules.Contains(ModuleName))
            {
                SaveModuleConfirmationRequest.Raise(new Confirmation
                {
                    Title   = "Overwrite Module?",
                    Content = "A module with that name already exists.\n\nAre you sure you want to overwrite it?"
                }, delegate(IConfirmation confirmation)
                {
                    doSave = confirmation.Confirmed;
                });
            }

            if (doSave)
            {
                _eventAggregator.GetEvent <ModuleSavedEvent>().Publish(ModuleName);
                Notification.Content = ModuleName;
                FinishInteraction();
            }
        }
示例#2
0
        /// <summary>
        /// Adds a module to the product
        /// </summary>
        /// <param name="module"></param>
        public void AddModule(Module module)
        {
            Contract.Requires(module != null);
            Contract.Ensures(Modules.Contains(module));

            modules.Add(module);
        }
 public void RemoveModule <T>()
     where T : class
 {
     if (Modules.Contains(typeof(T)))
     {
         Modules.Remove(typeof(T));
     }
 }
示例#4
0
 public void DeregisterModule(IAutoDarkModeModule module)
 {
     if (Modules.Contains(module))
     {
         module.Cleanup();
         Modules.Remove(Modules.Find(m => m.Name == module.Name));
         Logger.Info($"deregistered {module.Name} from timer {Name}");
     }
 }
示例#5
0
 /// <summary>
 ///     Метод, добавляющий модуль в многомодульное число.
 /// </summary>
 /// <param name="comparison"></param>
 /// <exception cref="InvalidOperationException">Модуль уже присутствует в числе</exception>
 public void AddModule(Comparison.LinearComparison comparison)
 {
     if (Modules.Contains(comparison.M))
     {
         throw new InvalidOperationException("Такой модуль уже присутствует в числе!");
     }
     Values.Add(comparison);
     Values = Values.OrderByDescending(element => element.M).ToList();
 }
        public ClientBuilder AddModule <T>()
            where T : class
        {
            if (!Modules.Contains(typeof(T)))
            {
                Modules.Add(typeof(T));
            }

            return(this);
        }
示例#7
0
 public void Collect(ModuleDefinition mod)
 {
     if (Modules.Contains(mod))
     {
         return;
     }
     Modules.Add(mod);
     foreach (var type in mod.Types)
     {
         Collect(type);
     }
 }
示例#8
0
 /// <summary>
 /// Register a new <see cref="IAutoDarkModeModule" module/>
 /// </summary>
 /// <param name="module"></param>
 public void RegisterModule(IAutoDarkModeModule module)
 {
     if (!Modules.Contains(module))
     {
         if (module.FireOnRegistration)
         {
             module.Fire();
         }
         Modules.Add(module);
         Modules.Sort();
         Logger.Info($"registered {module.Name} to timer {Name}");
     }
 }
示例#9
0
 /// <summary>
 /// Register a new <see cref="IAutoDarkModeModule" module/>
 /// </summary>
 /// <param name="module"></param>
 public void RegisterModule(IAutoDarkModeModule module)
 {
     if (!Modules.Contains(module))
     {
         if (module.FireOnRegistration)
         {
             module.Fire();
         }
         Modules.Add(module);
         Modules.Sort();
         Logger.Info($"registered {module.Name} to timer {Name}");
     }
     // possible call OnTimedEvent here to reduce wait time after module has been added
     // maybe counters concurrency mitigation delay
 }
示例#10
0
        public override bool Init()
        {
            Operation init = Begin("Initializing embedded Python interpreter");

            if (PythonEngine.IsInitialized && (HomeDir != string.Empty || ModulePath != string.Empty || Args.Count > 0))
            {
                Error("Python engine is already initialized and cannot be initilaized with another script or aditional arguments.");
                init.Cancel();
                return(false);
            }

            string originalDirectory = Directory.GetCurrentDirectory();

            try
            {
                SetVirtualEnvDir();
                SetBinDir();
                if (binDir.IsNotEmpty())
                {
                    Directory.SetCurrentDirectory(binDir);
                }
                SetPythonPath();
                PythonEngine.Initialize(Args);
            }
            catch (DllNotFoundException dnfe)
            {
                if (HomeDir.IsEmpty())
                {
                    Error(dnfe, $"Could not find the system-wide python36 shared library. Add Python 3.6 to your PATH environment variable or use the -P option to set the path to a Python 3.6 interpreter directory.");
                }
                else
                {
                    Error(dnfe, $"Could not find python36 shared library in {HomeDir}.");
                }
            }
            catch (Exception e)
            {
                Error(e, "Exception thrown initalizing Python engine.");
            }
            finally
            {
                if (Directory.GetCurrentDirectory() != originalDirectory)
                {
                    Directory.SetCurrentDirectory(originalDirectory);
                }
            }

            if (!PythonEngine.IsInitialized)
            {
                Error("Could not initalize Python engine.");
                init.Cancel();
                return(false);
            }

            Info("Python version {0} from {1}.", PythonEngine.Version.Trim(), binDir.IsEmpty() ? Runtime.PythonDLL : Path.Combine(binDir, Runtime.PythonDLL.WithDllExt()));
            Modules = GetModules();
            Info("{0} Python modules installed.", Modules.Count(m => !m.StartsWith("__")));
            HasPipModule = Modules.Contains("pip");
            if (!HasPipModule)
            {
                Warn("Python pip module is not installed.");
            }
            else
            {
                PipModules = GetPipModules();
                Info("{0} pip modules installed.", PipModules.Count);
            }

            foreach (string m in RequiredModules)
            {
                if (!Modules.Contains(m))
                {
                    Error("Python {0} module is not installed.", m);
                    init.Cancel();
                    return(false);
                }
            }

            init.Complete();
            return(true);
        }