Beispiel #1
0
 /// <summary>
 /// wątek odbierający wiadomości z chmury
 /// </summary>
 public void controlReceiver()
 {
     while (isConnectedToControlCloud)
     {
         BinaryFormatter bf = new BinaryFormatter();
         try {
             SPacket receivedPacket = (Packet.SPacket)bf.Deserialize(controlNetworkStream);
             //_msg = reader.ReadLine();
             SetText("Odczytano:\n" + receivedPacket.ToString() + "\n");
             LRM.OdczytajS(receivedPacket);
         } catch {
             SetText("WUT");
             if (++exceptionCount == 5)
             {
                 this.Invoke((MethodInvoker) delegate() {
                     isConnectedToControlCloud = false;
                     conToCloudButton.Text     = "Połącz";
                     SetText("Rozłączono!");
                     if (controlCloudSocket != null)
                     {
                         controlCloudSocket.Close();
                     }
                 });
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>Gets the Mean color value in the current image. If, optionally, a subimage is selected via virtual windowing then this function only operates on that window.</summary>
        public SPacket GetMeanColor()
        {
            SetLineMode(LineMode.Mean, 0);

            SPacketReader rdr = new SPacketReader();

            SPacket spak = _c.SendCommandGetPacket(rdr, "GM");

            return(spak);
        }
Beispiel #3
0
        public string CreatePacket(SPacket source)
        {
            var creator = serverPackets.GetValueOrDefault(source.GetType());

            if (creator == null)
            {
                throw new InvalidOperationException($"There is no packet creator for {source.GetType()}");
            }

            return(creator.Create(source));
        }
Beispiel #4
0
 /// <summary>
 /// wątek wysyłający wiadomości do chmury
 /// </summary>
 public void controlSender()
 {
     while (isConnectedToControlCloud)
     {
         //jeśli coś jest w kolejce - zdejmij i wyślij
         if (whatToSendQueue.Count != 0)
         {
             SPacket         _pck       = (SPacket)whatToSendQueue.Dequeue();
             BinaryFormatter bformatter = new BinaryFormatter();
             bformatter.Serialize(controlNetworkStream, _pck);
             controlNetworkStream.Flush();
             String[] _argsToShow = _pck.getParames().ToArray();
             String   argsToShow  = "";
             foreach (String str in _argsToShow)
             {
                 argsToShow += str + " ";
             }
             SetText("Wysłano: " + _pck.getSrc() + ":" + _pck.getDest() + ":" + argsToShow + "\n");
             Thread.Sleep(50);
         }
     }
 }
Beispiel #5
0
        public void SReader()
        {
            while (true)
            {
                if (kolejkaS.Count == 0)
                {
                    Thread.Sleep(100);
                    continue;
                }
                try
                {
                    SPacket pakiet;
                    if (!kolejkaS.TryDequeue(out pakiet))
                    {
                        Thread.Sleep(100);
                        continue;                                          //jeśli nie udało się zdejmowanie przejdź do następnego obiegu po chwili pauzy
                    }
                    String komenda     = pakiet.getParames().ElementAt(0); //zczytywanie komendy
                    String nowakomenda = "";
                    if (komenda.Equals("IS_LINK_AVAILABLE"))               //to jest do do wysyłania pakietu próbnego do sąsiada o zadanym adresie np. IS_ALIVE 1.2.3 dawne IS_ALIVE
                    {
                        int i2 = -1;
                        if (pakiet.getParames().Count > 1)
                        {
                            i2 = int.Parse(pakiet.getParames().ElementAt(2));
                        }
                        Address sprawdzany         = Address.Parse(pakiet.getParames().ElementAt(1));
                        Tuple <Address, int> argus = new Tuple <Address, int>(sprawdzany, i2);
                        CzyZyjeRun(argus);//odpowiedzią zajmuje się metoda CzyZyje
                        continue;
                    }

                    /*else if (komenda.Equals("IS_LINK_AVAILABLE"))
                     * {
                     *  Address sprawdzany = Address.Parse(pakiet.getParames().ElementAt(1));
                     *  for (int i = 0; i < parent.routeList.Count; i++)
                     *  {
                     *      if (sprawdzany.Equals(parent.routeList.ElementAt(i).destAddr))//szukamy na routelist zadanego adresu
                     *      {
                     *          if (parent.routeList.ElementAt(i).bandwidth >= 2)//gdy przepustowość co najmniej 2 to ok
                     *          {
                     *              nowakomenda = "YES_AVAILABLE " + sprawdzany.ToString();
                     *              break;
                     *          }
                     *          else
                     *          {
                     *              nowakomenda = "NO_AVAILABLE " + sprawdzany.ToString();
                     *              break;
                     *          }
                     *      }
                     *  }
                     * }*/
                    else if (komenda.Equals("ADD_MAPPING"))//ADD_MAPPING adres vp vc comnID
                    {
                        if (pakiet.getParames().Count == 5)
                        {
                            List <String> p = pakiet.getParames();
                            int           vp1, vc1, connID;
                            Address       a1;
                            a1     = Address.Parse(p.ElementAt(1));
                            vp1    = int.Parse(p.ElementAt(2));
                            vc1    = int.Parse(p.ElementAt(3));
                            connID = int.Parse(p.ElementAt(4));

                            int p1 = AddressToPort(a1);

                            parent.AddSingleEntry(a1, p1, vp1, vc1, connID);
                            ZajmijZasob(a1);
                            nowakomenda = "MSG zadanie ADD wykonane";
                        }
                        else
                        {
                            nowakomenda = "ERROR ZŁA LICZBA PARAMETRÓW W ADD";
                        }
                    }
                    else if (komenda.Equals("DEL_MAPPING"))//DEL_MAPPING adres vp vc comnID
                    {
                        if (pakiet.getParames().Count == 4)
                        {
                            List <String> p = pakiet.getParames();
                            int           vp1, vc1, connID;
                            Address       a1;
                            a1     = Address.Parse(p.ElementAt(1));
                            vp1    = int.Parse(p.ElementAt(2));
                            vc1    = int.Parse(p.ElementAt(3));
                            connID = 1;// int.Parse(p.ElementAt(4));



                            int p1 = AddressToPort(a1);
                            parent.RemoveSingleEntry(a1, p1, vp1, vc1, connID);
                            ZwolnijZasob(a1);
                            nowakomenda = "MSG zadanie DELETE wykonane";
                        }
                        else
                        {
                            nowakomenda = "ERROR ZŁA LICZBA PARAMETRÓW W DELETE";
                        }
                    }
                    else if (komenda.Equals("REQ_TOPOLOGY"))
                    {
                        nowakomenda = "TOPOLOGY";
                        for (int i = 0; i < parent.routeList.Count; i++)
                        {
                            nowakomenda += " " + parent.routeList.ElementAt(i).destAddr.ToString();
                        }
                    }
                    else if (komenda.Equals("DEAD"))
                    {
                        bool    czySonsiad = false;
                        Address sprawdzany = Address.Parse(pakiet.getParames().ElementAt(1));
                        for (int i = 0; i < parent.routeList.Count; i++)
                        {
                            if (sprawdzany.Equals(parent.routeList.ElementAt(i).destAddr))
                            {
                                czySonsiad = true;
                                break;
                            }
                        }
                        if (czySonsiad)
                        {
                            SPacket wysylanyCC, wysylanyRC;
                            wysylanyCC = new SPacket(adresLRM, adresCC, "DEAD " + sprawdzany.ToString());
                            wysylanyRC = new SPacket(adresLRM, adresRC, "DEAD " + sprawdzany.ToString());
                            wyslijSPacket(wysylanyCC);
                            wyslijSPacket(wysylanyRC);
                        }
                        else
                        {
                            //do nothing?
                        }
                        continue;//nie swapujemy pakietu, bo to nie odpowiedź
                    }
                    else if (komenda.Equals("REQ_VPATHS"))
                    {
                        List <String> lista = new List <string>();
                        lista.Add("RES_VPATHS");
                        for (int i = 0; i < parent.routeList.Count; i++)
                        {
                            String result = parent.routeList.ElementAt(i).destAddr.ToString();
                            for (int j = 0; j < parent.routeList.ElementAt(i).VPIList.Count; j++)
                            {
                                result += "#" + parent.routeList.ElementAt(i).VPIList.ElementAt(j).ToString();
                            }
                            lista.Add(result);
                        }
                        SPacket pkt = new SPacket(adresLRM, adresCC, lista);
                        wyslijSPacket(pkt);
                        continue;
                    }
                    pakiet.Swap(nowakomenda);//metoda zamienia src i dest i ustawia nowe parames
                    wyslijSPacket(pakiet);
                }
                catch (Exception e)
                {
                    Console.Out.WriteLine(e.Message);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// metoda wywołana po wciśnięciu "połącz z chmurąsterowania"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void conToCloudButton_Click(object sender, EventArgs e)
        {
            if (!isConnectedToControlCloud)
            {
                if (isNodeAddressSet)
                {
                    if (IPAddress.TryParse(controlCloudIPTextBox.Text, out controlCloudAddress))
                    {
                        SetText("IP ustawiono jako " + controlCloudAddress.ToString() + "\n");
                    }
                    else
                    {
                        SetText("Błąd podczas ustawiania IP chmury (zły format?)\n");
                    }
                    if (Int32.TryParse(controlCloudPortTextBox.Text, out controlCloudPort))
                    {
                        SetText("Port chmury ustawiony jako " + controlCloudPort.ToString() + "\n");
                    }
                    else
                    {
                        SetText("Błąd podczas ustawiania portu chmury (zły format?)\n");
                    }

                    controlCloudSocket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    controlCloudEndPoint = new IPEndPoint(controlCloudAddress, controlCloudPort);
                    try {
                        controlCloudSocket.Connect(controlCloudEndPoint);
                        isConnectedToControlCloud = true;
                        controlNetworkStream      = new NetworkStream(controlCloudSocket);
                        List <String> _welcArr = new List <String>();
                        _welcArr.Add("HELLO");
                        SPacket welcomePacket = new SPacket(myAddress.ToString(), new Address(0, 0, 0).ToString(), _welcArr);
                        whatToSendQueue.Enqueue(welcomePacket);
                        //whatToSendQueue.Enqueue("HELLO " + myAddr);
                        controlReceiveThread = new Thread(this.controlReceiver);
                        controlReceiveThread.IsBackground = true;
                        controlReceiveThread.Start();
                        controlSendThread = new Thread(this.controlSender);
                        controlSendThread.IsBackground = true;
                        controlSendThread.Start();
                        //conToCloudButton.Text = "Rozłącz";
                        LRM = new eLReMix(this);
                        SetText("Połączono!\n");
                        exceptionCount = 0;
                    } catch (SocketException) {
                        isConnectedToControlCloud = false;
                        SetText("Błąd podczas łączenia się z chmurą\n");
                        SetText("Złe IP lub port? Chmura nie działa?\n");
                    }
                }
                else
                {
                    SetText("Wprowadź numery sieci i podsieci\n");
                }
            }
            else
            {
                isConnectedToControlCloud = false;
                conToCloudButton.Text     = "Połącz";
                SetText("Rozłączono!\n");
                if (controlCloudSocket != null)
                {
                    controlCloudSocket.Close();
                }
            }
        }
 public PacketReceivedEventArgs(Enums.Type type, SPacket packet)
 {
     Type   = type;
     Packet = packet;
 }
Beispiel #8
0
 public abstract string Create(SPacket source);
Beispiel #9
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            SPacket   s  = _sPacket;
            SPacketM1 s1 = _sPacket as SPacketM1;
            SPacketM2 s2 = _sPacket as SPacketM2;

            if (s == null)
            {
                return;
            }

            // draw three columns
            int width = (ClientSize.Width - 1) / 5;

            Graphics g = pe.Graphics;

            int colsStartAt = (int)g.MeasureString("-devMean+dev", SystemFonts.IconTitleFont).Height;

            g.DrawString("-dev", SystemFonts.IconTitleFont, SystemBrushes.ControlText, 0, 0);
            g.DrawString("Mean", SystemFonts.IconTitleFont, SystemBrushes.ControlText, 2 * width, 0);
            g.DrawString("+dev", SystemFonts.IconTitleFont, SystemBrushes.ControlText, 4 * width, 0);

            Rectangle colMinO = new Rectangle(0, colsStartAt + 3, width, _frameSize + 2);
            Rectangle colMeaO = new Rectangle(2 * width, colsStartAt + 3, width, _frameSize + 2);
            Rectangle colMaxO = new Rectangle(4 * width, colsStartAt + 3, width, _frameSize + 2);

            g.DrawRectangle(Pens.Black, colMinO);
            g.DrawRectangle(Pens.Black, colMeaO);
            g.DrawRectangle(Pens.Black, colMaxO);

            Rectangle colMin = Program.DeflateRectangle(colMinO, new Padding(1)); colMin.Width++; colMin.Height++;
            Rectangle colMea = Program.DeflateRectangle(colMeaO, new Padding(1)); colMea.Width++; colMea.Height++;
            Rectangle colMax = Program.DeflateRectangle(colMaxO, new Padding(1)); colMax.Width++; colMax.Height++;

            Color mea = Color.FromArgb(s.RMean, s.GMean, s.BMean);
            Color min = Color.FromArgb(P(mea.R - s.RDeviation), P(mea.G - s.GDeviation), P(mea.B - s.BDeviation));
            Color max = Color.FromArgb(P(mea.R + s.RDeviation), P(mea.G + s.GDeviation), P(mea.B + s.BDeviation));

            if (s2 != null)
            {
                for (int y = 0; y < s2.Rows.Count; y++)
                {
                    SPacketM2Row row = s2.Rows[y];

                    Color rowMea = Color.FromArgb(row.RMean, row.GMean, row.BMean);
                    Color rowMin = Color.FromArgb(P(rowMea.R - row.RDeviation), P(rowMea.G - row.GDeviation), P(rowMea.B - row.BDeviation));
                    Color rowMax = Color.FromArgb(P(rowMea.R + row.RDeviation), P(rowMea.G + row.GDeviation), P(rowMea.B + row.BDeviation));

                    g.FillRectangle(new SolidBrush(rowMin), new Rectangle(colMin.X, colMin.Y + y, colMin.Width, 1));
                    g.FillRectangle(new SolidBrush(rowMea), new Rectangle(colMea.X, colMea.Y + y, colMea.Width, 1));
                    g.FillRectangle(new SolidBrush(rowMax), new Rectangle(colMax.X, colMax.Y + y, colMax.Width, 1));
                }
            }
            else if (s1 != null)
            {
                for (int y = 0; y < s1.Rows.Count; y++)
                {
                    SPacketM1Row row = s1.Rows[y];

                    Color rowMea = Color.FromArgb(row.RMean, row.GMean, row.BMean);
                    Color rowMin = Color.FromArgb(P(rowMea.R - s.RDeviation), P(rowMea.G - s.GDeviation), P(rowMea.B - s.BDeviation));
                    Color rowMax = Color.FromArgb(P(rowMea.R + s.RDeviation), P(rowMea.G + s.GDeviation), P(rowMea.B + s.BDeviation));

                    g.FillRectangle(new SolidBrush(rowMin), new Rectangle(colMin.X, colMin.Y + y, colMin.Width, 1));
                    g.FillRectangle(new SolidBrush(rowMea), new Rectangle(colMea.X, colMea.Y + y, colMea.Width, 1));
                    g.FillRectangle(new SolidBrush(rowMax), new Rectangle(colMax.X, colMax.Y + y, colMax.Width, 1));
                }
            }
            else
            {
                g.FillRectangle(new SolidBrush(min), colMin);
                g.FillRectangle(new SolidBrush(mea), colMea);
                g.FillRectangle(new SolidBrush(max), colMax);
            }

            String minStr = String.Format("R: {0}\nG: {1}\nB: {2}", min.R, min.G, min.B);
            String meaStr = String.Format("R: {0}\nG: {1}\nB: {2}\n\ndR: {3}\ndG: {4}\ndB: {5}", mea.R, mea.G, mea.B, s.RDeviation, s.RDeviation, s.BDeviation);
            String maxStr = String.Format("R: {0}\nG: {1}\nB: {2}", max.R, max.G, max.B);

            g.DrawString(minStr, SystemFonts.IconTitleFont, SystemBrushes.ControlText, 0, colsStartAt + 3 + _frameSize + 5);
            g.DrawString(meaStr, SystemFonts.IconTitleFont, SystemBrushes.ControlText, 2 * width, colsStartAt + 3 + _frameSize + 5);
            g.DrawString(maxStr, SystemFonts.IconTitleFont, SystemBrushes.ControlText, 4 * width, colsStartAt + 3 + _frameSize + 5);
        }