Пример #1
0
        void _setup()
        {
            client = new TcpClient(GetHostName(settings.Address), GetPort(settings.Address));

            MPChannels.Log(string.Format("*** Channel {0} connected {1}->{2}",
                                         Id, client.Client.LocalEndPoint, client.Client.RemoteEndPoint));

            client.SendTimeout    = SendByteTimeout;
            client.ReceiveTimeout = ReceiveByteTimeout;

            channelStreamReader = new BinaryReader(client.GetStream());
            channelStreamWriter = new BinaryWriter(client.GetStream());
            alg     = TripleDES.Create();
            alg.Key = Encoding.ASCII.GetBytes(settings.KeyForSend);

            packetBodyStreamReader = new BinaryReader(packetBodyStream);
            packetBodyStreamWriter = new BinaryWriter(packetBodyStream);

            channelStreamWriter.Write("PCh"); // Just HeaderId
            channelStreamWriter.Write("");    // Settings
            channelStreamWriter.Write(settings.NameForConnect);
            channelStreamReader.ReadString(); // OK

            stopTimer     = new ManualTimer(NotUsedTimeout);
            idleSendTimer = new ManualTimer(SendIdleTimeout);

            state = State.Connected;
        }
Пример #2
0
        public static MPProtectedChannel GetChannel(string channelName, int waitTime)
        {
            if (MPChannelSettings.Find(channelName) == null)
            {
                return(null);
            }

            if (waitTime <= 0)
            {
                waitTime = 20 * 1000;
            }
            ManualTimer        timer = new ManualTimer(waitTime);
            MPProtectedChannel pc    = GetChannel(channelName, true);

            while (!timer.Timeout)
            {
                if (pc != null)
                {
                    return(pc);
                }
                pc = GetChannel(channelName, false);
                System.Threading.Thread.Sleep(200);
            }
            MPChannels.Log(string.Format("Cannot open channel to {0}", channelName));
            return(null);
        }
Пример #3
0
 public void Close()
 {
     if (client != null)
     {
         try
         {
             MPChannels.Log(string.Format("*** Channel {0} closed", Id));
             client.Client.Close();
             client.Close();
             packetBodyStream.Close();
             alg.Clear();
         }
         catch { }
     }
     state  = State.Closed;
     client = null;
 }
Пример #4
0
        public static void AEVITest()
        {
            // Инициализация каналов, тестовая среда
            string[] channelsArray = new string[] { "TestChannel;192.168.34.31:53105;userWEBTestServer;keyASDF8765" };
            MPChannels.Init(channelsArray);

            if (MPChannels.IsAvailable("TestChannel"))
            {
            }

            // Запрос
            string retCode, text;

            AEVI.Request("TestChannel", "DeleteCard", "77777", out retCode, out text);
            if (retCode != "0")
            {
            }
        }
Пример #5
0
        // всегда возвращает непустой resultCode
        public static bool Request(
            string channels,
            string action,
            string data,
            out string resultCode,
            out string text
            )
        {
            //   try
            //   {
            resultCode = text = null;
            if (string.IsNullOrEmpty(channels))
            {
                resultCode = "5001"; text = "Empty request destination"; return(false);
            }
            string[] clist = channels.Split(',');

            string answer;
            string packet = "R1|" + action + "|" + data;

            foreach (string ch in clist)
            {
                if (!MPChannels.IsAvailable(ch))
                {
                    continue;
                }
                answer = MPChannels.SendAndWaitString(ch, "AEVI.WEB", packet, 10 * 1000);
                //if (answer == null) continue;
                TAG t = new TAG(answer);
                resultCode = t["RC"];
                if (string.IsNullOrEmpty(resultCode))
                {
                    continue;
                }
                text = t["Text"];
                return(true);
            }
            resultCode = "5002"; text = "No channel available";
            //   }
            //  catch(Exception ex) {log.Write(LogType.Error, "Request" + ex.Message);}
            return(false);
        }
Пример #6
0
 public void Release()
 {
     MPChannels.ReleaseChannel(this);
 }