Example #1
0
 /// <summary>
 /// Phương thức client ngắt kết nối vào Server.
 /// </summary>
 /// <param name="mac">Đối tượng máy người sử dụng đang dùng.</param>
 public void Disconnect(Machine mac)
 {
     try
     {
         lock (listCallbackChannels)
         {
             if (listCallbackChannels.Count > 0)
             {
                 IServiceCallback callbackChannel = OperationContext.Current.GetCallbackChannel <IServiceCallback>();
                 if (listCallbackChannels.Contains(callbackChannel))
                 {
                     if (listCallbackChannels.Remove(callbackChannel))
                     {
                         eventLoggingMessage?.Invoke(string.Format("Removed Callback Channel: {0}", callbackChannel.GetHashCode()));
                         EventChannelCount?.Invoke(1, false);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         eventLoggingMessage?.Invoke(string.Format("Disconnect-Removed Callback Channel: {0}", ex.Message));
     }
     finally
     {
         GC.SuppressFinalize(this);
     }
 }
Example #2
0
 public ReadService()
 {
     objChannelManager = ChannelService.GetChannelManager();
     ThreadPool.QueueUserWorkItem((th) =>
     {
         while (true)
         {
             try
             {
                 lock (listCallbackChannels)
                 {
                     if (listCallbackChannels.Count > 0)
                     {
                         foreach (IServiceCallback item in listCallbackChannels)
                         {
                             try
                             {
                                 if (((ICommunicationObject)item).State == CommunicationState.Opened)
                                 {
                                     item.UpdateCollection(XCollection.objConnectionState, TagCollection.Tags);
                                     item.UpdateCollectionDataBlock(XCollection.objConnectionState, DataBlockCollection.DataBlocks);
                                     Thread.Sleep(100);
                                 }
                             }
                             catch (Exception ex)
                             {
                                 if (listCallbackChannels.Remove(item))
                                 {
                                     eventLoggingMessage?.Invoke(string.Format("Removed Callback Channel: {0} | Exception: {1}", item.GetHashCode(), ex.Message));
                                     EventscadaException?.Invoke(GetType().Name, ex.Message);
                                     EventChannelCount?.Invoke(1, false);
                                 }
                             }
                         }
                     }
                     else
                     {
                         Thread.Sleep(500);
                     }
                 }
             }
             catch (Exception ex)
             {
                 if (ex.InnerException == null)
                 {
                     EventscadaException?.Invoke(GetType().Name, "+ Event ConnectorServiceCallback: " + ex.Message);
                 }
             }
             finally
             {
                 Thread.Sleep(100);
             }
         }
     });
 }
        public void Connect(Machine mac)
        {
            try
            {
                IServiceCallback EventDataChanged = OperationContext.Current.GetCallbackChannel <IServiceCallback>();
                eventLoggingMessage?.Invoke(string.Format("Added Callback Channel: {0}, IP Address: {1}.", mac.MachineName, mac.IPAddress));
                EventChannelCount?.Invoke(1, true);
                RUN_APPLICATION = true;

                ThreadPool.QueueUserWorkItem((WaitCallback) delegate
                {
                    while (RUN_APPLICATION)
                    {
                        try
                        {
                            if (EventDataChanged != null)
                            {
                                // Query the channel state. For example:-

                                var state = (EventDataChanged as IChannel).State;
                                if (state == CommunicationState.Closed || state == CommunicationState.Faulted)
                                {
                                    // Channel has closed, or has faulted...
                                    EventDataChanged = null;
                                    EventChannelCount?.Invoke(1, false);
                                }
                                else
                                {
                                    EventDataChanged?.DataTags(TagCollection.Tags);
                                }
                            }
                            Thread.Sleep(100);
                        }
                        catch (Exception ex)
                        {
                            RUN_APPLICATION = false;

                            eventLoggingMessage?.Invoke(string.Format("Removed Callback Channel: {0}, IP Address: {1}| Message Exception: {2}.", mac.MachineName, mac.IPAddress, ex.Message));

                            EventscadaException?.Invoke(this.GetType().Name, ex.Message);
                        }
                    }
                });
            }
            catch (System.Exception ex)
            {
                EventscadaException?.Invoke(this.GetType().Name, ex.Message);
            }
        }
 public void Disconnect(Machine mac)
 {
     try
     {
         RUN_APPLICATION = false;
         EventChannelCount?.Invoke(1, false);
         OperationContext.Current.GetCallbackChannel <IServiceCallback>();
         eventLoggingMessage?.Invoke(string.Format("Removed Callback Channel: {0}, IP Address: {1}.", mac.MachineName, mac.IPAddress));
     }
     catch (Exception ex)
     {
         Console.WriteLine("Disconnect-Removed Callback Channel: {0}", ex.Message);
         EventscadaException?.Invoke(this.GetType().Name, ex.Message);
     }
     finally
     {
         GC.SuppressFinalize(this);
     }
 }
Example #5
0
 /// <summary>
 /// Phương thức client kết nối vào Server.
 /// </summary>
 /// <param name="mac">Đối tượng máy người sử dụng đang dùng.</param>
 public void Connect(Machine mac)
 {
     try
     {
         lock (listCallbackChannels)
         {
             EventChannelCount?.Invoke(1, true);
             IServiceCallback callbackChannel = OperationContext.Current.GetCallbackChannel <IServiceCallback>();
             if (!listCallbackChannels.Contains(callbackChannel))
             {
                 listCallbackChannels.Add(callbackChannel);
                 eventLoggingMessage?.Invoke(string.Format("Added Callback Channel: {0}", callbackChannel.GetHashCode()));
             }
         }
     }
     catch (Exception ex)
     {
         throw new FaultException <IFaultException>(new IFaultException(ex.Message));
     }
 }