private void processButton_Click(object sender, RoutedEventArgs e) { var prefix = prefixTextBox.Text.Trim().ToLower(); if (!new Regex(@"^[0-9a-z\-]{1,28}$").IsMatch(prefix)) { MessageBox.Show(resources["InvalidGaeAppIdPrefixMessage"] as string); return; } var email = emailTextBox.Text.Trim(); if (!new Regex(@"^[0-9a-zA-Z\-.]+@[0-9a-zA-Z\-.]+$").IsMatch(email)) { MessageBox.Show(resources["InvalidGaeEmailMessage"] as string); return; } var password = passwordBox.Password; if (password.Length == 0) { MessageBox.Show(resources["EmptyGaePasswordMessage"] as string); return; } int appsNumber; var appsNumberParsed = int.TryParse(appsNumberTextBox.Text, out appsNumber); if (!(appsNumberParsed && appsNumber < 11 && appsNumber > 0)) { MessageBox.Show(resources["InvalidGaeAppsNumberMessage"] as string); return; } showStage(processingPanel); processingProgressBar.IsIndeterminate = true; processingStatusTextBlock.Text = resources["LoggingIn"] as string; gaeSimulator = new GAESimulator(); gaeSimulator.Login(email, password, (success, data) => { if (!success) { MessageBox.Show(resources["FailedToLoginMessage"] as string); showStage(homePanel); return; } gaeSimulator.CheckAppIdAvailability(prefix + "-1", (valid) => { if (!valid) { var r = MessageBox.Show(resources["InvalidGaeAppIdMessage"] as string, resources["XWall"] as string, MessageBoxButton.YesNo); if (r == MessageBoxResult.Yes) { prefix = prefixTextBox.Text = "ga-" + randomString(); } showStage(homePanel); return; } var ids = new List <string>(); var noneDeployedIds = new List <string>(data.NoneDeployedAppIds); if (data.AppIds.Length > 0) { var r = MessageBox.Show(resources["GaeAppsCreatedMessage"] as string, resources["XWall"] as string, MessageBoxButton.YesNoCancel); if (r == MessageBoxResult.Cancel) { showStage(homePanel); return; } else if (r == MessageBoxResult.Yes) { ids.AddRange(data.AppIds.Take(appsNumber)); } } var createNumber = Math.Min(data.RemainingNumber, appsNumber - ids.Count); processingProgressBar.IsIndeterminate = false; processingProgressBar.Value = 0; gaeSimulator.VerificationRequired += (callback) => { showStage(verifyPanel); gaeSimulatorVerifyCallback = callback; }; gaeSimulator.CreateApps(prefix, createNumber, (done, i, id, error) => { if (error) { showStage(homePanel); return; } if (!done) { processingStatusTextBlock.Text = String.Format(resources["CreatingGaeApps"] as string, i + 1, createNumber); setProgressBarValue(processingProgressBar, i * 1.0 / createNumber * 20); ids.Add(id); noneDeployedIds.Add(id); } else { string[] idsArr; if ( data.AppIds.Length != data.NoneDeployedAppIds.Length && MessageBox.Show(resources["DeployDeployedGaeAppsMessage"] as string, resources["XWall"] as string, MessageBoxButton.YesNo) == MessageBoxResult.Yes ) { idsArr = ids.ToArray(); } else { idsArr = ( from appId in ids where noneDeployedIds.Contains(appId) select appId ).ToArray(); } gaeSimulator.Deploy(email, password, idsArr, (dDone, dI, currentProgress, err) => { Dispatcher.Invoke(new Action(() => { if (err) { showStage(homePanel); return; } if (!dDone) { processingStatusTextBlock.Text = String.Format(resources["DeployingGaeApps"] as string, dI + 1, idsArr.Length); setProgressBarValue(processingProgressBar, (dI + currentProgress) / idsArr.Length * 80 + 20); } else { processingStatusTextBlock.Text = resources["GaeWizardFinished"] as string; setProgressBarValue(processingProgressBar, 100); settings.GaAppIds = string.Join("|", ids.ToArray()); Rules.Enabled = true; new Action(() => { Thread.Sleep(3000); Dispatcher.BeginInvoke(new Action(() => { Close(); })); }).BeginInvoke(null, null); } })); }); } }); }); }); }
private void processButton_Click(object sender, RoutedEventArgs e) { var prefix = prefixTextBox.Text.Trim().ToLower(); if (!new Regex(@"^[0-9a-z\-]{1,28}$").IsMatch(prefix)) { MessageBox.Show(resources["InvalidGaeAppIdPrefixMessage"] as string); return; } var email = emailTextBox.Text.Trim(); if (!new Regex(@"^[0-9a-zA-Z\-.]+@[0-9a-zA-Z\-.]+$").IsMatch(email)) { MessageBox.Show(resources["InvalidGaeEmailMessage"] as string); return; } var password = passwordBox.Password; if (password.Length == 0) { MessageBox.Show(resources["EmptyGaePasswordMessage"] as string); return; } int appsNumber; var appsNumberParsed = int.TryParse(appsNumberTextBox.Text, out appsNumber); if (!(appsNumberParsed && appsNumber < 11 && appsNumber > 0)) { MessageBox.Show(resources["InvalidGaeAppsNumberMessage"] as string); return; } showStage(processingPanel); processingProgressBar.IsIndeterminate = true; processingStatusTextBlock.Text = resources["LoggingIn"] as string; gaeSimulator = new GAESimulator(); gaeSimulator.Login(email, password, (success, data) => { if (!success) { MessageBox.Show(resources["FailedToLoginMessage"] as string); showStage(homePanel); return; } gaeSimulator.CheckAppIdAvailability(prefix + "-1", (valid) => { if (!valid) { var r = MessageBox.Show(resources["InvalidGaeAppIdMessage"] as string, resources["XWall"] as string, MessageBoxButton.YesNo); if (r == MessageBoxResult.Yes) { prefix = prefixTextBox.Text = "ga-" + randomString(); } showStage(homePanel); return; } var ids = new List<string>(); var noneDeployedIds = new List<string>(data.NoneDeployedAppIds); if (data.AppIds.Length > 0) { var r = MessageBox.Show(resources["GaeAppsCreatedMessage"] as string, resources["XWall"] as string, MessageBoxButton.YesNoCancel); if (r == MessageBoxResult.Cancel) { showStage(homePanel); return; } else if (r == MessageBoxResult.Yes) { ids.AddRange(data.AppIds.Take(appsNumber)); } } var createNumber = Math.Min(data.RemainingNumber, appsNumber - ids.Count); processingProgressBar.IsIndeterminate = false; processingProgressBar.Value = 0; gaeSimulator.VerificationRequired += (callback) => { showStage(verifyPanel); gaeSimulatorVerifyCallback = callback; }; gaeSimulator.CreateApps(prefix, createNumber, (done, i, id, error) => { if (error) { showStage(homePanel); return; } if (!done) { processingStatusTextBlock.Text = String.Format(resources["CreatingGaeApps"] as string, i + 1, createNumber); setProgressBarValue(processingProgressBar, i * 1.0 / createNumber * 20); ids.Add(id); noneDeployedIds.Add(id); } else { string[] idsArr; if ( data.AppIds.Length != data.NoneDeployedAppIds.Length && MessageBox.Show(resources["DeployDeployedGaeAppsMessage"] as string, resources["XWall"] as string, MessageBoxButton.YesNo) == MessageBoxResult.Yes ) { idsArr = ids.ToArray(); } else { idsArr = ( from appId in ids where noneDeployedIds.Contains(appId) select appId ).ToArray(); } gaeSimulator.Deploy(email, password, idsArr, (dDone, dI, currentProgress, err) => { Dispatcher.Invoke(new Action(() => { if (err) { showStage(homePanel); return; } if (!dDone) { processingStatusTextBlock.Text = String.Format(resources["DeployingGaeApps"] as string, dI + 1, idsArr.Length); setProgressBarValue(processingProgressBar, (dI + currentProgress) / idsArr.Length * 80 + 20); } else { processingStatusTextBlock.Text = resources["GaeWizardFinished"] as string; setProgressBarValue(processingProgressBar, 100); settings.GaAppIds = string.Join("|", ids.ToArray()); Rules.Enabled = true; new Action(() => { Thread.Sleep(3000); Dispatcher.BeginInvoke(new Action(() => { Close(); })); }).BeginInvoke(null, null); } })); }); } }); }); }); }