/// <summary> /// Ask password from user /// </summary> /// <param name="client">SMTP client</param> /// <param name="mailerSettingsConfig">Mailer settings</param> /// <returns>True if password was set</returns> public static bool Execute(SmtpClient client, GrfExporterSettingsConfig grfExporterSettingsConfig) { MailAuthorisationDlg dlg = new MailAuthorisationDlg(); dlg.Owner = App.Current.MainWindow; dlg.WindowStartupLocation = WindowStartupLocation.CenterOwner; dlg.Server.Text = grfExporterSettingsConfig.ServerAddress; dlg.UserName.Text = grfExporterSettingsConfig.UserName; dlg.Password.Focus(); bool?res = dlg.ShowDialog(); if (res.Value == true) { client.Credentials = new NetworkCredential(dlg.UserName.Text, dlg.Password.Password); if (dlg.RememberPassword.IsChecked.Value) { grfExporterSettingsConfig.RememberPassword = true; grfExporterSettingsConfig.Password = dlg.Password.Password; } } return(res.Value); }
/// <summary> /// Deserialize grf exporter settings config from string /// </summary> /// <param name="configText">String with serialized settings</param> public void Deserialize(string configText) { XmlSerializer ser = new XmlSerializer(typeof(GrfExporterSettingsConfig)); StringReader reader = new StringReader(configText); GrfExporterSettingsConfig deserialized = null; try { deserialized = (GrfExporterSettingsConfig)ser.Deserialize(reader); } catch (Exception ex) { Logger.Error(ex); } finally { reader.Close(); } // if settings loaded - copy it to instance if (deserialized != null) { ServerAddress = deserialized.ServerAddress; ServerPort = deserialized.ServerPort; AutenticationRequired = deserialized.AutenticationRequired; UserName = deserialized.UserName; Password = deserialized.Password; RememberPassword = deserialized.RememberPassword; EncryptedConnectionRequires = deserialized.EncryptedConnectionRequires; } }
/// <summary> /// Serialize grf exporter settings config /// </summary> /// <returns>Serialized grf exporter settings config</returns> private static GrfExporterSettingsConfig _Create() { GrfExporterSettingsConfig grfExporterSettingsConfig = new GrfExporterSettingsConfig(); grfExporterSettingsConfig.ServerPort = MAIL_PORT; grfExporterSettingsConfig.AutenticationRequired = true; grfExporterSettingsConfig.RememberPassword = true; return(grfExporterSettingsConfig); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Init grid content by grf exporter settings config /// </summary> /// <param name="grfExporterConfig">Grf exporter settings config to use</param> private void _SetContent(GrfExporterSettingsConfig grfExporterConfig) { ServerAddress.Text = grfExporterConfig.ServerAddress; ServerPort.Text = grfExporterConfig.ServerPort.ToString(); ServerRequiresAutentication.IsChecked = grfExporterConfig.AutenticationRequired; UserName.Text = grfExporterConfig.UserName; RememberPassword.IsChecked = grfExporterConfig.RememberPassword; Password.Password = grfExporterConfig.Password; EncryptedConnectionRequires.IsChecked = grfExporterConfig.EncryptedConnectionRequires; }
/// <summary> /// Mailer constructor /// </summary> /// <param name="mailerSettingsConfig">Mailer settings confuration</param> /// <param name="resources">Plugin resources</param> public Mailer(GrfExporterSettingsConfig grfExporterSettingsConfig) { _CreateSMTPClient(grfExporterSettingsConfig); if (!grfExporterSettingsConfig.RememberPassword) { bool passwordEntered = MailAuthorisationDlg.Execute(_client, grfExporterSettingsConfig); if (!passwordEntered) { throw new InvalidOperationException(Properties.Resources.CanceledByUser); } } ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(_ValidateServerCertificate); }
/// <summary> /// Create binding from page content to grf exporter settings config /// </summary> /// <param name="grfExporterConfig">Grf exporter settings config to use</param> private void _BindConfig(GrfExporterSettingsConfig grfExporterConfig) { _CreateBinding("ServerAddress", grfExporterConfig, ServerAddress, TextBox.TextProperty); _CreateBinding("ServerPort", grfExporterConfig, ServerPort, TextBox.TextProperty); _CreateBinding("AutenticationRequired", grfExporterConfig, ServerRequiresAutentication, ToggleButton.IsCheckedProperty); _CreateBinding("UserName", grfExporterConfig, UserName, TextBox.TextProperty); _CreateBinding("RememberPassword", grfExporterConfig, RememberPassword, ToggleButton.IsCheckedProperty); _CreateBinding("EncryptedConnectionRequires", grfExporterConfig, EncryptedConnectionRequires, ToggleButton.IsCheckedProperty); RouteGRFcompression.IsChecked = grfExporterConfig.RouteGrfCompression; _CreateBinding("RouteGrfCompression", grfExporterConfig, RouteGRFcompression, CheckBox.IsCheckedProperty); _isLoaded = true; }
/// <summary> /// Create internal smtp client /// </summary> private void _CreateSMTPClient(GrfExporterSettingsConfig grfExporterSettingsConfig) { if (string.IsNullOrEmpty(grfExporterSettingsConfig.ServerAddress)) { throw new MailerSettingsException(Properties.Resources.MailerSettingsEmpty); } else { _client = new SmtpClient(); _client.Host = grfExporterSettingsConfig.ServerAddress; _client.Port = grfExporterSettingsConfig.ServerPort; _client.EnableSsl = grfExporterSettingsConfig.EncryptedConnectionRequires; _client.UseDefaultCredentials = false; if (grfExporterSettingsConfig.AutenticationRequired && !string.IsNullOrEmpty(grfExporterSettingsConfig.UserName) && grfExporterSettingsConfig.Password != null) { _client.Credentials = new NetworkCredential(grfExporterSettingsConfig.UserName, grfExporterSettingsConfig.Password); } } }
/// <summary> /// Ask password from user /// </summary> /// <param name="client">SMTP client</param> /// <param name="mailerSettingsConfig">Mailer settings</param> /// <returns>True if password was set</returns> public static bool Execute(SmtpClient client, GrfExporterSettingsConfig grfExporterSettingsConfig) { MailAuthorisationDlg dlg = new MailAuthorisationDlg(); dlg.Owner = App.Current.MainWindow; dlg.WindowStartupLocation = WindowStartupLocation.CenterOwner; dlg.Server.Text = grfExporterSettingsConfig.ServerAddress; dlg.UserName.Text = grfExporterSettingsConfig.UserName; dlg.Password.Focus(); bool? res = dlg.ShowDialog(); if (res.Value == true) { client.Credentials = new NetworkCredential(dlg.UserName.Text, dlg.Password.Password); if (dlg.RememberPassword.IsChecked.Value) { grfExporterSettingsConfig.RememberPassword = true; grfExporterSettingsConfig.Password = dlg.Password.Password; } } return res.Value; }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Init grid content by grf exporter settings config /// </summary> /// <param name="grfExporterConfig">Grf exporter settings config to use</param> private void _SetContent(GrfExporterSettingsConfig grfExporterConfig) { ServerAddress.Text = grfExporterConfig.ServerAddress; ServerPort.Text = grfExporterConfig.ServerPort.ToString(); ServerRequiresAutentication.IsChecked = grfExporterConfig.AutenticationRequired; UserName.Text = grfExporterConfig.UserName; RememberPassword.IsChecked = grfExporterConfig.RememberPassword; Password.Password = grfExporterConfig.Password; EncryptedConnectionRequires.IsChecked = grfExporterConfig.EncryptedConnectionRequires; }
/// <summary> /// Create binding from page content to grf exporter settings config /// </summary> /// <param name="grfExporterConfig">Grf exporter settings config to use</param> private void _BindConfig(GrfExporterSettingsConfig grfExporterConfig) { _CreateBinding("ServerAddress", grfExporterConfig, ServerAddress, TextBox.TextProperty); _CreateBinding("ServerPort", grfExporterConfig, ServerPort, TextBox.TextProperty); _CreateBinding("AutenticationRequired", grfExporterConfig, ServerRequiresAutentication, ToggleButton.IsCheckedProperty); _CreateBinding("UserName", grfExporterConfig, UserName, TextBox.TextProperty); _CreateBinding("RememberPassword", grfExporterConfig, RememberPassword, ToggleButton.IsCheckedProperty); _CreateBinding("EncryptedConnectionRequires", grfExporterConfig, EncryptedConnectionRequires, ToggleButton.IsCheckedProperty); RouteGRFcompression.IsChecked = grfExporterConfig.RouteGrfCompression; _CreateBinding("RouteGrfCompression", grfExporterConfig, RouteGRFcompression, CheckBox.IsCheckedProperty); _isLoaded = true; }
/// <summary> /// Serialize grf exporter settings config /// </summary> /// <returns>Serialized grf exporter settings config</returns> private static GrfExporterSettingsConfig _Create() { GrfExporterSettingsConfig grfExporterSettingsConfig = new GrfExporterSettingsConfig(); grfExporterSettingsConfig.ServerPort = MAIL_PORT; grfExporterSettingsConfig.AutenticationRequired = true; grfExporterSettingsConfig.RememberPassword = true; return grfExporterSettingsConfig; }
/// <summary> /// Inits state /// </summary> /// <param name="app">Current application</param> /// <param name="sendRoutesPage">Page</param> /// <param name="resources">Resources</param> public void Initialize(App app, PageBase sendRoutesPage) { _app = app; _page = sendRoutesPage; _grfExporterConfig = GrfExporterSettingsConfig.Instance; }