public static void Initialize()
 {
     if (!Singleton.Any <ILogger>())
     {
         Singleton.Add(new LogStub());
     }
     if (!Singleton.Any <LazuriteContext>())
     {
         Singleton.Add(new LazuriteContext());
     }
     if (!Singleton.Any <SaviorBase>())
     {
         Singleton.Add(new JsonFileSavior());
     }
     if (!Singleton.Any <ISystemUtils>())
     {
         Singleton.Add(new SystemUtils());
     }
     if (!Singleton.Any <IServiceClientManager>())
     {
         Singleton.Add(new ServiceClientManager());
     }
     if (!Singleton.Any <AddictionalDataManager>())
     {
         Singleton.Add(new AddictionalDataManager());
     }
     if (!Singleton.Any <INotifier>())
     {
         Singleton.Add(new Notifier());
     }
     if (!Singleton.Any <IGeolocationView>())
     {
         Singleton.Add(new GeolocationViewIntentCreator());
     }
 }
Example #2
0
        public void TestSingletonResolver()
        {
            var tic = new TestInterfaceClass();

            Singleton.Add(tic);
            var tic2 = Singleton.Resolve <ITestInterface>();
            var tic3 = Singleton.Resolve <TestInterfaceClass>();

            var at = new ConcreteTest();

            Singleton.Add(at);
            var at2 = Singleton.Resolve <AbstractTest>();
            var at3 = Singleton.Resolve <ConcreteTest>();

            var tc = new TestSubClass();

            Singleton.Add(tc);
            var tc2 = Singleton.Resolve <TestClass>();

            if (tc2.GetInt() != tc.GetInt())
            {
                throw new Exception();
            }

            if (tic2 == null || at2 == null || at3 == null || tc2 == null)
            {
                throw new Exception();
            }
        }
Example #3
0
        public MainPage()
        {
            InitializeComponent();

            Singleton.Clear <INotificationsHandler>();
            Singleton.Add((INotificationsHandler)this);

            tabsView.AddTabInfo(new SliderTabsView.TabInfo(connectionSettingsSlider, LazuriteUI.Icons.Icon.Settings));
            tabsView.AddTabInfo(new SliderTabsView.TabInfo(messagesSlider, LazuriteUI.Icons.Icon.EmailMinimal));
            _supportsResume.StateChanged = (sender, currentState, previousState) =>
            {
                //do not reinit when app was "home button pressed"
                if (currentState == SupportsResumeState.Paused)
                {
                    DialogView.CloseAllDialogs();
                }
                if (previousState == SupportsResumeState.Closed || previousState == SupportsResumeState.Stopped)
                {
                    InitializeManager();
                }
            };
            settingsView.ConnectClicked     += SettingsView_ConnectClicked;
            _manager.ConnectionError        += _manager_ConnectionError;
            _manager.NeedRefresh            += _manager_NeedRefresh;
            _manager.ConnectionLost         += _manager_ConnectionLost;
            _manager.ConnectionRestored     += _manager_ConnectionRestored;
            _manager.NeedClientSettings     += _manager_NeedClientSettings;
            _manager.LoginOrPasswordInvalid += _manager_LoginOrPasswordInvalid;
            _manager.CredentialsLoaded      += _manager_CredentialsLoaded;
            _manager.SecretCodeInvalid      += _manager_SecretCodeInvalid;
            _manager.ScenariosChanged       += _manager_ScenariosChanged;
        }
Example #4
0
        public void RunServer()
        {
            Singleton.Add(new FileSavior());
            Singleton.Add(new WarningHandler());
            Singleton.Add(new ScenariosRepository());
            Singleton.Add(new UsersRepository());
            Singleton.Add(new VisualSettingsRepository());
            Singleton.Add(new ServiceClientFactory());

            var scenariosRepository = Singleton.Resolve <ScenariosRepositoryBase>();
            var usersRepository     = Singleton.Resolve <UsersRepository>();

            if (!usersRepository.Users.Any(x => x.Login.Equals("anton")))
            {
                usersRepository.Add(new User()
                {
                    Login        = "******",
                    PasswordHash = CryptoUtils.CreatePasswordHash("123")
                });
            }

            var server = new LazuriteServer();

            server.StartAsync(null);

            while (true)
            {
                Thread.Sleep(5000);
            }
        }
        public void SecureEncoding_test1()
        {
            Singleton.Add(new WarningHandler());
            Singleton.Add(new FileSavior());
            Singleton.Add(new SystemUtils());

            var str            = "test_string test this string string test test one one";
            var secretKey      = "0123456789123456";
            var secureEncoding = new SecureEncoding(secretKey);

            for (var i = 0; i <= 1000; i++)
            {
                var salt          = SecureEncoding.CreateSalt();
                var iv            = SecureEncoding.CreateIV(salt, secretKey);
                var encodedString = secureEncoding.Encrypt(Encoding.UTF8.GetBytes(str), iv);
                iv = SecureEncoding.CreateIV(salt, secretKey);
                var decodedString = secureEncoding.Decrypt(encodedString, iv);
                Debug.WriteLine("encoded = " + encodedString);
                Debug.WriteLine("decoded = " + decodedString);
                Debug.WriteLine("iv = " + Convert.ToBase64String(iv));
                if (str != decodedString)
                {
                    Debug.WriteLine("ERROR!!!!");
                    throw new Exception();
                }
                else
                {
                    Debug.WriteLine("OK");
                }
            }
        }
Example #6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            var log    = new WarningHandler();
            var savior = new FileSavior();

            Singleton.Add(savior);
            Singleton.Add(log);
            if (e.Args.Length == 1)
            {
                if (e.Args[0] == KillLazuriteProcessCommand)
                {
                    Utils.KillAllLazuriteProcesses();
                    App.Current.Shutdown();
                }
                else if (e.Args[0] == RemoveFromAutorunCommand)
                {
                    TaskSchedulerUtils.RemoveLogonTask();
                    App.Current.Shutdown();
                }
                else
                {
                    new MainWindow(e.Args[0]).Show();
                }
            }
            else
            {
                Lazurite.Windows.Utils.Utils.ExecuteProcess(Lazurite.Windows.Utils.Utils.GetAssemblyPath(typeof(App).Assembly), WindowsIdentity.GetCurrent().Name, true, false);
                App.Current.Shutdown();
            }
        }
        public void SecureEncoding_test2()
        {
            Singleton.Add(new WarningHandler());
            Singleton.Add(new FileSavior());
            Singleton.Add(new SystemUtils());

            var str1           = "test_string test this string string test test one one";
            var str2           = "test_string test this3 string str3ing test test one4 one";
            var str3           = "test_string test t123his stri2312ng string 121233test test123 one123 one";
            var str4           = "test_string 1234121";
            var str5           = "test_string tsest thsis strisng stsring tsest stest one sone";
            var str6           = "test_striasdfs";
            var str7           = "test";
            var secretKey      = "0123456789123456";
            var secureEncoding = new SecureEncoding(secretKey);
            var salt           = SecureEncoding.CreateSalt();
            var iv             = SecureEncoding.CreateIV(salt, secretKey);

            Debug.WriteLine(string.Format("encoded 1 = " + secureEncoding.Encrypt(str1, iv)));
            Debug.WriteLine(string.Format("encoded 2 = " + secureEncoding.Encrypt(str2, iv)));
            Debug.WriteLine(string.Format("encoded 3 = " + secureEncoding.Encrypt(str3, iv)));
            Debug.WriteLine(string.Format("encoded 4 = " + secureEncoding.Encrypt(str4, iv)));
            Debug.WriteLine(string.Format("encoded 5 = " + secureEncoding.Encrypt(str5, iv)));
            Debug.WriteLine(string.Format("encoded 6 = " + secureEncoding.Encrypt(str6, iv)));
            Debug.WriteLine(string.Format("encoded 7 = " + secureEncoding.Encrypt(str7, iv)));
        }
Example #8
0
 public LazuriteCore()
 {
     Singleton.Add(Savior                 = new FileSavior());
     Singleton.Add(WarningHandler         = new WarningHandler());
     Singleton.Add(SystemUtils            = new SystemUtils());
     Singleton.Add(AddictionalDataManager = new AddictionalDataManager());
 }
Example #9
0
 private void FastSwitchWindow_Closed(object sender, System.EventArgs e)
 {
     Singleton.Clear <IHardwareVolumeChanger>();
     if (_oldChanger != null)
     {
         Singleton.Add(_oldChanger);
     }
 }
        public void CreatePluginTest()
        {
            Singleton.Add(new FileSavior());
            var sourcePluginFolder = @"D:\Programming\Lazurite_2\LazuriteTestModules\LazuriteTestModules\LazuriteTestModules\bin\Debug\";
            var targetFile         = @"D:\Temporary\Lazurite_test.pyp";

            PluginsCreator.CreatePluginFile(sourcePluginFolder, targetFile);
        }
Example #11
0
        public void Singleton_AddAndGet()
        {
            var id = Guid.NewGuid();

            Singleton.Add(id);
            var res = Singleton.Get <Guid>();

            Assert.Equal(res, id);
        }
        public static void Initialize()
        {
            if (!Singleton.Any <ILogger>())
            {
                Singleton.Add(new LogStub());
            }

            if (!Singleton.Any <LazuriteContext>())
            {
                Singleton.Add(new LazuriteContext());
            }

            if (!Singleton.Any <DataEncryptor>())
            {
                Singleton.Add(new AndroidSpecificDataEncryptor());
            }

            if (!Singleton.Any <DataManagerBase>())
            {
                Singleton.Add(new JsonFileManager());
            }

            if (!Singleton.Any <ISystemUtils>())
            {
                Singleton.Add(new SystemUtils());
            }

            if (!Singleton.Any <AddictionalDataManager>())
            {
                Singleton.Add(new AddictionalDataManager());
            }

            if (!Singleton.Any <INotifier>())
            {
                Singleton.Add(new Notifier());
            }

            if (!Singleton.Any <IGeolocationView>())
            {
                Singleton.Add(new GeolocationViewIntentCreator());
            }

            if (!Singleton.Any <StoredPropertiesManager>())
            {
                Singleton.Add(new StoredPropertiesManager());
            }

            if (!Singleton.Any <IRuntimePermissionsHandler>())
            {
                Singleton.Add(new RuntimePermissionsHandler());
            }

            if (!Singleton.Any <IGeolocationListener>())
            {
                Singleton.Add(new GeolocationListener());
            }
        }
Example #13
0
        public void Singleton_AddAndGetWithKey()
        {
            var id = Guid.NewGuid();

            Singleton.Add("oka", id);
            var res = Singleton.Get <string>(id);

            Assert.Equal("oka", res);
        }
Example #14
0
 public LazuriteCore()
 {
     Singleton.Add(WarningHandler = new WarningHandler());
     Singleton.Add(new DataEncryptor());
     Singleton.Add(DataManager = new FileDataManager());
     Singleton.Add(new StoredPropertiesManager());
     Singleton.Add(SystemUtils            = new SystemUtils());
     Singleton.Add(AddictionalDataManager = new AddictionalDataManager());
 }
Example #15
0
    public void Singleton_AddAndGet()
    {
        var id = Guid.NewGuid();

        Singleton.Add(id);
        Assert.Equal(Singleton.Get <Guid>(), id);

        Singleton.Add <string?>(null);
        Assert.Null(Singleton.Get <string>());
    }
Example #16
0
        public MainWindow()
        {
            InitializeComponent();
            Icon = BitmapFrame.Create(Icons.Utils.GetIconData(Icons.Icon.Lazurite64));

            Singleton.Clear <IHardwareVolumeChanger>();
            Singleton.Add(this);

            MouseWheel += Window_MouseWheel;
        }
        public void TestExtModulesAcrossSerializing_part1()
        {
            var savior = new FileSavior();

            Singleton.Add(savior);
            var     manager    = new PluginsManager();
            IAction testAction = manager.CreateInstance(manager.GetModules().First(), null);

            testAction.SetValue(null, DateTime.Now.ToString());
            savior.Set("testAction", testAction);
        }
        public void RemoveLibTest()
        {
            Singleton.Add(new FileSavior());
            var modulesManager = new PluginsManager();

            modulesManager.RemovePlugin(modulesManager.GetPlugins().First().Name);
            if (modulesManager.GetModules().Any(x => x.Name.Contains("TestAction")))
            {
                throw new Exception();
            }
        }
Example #19
0
        public DIHelper TryAddSingleton <TService, TImplementation>(TService tservice, TImplementation tImplementation) where TService : Type where TImplementation : Type
        {
            var serviceName = $"{tservice}{tImplementation}";

            if (!Singleton.Contains(serviceName))
            {
                Singleton.Add(serviceName);
                ServiceCollection.TryAddSingleton(tservice, tImplementation);
            }
            return(this);
        }
        public void LoadPluginTest()
        {
            Singleton.Add(new FileSavior());
            var modulesManager = new PluginsManager();
            var targetFile     = @"D:\Temporary\Lazurite_test.pyp";

            modulesManager.AddPlugin(targetFile);
            if (!modulesManager.GetModules().Any(x => x.Name.Contains("TestAction")))
            {
                throw new Exception();
            }
        }
Example #21
0
        public MainHandler()
        {
            _config = BuildConfiguration();
            Singleton.Add <Configuration>(_config);
            Singleton.Add <HttpHandler>();
            Singleton.Add <CacheHandler>();
            Singleton.Add <SourceHandler>();
            Singleton.Add <WsServer>();

            _httpHandler = Singleton.Of <HttpHandler>();
            _wSServer    = Singleton.Of <WsServer>();
        }
Example #22
0
        public DIHelper TryAddSingleton <TService>(TService t) where TService : class
        {
            var serviceName = $"{typeof(TService)}";

            if (!Singleton.Contains(serviceName))
            {
                Singleton.Add(serviceName);
                ServiceCollection.TryAddSingleton(t);
            }

            return(this);
        }
Example #23
0
        public DIHelper AddSingleton <TService, TImplementation>() where TService : class where TImplementation : class, TService
        {
            var serviceName = $"{typeof(TService)}{typeof(TImplementation)}";

            if (!Singleton.Contains(serviceName))
            {
                Singleton.Add(serviceName);
                ServiceCollection.AddSingleton <TService, TImplementation>();
            }

            return(this);
        }
Example #24
0
        public DIHelper TryAddSingleton <TService>(Func <IServiceProvider, TService> implementationFactory) where TService : class
        {
            var serviceName = $"{typeof(TService)}";

            if (!Singleton.Contains(serviceName))
            {
                Singleton.Add(serviceName);
                ServiceCollection.TryAddSingleton(implementationFactory);
            }

            return(this);
        }
Example #25
0
        public App()
        {
            AppDomain.CurrentDomain.ProcessExit += (o, e) => {
                Core.WarningHandler.Info("Lazurite отключен");
            };

            System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            System.Windows.Forms.Application.ThreadException += (o, e) => {
                HandleUnhandledException(e.Exception);
            };

            AppDomain.CurrentDomain.UnhandledException += (o, e) => {
                HandleUnhandledException(e.ExceptionObject as Exception);
            };

            DispatcherUnhandledException += (o, e) => {
                HandleUnhandledException(e.Exception);
            };

            ShutdownMode = ShutdownMode.OnExplicitShutdown;
            try
            {
                Core = new LazuriteCore();

                // Crutch; after this actions first window run is faster
                JournalLightWindow.Show("Lazurite запущен...", WarnType.Info);
                JournalLightWindow.CloseWindow();

                Core.WarningHandler.OnWrite += (o, e) => {
                    var args = (WarningEventArgs)e;
                    JournalManager.Set(args.Message, args.Value, args.Exception);
                };
                Core.Initialize();
                Core.Server.StartAsync(null);
                Singleton.Add(Core);
                NotifyIconManager.Initialize();
                DuplicatedProcessesListener.Found += (o, e) => NotifyIconManager.ShowMainWindow();
                DuplicatedProcessesListener.Start();
            }
            catch (Exception e)
            {
                Core.WarningHandler.Fatal("Во время инициализации приложения возникла ошибка", e);
            }

            var ci = new CultureInfo("ru-RU");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
        }
Example #26
0
        public FastSwitchWindow()
        {
            if (Singleton.Any <IHardwareVolumeChanger>())
            {
                _oldChanger = Singleton.Resolve <IHardwareVolumeChanger>();
                Singleton.Clear <IHardwareVolumeChanger>();
            }
            Singleton.Add(this); // Add as IHardwareVolumeChanger

            MouseWheel += Window_MouseWheel;
            Closed     += FastSwitchWindow_Closed;
            InitializeComponent();
            switchesGrid.Initialize();
        }
        public void TestExtModulesAcrossSerializing_part2()
        {
            var savior = new FileSavior();

            Singleton.Add(savior);
            var     modulesManager = new PluginsManager();
            IAction testAction     = savior.Get <IAction>("testAction");

            Debug.WriteLine(testAction.GetValue(null));
            if (!testAction.GetType().Equals(modulesManager.GetModules().First()))
            {
                throw new Exception();
            }
        }
Example #28
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            AppDomain.CurrentDomain.UnhandledException += (o, args) => {
                HandleUnhandledException(args.ExceptionObject as Exception);
            };

            DispatcherUnhandledException += (o, args) => {
                HandleUnhandledException(args.Exception);
            };

            try
            {
                Singleton.Add(Log = new WarningHandler());

                Singleton.Add(new DataEncryptor());
                Singleton.Add(new FileDataManager());

                Log.OnWrite += (sender, eventArgs) =>
                {
                    var args = (WarningEventArgs)eventArgs;
                    if (args.Value == WarnType.Error || args.Value == WarnType.Fatal)
                    {
                        MessageBox.Show(args.Message, args.Exception?.Message);
                    }
                };

                if (e.Args.Any() && e.Args[0] == TaskSchedulerMode)
                {
                    if (new LauncherSettingsManager().Settings.RunOnUserLogon)
                    {
                        RunLazuriteWithAdminPrivileges();
                    }
                    else
                    {
                        Shutdown();
                    }
                }
                else
                {
                    RunLazuriteWithAdminPrivileges();
                }
            }
            catch (Exception exception)
            {
                HandleUnhandledException(exception);
            }
        }
Example #29
0
        public void Initialize()
        {
            var matches = Assembly.GetExecutingAssembly()
                          .GetTypes()
                          .Where(x => typeof(BaseSourceProvider).IsAssignableFrom(x) && !x.IsAbstract)
                          .ToArray();

            LogHandler <SourceHandler> .Log.Debug($"Discovered {matches.Length} SourceProviders.");

            foreach (var match in matches)
            {
                Singleton.Add(match);
            }

            _sources = Singleton.Of <Configuration>().Sources;
            _cache   = Singleton.Of <CacheHandler>();
        }
Example #30
0
        private void Awake()
        {
            if (isDontDestroyOnLoad)
            {
                DontDestroyOnLoad(gameObject);
            }

            GetComponents(_monoBehaviours);

            // We don't want SingletonBinders to bind themselves
            _monoBehaviours.RemoveAll(mono => mono.GetType() == typeof(SingletonBinder));

            foreach (var mono in _monoBehaviours)
            {
                Singleton.Add(mono.GetType(), mono);
            }
        }