Пример #1
0
        public p2p(int portA,int portB)
        {
            Generate.porta = portA;
            Generate.portb = portB;

            if (Generate.isFirst) { Recording record = new Recording(); record.RecordAgent(); }
            Create(ref _sepa,ref _sepb,ref _udpa,ref _udpb);
        }
Пример #2
0
        private void p1000(Coming c)
        {
            Recording recording = new Recording();
            clients _clients = recording.Record(ref c);
            DataHandle Handle = new DataHandle();

            if (Agent.clients.ContainsKey(c.id))
            {
                #region XML && CLIENT UPLOADED

                XmlDocument xmld = new XmlDocument();
                try { xmld.Load(xmlPath); }
                catch { Thread.Sleep(50); xmld.Load(xmlPath); }
                foreach (XmlElement xmle in xmld.GetElementsByTagName("clients"))
                {
                    if (xmle["id"].InnerText.Equals(_clients.id, StringComparison.CurrentCultureIgnoreCase))
                    {
                        xmle["id"].InnerText = _clients.id;
                        xmle["lep"].InnerText = _clients.lep;
                        xmle["macAddress"].InnerText = _clients.macAddress;
                        xmle["licence"].InnerText = _clients.licence;
                        xmle["Session"].InnerText = (Convert.ToInt32(xmle["Session"].InnerText) + 1).ToString();
                        xmle["port"].InnerText = _clients.port.ToString();
                        xmle["Address"].InnerText = _clients.Address;
                        xmle["cep"].InnerText = _clients.cep;
                    }
                }
                try { xmld.Save(xmlPath); }
                catch { Thread.Sleep(50); xmld.Save(xmlPath); }

                #endregion
                #region CLIENT CONNECTED AGAIN REPLACE PROPERTIES

                foreach (KeyValuePair<string, Coming> client in Agent.clients)
                {
                    if (client.Key.Equals(c.id, StringComparison.CurrentCultureIgnoreCase))
                    {

                        #region MAC ADDRESS DIFFERENT
                        if (!client.Value.macAddress.Equals("NOT"))
                        {
                            if (!client.Value.macAddress.Equals(c.macAddress))
                            {
                                byte[] data = Handle.HaSe(1001, "ID SAVED BEFORE FOR DIFFERENT CLIENT");
                                c._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
                                return;
                            }
                        }
                        #endregion
                        #region CLIENT UPDATE
                        client.Value.lep = c.lep;
                        client.Value._sock = c._sock;
                        client.Value.Address = c.Address;
                        client.Value.cep = c.cep;
                        client.Value.EventType = c.EventType;
                        client.Value.licence = c.licence;
                        client.Value.macAddress = c.macAddress;
                        client.Value.message = c.message;
                        client.Value.port = c.port;
                        #endregion
                        byte[] d = Handle.HaSe(1002, "CLIENT ALREADY IN THE LIST");
                        c._sock.BeginSendTo(d, 0, d.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
                    }
                }

                #endregion
            }
            else
            {
                Agent.clients.Add(c.id, c);
                if (!File.Exists(xmlPath))
                {
                    #region WRITE DOC
                    XmlTextWriter writer = new XmlTextWriter(xmlPath, Encoding.UTF8);
                    writer.Formatting = Formatting.Indented;
                    writer.WriteComment("Saved Clients list");
                    writer.WriteStartElement("Clients");
                    writer.WriteEndElement();
                    writer.Close();
                    #endregion
                }
                #region XML SAVE
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(xmlPath);
                }
                catch
                {
                    Thread.Sleep(50);
                    doc.Load(xmlPath);
                }

                XmlNode client = doc.DocumentElement;
                XmlElement element = doc.CreateElement("clients");

                XmlNode node1 = doc.CreateElement("id");
                node1.InnerText = _clients.id;
                element.AppendChild(node1);

                XmlNode node2 = doc.CreateElement("licence");
                node2.InnerText = _clients.licence;
                element.AppendChild(node2);

                XmlNode node3 = doc.CreateElement("macAddress");
                node3.InnerText = _clients.macAddress;
                element.AppendChild(node3);

                XmlNode node4 = doc.CreateElement("Address");
                node4.InnerText = _clients.Address;
                element.AppendChild(node4);

                XmlNode node5 = doc.CreateElement("port");
                node5.InnerText = _clients.port.ToString();
                element.AppendChild(node5);

                XmlNode node6 = doc.CreateElement("cep");
                node6.InnerText = _clients.cep;
                element.AppendChild(node6);

                XmlNode node7 = doc.CreateElement("lep");
                node7.InnerText = _clients.lep;
                element.AppendChild(node7);

                XmlNode node8 = doc.CreateElement("Session");
                node8.InnerText = "1";
                element.AppendChild(node8);

                XmlNode node9 = doc.CreateElement("message");
                node9.InnerText = _clients.message;
                element.AppendChild(node9);

                client.AppendChild(element);
                try
                {
                    doc.Save(xmlPath);
                }
                catch
                {
                    Thread.Sleep(50);
                    doc.Save(xmlPath);
                }
                #endregion
                byte[] data = Handle.HaSe(1003, "CLIENT RECORDED SUCCESFULY");
                c._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
            }
        }