コード例 #1
0
ファイル: SwarmAPI.cs プロジェクト: shranjan/SPINACH
 //*************************************
 public bool Join_Swarm(string DstIP, string DstPort,string SrcIP, string SrcPort,string Username)
 {
     Thread t1 = null;
     Thread t2 = null;
     try
     {
         t1 = new Thread(new ThreadStart(mSocket.StartListening));
         t1.Start();
         t1.IsBackground = true;
         string cpu = "1";
         mSocket.SetIP(SrcIP);
         mSocket.SetPort(SrcPort);
         mSocket.SetName(Username);
         mSocket.SetCPU(cpu);
         MessageGenerator msg = new MessageGenerator();
         string mMsg = msg.msgConnectionRequest
             (mSocket.GetIP(), mSocket.GetPort(), mSocket.GetName(), mSocket.GetCPU());
         AsynchronousClient client = new AsynchronousClient();
         client.SetSingleMsg(DstIP, DstPort, mMsg);
         t2 = new Thread(new ThreadStart(client.SendSingleClient));
         t2.Start();
         t2.IsBackground = true;
         return true;
    
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         return false;
     }
     
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: shranjan/pinac
 private void Connection_Request(object sender, EventArgs e)
 {
     MessageGenerator msg = new MessageGenerator();
     string DstIp = textBox1.Text;
     string DstPort = textBox2.Text;
     string mMsg = msg.msgConnectionRequest
         (mSocket.GetIP(), mSocket.GetPort(), mSocket.GetName(), mSocket.GetCPU());
     AsynchronousClient client = new AsynchronousClient();
     client.SetSingleMsg(DstIp, DstPort,mMsg);
     Thread t = null;
     t = new Thread(new ThreadStart(client.SendSingleClient));
     t.Start();
     t.IsBackground = true;
     this.button1.Enabled = false;
     this.button2.Enabled = false;
     this.button3.Enabled = true;
 }
コード例 #3
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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();
            }
        }
コード例 #4
0
ファイル: SwarmAPI.cs プロジェクト: shranjan/pinac
 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.");
     }
 }
コード例 #5
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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();
            }
        }
コード例 #6
0
ファイル: MessageParser.cs プロジェクト: shranjan/pinac
 private void getHeartBeatRequestMsg(String msg)
 {
     try
     {
         Thread t;
         string ipport = GetIP() + ":" + GetPort();
         string target = " ";
         string reply = " ";
         XDocument xml = XDocument.Parse(msg);
         var q = from x in xml.Descendants()
                 where (x.Name == "root")
                 select x;
         foreach (var elem in q)
             target = elem.Value;
         MessageGenerator temp = new MessageGenerator();
         reply = temp.msgHeartBeatReply(ipport);
         AsynchronousClient client = new AsynchronousClient();
         string[] str = target.Split(':');
         string ip = str[0];
         string port = str[1];
         client.SetSingleMsg(ip, port, reply);
         t = new Thread(new ThreadStart(client.SendSingleClient));
         t.IsBackground = true;
         t.Start();
     }
     catch (Exception e)
     { Console.WriteLine(e.ToString()); }
     
 }
コード例 #7
0
ファイル: Form1.cs プロジェクト: shranjan/pinac
        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);
        }
コード例 #8
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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();
            
        }
コード例 #9
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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();
            }
        }
コード例 #10
0
ファイル: SwarmMemory.cs プロジェクト: shranjan/pinac
        public void distributeParallelCode(int start, int end, string data, string body, string range)
        {
            try
            {
                rng = range;
                ParallelPortions = new Hashtable();
                ParallelResults = new Hashtable();
                ParallelForBody = body;
                ParallelForBody = ParallelForBody.Replace('<', '%');
                ParallelForBody = ParallelForBody.Replace('>', '@');
                ParallelForData = data;


                int numberofStatements = end - start + 1;
                numberOfIterations = numberofStatements;
                int numberofComputers = permissions.Count;

                List<int> lhs = new List<int>();
                List<int> rhs = new List<int>();
                int numberOfTasks = splitIndex(start, end, numberofComputers, out lhs, out rhs);
                Console.WriteLine("Tasks are splitted as follows:");
                for (int i = 0; i < lhs.Count; ++i)
                {
                    Console.WriteLine(lhs[i].ToString() + " " + rhs[i].ToString());
                }
                try
                {
                    int count = 0;
                    foreach (DictionaryEntry Permitted in permissions)
                    {
                        if (count < numberOfTasks)
                        {
                            string key = lhs[count].ToString() + ":" + rhs[count].ToString();
                            ParallelPortions.Add(key, Permitted.Key.ToString());
                            ++count;
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show(e.Message, "first for.");
                }
                //int StatementPerComputer;
                //if ((numberofStatements % numberofComputers) == 0)
                //    StatementPerComputer = (int)(numberofStatements / numberofComputers);
                //else
                //    StatementPerComputer = (int)(numberofStatements / numberofComputers + 1);
                ////split the codes
                //try
                //{
                //    foreach (DictionaryEntry Permitted in permissions)
                //    {
                //        for (int i = 0; i < StatementPerComputer; i++)
                //        {
                //            ParallelPortions[start.ToString()] = Permitted.Key.ToString();
                //            if (start > end)
                //                break;
                //            else
                //                start++;
                //        }
                //        if (start > end)
                //            break;
                //    }
                //}
                //catch (Exception e)
                //{ System.Windows.Forms.MessageBox.Show(e.Message, "first for."); }


                //List<string> calculationComputers = new List<string>();           
                //int totalCPU = 0;
                //foreach (DictionaryEntry allPeers in IPtoCPU)
                //{
                //    foreach (DictionaryEntry permitted in permissions)
                //    {
                //        if (allPeers.Key.ToString() == permitted.Key.ToString())
                //        {                        
                //            //this should be a struct
                //            totalCPU = totalCPU + int.Parse(allPeers.Value.ToString());
                //            calculationComputers.Add(permitted.Key.ToString());
                //        }
                //    }
                //}
                ////=======================================================
                //int LinePerCPU = (int)(numberofStatements / totalCPU + 1);

                //for (int k = 0; k < calculationComputers.Count; k++)
                //{
                //    int numberofCPU = (int)IPtoCPU[calculationComputers[k].ToString()];
                //    for (int a = 0; a < numberofCPU * LinePerCPU; a++)
                //    {
                //        ParallelPortions[start] = calculationComputers[k].ToString();
                //        start++;
                //        if (start > end)
                //        {
                //            break;
                //        }
                //    }
                //    if (start > end)
                //    {
                //        break;
                //    }
                //}
                //=======================================================
                //send the codes
                try
                {
                    List<string> allIP = new List<string>();
                    List<string> allPort = new List<string>();
                    List<string> allKey = new List<string>();
                    foreach (DictionaryEntry item in ParallelPortions)
                    {
                        allIP.Add(item.Value.ToString().Substring(0, item.Value.ToString().IndexOf(':')));
                        allPort.Add(item.Value.ToString().Substring(item.Value.ToString().IndexOf(':') + 1));
                        allKey.Add(item.Key.ToString());
                    }
                    //foreach (DictionaryEntry item in ParallelPortions)
                    //{
                    //    string theIP = item.Value.ToString();
                    //    theIP = theIP.Substring(0, theIP.IndexOf(':'));
                    //    string thePort = item.Value.ToString();
                    //    thePort = thePort.Substring(thePort.IndexOf(':') + 1);
                    //    AsynchronousClient client = new AsynchronousClient();
                    //    client.SetSingleMsg(theIP, thePort, createParallelDistributionMessage(item.Key.ToString()));
                    //    Thread t = new Thread(new ThreadStart(client.SendSingleClient));
                    //    t.IsBackground = true;
                    //    t.Start();
                    //    Thread.Sleep(5);
                    //}
                    for (int i = 0; i < lhs.Count; i++)
                    {
                        AsynchronousClient client = new AsynchronousClient();
                        client.SetSingleMsg(allIP[i], allPort[i], createParallelDistributionMessage(lhs[i].ToString(), rhs[i].ToString()));
                        Thread t = new Thread(new ThreadStart(client.SendSingleClient));
                        t.IsBackground = true;
                        t.Start();
                        Thread.Sleep(5);
                    }
                }
                catch (Exception e)
                { System.Windows.Forms.MessageBox.Show(e.Message, "seconde for."); }

            }
            catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message, "distributeParallelCode."); }
        }
コード例 #11
0
ファイル: SwarmMemory.cs プロジェクト: shranjan/pinac
 public void outgoingResult(string index, string result)
 {
     if (!string.IsNullOrEmpty(Master))
     {
         try
         {
             // if count < number of tasks for this machine, put the result into the table
             // if count == number of tasks for this machine, build a big message and send it to master
             int indexNum = Int32.Parse(index);
             if (TaskIndexList.Contains(indexNum))
             {
                 if (!ResultCollection.ContainsKey(index))
                 {
                     ResultCollection.Add(index, result);
                     SubResultCollection.Add(index, result);
                     if (SubResultCollection.Count == 1000 || ResultCollection.Count == TaskIndexList.Count)
                     {
                         string[] temp = Master.Split(':');
                         string theIP = temp[0];
                         string thePort = temp[1];
                         if (SubResultCollection.Count == 1000 && ResultCollection.Count != TaskIndexList.Count)
                         {
                             AsynchronousClient client = new AsynchronousClient();
                             client.SetSingleMsg(theIP, thePort, createParallelResultMessage(SubResultCollection));
                             Thread t = new Thread(new ThreadStart(client.SendSingleClient));
                             t.IsBackground = true;
                             t.Start();
                             SubResultCollection.Clear();
                         }
                         if (ResultCollection.Count == TaskIndexList.Count)
                         {
                             AsynchronousClient client = new AsynchronousClient();
                             client.SetSingleMsg(theIP, thePort, createParallelResultMessage(SubResultCollection));
                             Thread t = new Thread(new ThreadStart(client.SendSingleClient));
                             t.IsBackground = true;
                             t.Start();
                             Thread.Sleep(100);
                             TaskIndexList.Clear();
                             ResultCollection.Clear();
                             SubResultCollection.Clear();
                         }
                     }
                 }
             }
         }
         catch (Exception e)
         { Console.WriteLine(e.ToString()); }
     }
      
 }
コード例 #12
0
ファイル: SwarmMemory.cs プロジェクト: shranjan/SPINACH
        private void createInitialData(string IPPort)
        {

            string DstIp = IPPort.Substring(0, IPPort.IndexOf(':'));
            string DstPort = IPPort.Substring(IPPort.IndexOf(':') + 1);
            AsynchronousClient client = new AsynchronousClient();
            client.SetSingleMsg(DstIp, DstPort, InitialXMLString());
            Thread t = null;
            t = new Thread(new ThreadStart(client.SendSingleClient));
            t.Start();
            t.IsBackground = true;      
           
           /*
             *this is a part of Test1
            Console.WriteLine(InitialXMLString());            
             */
           
        }
コード例 #13
0
ファイル: SwarmMemory.cs プロジェクト: shranjan/SPINACH
        //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;
            
        }
コード例 #14
0
ファイル: SwarmMemory.cs プロジェクト: shranjan/SPINACH
 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;
     
 }
コード例 #15
0
ファイル: server.cs プロジェクト: shranjan/pinac
        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()); }
        }
コード例 #16
0
ファイル: MessageParser.cs プロジェクト: shranjan/pinac
        public void getRunMsg(String msg)
        {
            try
            {
                MessageGenerator temp = new MessageGenerator();
                string pid = " ";
                string ipport = "";
                string reply = "";
                XDocument xml = XDocument.Parse(msg);
                var q = from x in xml.Elements() select x;
                //var q = from x in xml.Elements().Descendants("root") select x;
                pid = q.ElementAt(0).Attributes().ElementAt(1).Value;
                ipport = q.ElementAt(0).Attributes().ElementAt(2).Value;
                SwarmMemory sm = GetProg(pid.ToString());
                if (sm.getRunFlag() == false)
                {
                    sm.setRunFlag(true);
                    reply = temp.msgRunSucessReply(pid);
                }
                else
                {
                    reply = temp.msgRunFailReply(pid);
                }
                if (ipport != "")
                {
                    string[] target = ipport.Split(':');
                    string ip = target[0];
                    string port = target[1];
                    AsynchronousClient client = new AsynchronousClient();
                    client.SetSingleMsg(ip, port, reply);
                    Thread t;
                    t = new Thread(new ThreadStart(client.SendSingleClient));
                    t.IsBackground = true;
                    t.Start();
                }
            }
            catch (Exception e)
            { Console.WriteLine(e.ToString()); }

        }
コード例 #17
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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;
            }
            
        }
コード例 #18
0
ファイル: SwarmMemory.cs プロジェクト: shranjan/pinac
        //public void PeerGone(string IPPort)
        //{
        //    try
        //    {
        //        List<string> temp = new List<string>();
        //        foreach (DictionaryEntry item in ParallelPortions)
        //        {
        //            if (item.Value.ToString() == IPPort)
        //            {
        //                temp.Add(item.Key.ToString());
        //            }
        //        }
        //        if (temp.Count > 0)
        //        {
        //            int nextStatement = 0;
        //            int numberofStatements = temp.Count;
        //            int numberofComputers = permissions.Count;
        //            int StatementPerComputer;
        //            if ((numberofStatements % numberofComputers) == 0)
        //                StatementPerComputer = (int)(numberofStatements / numberofComputers);
        //            else
        //                StatementPerComputer = (int)(numberofStatements / numberofComputers + 1);
        //            //split the codes
        //            foreach (DictionaryEntry Permitted in permissions)
        //            {
        //                for (int i = 0; i < StatementPerComputer; i++)
        //                {
        //                    ParallelPortions[temp[nextStatement]] = Permitted.Key.ToString();
        //                    if (nextStatement >= temp.Count)
        //                        break;
        //                    else
        //                        nextStatement++;
        //                }
        //                if (nextStatement >= temp.Count)
        //                    break;
        //            }
        //            foreach (DictionaryEntry item in ParallelPortions)
        //            {
        //                if (temp.Contains(item.Key.ToString()))
        //                {
        //                    string theIP = item.Value.ToString();
        //                    theIP = theIP.Substring(0, theIP.IndexOf(':'));
        //                    string thePort = item.Value.ToString();
        //                    thePort = thePort.Substring(thePort.IndexOf(':') + 1);
        //                    AsynchronousClient client = new AsynchronousClient();
        //                    client.SetSingleMsg(theIP, thePort, createParallelDistributionMessage(item.Key.ToString()));
        //                    Thread t = new Thread(new ThreadStart(client.SendSingleClient));
        //                    t.IsBackground = true;
        //                    t.Start();

        //                }
        //            }
        //        }
        //    }
        //    catch (Exception e)
        //    { Console.WriteLine(e.ToString()); }

        //}

        // new function for using large message
        public void PeerGone(string IPPort)
        {
            try
            {
                List<string> temp = new List<string>();
                foreach (DictionaryEntry item in ParallelPortions)
                {
                    if (item.Value.ToString() == IPPort)
                    {
                        temp.Add(item.Key.ToString());
                    }
                }
                if (temp.Count > 0)
                {
                    // first get the portion that is not finished
                    string IndexRange = temp[0];
                    string startIndex = IndexRange.Substring(0, IndexRange.IndexOf(':'));
                    string endIndex = IndexRange.Substring(IndexRange.IndexOf(':') + 1);
                    int startNumber = Int32.Parse(startIndex);
                    int endNumber = Int32.Parse(endIndex);

                    int numberofStatements = endNumber - startNumber + 1;
                    int numberofComputers = permissions.Count;

                    List<int> lhs = new List<int>();
                    List<int> rhs = new List<int>();
                    int numberOfTasks = splitIndex(startNumber, endNumber, numberofComputers, out lhs, out rhs);
                    Console.WriteLine("(PeerGone)Tasks are re-splitted as follows:");
                    for (int i = 0; i < lhs.Count; ++i)
                    {
                        Console.WriteLine(lhs[i].ToString() + " " + rhs[i].ToString());
                    }

                    Hashtable rescheduleParallelPortions = new Hashtable();
                    ParallelPortions.Remove(IndexRange);

                    try
                    {
                        int count = 0;
                        foreach (DictionaryEntry Permitted in permissions)
                        {
                            if (count < numberOfTasks)
                            {
                                string key = lhs[count].ToString() + ":" + rhs[count].ToString();
                                rescheduleParallelPortions.Add(key, Permitted.Key.ToString());
                                ParallelPortions.Add(key, Permitted.Key.ToString());
                                ++count;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Windows.Forms.MessageBox.Show(e.Message, "first for.");
                    }

                    //int nextStatement = 0;
                    //int numberofStatements = temp.Count;
                    //int numberofComputers = permissions.Count;
                    //int StatementPerComputer;
                    //if ((numberofStatements % numberofComputers) == 0)
                    //    StatementPerComputer = (int)(numberofStatements / numberofComputers);
                    //else
                    //    StatementPerComputer = (int)(numberofStatements / numberofComputers + 1);
                    ////split the codes
                    //foreach (DictionaryEntry Permitted in permissions)
                    //{
                    //    for (int i = 0; i < StatementPerComputer; i++)
                    //    {
                    //        ParallelPortions[temp[nextStatement]] = Permitted.Key.ToString();
                    //        if (nextStatement >= temp.Count)
                    //            break;
                    //        else
                    //            nextStatement++;
                    //    }
                    //    if (nextStatement >= temp.Count)
                    //        break;
                    //}
                    foreach (DictionaryEntry item in rescheduleParallelPortions)
                    {
                        //if (temp.Contains(item.Key.ToString()))
                        {
                            string theIP = item.Value.ToString();
                            theIP = theIP.Substring(0, theIP.IndexOf(':'));
                            string thePort = item.Value.ToString();
                            thePort = thePort.Substring(thePort.IndexOf(':') + 1);

                            string tmpIndexRange = item.Key.ToString();
                            string tmpStartIndex = tmpIndexRange.Substring(0, tmpIndexRange.IndexOf(':'));
                            string tmpEndIndex = tmpIndexRange.Substring(tmpIndexRange.IndexOf(':') + 1);

                            AsynchronousClient client = new AsynchronousClient();
                            client.SetSingleMsg(theIP, thePort, createParallelDistributionMessage(tmpStartIndex, tmpEndIndex));
                            Thread t = new Thread(new ThreadStart(client.SendSingleClient));
                            t.IsBackground = true;
                            t.Start();

                        }
                    }
                }
            }
            catch (Exception e)
            { Console.WriteLine(e.ToString()); }

        }
コード例 #19
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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;

        }
コード例 #20
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
 public void outgoingResult(string index, string result)
 {
     string[] temp = Master.Split(':');
     string theIP = temp[0];
     string thePort = temp[1];
     AsynchronousClient client = new AsynchronousClient();
     client.SetSingleMsg(theIP, thePort, createParallelResultMessage(index, result));
     Thread t = new Thread(new ThreadStart(client.SendSingleClient));
     t.IsBackground = true;
     t.Start();
     Thread.Sleep(5);
      
 }
コード例 #21
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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();
                
            }
        }
コード例 #22
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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("");
        }
コード例 #23
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        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();
                }

            }
        }
コード例 #24
0
ファイル: MessageParser.cs プロジェクト: shranjan/pinac
        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()); }
        }
コード例 #25
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        public void PeerGone(string IPPort)
        {
            List<string> temp = new List<string>();
            foreach (DictionaryEntry item in ParallelPortions)
            {
                if (item.Value.ToString() == IPPort)
                {
                    temp.Add(item.Key.ToString());
                }
            }
            if (temp.Count > 0)
            {
                int nextStatement = 0;
                int numberofStatements = temp.Count;
                int numberofComputers = permissions.Count;
                int StatementPerComputer;
                if ((numberofStatements % numberofComputers) == 0)
                    StatementPerComputer = (int)(numberofStatements / numberofComputers);
                else
                    StatementPerComputer = (int)(numberofStatements / numberofComputers + 1);
                //split the codes
                foreach (DictionaryEntry Permitted in permissions)
                {
                    for (int i = 0; i < StatementPerComputer; i++)
                    {
                        ParallelPortions[temp[nextStatement]] = Permitted.Key.ToString();
                        if (nextStatement >= temp.Count)
                            break;
                        else
                            nextStatement++;
                    }
                    if (nextStatement >= temp.Count)
                        break;
                }
                foreach (DictionaryEntry item in ParallelPortions)
                {
                    if (temp.Contains(item.Key.ToString()))
                    {
                        string theIP = item.Value.ToString();
                        theIP = theIP.Substring(0, theIP.IndexOf(':'));
                        string thePort = item.Value.ToString();
                        thePort = thePort.Substring(thePort.IndexOf(':') + 1);
                        AsynchronousClient client = new AsynchronousClient();
                        client.SetSingleMsg(theIP, thePort, createParallelDistributionMessage(item.Key.ToString()));
                        Thread t = new Thread(new ThreadStart(client.SendSingleClient));
                        t.IsBackground = true;
                        t.Start();

                    }
                }
            }

        }
コード例 #26
0
ファイル: server.cs プロジェクト: shranjan/SPINACH
 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;
 }
コード例 #27
0
ファイル: SwarmMemory.cs プロジェクト: rkpandya/pinac
        public void distributeParallelCode(int start, int end, string data, string body, string range)
        {
            rng = range;
            ParallelPortions = new Hashtable();
            ParallelResults = new Hashtable();
            ParallelForBody = body;
            ParallelForBody = ParallelForBody.Replace('<', '%');
            ParallelForBody = ParallelForBody.Replace('>', '@');
            ParallelForData = data ;

           
            int numberofStatements = end - start + 1;
            int numberofComputers = permissions.Count;
            int StatementPerComputer;
            if((numberofStatements % numberofComputers)==0)
                StatementPerComputer = (int)(numberofStatements / numberofComputers);
            else
                StatementPerComputer = (int)(numberofStatements / numberofComputers + 1);
            //split the codes
            foreach (DictionaryEntry Permitted in permissions)
            {
                for (int i = 0; i < StatementPerComputer; i++)
                {
                    ParallelPortions[start.ToString()] = Permitted.Key.ToString();
                    if (start > end)
                        break;
                    else
                        start++;
                }
                if (start > end)
                    break;
            }            
        //List<string> calculationComputers = new List<string>();           
        //int totalCPU = 0;
        //foreach (DictionaryEntry allPeers in IPtoCPU)
        //{
        //    foreach (DictionaryEntry permitted in permissions)
        //    {
        //        if (allPeers.Key.ToString() == permitted.Key.ToString())
        //        {                        
        //            //this should be a struct
        //            totalCPU = totalCPU + int.Parse(allPeers.Value.ToString());
        //            calculationComputers.Add(permitted.Key.ToString());
        //        }
        //    }
        //}
        ////=======================================================
        //int LinePerCPU = (int)(numberofStatements / totalCPU + 1);

        //for (int k = 0; k < calculationComputers.Count; k++)
        //{
        //    int numberofCPU = (int)IPtoCPU[calculationComputers[k].ToString()];
        //    for (int a = 0; a < numberofCPU * LinePerCPU; a++)
        //    {
        //        ParallelPortions[start] = calculationComputers[k].ToString();
        //        start++;
        //        if (start > end)
        //        {
        //            break;
        //        }
        //    }
        //    if (start > end)
        //    {
        //        break;
        //    }
        //}
            //=======================================================
            //send the codes
            foreach (DictionaryEntry item in ParallelPortions)
            {
                string theIP = item.Value.ToString();
                theIP = theIP.Substring(0, theIP.IndexOf(':'));
                string thePort = item.Value.ToString();
                thePort = thePort.Substring(thePort.IndexOf(':') + 1);
                AsynchronousClient client = new AsynchronousClient();
                client.SetSingleMsg(theIP, thePort, createParallelDistributionMessage(item.Key.ToString()));
                Thread t = new Thread(new ThreadStart(client.SendSingleClient));
                t.IsBackground = true;
                t.Start();
                Thread.Sleep(5);
            }
           
        }
コード例 #28
0
ファイル: SwarmAPI.cs プロジェクト: shranjan/pinac
        //*************************************
        public bool Join_Swarm(string DstIP, string DstPort, string SrcIP, string SrcPort, string Username)
        {
            Thread t1 = null;
            Thread t2 = null;
            try
            {
                string cpu = "1";
                mSocket.SetIP(SrcIP);
                mSocket.SetPort(SrcPort);
                mSocket.SetName(Username);
                mSocket.SetCPU(cpu);

                listenerThread = new Thread(new ThreadStart(mSocket.StartListening));
                listenerThread.IsBackground = true;
                listenerThread.Start();

                t1 = new Thread(new ThreadStart(mSocket.StarHeartBeat));
                t1.IsBackground = true;
                t1.Start();

                MessageGenerator msg = new MessageGenerator();
                string mMsg = msg.msgConnectionRequest
                    (mSocket.GetIP(), mSocket.GetPort(), mSocket.GetName(), mSocket.GetCPU());
                AsynchronousClient client = new AsynchronousClient();
                client.ErrorExcep += new AsynchronousClient.EventHandlerExcep(Error_Changed);
                client.SetSingleMsg(DstIP, DstPort, mMsg);
                // t2 = new Thread(new ThreadStart(client.SendSingleClient));
                client.SendSingleClient();
                // t2.Start();
                // t2.IsBackground = true;
                Thread.Sleep(2000);
                if (mSocket.GetIPtoPeer().Count > 0)
                    return true;
                else
                    return false;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to join swarm.");
                return false;
            }

        }