Ejemplo n.º 1
0
 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());
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 5
0
        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");
                }
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 7
0
        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)));
        }
Ejemplo n.º 8
0
 public LazuriteCore()
 {
     Singleton.Add(Savior                 = new FileSavior());
     Singleton.Add(WarningHandler         = new WarningHandler());
     Singleton.Add(SystemUtils            = new SystemUtils());
     Singleton.Add(AddictionalDataManager = new AddictionalDataManager());
 }
Ejemplo n.º 9
0
 private void FastSwitchWindow_Closed(object sender, System.EventArgs e)
 {
     Singleton.Clear <IHardwareVolumeChanger>();
     if (_oldChanger != null)
     {
         Singleton.Add(_oldChanger);
     }
 }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 13
0
        public void Singleton_AddAndGetWithKey()
        {
            var id = Guid.NewGuid();

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

            Assert.Equal("oka", res);
        }
Ejemplo n.º 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());
 }
Ejemplo n.º 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>());
    }
Ejemplo n.º 16
0
        public MainWindow()
        {
            InitializeComponent();
            Icon = BitmapFrame.Create(Icons.Utils.GetIconData(Icons.Icon.Lazurite64));

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

            MouseWheel += Window_MouseWheel;
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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();
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 20
0
        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();
            }
        }
Ejemplo n.º 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>();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 27
0
        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();
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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>();
        }
Ejemplo n.º 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);
            }
        }