Esempio n. 1
0
        /// <summary>
        /// Receive data from receiver
        /// </summary>
        /// <param name="ip">Remote IP</param>
        /// <param name="data">Data</param>
        void r_OnReceived(string ip, byte[] data)
        {
            lock (lockThis)
            {
                /*Disassemble data*/
                PacketDisassembler  packetDisassembler = new PacketDisassembler();
                List <DataReceived> listPackets        = packetDisassembler.Disassemble(data);
                /*Read each packets*/
                for (int i = 0; i < listPackets.Count; i++)
                {
                    Command cmd = listPackets[i].cmd;
                    switch (cmd)
                    {
                    /*Receive the function*/
                    case Command.ClientInit:
                        DataInitServer dic = new DataInitServer(listPackets[i].data);
                        calculation = new Calculation();
                        calculation.LoadSource(dic.src);
                        Initialized.sendInitialized(serverIP, serverPort);     //Send initialized data
                        calculation.OnFinished += new Calculation.finished(calculation_OnFinished);
                        break;

                    case Command.Work:
                        if (timer == null)     //Start interval timer
                        {
                            timer          = new Timer();
                            timer.Enabled  = true;
                            timer.Interval = 1000;
                            timer.Start();
                            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
                        }
                        listTasks.Add(new Task(listPackets[i].noPacket, listPackets[i].data, listPackets[i].secondSince1970, listPackets[i].issueNumber));     //add a new task
                        break;

                    default:
                        break;
                    }
                }
                if (listPackets.Count > 0 && listPackets[0].cmd == Command.Work) //Start calculating of all received tasks
                {
                    working = true;
                    doWork();
                    working = false;
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Receive data from receiver
 /// </summary>
 /// <param name="ip">Remote IP</param>
 /// <param name="data">Data</param>
 void r_OnReceived(string ip, byte[] data)
 {
     lock (lockThis)
     {
         /*Disassemble data*/
         PacketDisassembler packetDisassembler = new PacketDisassembler();
         List<DataReceived> listPackets = packetDisassembler.Disassemble(data);
         /*Read each packets*/
         for (int i = 0; i < listPackets.Count; i++)
         {
             Command cmd = listPackets[i].cmd;
             switch (cmd)
             {
                 /*Receive the function*/
                 case Command.ClientInit:
                     DataInitServer dic = new DataInitServer(listPackets[i].data);
                     calculation = new Calculation();
                     calculation.LoadSource(dic.src);
                     Initialized.sendInitialized(serverIP, serverPort); //Send initialized data
                     calculation.OnFinished += new Calculation.finished(calculation_OnFinished);
                     break;
                 case Command.Work:
                     if (timer == null) //Start interval timer
                     {
                         timer = new Timer();
                         timer.Enabled = true;
                         timer.Interval = 1000;
                         timer.Start();
                         timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
                     }
                     listTasks.Add(new Task(listPackets[i].noPacket, listPackets[i].data, listPackets[i].secondSince1970, listPackets[i].issueNumber)); //add a new task
                     break;
                 default:
                     break;
             }
         }
         if (listPackets.Count > 0 && listPackets[0].cmd == Command.Work) //Start calculating of all received tasks
         {
             working = true;
             doWork();
             working = false;
         }
     }
 }