Beispiel #1
0
        public override void HandleMessage(Notification notification)
        {
            if (!String.IsNullOrEmpty(notification.PayloadType))
            {
                switch (notification.PayloadType)
                {
                case "DeviceArchive":
                    var archive = JsonConvert.DeserializeObject <DeviceArchive>(notification.Payload);
                    DispatcherServices.Invoke(() =>
                    {
                        DeviceMessages.Insert(0, archive);
                    });
                    break;

                case "LagoVista.IoT.DeviceManagement.Core.Models.Device":
                    DispatcherServices.Invoke(() =>
                    {
                        Device = JsonConvert.DeserializeObject <Device>(notification.Payload);
                    });

                    break;
                }
                Debug.WriteLine("----");
                Debug.WriteLine(notification.PayloadType);
                Debug.WriteLine(notification.Payload);
                Debug.WriteLine("BYTES: " + notification.Payload.Length);
                Debug.WriteLine("----");
            }
            else
            {
                Debug.WriteLine(notification.Text);
            }
        }
 public VerifyDeviceKeysResponseReceivedEventArgs(DeviceMessages.VerifyDeviceKeysResponse message)
 {
     Message = message;
 }
 private bool ProcessMessageConfirmNewLink(DeviceMessages.NewDatabase messageItem)
 {
     _controller.CompleteNewLink(_model, messageItem.LinkIdentifier);
     return true;
 }
        private bool ProcessMessageVerifyDeviceKeys(DeviceMessages.VerifyDeviceKeysRequest message)
        {
            /*var keyHash = HashUtil.Sha256(message.PublicKeyPem);
            var cryptoKey = _model.CryptoKeys.Query()
                .FirstOrDefault(r => r.PublicKeyPemHash == keyHash);

            if (cryptoKey != null && cryptoKey.Trust)
                return true;

            var confirmed = _controller.PromptVerifyDeviceKeysSafe(message.PublicKeyPem);
            if (!confirmed)
                return false;

            if (cryptoKey == null)
            {
                _model.CryptoKeys.Create(new CryptoKey
                {
                    Trust = true,
                    PublicKeyPem = message.PublicKeyPem,
                    PublicKeyPemHash = keyHash
                });
            }
            else
            {
                _model.CryptoKeys.Update(cryptoKey.Id, new CryptoKey {Trust = true});
            }*/

            // TEMP return false;

            return true;
        }
        private bool ProcessMessageUserLoginRequest(DeviceMessages.ServerLoginRequest messageItem)
        {
            var confirmRequest = _controller.PromptUserLoginRequestSafe(
                    messageItem.RequestingDeviceLabel,messageItem.RequestingDeviceType);

            if (!confirmRequest)
                return false;
            
            var apiRequest = new SendOtpLoginCode
            {
                LoginRequestIdentifier = messageItem.LoginRequestIdentifier,
                OtpDeviceCode = _controller.GenerateOtpCodeForServerAccount(_model)
            };
            apiRequest.GetResponse(GetApiClient());

            return true;
        }