Пример #1
0
        public void ReconnectToService()
        {
            //m_serviceClient = new WindowsServiceClient(((App)Application.Current).RemoteStatusServiceUrl);
            //m_serviceClient.Helper.RemotingClient.MaxConnectionAttempts = 10;

            m_serviceClient = ((App)Application.Current).ServiceClient;
            if (m_serviceClient != null)
            {
                m_serviceClient.Helper.ReceivedServiceUpdate += new EventHandler<TVA.EventArgs<UpdateType, string>>(Helper_ReceivedServiceUpdate);        // += ClientHelper_ReceivedServiceUpdate;
                m_serviceClient.Helper.ReceivedServiceResponse += new EventHandler<TVA.EventArgs<ServiceResponse>>(Helper_ReceivedServiceResponse);          //+= ClientHelper_ReceivedServiceResponse;
                ConnectWindowsServiceClient(m_serviceClient);
            }
        }
Пример #2
0
 void Initialize()
 {
     serviceClient = ((App)Application.Current).ServiceClient;
     if (((App)Application.Current).Principal.IsInRole("Administrator, Editor"))
     {
         ButtonSave.IsEnabled = true;
         ButtonInitialize.IsEnabled = true;
     }
     else
     {
         ButtonSave.IsEnabled = false;
         ButtonInitialize.IsEnabled = false;
     }
 }
Пример #3
0
        private void RefreshServiceClientList(object obj)
        {
            System.Diagnostics.Debug.WriteLine("Refreshing Service Clients List");
            nodeList = CommonFunctions.GetNodeList(null, true);

            //For each node defined in the database, we need to have a TCP client created to listen to the events.
            foreach (Node node in nodeList)
            {
                lock (serviceClientList)
                {
                    if (serviceClientList.ContainsKey(node.ID))
                    {
                        if (node.RemoteStatusServiceUrl != serviceClientList[node.ID].Helper.RemotingClient.ConnectionString)
                        {
                            System.Diagnostics.Debug.WriteLine("Resetting Service Client for Node: " + node.ID);
                            serviceClientList[node.ID].Helper.ReceivedServiceUpdate -= ClientHelper_ReceivedServiceUpdate;
                            serviceClientList[node.ID].Helper.ReceivedServiceResponse -= ClientHelper_ReceivedServiceResponse;
                            serviceClientList[node.ID].Dispose();
                            if (!string.IsNullOrEmpty(node.RemoteStatusServiceUrl))
                            {
                                System.Diagnostics.Debug.WriteLine("Reconnecting Service Client for Node: " + node.ID);
                                serviceClientList[node.ID] = null;
                                serviceClient = new WindowsServiceClient(node.RemoteStatusServiceUrl);
                                serviceClient.Helper.RemotingClient.MaxConnectionAttempts = 10;
                                serviceClientList[node.ID] = serviceClient;
                                serviceClient.Helper.ReceivedServiceUpdate += ClientHelper_ReceivedServiceUpdate;
                                serviceClient.Helper.ReceivedServiceResponse += ClientHelper_ReceivedServiceResponse;
                                ThreadPool.QueueUserWorkItem(ConnectWindowsServiceClient, serviceClient);
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine("Removing Service Client for Node: " + node.ID);
                                serviceClientList.Remove(node.ID);
                            }
                        }
                        else if (!serviceClientList[node.ID].Helper.RemotingClient.Enabled)
                        {
                            ThreadPool.QueueUserWorkItem(ConnectWindowsServiceClient, serviceClientList[node.ID]);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(node.RemoteStatusServiceUrl))
                        {
                            System.Diagnostics.Debug.WriteLine("Adding New Service Client for Node: " + node.ID);
                            serviceClient = new WindowsServiceClient(node.RemoteStatusServiceUrl);
                            serviceClient.Helper.RemotingClient.MaxConnectionAttempts = 10;
                            serviceClientList.Add(node.ID, serviceClient);
                            serviceClient.Helper.ReceivedServiceUpdate += ClientHelper_ReceivedServiceUpdate;
                            serviceClient.Helper.ReceivedServiceResponse += ClientHelper_ReceivedServiceResponse;
                            ThreadPool.QueueUserWorkItem(ConnectWindowsServiceClient, serviceClient);
                        }
                    }
                }
            }
        }
Пример #4
0
 private void DisconnectFromService()
 {
     try
     {
         if (m_serviceClient != null)
         {
             m_serviceClient.Helper.RemotingClient.ConnectionEstablished -= RemotingClient_ConnectionEstablished;
             m_serviceClient.Helper.RemotingClient.ConnectionTerminated -= RemotingClient_ConnectionTerminated;
             m_serviceClient.Helper.RemotingClient.ConnectionAttempt -= RemotingClient_ConnectionAttempt;
             m_serviceClient.Dispose();
         }
         m_serviceClient = null;
     }
     catch (Exception ex)
     {
         CommonFunctions.LogException(null, "WPF.DisconnectFromService", new InvalidOperationException("Exception encountered while attempting to disconnect from openPDC: " + ex.Message, ex));
     }
 }
Пример #5
0
        private void ConnectToService()
        {
            EllipseConnectionState.Fill = Application.Current.Resources["RedRadialGradientBrush"] as RadialGradientBrush;
            ToolTipService.SetToolTip(EllipseConnectionState, "Disconnected from openPDC Service");

            if (!string.IsNullOrEmpty(((App)Application.Current).RemoteStatusServiceUrl))
            {
                try
                {
                    // Disconnect from existsing connection if active
                    if (m_serviceClient != null)
                        DisconnectFromService();

                    Dictionary<string, string> settings = ((App)Application.Current).RemoteStatusServiceUrl.ToLower().ParseKeyValuePairs();

                    if (settings.ContainsKey("server"))
                    {
                        m_serviceClient = new WindowsServiceClient("server=" + settings["server"].Replace("{", "").Replace("}", ""));
                        m_serviceClient.Helper.RemotingClient.ConnectionEstablished += RemotingClient_ConnectionEstablished;
                        m_serviceClient.Helper.RemotingClient.ConnectionTerminated += RemotingClient_ConnectionTerminated;
                        m_serviceClient.Helper.RemotingClient.ConnectionAttempt += RemotingClient_ConnectionAttempt;

                        // Start connection cycle
                        System.Threading.ThreadPool.QueueUserWorkItem(ConnectAsync, null);

                        ((App)Application.Current).ServiceClient = m_serviceClient;
                    }
                    else
                    {
                        SystemMessages sm = new SystemMessages(new Message() { UserMessage = "Please provide proper Remote Status Service Url value for node.", SystemMessage = "Remote Status Service Url value is not set properly for " + ((App)Application.Current).NodeName + " node." + Environment.NewLine + "Please go to Manage => Nodes screen to configure node settings." + Environment.NewLine + "For example: Server=localhost:8500", UserMessageType = MessageType.Error }, ButtonType.OkOnly);
                        sm.Owner = Window.GetWindow(this);
                        sm.ShowPopup();
                    }
                }
                catch (Exception ex)
                {
                    CommonFunctions.LogException(null, "MasterLayoutWindow_Loaded", new InvalidOperationException("Exception encountered while attempting to establish openPDC connection: " + ex.Message, ex));
                    ((App)Application.Current).ServiceClient = null;
                }
            }
            else
            {
                SystemMessages sm = new SystemMessages(new Message() { UserMessage = "Please provide Remote Status Service Url value for node.", SystemMessage = "Remote Status Service Url value is not set for " + ((App)Application.Current).NodeName + " node." + Environment.NewLine + "Please go to Manage => Nodes screen to configure node settings." + Environment.NewLine + "For example: Server=localhost:8500", UserMessageType = MessageType.Error }, ButtonType.OkOnly);
                sm.Owner = Window.GetWindow(this);
                sm.ShowPopup();
            }
        }
Пример #6
0
        public static string SendCommandToWindowsService(WindowsServiceClient serviceClient, string command)
        {
            //WindowsServiceClient serviceClient = new WindowsServiceClient(connectionString);
            try
            {
                //serviceClient.Helper.RemotingClient.MaxConnectionAttempts = connectionAttempts;
                //serviceClient.Helper.Connect();

                if (serviceClient.Helper.RemotingClient.CurrentState == TVA.Communication.ClientState.Connected)
                    serviceClient.Helper.SendRequest(command);
                else
                    throw new Exception("Failed to Connect to openPDC Windows Service (" + serviceClient.Helper.RemotingClient.ConnectionString + ").");

                return "Successfully sent " + command + " command.";
            }
            finally
            {
                //try
                //{
                //    if (serviceClient.Helper.RemotingClient.CurrentState == TVA.Communication.ClientState.Connected)
                //        serviceClient.Helper.Disconnect();
                //}
                //catch { }
            }
        }
Пример #7
0
        public static List<WizardDeviceInfo> RetrieveConfigurationFrame(string nodeConnectionString, string deviceConnectionString, int protocolID)
        {
            s_responseMessage = string.Empty;
            s_responseAttachment = null;

            Dictionary<string, string> settings = nodeConnectionString.ToLower().ParseKeyValuePairs();

            WindowsServiceClient windowsServiceClient = new WindowsServiceClient("server=" + settings["server"].Replace("{", "").Replace("}", ""));
            try
            {
                s_responseWaitHandle = new ManualResetEvent(false);
                windowsServiceClient.Helper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;
                windowsServiceClient.Helper.ReceivedServiceUpdate += Helper_ReceivedServiceUpdate;
                windowsServiceClient.Helper.RemotingClient.MaxConnectionAttempts = 10;
                windowsServiceClient.Helper.Connect();
                if (windowsServiceClient.Helper.RemotingClient.Enabled)
                {
                    if (deviceConnectionString.ToLower().Contains("phasorprotocol"))
                        windowsServiceClient.Helper.SendRequest(string.Format("invoke 0 requestdeviceconfiguration \"{0}\"", deviceConnectionString));
                    else
                        windowsServiceClient.Helper.SendRequest(string.Format("invoke 0 requestdeviceconfiguration \"{0}\"", deviceConnectionString + "; phasorProtocol=" + GetProtocolAcronymByID(null, protocolID)));

                    if (s_responseWaitHandle.WaitOne(65000))
                    {
                        if (s_responseAttachment is ConfigurationErrorFrame)
                            throw new ApplicationException("Received configuration error frame, invocation request for device configuration has failed.\r\n");
                        else if (s_responseAttachment is IConfigurationFrame)
                            return ParseConfigurationFrame(s_responseAttachment as IConfigurationFrame);
                        else
                            throw new ApplicationException("Invalid frame received, invocation for device configuration has failed.");
                    }
                    else
                        throw new ApplicationException("Response timeout occured. Waited 60 seconds for Configuration Frame to arrive.");
                }
                else
                {
                    throw new ApplicationException("Connection timeout occured. Tried 10 times to connect to openPDC windows service.");
                }
            }
            finally
            {
                windowsServiceClient.Helper.Disconnect();
                //windowsServiceClient.Dispose();
            }
        }