public LoginResultMessage(LoginResult logData) { LoginResult = logData; }
void OnDatareceived(byte[] data) { if (subscription != null) { subscription.Dispose(); subscription = null; } string response = Encoding.Default.GetString(data); if (!string.IsNullOrEmpty(response)) { dynamic authObj = JsonConvert.DeserializeObject<dynamic>(response); if (authObj.error != null) { ViewModelLocator.Logger.WarnFormat("Authentication has failed. {0}", authObj.error); LocalStateContainer.LoginMessenger.Send<Message.LoginResultMessage>(new Message.LoginResultMessage( new LoginResult() { IsAuthorized = false, UserName = LoginData.LoginName })); return; } var loginResult = new LoginResult() { IsAuthorized = true, UserId = authObj.userId, AuthToken = authObj.authToken, UserName = LoginData.LoginName, UserIdentity = authObj.userIdentity }; if (LoginData.SaveCredentials) { var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); var file = System.IO.Path.Combine(path, "data.dat"); if (System.IO.File.Exists(file)) System.IO.File.Delete(file); var json = JsonConvert.SerializeObject(loginResult); json.EncryptToFile(file, "key1key2key3key4"); } LocalStateContainer.LoginMessenger.Send<Message.LoginMessage>(new Message.LoginMessage(LoginData)); LocalStateContainer.LoginMessenger.Send<Message.LoginResultMessage>(new Message.LoginResultMessage(loginResult)); } }