Example #1
0
 async Task OnSendActivationCodeMessage(SendActivationCodeMessage obj)
 {
     try
     {
         await _metaMessenger.PublishOnServer(new HideezMiddleware.IPC.IncommingMessages.SendActivationCodeMessage(obj.DeviceId, obj.Code));
     }
     catch (Exception ex)
     {
         log.WriteLine(ex);
     }
 }
        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());
        }
 async Task ApplyChangesInService(bool newValue)
 {
     try
     {
         await _metaMessenger.PublishOnServer(new SetSoftwareVaultUnlockModuleStateMessage(newValue));
     }
     catch (Exception) { }
 }
Example #4
0
        private async void OnDisconnectDevice(object param)
        {
            if (param is Device device)
            {
                try
                {
                    var result = await _windowsManager.ShowDisconnectDevicePromptAsync(device.Name);

                    if (result)
                    {
                        await _metaMessenger.PublishOnServer(new DisconnectDeviceMessage(device.Id));
                    }
                }
                catch (Exception ex)
                {
                    await _metaMessenger.Publish(new ShowErrorNotificationMessage(ex.Message, notificationId : device.Mac));
                }
            }
        }
        public SoftwareUnlockSettingViewModel(IMetaPubSub metaMessenger)
        {
            _metaMessenger = metaMessenger;

            _metaMessenger.TrySubscribeOnServer <ServiceSettingsChangedMessage>(OnServiceSettingsChanged);
            try
            {
                _metaMessenger.PublishOnServer(new RefreshServiceInfoMessage());
            }
            catch (Exception) { } // Handle error in case we are not connected to server
        }
Example #6
0
 public async Task PublishEventAsync(WorkstationEventDTO dto)
 {
     try
     {
         await _metaMessenger.PublishOnServer(new PublishEventMessage(dto));
     }
     catch (Exception ex)
     {
         _log.WriteLine(ex);
     }
 }
        // TODO: Add error handling if service is offline
        public ServerAddressEditControlViewModel(IMetaPubSub metaMessenger, ILog log)
        {
            _metaMessenger = metaMessenger;
            _log           = log;

            _metaMessenger.TrySubscribeOnServer <ServiceSettingsChangedMessage>(OnServiceSettingsChanged);
            try
            {
                _metaMessenger.PublishOnServer(new RefreshServiceInfoMessage());
            }
            catch (Exception) { } // Handle error in case we are not connected to server
        }
        public HardwareKeyPageViewModel(IMetaPubSub metaMessenger, ServiceViewModel serviceViewModel)
        {
            _metaMessenger = metaMessenger;
            Service        = serviceViewModel;

            _metaMessenger.TrySubscribeOnServer <ServiceSettingsChangedMessage>(OnServiceSettingsChanged);
            try
            {
                _metaMessenger.PublishOnServer(new RefreshServiceInfoMessage());
            }
            catch (Exception) { } // Handle error in case we are not connected to server
        }
        async Task HandleActionAsync(string deviceId, UserAction action)
        {
            if (Interlocked.CompareExchange(ref _isPerformingActionLock, 1, 0) == 0)
            {
                WriteLine("User action lock engaged");
                try
                {
                    switch (action)
                    {
                    case UserAction.InputLogin:
                        await HandleInputActionAsync(deviceId, _inputLogin);

                        break;

                    case UserAction.InputPassword:
                        await HandleInputActionAsync(deviceId, _inputPassword);

                        break;

                    case UserAction.InputOtp:
                        await HandleInputActionAsync(deviceId, _inputOtp);

                        break;

                    case UserAction.AddAccount:
                        await OnAddNewAccount(deviceId);

                        break;

                    case UserAction.LockWorkstation:
                        await _metaMessenger.PublishOnServer(new HideezMiddleware.IPC.Messages.LockWorkstationMessage());

                        break;

                    default:
                        throw new NotImplementedException($"\"{action.ToString()}\" action is not implemented in UserActionHandler.");
                    }
                }
                finally
                {
                    await Task.Delay(DELAY_BEFORE_NEXT_ACTION);

                    Interlocked.Exchange(ref _isPerformingActionLock, 0);
                    WriteLine("User action lock lifted");
                }
            }
            else
            {
                WriteLine($"{action.ToString()} canceled because another action is in progress");
            }
        }
Example #10
0
        public async Task ShutdownRemoteDeviceAsync(HideezErrorCode code)
        {
            try
            {
                if (_remoteDevice != null)
                {
                    CancelRemoteDeviceCreation();
                    CancelDeviceAuthorization();

                    var tempRemoteDevice = _remoteDevice;
                    _remoteDevice   = null;
                    PasswordManager = null;

                    if (tempRemoteDevice != null)
                    {
                        tempRemoteDevice.ButtonPressed   -= RemoteDevice_ButtonPressed;
                        tempRemoteDevice.StorageModified -= RemoteDevice_StorageModified;
                        tempRemoteDevice.PropertyChanged -= RemoteDevice_PropertyChanged;
                        await tempRemoteDevice.Shutdown(code);

                        await _metaMessenger.PublishOnServer(new RemoveDeviceMessage(tempRemoteDevice.Id));

                        await tempRemoteDevice.DeleteContext();

                        tempRemoteDevice.Dispose();
                    }
                    try
                    {
                        await _remoteDeviceMessenger.DisconnectFromServer();
                    }
                    catch (InvalidOperationException)
                    {
                        // IMetaPubSub may throw InvalidOperationException if we try to disconnect without first connecting
                    }
                }
            }
            catch (Exception ex)
            {
                _log.WriteLine(ex);
            }

            IsCreatingRemoteDevice    = false;
            IsAuthorizingRemoteDevice = false;
            IsLoadingStorage          = false;
            IsStorageLoaded           = false;

            NotifyPropertyChanged(nameof(IsAuthorized));
        }
 void OnCancel()
 {
     _metaMessenger.Publish(new CancelActivationCodeEntryMessage(Device.Id));
     _metaMessenger.PublishOnServer(new HideActivationCodeUi());
     Device.CancelDeviceAuthorization();
 }
 public async Task ResetChannel()
 {
     await _metaMessenger.PublishOnServer(new RemoteConnection_ResetChannelMessage(RemoteDevice.Id));
 }
Example #13
0
 /// <summary>
 /// Called when MetaPubSub was connected to a server on the service side
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 async Task OnConnectedToServer(ConnectedToServerEvent arg)
 {
     await _metaMessenger.PublishOnServer(new LoginClientRequestMessage());
 }