Beispiel #1
0
        /*Broadcasts the script to all other peers*/
        public static void BroadcastTransaction(string[] script)
        {
            RestRequest   request = new RestRequest("api/client/getclientlist/");
            IRestResponse resp    = RestClient.Get(request);

            if (resp.IsSuccessful)
            {
                List <Client> clients = JsonConvert.DeserializeObject <List <Client> >(resp.Content);

                foreach (Client c in clients)
                {
                    if (c.port != me.port)                    //Don't broadcast it to me i already have it
                    {
                        ChannelFactory <PeerServerInterface> channelFactory;
                        NetTcpBinding tcp = new NetTcpBinding();
                        tcp.MaxReceivedMessageSize = 2147483647;
                        string clientURL = String.Format("net.tcp://{0}:{1}/DataService", c.ipaddress, c.port);
                        channelFactory = new ChannelFactory <PeerServerInterface>(tcp, clientURL);
                        PeerServerInterface channel = channelFactory.CreateChannel();
                        channel.GetNewScript(script);
                    }
                }
                logger.LogFunc("SUCCESS:Broadcasted script to all clients");
            }
            else
            {
                logger.LogFunc("ERROR:Could not broadcast script to all clients");
            }
        }
Beispiel #2
0
        /*Called when the users enters and submits code*/
        public void SubmitCode_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ChannelFactory <PeerServerInterface> channelFactory;
                NetTcpBinding tcp = new NetTcpBinding();
                tcp.MaxReceivedMessageSize = 2147483647;
                string clientURL = String.Format("net.tcp://{0}:{1}/DataService", me.ipaddress, me.port);
                channelFactory = new ChannelFactory <PeerServerInterface>(tcp, clientURL);
                PeerServerInterface channel = channelFactory.CreateChannel();
                //Channel to the peer server has been created

                string   scriptStr  = CodeBox.Text;
                string   encodedStr = EncodeString(scriptStr);
                string[] codeStr    = new string[2] {
                    encodedStr, ""
                };                                                                  //Converting the ans to a string if it isn't already
                Job j = new Job(codeStr[0], codeStr[1], jobId);
                myJobs.Add(j);
                jobId++;                //incremented for the next job this client creates

                RestRequest   request = new RestRequest("api/client/getclientlist/");
                IRestResponse resp    = RestClient.Get(request);

                if (resp.IsSuccessful)                //Checking if the client list was available to get
                {
                    List <Client> clients = JsonConvert.DeserializeObject <List <Client> >(resp.Content);

                    foreach (Client c in clients)                    //Give this to every client including myself
                    {
                        tcp = new NetTcpBinding();
                        tcp.MaxReceivedMessageSize = 2147483647;
                        clientURL      = String.Format("net.tcp://{0}:{1}/DataService", c.ipaddress, c.port);
                        channelFactory = new ChannelFactory <PeerServerInterface>(tcp, clientURL);
                        channel        = channelFactory.CreateChannel();
                        channel.GetNewScript(codeStr);                        //Adding it to every clients script queue
                    }
                    UpdateJobList();
                }
                else
                {
                    logger.LogFunc("ERROR: Could not retrieve the list of clients");
                }
            }
            catch (FormatException ex)
            {
                logger.LogFunc("ERROR: The user input was incorrect");
                MessageBox.Show("Please input python script correctly");
            }
        }