public async Task EnumerateDevices_QuickReconnect_DevicesCollectionEnumerated()
        {
            var            devices       = new List <DeviceDTO>();
            IMetaPubSub    messenger     = GetMessenger();
            IDeviceManager deviceManager = GetDeviceManager(messenger);
            IMetaPubSub    hub           = new MetaPubSub();

            hub.StartServer("Test3");

            int devicesCount = 1000;

            for (int i = 0; i < devicesCount; i++)
            {
                devices.Add(GetRandomDeviceDTO());
            }

            var connectionTask = Task.Factory.StartNew(() =>
            {
                messenger.TryConnectToServer("Test3");
                deviceManager = GetDeviceManager(messenger, devices);
            });
            var disconnectionTask = Task.Factory.StartNew(messenger.DisconnectFromServer);
            var reconnectionTask  = Task.Factory.StartNew(() => messenger.TryConnectToServer("Test3"));

            await Task.WhenAll(connectionTask, disconnectionTask, reconnectionTask);

            await Task.Delay(2000);

            Assert.AreEqual(devicesCount, deviceManager.Devices.Count());
        }
        public async Task EnumerateDevices_FluctuatingServiceConnection_DevicesEnumerated()
        {
            var         devices   = new List <DeviceDTO>();
            IMetaPubSub messenger = GetMessenger();
            IMetaPubSub hub       = new MetaPubSub();

            hub.StartServer("Test1");

            int devicesCount = 100;

            for (int i = 0; i < devicesCount; i++)
            {
                devices.Add(GetRandomDeviceDTO());
            }

            int serviceReconnectsCount = 10;

            for (int i = 0; i < serviceReconnectsCount; i++)
            {
                await messenger.TryConnectToServer("Test1");

                IDeviceManager deviceManager = GetDeviceManager(messenger, devices);
                await Task.Delay(200);

                Assert.AreEqual(devicesCount, deviceManager.Devices.Count());

                await messenger.DisconnectFromServer();

                await Task.Delay(200);

                Assert.AreEqual(0, deviceManager.Devices.Count());
            }
        }
        public async Task EnumerateDevices_ClearDevices_DevicesCollectionCleared()
        {
            var         devices   = new List <DeviceDTO>();
            IMetaPubSub messenger = GetMessenger();
            IMetaPubSub hub       = new MetaPubSub();

            hub.StartServer("Test2");

            await messenger.TryConnectToServer("Test2");

            IDeviceManager deviceManager = GetDeviceManager(messenger);

            int devicesCount = 1000;

            for (int i = 0; i < devicesCount; i++)
            {
                devices.Add(GetRandomDeviceDTO());
            }

            await messenger.PublishOnServer(new DevicesCollectionChangedMessage(devices.ToArray()));

            await messenger.DisconnectFromServer();

            await Task.Delay(200);

            Assert.AreEqual(0, deviceManager.Devices.Count());
        }
Example #4
0
        public async Task <RemoteDevice> CreateRemoteDeviceAsync(string serialNo, byte channelNo, IMetaPubSub remoteDeviceMessenger)
        {
            _log.WriteLine($"({serialNo}) Creating remote vault on channel:{channelNo}");
            var reply = await _metaMessenger.ProcessOnServer <EstablishRemoteDeviceConnectionMessageReply>(new EstablishRemoteDeviceConnectionMessage(serialNo, channelNo));

            var remoteDeviceId = reply.RemoteDeviceId;

            var remoteCommands = new RemoteDeviceCommands(_serviceProxy, _metaMessenger);
            var remoteEvents   = new RemoteDeviceEvents(_metaMessenger);

            var device = new RemoteDevice(remoteDeviceId, channelNo, remoteCommands, remoteEvents, SdkConfig.DefaultRemoteCommandTimeout, new NLogWrapper());
            await remoteDeviceMessenger.TryConnectToServer(reply.ConnectionId);

            remoteCommands.RemoteDevice = device;
            remoteEvents.RemoteDevice   = device;

            _log.WriteLine($"({serialNo}) Created remote vault with id: ({device.Id})");

            return(device);
        }
Example #5
0
        protected override async void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            InitializeDIContainer();

            // Init settings
            ApplicationSettings settings = null;
            ISettingsManager <ApplicationSettings> appSettingsManager = Container.Resolve <ISettingsManager <ApplicationSettings> >();

            try
            {
                var appSettingsDirectory = Path.GetDirectoryName(appSettingsManager.SettingsFilePath);
                if (!Directory.Exists(appSettingsDirectory))
                {
                    Directory.CreateDirectory(appSettingsDirectory);
                }

                settings = await appSettingsManager.LoadSettingsAsync().ConfigureAwait(true);

                // Init localization
                var culture = new CultureInfo(settings.SelectedUiLanguage);
                TranslationSource.Instance.CurrentCulture = culture;
                Thread.CurrentThread.CurrentCulture       = culture;
                Thread.CurrentThread.CurrentUICulture     = culture;
            }
            catch (Exception exp)
            {
                var sb = new StringBuilder();
                sb.AppendLine();
                sb.AppendLine("Unexpected Error 1 in App.Application_Startup()");
                sb.AppendLine($"   Message:{exp.Message}");
                sb.AppendLine($"StackTrace:{exp.StackTrace}");
                sb.AppendLine();
                _log.WriteLine(sb.ToString(), LogErrorSeverity.Error);
            }

            // Due to implementation constraints, taskbar icon must be instantiated as late as possible
            Container.RegisterInstance(FindResource("TaskbarIcon") as TaskbarIcon, new ContainerControlledLifetimeManager());
            Container.Resolve <ITaskbarIconManager>();
            _log.WriteLine("Resolve DI container");
            _startupHelper      = Container.Resolve <IStartupHelper>();
            _workstationManager = Container.Resolve <IWorkstationManager>();

            _metaMessenger = Container.Resolve <IMetaPubSub>();

            _metaMessenger.Subscribe <ConnectedToServerEvent>(OnConnectedToServer);

            _serviceWatchdog = Container.Resolve <IServiceWatchdog>();
            _serviceWatchdog.Start();
            _deviceManager         = Container.Resolve <IDeviceManager>();
            _userActionHandler     = Container.Resolve <UserActionHandler>();
            _hotkeyManager         = Container.Resolve <IHotkeyManager>();
            _hotkeyManager.Enabled = true;
            _buttonManager         = Container.Resolve <IButtonManager>();
            _buttonManager.Enabled = true;
            _messageWindow         = Container.Resolve <MessageWindow>();
            Container.Resolve <IProximityLockManager>();
            Container.Resolve <IVaultLowBatteryMonitor>();

            SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;


            // This will create an instance of password manager view model and allow handling of "Add new account" user action
            // It is required for subscribtion of PasswordManagerViewModel to the "AddAccountForApp" message
            // Note: PasswordManagerViewModel is not required for simplified UI
            Container.Resolve <PasswordManagerViewModel>();

            // Public Suffix list loading and updating may take some time (more than 8000 entries)
            // Better to load it before its required (for main domain extraction)
            await Task.Run(URLHelper.PreloadPublicSuffixAsync);

            // Handle first launch
            if (settings.IsFirstLaunch)
            {
                OnFirstLaunch();

                settings.IsFirstLaunch = false;
                appSettingsManager.SaveSettings(settings);
            }

            _windowsManager = Container.Resolve <IWindowsManager>();
            await _windowsManager.InitializeMainWindowAsync();

            await _metaMessenger.TryConnectToServer("HideezServicePipe");
        }