Пример #1
0
 public PBHosterEventArgs(PBCommandType cmd, PBClimber clm, int route, ManualResetEvent ev)
 {
     this.cmd   = cmd;
     this.clm   = clm;
     this.route = route;
     this.ev    = ev;
 }
Пример #2
0
 public void SetClimber(PBClimber clm, PBHosterEventArgs e)
 {
     if (clm == null)
     {
         this.clm = PBClimber.GetEmpty();
     }
     else
     {
         this.clm = clm;
     }
     e.Event.Set();
 }
Пример #3
0
        private void ProcessData(byte[] data, args a)
        {
            string        msg = Encoding.UTF8.GetString(data);
            PBCommandType cmd;
            string        strTmp = PBClimber.getParam(msg, CommandStart);

            try { cmd = (PBCommandType)Enum.Parse(typeof(PBCommandType), strTmp); }
            catch
            {
                sendError(a);
                return;
            }
            PBHosterEventArgs e = null;
            ManualResetEvent  ev = new ManualResetEvent(false);
            int route, iid;

            switch (cmd)
            {
            case PBCommandType.GETLIST:
                e = new PBHosterEventArgs(cmd, null, 0, ev);
                break;

            case PBCommandType.GETNEXT:
                if (int.TryParse(PBClimber.getParam(msg, "ROUTE"), out route))
                {
                    e = new PBHosterEventArgs(cmd, null, route, ev);
                }
                break;

            case PBCommandType.GETBYIID:
                if (int.TryParse(PBClimber.getParam(msg, "ROUTE"), out route))
                {
                    if (int.TryParse(PBClimber.getParam(msg, "IID"), out iid))
                    {
                        e = new PBHosterEventArgs(cmd,
                                                  new PBClimber(iid, "", "", 0), route, ev);
                    }
                }
                break;

            case PBCommandType.GETBYSTART:
                if (int.TryParse(PBClimber.getParam(msg, "ROUTE"), out route))
                {
                    if (int.TryParse(PBClimber.getParam(msg, "START"), out iid))
                    {
                        e = new PBHosterEventArgs(cmd,
                                                  new PBClimber(0, "", "", iid), route, ev);
                    }
                }
                break;

            case PBCommandType.SETRES:
                if (int.TryParse(PBClimber.getParam(msg, "ROUTE"), out route))
                {
                    PBClimber clm = PBClimber.GetFromString(msg);
                    if (clm != null && !clm.Empty)
                    {
                        e = new PBHosterEventArgs(cmd, clm, route, ev);
                    }
                }
                break;
            }
            bool toSetErr = true;

            if (e != null)
            {
                if (PBHosterEvent != null)
                {
                    PBHosterEvent(this, e);
                    toSetErr = false;
                    ev.WaitOne();
                }
            }
            if (toSetErr)
            {
                sendError(a);
            }
            else
            {
                string pck = CommandStart + "=";
                switch (cmd)
                {
                case PBCommandType.GETLIST:
                    pck += PBCommandType.LIST.ToString() + ";NAME=" + opResStr + ";";
                    break;

                case PBCommandType.SETRES:
                    if (opRes)
                    {
                        pck += PBCommandType.ACK.ToString() + ";";
                    }
                    else
                    {
                        pck += PBCommandType.DECL.ToString() + ";";
                    }
                    break;

                default:
                    pck += clm.ToString();
                    break;
                }
                pck += CommandEnd;
                List <byte> pc = new List <byte>();
                pc.Add(CommandPr);
                foreach (byte b in Encoding.UTF8.GetBytes(pck))
                {
                    pc.Add(b);
                }
                pc.Add(CommandTail);
                a.buffer = pc.ToArray();
                a.cnt    = 0;
                a.s.BeginSend(a.buffer, 0, a.buffer.Length, SocketFlags.None,
                              EndSend, a);
            }
        }