SetMultiMsg() public method

public SetMultiMsg ( Hashtable IPtoPeer, String msg, String self ) : void
IPtoPeer System.Collections.Hashtable
msg String
self String
return void
Example #1
0
        private void computationDone()
        {
            if (permissions.Count > 1)
            {
                string xml = "<ComputationDone>" + "<Pid>" + Pid + "</Pid></ComputationDone>";
                AsynchronousSocketListener msocket = conn.getSocket();
                string myIP = msocket.GetIP();
                string myPort = msocket.GetPort();
                List<string> endPoints = Peers();
                Hashtable temp = conn.GetIPtoPeer();
                Hashtable tempToSend = new Hashtable();

                foreach (DictionaryEntry item in temp)
                {
                    if (endPoints.Contains(item.Key.ToString()))
                    {
                        tempToSend.Add(item.Key, item.Value);
                    }
                }        

                AsynchronousClient client = new AsynchronousClient();
                client.SetMultiMsg(temp, xml, myIP + ":" + myPort);
                Thread t = new Thread(new ThreadStart(client.SendMultiClient));
                t.IsBackground = true;
                t.Start();
            }
            setRunFlag(false);
            setStartFlag("");
        }
Example #2
0
        public void sourceCodeChanged(string lno, string inputs, string mod, string uname)
        {
            if (permissions.Count > 1)
            {
                string s = inputs.Replace('<', '%');
                s = s.Replace('>', '@');
                string codechange = "<SourceChange>" + "<Pid>" + Pid.ToString() + "</Pid>" + "<lno>" + lno.ToString() + "</lno>" + "<s>" + s.ToString() + "</s>" + "<mod>" + mod + "</mod>" + "<uname>" + uname + "</uname>" + "</SourceChange>";
                AsynchronousSocketListener msocket = conn.getSocket();
                string myIP = msocket.GetIP();
                string myPort = msocket.GetPort();

                List<string> endPoints = Peers();
                Hashtable temp = conn.GetIPtoPeer();
                Hashtable tempToSend = new Hashtable();

                foreach (DictionaryEntry item in temp)
                {
                    if (endPoints.Contains(item.Key.ToString()))
                    {
                        tempToSend.Add(item.Key, item.Value);
                    }
                }        

                AsynchronousClient client = new AsynchronousClient();
                client.SetMultiMsg(temp, codechange, myIP + ":" + myPort);
                Thread t = new Thread(new ThreadStart(client.SendMultiClient));
                t.IsBackground = true;
                t.Start();
            }
        }
Example #3
0
        public void addPermissionRequest(string myIP, string myPort, string inputcode, string IPPort, string read, string write)
        {
            string myIPPort = myIP + ":" + myPort;
            string code=inputcode.Replace('<', '%');
            code=code.Replace('>', '@');
            //string IPPort = theIP + ":" + thePort;
            if (read == "false")
            { }
            else
            {
                string[] privileges = { read, write };
                permissions[IPPort] = privileges;
                if (permissions.Count > 1)
                {
                    List<string> endPoints = Peers();
                    Hashtable temp = conn.GetIPtoPeer();
                    Hashtable tempToSend = new Hashtable();
                   
                    foreach (DictionaryEntry item in temp)
                    {                       
                        if (endPoints.Contains(item.Key.ToString()))
                        {
                            tempToSend.Add(item.Key, item.Value);
                        }
                    }                  

                    code = "<NewProg>" + "<Code>" + code + "</Code>" + "<Pid>" + Pid + "</Pid>" + "<Owner>" + owner + "</Owner>" + "<IPPort>" + IPPort + "</IPPort>" + "<Read>" + read + "</Read>" + "<Write>" + write + "</Write>";
                    code = code + InitialXMLString().ToString() + "</NewProg>";
                    BuildList();
                    //Console.WriteLine(code); //this line is a part of test1
                    AsynchronousClient client = new AsynchronousClient();
                    client.SetMultiMsg(tempToSend, code, myIPPort);
                    Thread t = new Thread(new ThreadStart(client.SendMultiClient));
                    t.IsBackground = true;
                    t.Start();
                }

            }
        }
Example #4
0
        public void changeTheOwner(string IPPort, string myIP, string myPort)
        {
            //string IPPort = theIP + ":" + thePort;
            string myIPPort = myIP + ":" + myPort;
            setOwner(IPPort);
            string changeOwner = "<ChangeOwner><Pid>" + Pid + "</Pid><IPPort>" + IPPort + "</IPPort></ChangeOwner>";
            List<string> endPoints = Peers();
            Hashtable temp = conn.GetIPtoPeer();
            Hashtable tempToSend = new Hashtable();

            foreach (DictionaryEntry item in temp)
            {
                if (endPoints.Contains(item.Key.ToString()))
                {
                    tempToSend.Add(item.Key, item.Value);
                }
            }        
            AsynchronousClient client = new AsynchronousClient();
            client.SetMultiMsg(temp, changeOwner, myIPPort);
            Thread t = new Thread(new ThreadStart(client.SendMultiClientChat));
            t.IsBackground = true;
            t.Start();
            
        }
Example #5
0
        public void changePermissionRequest(string myIP, string myPort, string IPPort, string read, string write)
        {
            //string IPPort = theIP + ":" + thePort;
            string myIPPort = myIP + ":" + myPort;
            string[] tempPermissions = (string[])permissions[IPPort];
            if ((read == "false" && write == "true") || (tempPermissions[1].ToString() == "true" && write == "false") || (tempPermissions[0].ToString() == "true" && read == "false"))
            {
            }
            else
            {
                string[] privileges = { read, write };
                permissions[IPPort] = privileges;
                List<string> endPoints = Peers();
                Hashtable temp = conn.GetIPtoPeer();
                Hashtable tempToSend = new Hashtable();

                foreach (DictionaryEntry item in temp)
                {
                    if (endPoints.Contains(item.Key.ToString()))
                    {
                        tempToSend.Add(item.Key, item.Value);
                    }
                }        
                string permissionMessage = changePermissionMessage(IPPort, read, write);
                //Console.WriteLine(permissionMessage);
                AsynchronousClient client = new AsynchronousClient();
                client.SetMultiMsg(temp, permissionMessage, myIPPort);
                Thread t = new Thread(new ThreadStart(client.SendMultiClientChat));
                t.IsBackground = true;
                t.Start();
                
            }
        }
Example #6
0
        public bool RunClicked(string myIP, string myPort)
        {
            string[] target = owner.Split(':');
            string ip = target[0];
            string port = target[1];
            MessageGenerator mg = new MessageGenerator();
            string request = mg.msgRunRequest(Pid, myIP + ":" + myPort);
            AsynchronousClient client = new AsynchronousClient();
            client.SetSingleMsg(ip, port, request);
            Thread t = new Thread(new ThreadStart(client.SendSingleClient));
            t.IsBackground = true;
            t.Start();
            while (StartFlag == "")
                Thread.Sleep(500);

            if (StartFlag == "Fail")
                return false;
            else
            {
                setMaster(myIP + ":" + myPort);
                setBackUp(selectBackUp());

                if (rnBtnClicked != null)
                    rnBtnClicked(true);
                if (permissions.Count > 1)
                {
                    List<string> endPoints = Peers();
                    Hashtable temp = conn.GetIPtoPeer();
                    Hashtable tempToSend = new Hashtable();

                    foreach (DictionaryEntry item in temp)
                    {
                        if (endPoints.Contains(item.Key.ToString()))
                        {
                            tempToSend.Add(item.Key, item.Value);
                        }
                    }        

                    AsynchronousClient client1 = new AsynchronousClient();
                    client1.SetMultiMsg(temp, getMasterBackUpXML(), myIP + ":" + myPort);
                    Thread t1 = new Thread(new ThreadStart(client1.SendMultiClient));
                    t1.IsBackground = true;
                    t1.Start();
                }
                return true;
            }
            
        }
Example #7
0
        public bool ReRunClicked(string myIP, string myPort)
        {
            
                setMaster(myIP + ":" + myPort);
                setBackUp(selectBackUp());

                if (rnBtnClicked != null)
                    rnBtnClicked(true);
                if (permissions.Count > 1)
                {
                    List<string> endPoints = Peers();
                    Hashtable temp = conn.GetIPtoPeer();
                    Hashtable tempToSend = new Hashtable();

                    foreach (DictionaryEntry item in temp)
                    {
                        if (endPoints.Contains(item.Key.ToString()))
                        {
                            tempToSend.Add(item.Key, item.Value);
                        }
                    }        

                    AsynchronousClient client1 = new AsynchronousClient();
                    client1.SetMultiMsg(temp, getMasterBackUpXML(), myIP + ":" + myPort);
                    Thread t1 = new Thread(new ThreadStart(client1.SendMultiClient));
                    t1.IsBackground = true;
                    t1.Start();
                }
            return true;

        }
Example #8
0
        public void BroadcastError(string num,string error)
        {
            if (permissions.Count > 1)
            {
                string xml = "<ComError>" + "<Pid>" + Pid + "</Pid>" + "<ErrorNum>" + num + "</ErrorNum>" + "<ErrorDetail>" + error + "</ErrorDetail>" + "</ComError>";
                AsynchronousSocketListener msocket = conn.getSocket();
                string myIP = msocket.GetIP();
                string myPort = msocket.GetPort();
                List<string> endPoints = Peers();
                Hashtable temp = conn.GetIPtoPeer();
                Hashtable tempToSend = new Hashtable();

                foreach (DictionaryEntry item in temp)
                {
                    if (endPoints.Contains(item.Key.ToString()))
                    {
                        tempToSend.Add(item.Key, item.Value);
                    }
                }

                AsynchronousClient client = new AsynchronousClient();
                client.SetMultiMsg(temp, xml, myIP + ":" + myPort);
                Thread t = new Thread(new ThreadStart(client.SendMultiClientChat));
                t.IsBackground = true;
                t.Start();
            }
        }
Example #9
0
        public void programClosed()
        {
            if (permissions.Count > 1)
            {

                AsynchronousSocketListener msocket = conn.getSocket();
                string myIP = msocket.GetIP();
                string myPort = msocket.GetPort();
                string xml = "<ProgramClosed>" + "<Pid>" + Pid + "</Pid><IPPort>" + myIP + ":" + myPort + "</IPPort></ProgramClosed>";
                List<string> endPoints = Peers();
                Hashtable temp = conn.GetIPtoPeer();
                Hashtable tempToSend = new Hashtable();

                foreach (DictionaryEntry item in temp)
                {
                    if (endPoints.Contains(item.Key.ToString()))
                    {
                        tempToSend.Add(item.Key, item.Value);
                    }
                }        

                AsynchronousClient client = new AsynchronousClient();
                client.SetMultiMsg(temp, xml, myIP + ":" + myPort);
                Thread t = new Thread(new ThreadStart(client.SendMultiClient));
                t.IsBackground = true;
                t.Start();
            }
        }
Example #10
0
 public void Disconnect()
 {
     MessageGenerator temp = new MessageGenerator();
     string msg = temp.msgDisconnect(mPeer.mIP + ":" + mPeer.mPort);
     Thread t = null;
     AsynchronousClient client = new AsynchronousClient();
     client.SetMultiMsg(GetIPtoPeer(), msg, GetIP() + ":" + GetPort());
     t = new Thread(new ThreadStart(client.SendMultiClient));
     t.Start();
     t.IsBackground = true;
 }
Example #11
0
 public void Send_ChatMsg(string chatMsg, string Username)
 {
     try
     {
         Thread t = null;
         MessageGenerator mMsg = new MessageGenerator();
         //Chat username to be included
         string msg = mMsg.msgChat(chatMsg, mSocket.GetIP() + ":" + mSocket.GetPort());
         AsynchronousClient client = new AsynchronousClient();
         client.SetMultiMsg(mSocket.GetIPtoPeer(), msg, mSocket.GetIP() + ":" + mSocket.GetPort());
         t = new Thread(new ThreadStart(client.SendMultiClientChat));
         t.IsBackground = true;
         t.Start();
         
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Failed to send chat message.");
     }
 }
Example #12
0
        //this function is used to give a privilege to a computer for the first time, so it includes
        //the source code as well among the parameters. before that it has to initialize all the other
        //data on the new machine so it calls createInitialData function
        public void addPermissionRequest(string myIPPort, Hashtable dests, string code, string IPPort, string read, string write)
        {

            createInitialData(IPPort);
            string[] privileges = { read, write };
            permissions[IPPort]= privileges;

            List<string> endPoints = Peers();
            Hashtable temp = dests;
            List<string> removed = new List<string>();
            foreach (DictionaryEntry item in temp)
            {
                if (!endPoints.Contains(item.Key.ToString()))
                {
                    removed.Add(item.Key.ToString());
                }
            }
            for (int i = 0; i < removed.Count; i++)
			{
			    temp.Remove(removed[i].ToString());
			}
            
            code = "<newProg>" +"<code>"+ code +"</code>"+"<Pid>"+Pid+"</Pid>"+"<IPPort>"+IPPort+"</IPPort>"+"<read>"+read+"</read>"+"<write>"+write+"</write>"+"</newProg>";
           // Console.WriteLine(code); //this line is a part of test1
            AsynchronousClient client = new AsynchronousClient();
            client.SetMultiMsg(temp, code, myIPPort);
            Thread t = new Thread(new ThreadStart(client.SendMultiClient));
            t.Start();
            t.IsBackground = true;
            
        }
Example #13
0
 public void changePermissionRequest(string myIPPort, Hashtable dests, string IPPort, string read, string write)
 {
    
     string[] privileges = { read, write };
     permissions[IPPort] = privileges;
     List<string> endPoints = Peers();
     Hashtable temp = dests;
     List<string> removed = new List<string>();
     foreach (DictionaryEntry item in temp)
     {
         if (!endPoints.Contains(item.Key.ToString()))
             removed.Add(item.Key.ToString());
     }
     for (int i = 0; i < removed.Count; i++)
     {
         temp.Remove(removed[i].ToString());
     }
     string permissionMessage = changePermissionMessage(IPPort, read, write);
     AsynchronousClient client = new AsynchronousClient();
     client.SetMultiMsg(temp, permissionMessage, myIPPort);
     Thread t = new Thread(new ThreadStart(client.SendMultiClient));
     t.Start();
     t.IsBackground = true;
     
 }
Example #14
0
        public void Disconnect()
        {
            try
            {
                MessageGenerator temp = new MessageGenerator();
                string msg = temp.msgDisconnect(mPeer.mIP + ":" + mPeer.mPort);
                Thread t = null;
                AsynchronousClient client = new AsynchronousClient();
                client.SetMultiMsg(GetIPtoPeer(), msg, GetIP() + ":" + GetPort());

                t = new Thread(new ThreadStart(client.SendMultiClient));
                t.IsBackground = true;
                t.Start();
            }
            catch (Exception e)
            { Console.WriteLine(e.ToString()); }
        }
Example #15
0
        private void getConnectionRequestMsg(String msg)
        {
            try
            {
                String ip;
                String port;
                String name;
                String cpu;
                Thread t1 = null;
                Thread t2 = null;
                Thread t3 = null;

                XDocument xml = XDocument.Parse(msg);
                var q = from x in xml.Elements("root").Descendants()
                        select x;
                foreach (var elem in q)
                {

                    ip = elem.Attributes().ElementAt(0).Value;
                    port = elem.Attributes().ElementAt(1).Value;
                    name = elem.Attributes().ElementAt(2).Value;
                    cpu = elem.Attributes().ElementAt(3).Value;
                    if (IPtoPeer.Count > 0)
                    {
                        if (!NametoIP.Contains(name))
                        {
                            InsertPeer(ip, port, name, cpu);
                            if (IPtoPeer.Count == 2)
                                SetBackup(ip + ":" + port);

                            MessageGenerator temp = new MessageGenerator();
                            string mMsg = temp.msgIPtoPeer(IPtoPeer);
                            string master = temp.msgMaster(GetMaster());
                            string backup = temp.msgBackup(GetBackup());
                            AsynchronousClient client1 = new AsynchronousClient();
                            client1.SetMultiMsg(IPtoPeer, mMsg, mPeer.mIP + ":" + mPeer.mPort);
                            t1 = new Thread(new ThreadStart(client1.SendMultiClient));
                            t1.IsBackground = true;
                            t1.Start();

                            AsynchronousClient client2 = new AsynchronousClient();
                            client2.SetSingleMsg(ip, port, master);
                            t2 = new Thread(new ThreadStart(client2.SendSingleClient));
                            t2.IsBackground = true;
                            t2.Start();

                            AsynchronousClient client3 = new AsynchronousClient();
                            client3.SetSingleMsg(ip, port, backup);
                            t3 = new Thread(new ThreadStart(client3.SendSingleClient));
                            t3.IsBackground = true;
                            t3.Start();

                        }
                        else
                        {
                            MessageGenerator temp = new MessageGenerator();
                            string error = temp.msgError("10:Username Already Exists");
                            AsynchronousClient client = new AsynchronousClient();
                            client.SetSingleMsg(ip, port, error);
                            t1 = new Thread(new ThreadStart(client.SendSingleClient));
                            t1.IsBackground = true;
                            t1.Start();

                        }
                    }
                    else
                    {
                        MessageGenerator temp = new MessageGenerator();
                        string error = temp.msgError("10:Peer is not a part of Swarm");
                        AsynchronousClient client = new AsynchronousClient();
                        client.SetSingleMsg(ip, port, error);
                        t1 = new Thread(new ThreadStart(client.SendSingleClient));
                        t1.IsBackground = true;
                        t1.Start();

                    }
                }
                showTable();
            }
            catch (Exception e)
            { Console.WriteLine(e.ToString()); }
        }
Example #16
0
        private void Send_ChatMsg(object sender, EventArgs e)
        {
            Thread t = null;
            MessageGenerator mMsg = new MessageGenerator();
            string msg = mMsg.msgChat(this.richTextBox1.Text, mSocket.GetIP() + ":" + mSocket.GetPort());
            AsynchronousClient client = new AsynchronousClient();
            client.SetMultiMsg(mSocket.GetIPtoPeer(), msg, mSocket.GetIP() + ":" + mSocket.GetPort());
            t = new Thread(new ThreadStart(client.SendMultiClient));
            t.Start();
            t.IsBackground = true;

            //m.HandleChatMessages("Peer1", richTextBox1.Text);
        }