private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var args = Environment.GetCommandLineArgs(); var controller = new SingleInstanceController(); try { controller.Run(args); } catch (NoStartupFormException) { } catch (Exception e) { FrmExceptionDialog.ShowException(e); } }
/// <summary> /// Executes the current extension. /// </summary> /// <param name="shell">The <see cref="IShell" /> object on which the current extension will be executed.</param> protected override async void DoExecute(IShell shell) { try { var setting = this.SettingProvider.GetExtensionSetting <ImportFromWebSetting>(); var dialog = new ImportFromWebDialog(setting); if (dialog.ShowDialog() == DialogResult.OK) { var title = HtmlUtilities.ExtractTitle(dialog.HtmlContent); if (string.IsNullOrEmpty(title) || shell.ExistingNotesTitle.Contains(title)) { var titleInputDialog = new TextInputBox(Resources.ImportFromWebInputTitleText, Resources.ImportFromWebInputTitlePrompt, title, new[] { new Tuple <Func <string, bool>, string>(string.IsNullOrEmpty, Resources.ImportFromWebEmptyTitleErrorMsg), new Tuple <Func <string, bool>, string>(shell.ExistingNotesTitle.Contains, Resources.ImportFromWebDuplicatedTitleErrorMsg) }); if (titleInputDialog.ShowDialog() == DialogResult.OK) { title = titleInputDialog.InputText; } else { return; } } await shell.ImportNote(new Note { Title = title, Content = dialog.HtmlContent }); } } catch (Exception ex) { FrmExceptionDialog.ShowException(ex); } }
private async Task ListCategoriesAsync() { try { lstCategories.Items.Clear(); var categories = await this.gateway.GetCategoriesAsync(); if (categories.Count > 0) { foreach (var category in categories) { var listViewItem = lstCategories.Items.Add(category.Title); listViewItem.Tag = category; } } UpdateControlState(); } catch (Exception ex) { FrmExceptionDialog.ShowException(ex); } }
private void btnOK_Click(object sender, EventArgs e) { var hasError = false; this.errorProvider.Clear(); if (string.IsNullOrWhiteSpace(cbUserName.Text)) { hasError = true; errorProvider.SetError(cbUserName, Resources.UserNameRequired); } if (string.IsNullOrWhiteSpace(txtPassword.Text)) { hasError = true; errorProvider.SetError(txtPassword, Resources.PasswordRequired); } if (string.IsNullOrWhiteSpace(cbServer.Text)) { hasError = true; errorProvider.SetError(cbServer, Resources.ServerRequired); } if (hasError) { // prevent the dialog from closing this.DialogResult = DialogResult.None; return; } Credential = new ClientCredential { Password = txtPassword.Text, ServerUri = cbServer.Text.Trim(), UserName = cbUserName.Text.Trim() }; // reset the IsSelected property for users profile.UserProfiles.ForEach(up => up.IsSelected = false); var userProfile = profile.UserProfiles.FirstOrDefault(p => p.UserName == Credential.UserName); var encryptedPassword = crypto.Encrypt(Credential.Password); if (userProfile == null) { userProfile = new UserProfile { AutoLogin = chkAutomaticLogin.Checked, IsSelected = true, Password = encryptedPassword, RememberPassword = chkRememberPassword.Checked, UserName = Credential.UserName }; profile.UserProfiles.Add(userProfile); } else { userProfile.AutoLogin = chkAutomaticLogin.Checked; userProfile.IsSelected = true; userProfile.Password = encryptedPassword; userProfile.RememberPassword = chkRememberPassword.Checked; userProfile.UserName = Credential.UserName; } // reset the IsSelected property for servers profile.ServerProfiles.ForEach(sp => sp.IsSelected = false); var serverProfile = profile.ServerProfiles.FirstOrDefault(p => p.Uri == Credential.ServerUri); if (serverProfile == null) { serverProfile = new ServerProfile(Credential.ServerUri) { IsSelected = true }; profile.ServerProfiles.Add(serverProfile); } else { serverProfile.IsSelected = true; serverProfile.Uri = cbServer.Text; } try { cbUserName.Enabled = false; txtPassword.Enabled = false; cbServer.Enabled = false; btnOK.Enabled = false; this.Cursor = Cursors.WaitCursor; using (var proxy = new ServiceProxy(Credential)) { var result = proxy.PostAsJsonAsync( "api/users/authenticate", new { Credential.UserName, EncodedPassword = Convert.ToBase64String( Encoding.ASCII.GetBytes(Crypto.ComputeHash(Credential.Password, Credential.UserName))) }).Result; switch (result.StatusCode) { case HttpStatusCode.OK: break; case HttpStatusCode.Forbidden: MessageBox.Show( Resources.IncorrectUserNamePassword, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; default: dynamic message = JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result); MessageBox.Show( message.ExceptionMessage.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } } Profile.Save(fileName, profile); } catch (Exception ex) { FrmExceptionDialog.ShowException(ex); this.DialogResult = DialogResult.None; } finally { cbUserName.Enabled = true; txtPassword.Enabled = true; cbServer.Enabled = true; btnOK.Enabled = true; this.Cursor = Cursors.Default; } }
private void btnOK_Click(object sender, EventArgs e) { errorProvider.Clear(); this.DialogResult = DialogResult.OK; if (string.IsNullOrEmpty(txtUserName.Text)) { errorProvider.SetError(txtUserName, Resources.UserNameRequired); txtUserName.Focus(); this.DialogResult = DialogResult.None; return; } if (string.IsNullOrEmpty(txtPassword.Text)) { errorProvider.SetError(txtPassword, Resources.PasswordRequired); txtPassword.Focus(); this.DialogResult = DialogResult.None; return; } if (string.IsNullOrEmpty(txtConfirm.Text)) { errorProvider.SetError(txtConfirm, Resources.ConfirmPasswordRequired); txtConfirm.Focus(); this.DialogResult = DialogResult.None; return; } if (string.Compare(txtPassword.Text, txtConfirm.Text, StringComparison.InvariantCultureIgnoreCase) != 0) { errorProvider.SetError(txtConfirm, Resources.IncorrectConfirmPassword); txtConfirm.Focus(); this.DialogResult = DialogResult.None; return; } if (string.IsNullOrEmpty(txtEmail.Text)) { errorProvider.SetError(txtEmail, Resources.EmailRequired); txtEmail.Focus(); this.DialogResult = DialogResult.None; return; } var regex = new Regex(Constants.EmailAddressFormatPattern); if (!regex.IsMatch(txtEmail.Text)) { errorProvider.SetError(txtEmail, Resources.InvalidEmailAddress); txtEmail.Focus(); this.DialogResult = DialogResult.None; return; } if (string.IsNullOrEmpty(txtServer.Text)) { errorProvider.SetError(txtServer, Resources.ServerRequired); txtServer.Focus(); this.DialogResult = DialogResult.None; return; } try { txtUserName.Enabled = false; txtPassword.Enabled = false; txtConfirm.Enabled = false; txtEmail.Enabled = false; txtServer.Enabled = false; btnOK.Enabled = false; using ( var proxy = new ServiceProxy( new ClientCredential { UserName = Crypto.ProxyUserName, Password = Crypto.ProxyUserPassword, ServerUri = txtServer.Text.Trim() })) { var result = proxy.PutAsJsonAsync( "api/users/create", new { UserName = txtUserName.Text.Trim(), Password = Convert.ToBase64String( Encoding.ASCII.GetBytes( Crypto.ComputeHash(txtPassword.Text.Trim(), txtUserName.Text.Trim()))), Email = txtEmail.Text.Trim() }).Result; // Here we cannot use the async/await feature, since // the dialog will be closed even if we set the DialogResult to None. if (result.IsSuccessStatusCode) { this.UserName = txtUserName.Text.Trim(); this.Password = txtPassword.Text.Trim(); this.ServerUri = txtServer.Text.Trim(); MessageBox.Show( Resources.CreateAccountSuccessful, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { dynamic details = JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result); if (details != null) { MessageBox.Show( details.ExceptionMessage.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Register failed!", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } this.DialogResult = DialogResult.None; } } } catch (Exception ex) { FrmExceptionDialog.ShowException(ex); this.DialogResult = DialogResult.None; } finally { txtUserName.Enabled = true; txtPassword.Enabled = true; txtConfirm.Enabled = true; txtEmail.Enabled = true; txtServer.Enabled = true; btnOK.Enabled = true; } }
private void btnOK_Click(object sender, EventArgs e) { errorProvider.Clear(); var hasError = false; if (string.IsNullOrEmpty(txtOldPassword.Text)) { errorProvider.SetError(txtOldPassword, Resources.OriginalPasswordRequired); hasError = true; } if (string.IsNullOrEmpty(txtNewPassword.Text)) { errorProvider.SetError(txtNewPassword, Resources.NewPasswordRequired); hasError = true; } if (string.IsNullOrEmpty(txtConfirmPassword.Text)) { errorProvider.SetError(txtConfirmPassword, Resources.ConfirmPasswordRequired); hasError = true; } if (string.Compare(txtNewPassword.Text, txtConfirmPassword.Text, StringComparison.InvariantCulture) != 0) { errorProvider.SetError(txtConfirmPassword, Resources.IncorrectConfirmPassword); hasError = true; } if (hasError) { this.DialogResult = DialogResult.None; } else { oldPassword = txtOldPassword.Text; newPassword = txtNewPassword.Text; var encodedOldPassword = Convert.ToBase64String( Encoding.ASCII.GetBytes(Crypto.ComputeHash(oldPassword, this.clientCredential.UserName))); var encodedNewPassword = Convert.ToBase64String( Encoding.ASCII.GetBytes(Crypto.ComputeHash(newPassword, this.clientCredential.UserName))); using (var proxy = new ServiceProxy(this.clientCredential)) { try { txtConfirmPassword.Enabled = false; txtNewPassword.Enabled = false; txtOldPassword.Enabled = false; btnOK.Enabled = false; var result = proxy.PostAsJsonAsync( "api/users/password/change", new { clientCredential.UserName, EncodedOldPassword = encodedOldPassword, EncodedNewPassword = encodedNewPassword }).Result; switch (result.StatusCode) { case HttpStatusCode.OK: // Re-assign the new password to client credential clientCredential.Password = newPassword; MessageBox.Show( Resources.PasswordChangedSuccessfully, Resources.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); break; case HttpStatusCode.Forbidden: MessageBox.Show( Resources.IncorrectUserNamePassword, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; default: var message = result.Content.ReadAsStringAsync().Result; MessageBox.Show( message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } } catch (Exception ex) { FrmExceptionDialog.ShowException(ex); this.DialogResult = DialogResult.None; } finally { txtConfirmPassword.Enabled = true; txtNewPassword.Enabled = true; txtOldPassword.Enabled = true; btnOK.Enabled = true; } } } }
private void btnOK_Click(object sender, EventArgs e) { errorProvider.Clear(); if (string.IsNullOrEmpty(txtLink.Text)) { errorProvider.SetError(txtLink, Resources.LinkEmpty); this.DialogResult = DialogResult.None; return; } string baseUri; StringBuilder stringBuilder; try { var uri = new Uri(txtLink.Text); baseUri = string.Format("{0}://{1}", uri.Scheme, uri.DnsSafeHost); if ((uri.Scheme == Uri.UriSchemeHttps && uri.Port != 443) || (uri.Scheme == Uri.UriSchemeHttp && uri.Port != 80)) { baseUri = string.Format("{0}:{1}", baseUri, uri.Port); } stringBuilder = new StringBuilder(baseUri); for (int i = 0; i < uri.Segments.Length - 1; i++) { var segment = uri.Segments[i]; stringBuilder.Append(segment); } } catch { errorProvider.SetError(txtLink, Resources.LinkNotValid); this.DialogResult = DialogResult.None; return; } btnOK.Enabled = false; txtLink.ReadOnly = true; webClient.Encoding = Encoding.GetEncoding(this.setting.EncodingCodePage); progressBar.Visible = true; progressBar.Style = ProgressBarStyle.Marquee; webClient.DownloadStringCompleted += async(sdSender, sdArgs) => { if (sdArgs.Error != null) { FrmExceptionDialog.ShowException(sdArgs.Error); this.DialogResult = DialogResult.Cancel; this.Close(); return; } if (!sdArgs.Cancelled) { this.HtmlContent = sdArgs.Result; if (this.setting.EmbedImages) { slblStatus.Text = Resources.ProcessingImages; progressBar.Style = ProgressBarStyle.Continuous; this.HtmlContent = await HtmlUtilities.ReplaceWebImagesAsync(this.HtmlContent, baseUri, stringBuilder.ToString(), this.cancellationTokenSource.Token, (a, b) => { progressBar.Maximum = b; progressBar.Value = a; }); } slblStatus.Text = string.Empty; this.DialogResult = DialogResult.OK; this.Close(); } }; slblStatus.Text = Resources.DownloadingWebPage; slblStatus.Visible = true; webClient.DownloadStringAsync(new Uri(txtLink.Text)); }