예제 #1
0
파일: Form1.cs 프로젝트: imgits/WebCrawler
        public void CreateWorkThread(SimpleObj rec)
        {
            ThreadWorker item = new ThreadWorker(rec);

            //subscribe to be notified when result is ready
            item.Completed += WorkThread_Completed;
            item.DoWork();
        }
예제 #2
0
        private async void PerformWork(SimpleObj rec)
        {
            // call the main work method and wait for it to return
            SimpleObj resultObj = await Shared.SendWebRequest(rec);

            ARec.ResultCode = resultObj.ResultCode;
            ARec.XMLData    = resultObj.XMLData;
            //once completed, call the "post completed" method, passing in the result received
            PostCompleted();
        }
예제 #3
0
파일: Form1.cs 프로젝트: imgits/WebCrawler
        public void RunProcessThreaded()
        {
            updateStatusLabel("Status: threaded mode - watch thread count and list status");
            lblThreadCount.Visible = true;

            for (int i = 0; i < RunTimes; i++)
            {
                updateStatusLabel("Processing: " + (i + 1).ToString() + "/" + RunTimes.ToString());
                lvMain.Items[i].Selected         = true;
                lvMain.Items[i].SubItems[1].Text = "Processing...";
                SimpleObj rec = new SimpleObj()
                {
                    ItemID = i.ToString(), WebURL = edtTestServer.Text
                };
                CreateWorkThread(rec);
                RunningThreadCount++;
                UpdateThreadCount();
            }
        }
예제 #4
0
        public static async Task <SimpleObj> SendWebRequest(SimpleObj rec)
        {
            SimpleObj rslt = new SimpleObj();

            rslt = rec;
            var httpClient = new HttpClient();
            //content string
            StringContent content = new StringContent(rec.ItemID); // we send the server the ItemID

            try
            {
                HttpResponseMessage response = await httpClient.PostAsync(rec.WebURL, content);

                if (response.IsSuccessStatusCode)
                {
                    HttpContent   stream = response.Content;
                    Task <string> data   = stream.ReadAsStringAsync();
                    rslt.XMLData = data.Result.ToString();

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(rslt.XMLData);
                    XmlNode resultNode   = doc.SelectSingleNode("response");
                    string  resultStatus = resultNode.InnerText;
                    if (resultStatus == "1")
                    {
                        rslt.ResultCode = "OK";
                    }
                    else if (resultStatus == "0")
                    {
                        rslt.ResultCode = "ERR";
                    }
                    rslt.Message = doc.InnerXml;
                }
            }
            catch (Exception ex)
            {
                rslt.ResultCode = "ERR";
                rslt.Message    = "Connection error: " + ex.Message;
            }

            return(rslt);
        }
예제 #5
0
파일: Form1.cs 프로젝트: imgits/WebCrawler
        public async void RunProcess()
        {
            for (int i = 0; i < RunTimes; i++)
            {
                updateStatusLabel("Processing: " + (i + 1).ToString() + "/" + RunTimes.ToString());
                lvMain.Items[i].Selected = true;
                lvMain.Items[i].EnsureVisible();
                lvMain.Items[i].SubItems[1].Text = "Processing...";
                SimpleObj result = await Shared.SendWebRequest(new SimpleObj()
                {
                    ItemID = i.ToString(), WebURL = edtTestServer.Text
                });

                lvMain.Items[i].SubItems[1].Text = result.ResultCode;
                if (result.ResultCode == "ERR")
                {
                    lvMain.Items[i].SubItems[2].Text = result.Message;
                }
            }
            CleanUp();
        }
예제 #6
0
 // Constructor takes parameters that will be used to store informaiton we need to update the main UI on completion
 public WorkItemCompletedEventArgs(SimpleObj result)
 {
     this.Result = result;
 }
예제 #7
0
        public event EventHandler <WorkItemCompletedEventArgs> Completed; //event handler to be run when work has completed with a result


        // constructor for the thread. Takes param ID index of the Listview to keep track of.
        public ThreadWorker(SimpleObj Rec)
        {
            ARec = Rec;
        }