Exemplo n.º 1
0
        protected override void Execute()
        {
            while (Terminated == false)
            {
                lock (server.Clients)
                {
                    foreach (KeyValuePair <string, ClientRow> row in server.Clients)
                    {
                        ClientRow client = row.Value;
                        if (client.BeginTime == 0)
                        {
                            client.BeginTime = ElapsedMilliseconds;
                        }

                        if (client.State != EClientState.Observation)
                        {
                            if (IsTimeoutMilliseconds(client.BeginTime, client.ScanTime) == true)
                            {
                                // Timer 초기화
                                client.BeginTime += client.ScanTime;
                                Send(client);
                            }
                        }
                    }
                }

                Yield();
            }
        }
Exemplo n.º 2
0
 private void RemoveClient(ClientRow client)
 {
     if (server.Clients.ContainsKey(client.Ip) == true)
     {
         server.ClientList.Remove(client);
         server.Clients.Remove(client.Ip);
         ResetClientIndex();
     }
 }
Exemplo n.º 3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            ClientRow client = obj as ClientRow;

            if (client == null)
            {
                return(false);
            }

            return(Equals(client.IpPort));
        }
Exemplo n.º 4
0
        private void Send(ClientRow client)
        {
            try
            {
                lock (server.Udp)
                {
                    server.Devices.Lock();
                    try
                    {
                        packet.Clear();
                        packet.Command = EServerCommand.DeviceValues;
                        packet.IArg1   = (server.Devices.PowerMeterConnected == true) ? 1 : 0;
                        packet.IArg2   = (server.Devices.RecorderConnected == true) ? 1 : 0;
                        packet.IArg3   = (server.Devices.ControllerConnected == true) ? 1 : 0;
                        packet.IArg4   = (server.Devices.PlcConnected == true) ? 1 : 0;

                        Buffer.BlockCopy(
                            server.Devices.Bytes, 0, packet.Bytes, 17, server.Devices.Bytes.Length);
                    }
                    finally
                    {
                        server.Devices.Unlock();
                    }

                    server.Udp.Send(packet.Bytes, packet.Length, client.IpPoint);
                }

                if (Logging == ESenderLogging.All)
                {
                    logger.Log((int)ESenderLogItem.Send,
                               "To {0} - Command : {1}, PowerMeter : {2}, Recorder : {3}, Controller : {4}, Plc : {5}",
                               client.IpPort, packet.Command.ToString(), packet.IArg1, packet.IArg2, packet.IArg3, packet.IArg4);
                }
            }
            catch (Exception e)
            {
                logger.Log((int)ESenderLogItem.Exception, e.ToString());
            }
        }
Exemplo n.º 5
0
        private void SetClientState(IPEndPoint ipPoint)
        {
            lock (server.Clients)
            {
                if (server.Clients.ContainsKey(ipPoint.ToString()) == false)
                {
                    logger.Log((int)EListenerLogItem.Note,
                               "Can't find a client({0}) in Client Dictionary",
                               ipPoint.ToString());
                    return;
                }

                ClientRow    client = server.Clients[ipPoint.ToString()];
                EClientState state  = (EClientState)packet.IArg1;
                client.State = state;

                logger.Log((int)EListenerLogItem.Note,
                           "Changed client({0}) to {1}",
                           ipPoint.ToString(), state.ToString());
            }

            OnChangedClients(this, null);
        }
Exemplo n.º 6
0
 private void AddClient(ClientRow client)
 {
     server.Clients.Add(client.Ip, client);
     server.ClientList.Add(client);
     ResetClientIndex();
 }