public string RunScrapping(Func <string, string, string, string, string[], IScrappingProcess> action, string code, string id, string pw, params string[] other) { string scrapcode = "SCRAP" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); IScrappingProcess scrap = action(scrapcode, code, id, pw, other); scrap.Run(); memory.Add(scrapcode, scrap); return(scrapcode); }
public ScrapState StateScrapping(string code) { if (!memory.ContainsKey(code)) { return(ScrapState.EMPTY); } IScrappingProcess scrap = memory[code]; return(scrap.GetState()); }
public IScrappingProcess CompleteScrapping(String code) { ScrapState state = StateScrapping(code); if (Object.Equals(ScrapState.COMPLETE, state)) { IScrappingProcess ret = memory[code]; return(ret); } return(null); }
private void button1_Click(object sender, EventArgs e) { String port = textBox1.Text; int portNumber = 10000; try { portNumber = Convert.ToInt32(port); } catch (FormatException) { WriteLog("This port setting is wrong.Select to number between 10000 to 20000,please."); this.textBox1.Text = "10000"; return; } try { webServer = new HttpServer(portNumber); } catch (Exception) { WriteLog("This port setting is wrong.Do not overlapped the other port."); WriteLog("The step of confirmation) This order press prompt on commander; netstat -an |find \"LISTEN\" . Then the port check at. Finally, The port set that is not overlapped."); this.textBox1.Text = "10000"; return; } button1.Enabled = false; textBox1.Enabled = false; this.textBox2.Text = "Processing"; this.textBox2.BackColor = Color.Blue; webServer.Start((header) => { if (String.IsNullOrEmpty(header["TYPE"])) { return("PARAMETER_ERROR"); } if (String.IsNullOrEmpty(header["CODE"])) { return("PARAMETER_ERROR"); } // It check code type that is defined the scrap code. if (!ScrapKindDic.ContainsKey(header["CODE"])) { return("PARAMETER_ERROR"); } switch ((header["TYPE"])) { case "scrap_request": { if (String.IsNullOrEmpty(header["ID"])) { return("PARAMETER_ERROR"); } if (String.IsNullOrEmpty(header["PW"])) { return("PARAMETER_ERROR"); } if (String.IsNullOrEmpty(header["APPLY"])) { return("PARAMETER_ERROR"); } String scrapcode = AdapterScrapping.Instance().RunScrapping((scrap_code, _code, _id, _pw, _param) => { int gridIndex = (int)this.Invoke(new Func <int>(() => { String[] gridData = { _code, _id, _pw, scrap_code, DateTime.Now.ToString(), ScrapState.RUNNING.ToString() }; return(this.dataGridView1.Rows.Add(gridData)); })); ICommonScrap scrap = FactoryScrapClass(_code, _id, _pw, _param); ScrappingStruct item; item.code = _code; item.id = _id; item.pw = _pw; item.scrapcode = scrap_code; scraplist.Insert(0, item); //It enroll data of scrap to datagridview. scrap.SetHandler((state) => { this.Invoke(new Action(() => { this.dataGridView1.Rows[gridIndex].Cells[5].Value = state.ToString(); })); }); return(scrap); }, header["CODE"], header["ID"], header["PW"], header["APPLY"]); return(scrapcode); } case "scrap_state": { return(AdapterScrapping.Instance().StateScrapping(header["CODE"]).ToString()); } case "scrap_get": { ScrapState state = AdapterScrapping.Instance().StateScrapping(header["CODE"]); if (object.Equals(state, ScrapState.COMPLETE)) { IScrappingProcess scrap = AdapterScrapping.Instance().CompleteScrapping(header["CODE"]); return(scrap.ToString()); } return(state.ToString()); } case "scrap_codesearch": { foreach (ScrappingStruct item in scraplist) { if (object.Equals(item.code, header["CODE"]) && object.Equals(item.id, header["ID"]) && object.Equals(item.pw, header["PW"])) { return(item.scrapcode); } } return("NOTHING"); } default: return("TYPE_PARAMETER_ERROR"); } }); }