/// <summary> /// Handles loaded event for <see cref="SubscriberUserControl"/>. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">Event arguments.</param> private void SubscriberUserControl_Loaded(object sender, RoutedEventArgs e) { // Attach to load/before save event so class can load/add crypto keys from/to local keyIV cache m_dataContext.PropertyChanged += SubscriberUserControl_PropertyChanged; m_dataContext.BeforeSave += SubscriberUserControl_BeforeSave; LoadCurrentKeyIV(); try { using (AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory)) { Dictionary <string, string> settings; string server; IPAddress[] hostIPs = null; IEnumerable <IPAddress> localIPs; settings = database.DataPublisherConnectionString().ToNonNullString().ParseKeyValuePairs(); if (settings.TryGetValue("server", out server)) { hostIPs = Dns.GetHostAddresses(server.Split(':')[0]); } localIPs = Dns.GetHostAddresses("localhost").Concat(Dns.GetHostAddresses(Dns.GetHostName())); // Check to see if entered host name corresponds to a local IP address if ((object)hostIPs == null) { MessageBox.Show("Failed to find service host address. If using Gateway security, secure key exchange may not succeed." + Environment.NewLine + "Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Authorize Subcriber", MessageBoxButton.OK, MessageBoxImage.Warning); } else if (!hostIPs.Any(ip => localIPs.Contains(ip))) { MessageBox.Show("If using Gateway security, secure key exchange may not succeed." + Environment.NewLine + "Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Authorize Subscriber", MessageBoxButton.OK, MessageBoxImage.Warning); } } // If the user is not an Administrator, then the following properties for these controls are readonly and not enable bool isAdmin = CommonFunctions.CurrentPrincipal.IsInRole("Administrator,Editor"); AcronymField.IsReadOnly = !isAdmin; NameField.IsReadOnly = !isAdmin; ValidIpAddressesField.IsReadOnly = !isAdmin; EnablePGConnectionCheckBox.IsEnabled = isAdmin; ImportSRQButton.IsEnabled = isAdmin; ImportCERButton.IsEnabled = isAdmin; FooterControl.IsEnabled = isAdmin; } catch { MessageBox.Show("Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Authorize Subscriber", MessageBoxButton.OK, MessageBoxImage.Warning); } }
// Gets the current data publisher connection string private string GetDataPublisherConnectionString() { AdoDataConnection database = null; try { // Create database connection to get the current data publisher connection string database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory); return(database.DataPublisherConnectionString()); } finally { if ((object)database != null) { database.Dispose(); } } }
private void InitializeUnsynchronizedSubscription() { try { using (AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory)) { m_unsynchronizedSubscriber = new DataSubscriber(); m_unsynchronizedSubscriber.StatusMessage += m_unsynchronizedSubscriber_StatusMessage; m_unsynchronizedSubscriber.ProcessException += m_unsynchronizedSubscriber_ProcessException; m_unsynchronizedSubscriber.ConnectionEstablished += m_unsynchronizedSubscriber_ConnectionEstablished; m_unsynchronizedSubscriber.NewMeasurements += m_unsynchronizedSubscriber_NewMeasurements; m_unsynchronizedSubscriber.ConnectionTerminated += m_unsynchronizedSubscriber_ConnectionTerminated; m_unsynchronizedSubscriber.ConnectionString = database.DataPublisherConnectionString(); m_unsynchronizedSubscriber.Initialize(); m_unsynchronizedSubscriber.Start(); } } catch (Exception ex) { Popup("Failed to initialize subscription." + Environment.NewLine + ex.Message, "Failed to Subscribe", MessageBoxImage.Error); } }
/// <summary> /// Handles loaded event for <see cref="SubscriberUserControl"/>. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">Event arguments.</param> private void SubscriberUserControl_Loaded(object sender, RoutedEventArgs e) { // Attach to load/before save event so class can load/add crypto keys from/to local keyIV cache m_dataContext.PropertyChanged += SubscriberUserControl_PropertyChanged; m_dataContext.BeforeSave += SubscriberUserControl_BeforeSave; LoadCurrentKeyIV(); try { using (AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory)) { Dictionary<string, string> settings; string server; IPAddress[] hostIPs = null; IEnumerable<IPAddress> localIPs; settings = database.DataPublisherConnectionString().ToNonNullString().ParseKeyValuePairs(); if (settings.TryGetValue("server", out server)) hostIPs = Dns.GetHostAddresses(server.Split(':')[0]); localIPs = Dns.GetHostAddresses("localhost").Concat(Dns.GetHostAddresses(Dns.GetHostName())); // Check to see if entered host name corresponds to a local IP address if ((object)hostIPs == null) MessageBox.Show("Failed to find service host address. If using Gateway security, secure key exchange may not succeed." + Environment.NewLine + "Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Authorize Subcriber", MessageBoxButton.OK, MessageBoxImage.Warning); else if (!hostIPs.Any(ip => localIPs.Contains(ip))) MessageBox.Show("If using Gateway security, secure key exchange may not succeed." + Environment.NewLine + "Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Authorize Subscriber", MessageBoxButton.OK, MessageBoxImage.Warning); } // If the user is not an Administrator, then the following properties for these controls are readonly and not enable bool isAdmin = CommonFunctions.CurrentPrincipal.IsInRole("Administrator,Editor"); AcronymField.IsReadOnly = !isAdmin; NameField.IsReadOnly = !isAdmin; ValidIpAddressesField.IsReadOnly = !isAdmin; EnablePGConnectionCheckBox.IsEnabled = isAdmin; ImportSRQButton.IsEnabled = isAdmin; ImportCERButton.IsEnabled = isAdmin; FooterControl.IsEnabled = isAdmin; } catch { MessageBox.Show("Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Authorize Subscriber", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void InitializeUnsynchronizedSubscription() { try { using (AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory)) { m_unsynchronizedSubscriber = new DataSubscriber(); m_unsynchronizedSubscriber.StatusMessage += m_unsynchronizedSubscriber_StatusMessage; m_unsynchronizedSubscriber.ProcessException += m_unsynchronizedSubscriber_ProcessException; m_unsynchronizedSubscriber.ConnectionEstablished += m_unsynchronizedSubscriber_ConnectionEstablished; m_unsynchronizedSubscriber.NewMeasurements += m_unsynchronizedSubscriber_NewMeasurements; m_unsynchronizedSubscriber.ConnectionTerminated += m_unsynchronizedSubscriber_ConnectionTerminated; // Statistics move slowly, typically every 10 seconds, so we reduce data loss interval to every 20 seconds m_unsynchronizedSubscriber.ConnectionString = "dataLossInterval = 20.0; " + database.DataPublisherConnectionString(); m_unsynchronizedSubscriber.Initialize(); m_unsynchronizedSubscriber.Start(); } } catch (Exception ex) { Popup("Failed to initialize subscription." + Environment.NewLine + ex.Message, "Failed to Subscribe", MessageBoxImage.Error); } }
private void InitializeUnsynchronizedSubscription() { try { using (AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory)) { m_unsynchronizedSubscriber = new DataSubscriber(); m_unsynchronizedSubscriber.StatusMessage += m_unsynchronizedSubscriber_StatusMessage; m_unsynchronizedSubscriber.ProcessException += m_unsynchronizedSubscriber_ProcessException; m_unsynchronizedSubscriber.ConnectionEstablished += m_unsynchronizedSubscriber_ConnectionEstablished; m_unsynchronizedSubscriber.NewMeasurements += m_unsynchronizedSubscriber_NewMeasurements; m_unsynchronizedSubscriber.ConnectionTerminated += m_unsynchronizedSubscriber_ConnectionTerminated; m_unsynchronizedSubscriber.ConnectionString = database.DataPublisherConnectionString(); m_unsynchronizedSubscriber.Initialize(); m_unsynchronizedSubscriber.Start(); } } catch (Exception ex) { MessageBox.Show("Failed to initialize subscription." + Environment.NewLine + ex.Message, "Failed to Subscribe", MessageBoxButton.OK); } }
private void InitializeSubscription() { try { using (AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory)) { m_subscriber = new DataSubscriber(); m_subscriber.StatusMessage += m_subscriber_StatusMessage; m_subscriber.ProcessException += m_subscriber_ProcessException; m_subscriber.ConnectionEstablished += m_subscriber_ConnectionEstablished; m_subscriber.NewMeasurements += m_subscriber_NewMeasurements; m_subscriber.ConnectionTerminated += m_subscriber_ConnectionTerminated; m_subscriber.ProcessingComplete += m_subscriber_ProcessingComplete; m_subscriber.ConnectionString = database.DataPublisherConnectionString(); m_subscriber.Initialize(); m_subscriber.Start(); } } catch { // TODO: show error in popup window //Popup("Failed to initialize subscription." + Environment.NewLine + ex.Message, "Failed to Subscribe", MessageBoxImage.Error); } }
// Gets the current data publisher connection string private string GetDataPublisherConnectionString() { AdoDataConnection database = null; try { // Create database connection to get the current data publisher connection string database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory); return database.DataPublisherConnectionString(); } finally { if ((object)database != null) database.Dispose(); } }
private void Load() { string companyAcronym; // Try to populate defaults for subscriber acronym and name using company information from the host application configuration file if (TryGetCompanyAcronym(out companyAcronym)) { SubscriberAcronym = companyAcronym; SubscriberName = string.Format("{0} Subscription Authorization", companyAcronym); } // Connect to database to retrieve company information for current node using (AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory)) { try { string query = database.ParameterizedQueryString("SELECT Company.Acronym, Company.Name FROM Company, Node WHERE Company.ID = Node.CompanyID AND Node.ID = {0}", "id"); DataRow row = database.Connection.RetrieveRow(database.AdapterType, query, database.CurrentNodeID()); PublisherAcronym = row.Field<string>("Acronym"); PublisherName = row.Field<string>("Name"); // Generate a default shared secret password for subscriber key and initialization vector byte[] buffer = new byte[4]; Random.GetBytes(buffer); string generatedSecret = Convert.ToBase64String(buffer).RemoveCrLfs(); if (generatedSecret.Contains("=")) generatedSecret = generatedSecret.Split('=')[0]; SharedKey = generatedSecret; // Generate an identity for this subscriber AesManaged sa = new AesManaged(); sa.GenerateKey(); IdentityCertificate = Convert.ToBase64String(sa.Key); // Generate valid local IP addresses for this connection IEnumerable<IPAddress> addresses = Dns.GetHostAddresses(Dns.GetHostName()).OrderBy(key => key.AddressFamily); ValidIPAddresses = addresses.ToDelimitedString("; "); } catch (Exception ex) { MessageBox.Show("ERROR: " + ex.Message, "Subscriber Request", MessageBoxButton.OK); } try { Dictionary<string, string> settings; string server; string[] splitServer; int dataPublisherPort; //IPAddress[] hostIPs = null; //IEnumerable<IPAddress> localIPs; settings = database.DataPublisherConnectionString().ToNonNullString().ParseKeyValuePairs(); //localIPs = Dns.GetHostAddresses("localhost").Concat(Dns.GetHostAddresses(Dns.GetHostName())); if (settings.TryGetValue("server", out server)) { splitServer = server.Split(':'); //hostIPs = Dns.GetHostAddresses(splitServer[0]); if (splitServer.Length > 1 && int.TryParse(splitServer[1], out dataPublisherPort)) InternalDataPublisherPort = dataPublisherPort; } // These messages show up when not desired and are not very useful anymore... //// Check to see if entered host name corresponds to a local IP address //if (hostIPs == null) // MessageBox.Show("Failed to find service host address. If using Gateway security, secure key exchange may not succeed." + Environment.NewLine + "Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Subscription Request", MessageBoxButton.OK, MessageBoxImage.Warning); //else if (!hostIPs.Any(ip => localIPs.Contains(ip))) // MessageBox.Show("If using Gateway security, secure key exchange may not succeed." + Environment.NewLine + "Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Subscription Request", MessageBoxButton.OK, MessageBoxImage.Warning); } catch { MessageBox.Show("Please make sure to run manager application with administrative privileges on the server where service is hosted.", "Subscription Request", MessageBoxButton.OK, MessageBoxImage.Warning); } } }