private async void LoadSetting() { (bool res, string ip, string port) = await CustomIO.GetIpAndPort(); if (res == true) { IpAddress = ip; Port = port; } }
private async void CheckServerSettingFile() { (bool res, string ip, string port) = await CustomIO.GetIpAndPort(); if (res == false) { await CustomDialog.ServerSettingLoadError(); PageStack.Push(page.GetType()); page.Frame.Navigate(typeof(ServerSettingPage), PageStack); return; } }
private async void Register(object parameter) { Registering = true; ResultVisibility = Visibility.Collapsed; var passwordBox = parameter as PasswordBox; switch (CheckInputData(Email, passwordBox.Password)) { case CheckInputDataResult.PasswordTooShort: await CustomDialog.UserRegisterPasswordLengthError(); Registering = false; return; case CheckInputDataResult.EmailTooShort: case CheckInputDataResult.EmailTooLong: await CustomDialog.UserRegisterEmailLengthError(); Registering = false; return; } (bool res, string ip, string port) = await CustomIO.GetIpAndPort(); if (res == false) { // 一応ここでもチェックする await CustomDialog.ServerSettingLoadError(); PageStack.Push(page.GetType()); page.Frame.Navigate(typeof(ServerSettingPage), PageStack); Registering = false; return; } Communication tcp = new Communication(); var stat = await tcp.ConnectAndTest(ip, port); if (stat != Communication.TcpError.NoError) { await CustomDialog.ServerConnectError(); tcp.Disconnect(); Registering = false; return; } var hash = CalcHash.Sha256(passwordBox.Password); await tcp.SendMessageAsync(tcp.GetTcpCommand(Communication.TcpCommandNumber.CmdAddUser)); Communication.TcpStatus comStat; do { var resMsg = await tcp.ReceiveMessageAsync(); comStat = tcp.GetStatus(resMsg); switch (comStat) { case Communication.TcpStatus.StatRequestHash: await tcp.SendMessageAsync(hash); break; case Communication.TcpStatus.StatRequestEmail: await tcp.SendMessageAsync(Email); break; case Communication.TcpStatus.StatFIN: break; case Communication.TcpStatus.StatHashConflict: await CustomDialog.UserRegisterHashConflictError(); tcp.Disconnect(); Registering = false; return; default: await CustomDialog.UnknownError(); tcp.Disconnect(); Registering = false; return; } } while (comStat != Communication.TcpStatus.StatFIN); ResultVisibility = Visibility.Visible; passwordBox.Password = ""; Email = ""; await CustomDialog.UserRegisterComplete(); tcp.Disconnect(); Registering = false; }
private async Task BeginBuyProducts(string hash) { Connecting = true; (bool res, string ip, string port) = await CustomIO.GetIpAndPort(); if (res == false) { // 一応ここでもチェックする await CustomDialog.ServerSettingLoadError(); PageStack.Push(page.GetType()); page.Frame.Navigate(typeof(ServerSettingPage), PageStack); Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; return; } Communication tcp = new Communication(); var stat = await tcp.ConnectAndTest(ip, port); if (stat != Communication.TcpError.NoError) { await CustomDialog.ServerConnectError(); tcp.Disconnect(); Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; return; } await tcp.SendMessageAsync(tcp.GetTcpCommand(Communication.TcpCommandNumber.CmdBuyProduct)); Communication.TcpStatus comStat; var products = CreateStack(); ProductInfo p = new ProductInfo("", 0); do { var resMsg = await tcp.ReceiveMessageAsync(); comStat = tcp.GetStatus(resMsg); switch (comStat) { case Communication.TcpStatus.StatRequestHash: await tcp.SendMessageAsync(hash); break; case Communication.TcpStatus.StatRequestBuyProductName: if (products.Count == 0) { await tcp.SendMessageAsync(tcp.GetTcpCommand(Communication.TcpCommandNumber.CmdClientFIN)); break; } p = products.Pop(); await tcp.SendMessageAsync(p.Name); break; case Communication.TcpStatus.StatRequestBuyProductAmount: if (p.Name == "") { await CustomDialog.UnknownError(); tcp.Disconnect(); Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; } await tcp.SendMessageAsync(p.Amount.ToString()); if (products.Count == 0) { await tcp.SendMessageAsync(tcp.GetTcpCommand(Communication.TcpCommandNumber.CmdClientFIN)); } break; case Communication.TcpStatus.StatFIN: break; case Communication.TcpStatus.StatNoEnoughMoney: await CustomDialog.NoEnoughMoney(); tcp.Disconnect(); Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; PageStack.Push(page.GetType()); page.Frame.Navigate(typeof(MoneyChargePage), PageStack); return; case Communication.TcpStatus.StatNoUser: await CustomDialog.NoUserError(); tcp.Disconnect(); Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; return; default: await CustomDialog.UnknownError(); tcp.Disconnect(); Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; return; } } while (comStat != Communication.TcpStatus.StatFIN); Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; await CustomDialog.PurchaseComplete(); page.Frame.Navigate(typeof(MainPage)); }
private async Task BeginChargeMoney(string hash) { Connecting = true; (bool res, string ip, string port) = await CustomIO.GetIpAndPort(); if (res == false) { // 一応ここでもチェックする await CustomDialog.ServerSettingLoadError(); PageStack.Push(page.GetType()); page.Frame.Navigate(typeof(ServerSettingPage), PageStack); amountOfCharge = 0; Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; return; } Communication tcp = new Communication(); var stat = await tcp.ConnectAndTest(ip, port); if (stat != Communication.TcpError.NoError) { await CustomDialog.ServerConnectError(); tcp.Disconnect(); amountOfCharge = 0; Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; return; } await tcp.SendMessageAsync(tcp.GetTcpCommand(Communication.TcpCommandNumber.CmdChargeMoney)); Communication.TcpStatus comStat; do { var resMsg = await tcp.ReceiveMessageAsync(); comStat = tcp.GetStatus(resMsg); switch (comStat) { case Communication.TcpStatus.StatRequestHash: await tcp.SendMessageAsync(hash); break; case Communication.TcpStatus.StatRequestAmountOfMoney: await tcp.SendMessageAsync(amountOfCharge.ToString()); break; case Communication.TcpStatus.StatFIN: break; case Communication.TcpStatus.StatNoUser: await CustomDialog.NoUserError(); tcp.Disconnect(); amountOfCharge = 0; Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; return; default: await CustomDialog.UnknownError(); tcp.Disconnect(); amountOfCharge = 0; Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; return; } } while (comStat != Communication.TcpStatus.StatFIN); amountOfCharge = 0; Connecting = false; PasswordInputPanelVisibility = Visibility.Collapsed; await CustomDialog.ChargeComplete(); }