private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            backgroundWorker1.ReportProgress(0, "Waiting for subscriber host to be opened...");

            SubscriberInfo subscriberInfo = ApplicationService.GetSubscriberInfo();

            if (subscriberInfo.OpenedSuccessfully)
            {
                backgroundWorker1.ReportProgress(0, "Starting subscription...");
                try
                {
                    subscription = ConnectionInfo.DoWithExceptionTranslation(() => new Subscription(ConnectionInfo.Proxy,
                                                                                                    subscriberInfo.EndpointAddress, "SUBSCRIBE System.QueryExecuted"));
                    backgroundWorker1.ReportProgress(0, "Waiting for notifications");
                }
                catch (ApplicationException ex)
                {
                    e.Result = ex;
                }
            }
            else
            {
                e.Result = new ApplicationException(subscriberInfo.ErrorMessage);
            }
        }
Beispiel #2
0
        public void Connect()
        {
            if (_proxy == null || (_proxy != null && (_proxy.Channel.State == CommunicationState.Closed || _proxy.Channel.State == CommunicationState.Faulted)))
            {
                if (_proxy != null)
                {
                    _proxy.Dispose();
                }

                _proxy = _infoServiceType.CreateProxy(_server);
                _proxy.OperationTimeout = TimeSpan.FromMinutes(Settings.Default.OperationTimeout);
                _proxy.ChannelFactory.Endpoint.Behaviors.Add(new LogHeaderReaderBehavior());
                _proxy.Open();
            }

            Connection = new InformationServiceConnection((IInformationService)_proxy);
            Connection.Open();

            if (Settings.Default.UseActiveSubscriber && _infoServiceType.SupportsActiveSubscriber)
            {
                _notificationDeliveryServiceProxy = _infoServiceType.CreateNotificationDeliveryServiceProxy(_server, NotificationSubscriber);
                _notificationDeliveryServiceProxy.Open();
                _activeSubscriberAddress = string.Format("active://{0}/SolarWinds/SwqlStudio/{1}", Utility.GetFqdn(), Process.GetCurrentProcess().Id);
                _notificationDeliveryServiceProxy.ReceiveIndications(_activeSubscriberAddress);
                _activeSubscriberInfo = new SubscriberInfo()
                {
                    EndpointAddress    = _activeSubscriberAddress,
                    OpenedSuccessfully = true,
                    DataFormat         = "Xml"
                };
            }
        }
Beispiel #3
0
 private Subscription SubscribeHttp(InfoServiceProxy proxy, string query, SubscriberInfo subscriberInfo)
 {
     return(new Subscription(proxy, subscriberInfo.EndpointAddress, query, subscriberInfo.Binding, subscriberInfo.DataFormat, CredentialType.Username, "subscriber", "subscriber"));
 }
Beispiel #4
0
 private Subscription SubscribeNetTcp(InfoServiceProxy proxy, string query, SubscriberInfo subscriberInfo)
 {
     return(new Subscription(proxy, subscriberInfo.EndpointAddress, query, subscriberInfo.Binding, subscriberInfo.DataFormat));
 }
Beispiel #5
0
 private Subscription SubscribeHttp(InfoServiceProxy proxy, string query, SubscriberInfo subscriberInfo)
 {
     return new Subscription(proxy, subscriberInfo.EndpointAddress, query, subscriberInfo.Binding, subscriberInfo.DataFormat, CredentialType.Username, "subscriber", "subscriber");
 }
Beispiel #6
0
 private Subscription SubscribeNetTcp(InfoServiceProxy proxy, string query, SubscriberInfo subscriberInfo)
 {
     return new Subscription(proxy, subscriberInfo.EndpointAddress, query, subscriberInfo.Binding, subscriberInfo.DataFormat);
 }
Beispiel #7
0
        private void OpenSubscriber()
        {
            string ipAddress;

            try
            {
                // Instance should run on a different machine (i.e. where the additional poller is), so in that case must be subscription done via IP instead of relative localhost
                ipAddress = ResolveLocalIPAddress();
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Unable to retrieve ip address", ex);
                return;
            }

            string address = string.Format("net.tcp://{0}:17777/SolarWinds/SwqlStudio/{1}/Subscriber", ipAddress, Process.GetCurrentProcess().Id);

            try
            {
                log.InfoFormat("Opening subscriber endpoint at {0}", address);

                ServiceHost host = new ServiceHost(this);
                host.AddServiceEndpoint(typeof(INotificationSubscriber), new NetTcpBinding("NotificationSubscriber"), address);
                host.Open();
                subscriberHosts.Add(host);

                log.Info("Subscriber endpoint opened");

                subscriberInfo = new SubscriberInfo {
                    EndpointAddress = address, OpenedSuccessfully = true, Binding = "NetTcp", DataFormat = "Xml", CredentialType = "Certificate"
                };
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Exception opening subscriber host with address {0}.\n{1}", address, ex);
                subscriberInfo = new SubscriberInfo {
                    OpenedSuccessfully = false, ErrorMessage = ex.Message
                };
            }

            string httpAddress = string.Format("https://{0}:17778/SolarWinds/SwqlStudio/{1}", Utility.GetFqdn(), Process.GetCurrentProcess().Id);

            try
            {
                log.InfoFormat("Opening http subscriber endpoint at {0}", httpAddress);

                NotificationSubscriber notificationSubscriber = new NotificationSubscriber();
                notificationSubscriber.IndicationReceived += OnIndication;

                CngKeyCreationParameters keyCreationParameters = new CngKeyCreationParameters();
                keyCreationParameters.ExportPolicy = CngExportPolicies.AllowExport | CngExportPolicies.AllowPlaintextExport | CngExportPolicies.AllowPlaintextArchiving | CngExportPolicies.AllowArchiving;
                keyCreationParameters.KeyUsage     = CngKeyUsages.AllUsages;

                X509CertificateCreationParameters configCreate = new X509CertificateCreationParameters(new X500DistinguishedName("CN=SolarWinds-SwqlStudio"));
                configCreate.EndTime   = DateTime.Now.AddYears(1);
                configCreate.StartTime = DateTime.Now;

                using (CngKey cngKey = CngKey.Create(CngAlgorithm2.Rsa))
                {
                    X509Certificate2 certificate = cngKey.CreateSelfSignedCertificate(configCreate);
                    ServiceHost      host        = new ServiceHost(notificationSubscriber, new Uri(httpAddress));
                    host.Credentials.ServiceCertificate.Certificate = certificate;
                    // SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectDistinguishedName, "CN=SolarWinds-Orion");
                    host.Open();
                    subscriberHosts.Add(host);
                }

                log.Info("Http Subscriber endpoint opened");

                httpSubscriberInfo = new SubscriberInfo {
                    EndpointAddress = httpAddress + "/Subscriber", OpenedSuccessfully = true, DataFormat = "Xml", Binding = "Soap1_1", CredentialType = "Username"
                };
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Exception opening subscriber host with address {0}.\n{1}", address, ex);
                httpSubscriberInfo = new SubscriberInfo {
                    OpenedSuccessfully = false, ErrorMessage = ex.Message
                };
            }

            foreach (ServiceHost serviceHost in subscriberHosts)
            {
                foreach (ChannelDispatcherBase channelDispatcher in serviceHost.ChannelDispatchers)
                {
                    log.InfoFormat("Listening on {0}", channelDispatcher.Listener.Uri.AbsoluteUri);
                }
            }

            subscriberHostOpened.Set();
        }