Пример #1
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="AuthorizedMeasurementsQuery"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if ((object)m_serviceClient != null && (object)m_serviceClient.Helper != null)
                        {
                            m_serviceClient.Helper.ReceivedServiceResponse -= Helper_ReceivedServiceResponse;
                        }

                        m_serviceClient = null;

                        if ((object)m_responseComplete != null)
                        {
                            // Release any waiting threads before disposing wait handle
                            m_responseComplete.Set();
                            m_responseComplete.Dispose();
                        }

                        m_responseComplete = null;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a new <see cref="AuthorizedMeasurementsQuery"/>.
        /// </summary>
        public AuthorizedMeasurementsQuery()
        {
            m_serviceClient = CommonFunctions.GetWindowsServiceClient();
            m_serviceClient.Helper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;

            m_authorizedSignalIDs         = new List <Guid>();
            m_responseComplete            = new AutoResetEvent(false);
            m_authorizationQueryOperation = new LongSynchronizedOperation(ExecuteAuthorizationQuery)
            {
                IsBackground = true
            };
            m_authorizationQueryIDs  = new HashSet <Guid>();
            m_authorizationQueryLock = new object();
            m_responseTimeout        = DefaultResponseTimeout;
        }
Пример #3
0
        /// <summary>
        /// Creates a new <see cref="SubscriberStatusQuery"/>.
        /// </summary>
        public SubscriberStatusQuery()
        {
            m_serviceClient = CommonFunctions.GetWindowsServiceClient();
            m_serviceClient.Helper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;

            m_subscriberStatuses   = new List <Tuple <Guid, bool, string> >();
            m_responseComplete     = new AutoResetEvent(false);
            m_statusQueryOperation = new LongSynchronizedOperation(ExecuteStatusQuery)
            {
                IsBackground = true
            };
            m_statusQueryIDs  = new HashSet <Guid>();
            m_statusQueryLock = new object();
            m_responseTimeout = DefaultResponseTimeout;

            m_statusQueryOperation.IsBackground = true;
        }
Пример #4
0
        private void UpdateServiceConnectivity(bool refreshRaisedAlarms = false)
        {
            // Detach from original service response if refreshing service connection
            if ((object)m_serviceClient != null && (object)m_serviceClient.Helper != null)
            {
                m_serviceClient.Helper.ReceivedServiceResponse -= Helper_ReceivedServiceResponse;
            }

            // Get new service client
            m_serviceClient = CommonFunctions.GetWindowsServiceClient();
            ClientHelper clientHelper   = ((object)m_serviceClient != null) ? m_serviceClient.Helper : null;
            IClient      remotingClient = ((object)clientHelper != null) ? clientHelper.RemotingClient : null;

            if ((object)clientHelper != null)
            {
                clientHelper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;
            }

            if ((object)remotingClient == null || remotingClient.CurrentState != ClientState.Connected)
            {
                // Remoting client is not connected to service
                m_connectedToService = false;

                // Release any waiting threads if service has been disconnected
                if ((object)m_responseComplete != null)
                {
                    m_responseComplete.Set();
                }
            }
            else
            {
                // If remoting client is connected, refresh raised alarms if requested and attach to connection terminated event
                m_connectedToService = true;

                if (refreshRaisedAlarms)
                {
                    RequestRaisedAlarmStates();
                }

                remotingClient.ConnectionTerminated += RemotingClient_ConnectionTerminated;
            }
        }
        private void ConnectToService()
        {
            if ((object)m_windowsServiceClient != null && (object)m_windowsServiceClient.Helper != null && (object)m_windowsServiceClient.Helper.RemotingClient != null)
            {
                m_windowsServiceClient.Helper.RemotingClient.ConnectionEstablished -= RemotingClient_ConnectionEstablished;
                m_windowsServiceClient.Helper.RemotingClient.ConnectionTerminated -= RemotingClient_ConnectionTerminated;
            }

            m_windowsServiceClient = CommonFunctions.GetWindowsServiceClient();

            if ((object)m_windowsServiceClient != null)
            {
                m_windowsServiceClient.Helper.RemotingClient.ConnectionEstablished += RemotingClient_ConnectionEstablished;
                m_windowsServiceClient.Helper.RemotingClient.ConnectionTerminated += RemotingClient_ConnectionTerminated;

                if (m_windowsServiceClient.Helper.RemotingClient.CurrentState == GSF.Communication.ClientState.Connected)
                {
                    EllipseConnectionState.Dispatcher.BeginInvoke((Action)delegate()
                    {
                        EllipseConnectionState.Fill = Application.Current.Resources["GreenRadialGradientBrush"] as RadialGradientBrush;
                        ToolTipService.SetToolTip(EllipseConnectionState, "Connected to the service");
                    });
                }
                else
                {
                    EllipseConnectionState.Dispatcher.BeginInvoke((Action)delegate()
                    {
                        EllipseConnectionState.Fill = Application.Current.Resources["RedRadialGradientBrush"] as RadialGradientBrush;
                        ToolTipService.SetToolTip(EllipseConnectionState, "Disconnected from the service");
                    });
                }
            }
        }
Пример #6
0
        private void UpdateServiceConnectivity(bool refreshRaisedAlarms = false)
        {
            // Detach from original service response if refreshing service connection
            if ((object)m_serviceClient != null && (object)m_serviceClient.Helper != null)
                m_serviceClient.Helper.ReceivedServiceResponse -= Helper_ReceivedServiceResponse;

            // Get new service client
            m_serviceClient = CommonFunctions.GetWindowsServiceClient();
            ClientHelper clientHelper = ((object)m_serviceClient != null) ? m_serviceClient.Helper : null;
            IClient remotingClient = ((object)clientHelper != null) ? clientHelper.RemotingClient : null;

            if ((object)clientHelper != null)
                clientHelper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;

            if ((object)remotingClient == null || remotingClient.CurrentState != ClientState.Connected)
            {
                // Remoting client is not connected to service
                m_connectedToService = false;

                // Release any waiting threads if service has been disconnected
                if ((object)m_responseComplete != null)
                    m_responseComplete.Set();
            }
            else
            {
                // If remoting client is connected, refresh raised alarms if requested and attach to connection terminated event
                m_connectedToService = true;

                if (refreshRaisedAlarms)
                    RequestRaisedAlarmStates();

                remotingClient.ConnectionTerminated += RemotingClient_ConnectionTerminated;
            }
        }
Пример #7
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="AlarmStatusQuery"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if ((object)m_serviceClient != null && (object)m_serviceClient.Helper != null)
                            m_serviceClient.Helper.ReceivedServiceResponse -= Helper_ReceivedServiceResponse;

                        m_serviceClient = null;

                        if ((object)m_responseComplete != null)
                        {
                            // Release any waiting threads before disposing wait handle
                            m_responseComplete.Set();
                            m_responseComplete.Dispose();
                        }

                        m_responseComplete = null;

                        // Detach from service connected events
                        CommonFunctions.ServiceConnectionRefreshed -= CommonFunctions_ServiceConnectionRefreshed;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
        private void HomeUserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!CommonFunctions.CurrentPrincipal.IsInRole("Administrator"))
                ButtonRestart.IsEnabled = false;

            //if (!CommonFunctions.CurrentPrincipal.IsInRole("Administrator,Editor"))
            //    ButtonInputWizard.IsEnabled = false;

            m_windowsServiceClient = CommonFunctions.GetWindowsServiceClient();

            if (m_windowsServiceClient == null || m_windowsServiceClient.Helper.RemotingClient.CurrentState != ClientState.Connected)
            {
                ButtonRestart.IsEnabled = false;
            }
            else
            {
                m_windowsServiceClient.Helper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;
                CommonFunctions.SendCommandToService("Health -actionable");
                CommonFunctions.SendCommandToService("Version -actionable");
                CommonFunctions.SendCommandToService("Status -actionable");
                CommonFunctions.SendCommandToService("Time -actionable");
                m_eventHandlerRegistered = true;
            }

            m_refreshTimer = new DispatcherTimer();
            m_refreshTimer.Interval = TimeSpan.FromSeconds(5);
            m_refreshTimer.Tick += RefreshTimer_Tick;
            m_refreshTimer.Start();

            if (IntPtr.Size == 8)
                TextBlockInstance.Text = "64-bit";
            else
                TextBlockInstance.Text = "32-bit";

            TextBlockLocalTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

            Version appVersion = AssemblyInfo.EntryAssembly.Version;
            TextBlockManagerVersion.Text = appVersion.Major + "." + appVersion.Minor + "." + appVersion.Build + ".0";

            try
            {
                using (AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory))
                {
                    TextBlockDatabaseType.Text = database.DatabaseType.ToString();

                    try
                    {
                        if (database.IsSqlite || database.IsJetEngine)
                        {
                            // Extract database file name from connection string for file centric databases
                            TextBlockDatabaseName.Text = FilePath.GetFileName(database.Connection.ConnectionString.ParseKeyValuePairs()["Data Source"]);
                        }
                        else if (database.IsOracle)
                        {
                            // Extract user name from connection string for Oracle databases
                            TextBlockDatabaseName.Text = database.Connection.ConnectionString.ParseKeyValuePairs()["User Id"];
                        }
                        else
                        {
                            TextBlockDatabaseName.Text = database.Connection.Database;
                        }
                    }
                    catch
                    {
                        // Fall back on database name if file anything fails
                        TextBlockDatabaseName.Text = database.Connection.Database;
                    }
                }
            }
            catch
            {
                TextBlockDatabaseName.Text = "Not Avaliable";
            }

            try
            {
                using (UserInfo info = new UserInfo(CommonFunctions.CurrentUser))
                {
                    if (info.Exists)
                        TextBlockUser.Text = info.LoginID;
                    else
                        TextBlockUser.Text = CommonFunctions.CurrentUser;
                }
            }
            catch
            {
                TextBlockUser.Text = CommonFunctions.CurrentUser;
            }

            ((HorizontalAxis)ChartPlotterDynamic.MainHorizontalAxis).LabelProvider.LabelStringFormat = "";

            //Remove legend on the right.
            Panel legendParent = (Panel)ChartPlotterDynamic.Legend.ContentGrid.Parent;
            if (legendParent != null)
                legendParent.Children.Remove(ChartPlotterDynamic.Legend.ContentGrid);

            ChartPlotterDynamic.NewLegendVisible = false;

            m_xAxisDataCollection = new int[m_numberOfPointsToPlot];
            for (int i = 0; i < m_numberOfPointsToPlot; i++)
                m_xAxisDataCollection[i] = i;
            m_xAxisBindingCollection = new EnumerableDataSource<int>(m_xAxisDataCollection);
            m_xAxisBindingCollection.SetXMapping(x => x);

            ComboBoxDevice.ItemsSource = Device.GetLookupList(null);
            if (ComboBoxDevice.Items.Count > 0)
                ComboBoxDevice.SelectedIndex = 0;
        }
Пример #9
0
        /// <summary>
        /// Creates a new <see cref="AuthorizedMeasurementsQuery"/>.
        /// </summary>
        public AuthorizedMeasurementsQuery()
        {
            m_serviceClient = CommonFunctions.GetWindowsServiceClient();
            m_serviceClient.Helper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;

            m_authorizedSignalIDs = new List<Guid>();
            m_responseComplete = new AutoResetEvent(false);
            m_authorizationQueryOperation = new LongSynchronizedOperation(ExecuteAuthorizationQuery) { IsBackground = true };
            m_authorizationQueryIDs = new HashSet<Guid>();
            m_authorizationQueryLock = new object();
            m_responseTimeout = DefaultResponseTimeout;
        }
Пример #10
0
        /// <summary>
        /// Creates a new <see cref="SubscriberStatusQuery"/>.
        /// </summary>
        public SubscriberStatusQuery()
        {
            m_serviceClient = CommonFunctions.GetWindowsServiceClient();
            m_serviceClient.Helper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;

            m_subscriberStatuses = new List<Tuple<Guid, bool, string>>();
            m_responseComplete = new AutoResetEvent(false);
            m_statusQueryOperation = new LongSynchronizedOperation(ExecuteStatusQuery) { IsBackground = true };
            m_statusQueryIDs = new HashSet<Guid>();
            m_statusQueryLock = new object();
            m_responseTimeout = DefaultResponseTimeout;

            m_statusQueryOperation.IsBackground = true;
        }
Пример #11
0
 /// <summary>
 /// Disconnects from backend windows service.
 /// </summary>
 public static void DisconnectWindowsServiceClient()
 {
     try
     {
         if (s_windowsServiceClient != null)
         {
             s_windowsServiceClient.Dispose();
             s_windowsServiceClient = null;
         }
     }
     catch (Exception ex)
     {
         LogException(null, "RemoteConsoleConnection", ex);
     }
 }
Пример #12
0
        /// <summary>
        /// Connects to backend windows service.
        /// </summary>
        public static void ConnectWindowsServiceClient(bool overwrite = false)
        {
            TlsClient remotingClient;
            ISecurityProvider provider;
            UserData userData;

            if (overwrite)
            {
                DisconnectWindowsServiceClient();
                ServiceConnectionRefreshed(null, EventArgs.Empty);
            }
            else if (s_windowsServiceClient == null || s_windowsServiceClient.Helper.RemotingClient.CurrentState != ClientState.Connected)
            {
                if (s_windowsServiceClient != null)
                    DisconnectWindowsServiceClient();

                AdoDataConnection database = new AdoDataConnection(DefaultSettingsCategory);

                try
                {
                    string connectionString = database.ServiceConnectionString(true);

                    if (!string.IsNullOrWhiteSpace(connectionString))
                    {
                        s_windowsServiceClient = new WindowsServiceClient(connectionString);

                        if (SecurityProviderCache.TryGetCachedProvider(CurrentPrincipal.Identity.Name, out provider))
                        {
                            userData = provider.UserData;

                            if ((object)userData != null)
                            {
                                s_windowsServiceClient.Helper.Username = userData.LoginID;
                                s_windowsServiceClient.Helper.Password = SecurityProviderUtility.EncryptPassword(provider.Password);
                                remotingClient = s_windowsServiceClient.Helper.RemotingClient as TlsClient;

                                if ((object)remotingClient != null && (object)provider.SecurePassword != null && provider.SecurePassword.Length > 0)
                                    remotingClient.NetworkCredential = new NetworkCredential(userData.LoginID, provider.SecurePassword);
                            }
                        }

                        s_windowsServiceClient.Helper.RemotingClient.MaxConnectionAttempts = -1;
                        s_windowsServiceClient.Helper.RemotingClient.ConnectionEstablished += RemotingClient_ConnectionEstablished;
                        s_windowsServiceClient.Helper.RemotingClient.ConnectionException += RemotingClient_ConnectionException;

                        ConnectAsync();
                    }
                }
                finally
                {
                    database.Dispose();
                }
            }
        }