static void Main(string[] args) { Rawler.Tool.ReportManage.ErrReportEvent += ReportManage_ErrReportEvent; Rawler.Tool.ReportManage.ReportEvnet += ReportManage_ReportEvnet; // args = new List<string>() { @"C:\Users\kiichi\Documents\TwitterData\hamano_satoshi\tweet.xaml" }.ToArray(); if (args.Length > 0) { try { Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (var item in args.Skip(1)) { var d = item.Split('='); if (d.Length > 1) { dic[d[0]] = d[1]; Rawler.Tool.TempVar.SetVar(d[0], d[1]); } } RawlerBase rawler = (RawlerBase)System.Xaml.XamlServices.Load(args[0]); rawler.SetParent(); rawler.Run(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }
public override void Run(bool runChildren) { RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink urlListCreate"); urlList = new System.Collections.Concurrent.ConcurrentBag <string>(); RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink autoNextLink.Run"); autoNextLink.Run(); RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink autoNextLink.Run End"); var page = this.GetUpperRawler <Page>(); if (page != null) { if (maxCount > count) { var url = page.GetCurrentUrl(); Uri url_uri = new Uri(url); if (urlList.Any()) { var test = urlList.Distinct().Where(n => new Uri(n).Host == url_uri.Host && urlHash.Contains(n) == false).ToList(); var nextUrl = urlList.Distinct().Where(n => new Uri(n).Host == url_uri.Host && urlHash.Contains(n) == false) .Select(n => new { url = n, Distance = Rawler.NPL.LevenshteinDistance.Compute(url, n) }) .OrderBy(n => n.Distance); if (nextUrl.Any()) { page.PushUrl(nextUrl.First().url); urlHash.Add(nextUrl.First().url); count++; } urlHash.Add(url); } else { ReportManage.ErrReport(this, "NextLinkの取得がありません"); } } } RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink End"); base.Run(runChildren); }
private void button1_Click(object sender, RoutedEventArgs e) { if (isBusy) { MessageBox.Show("実行中です"); return; } tokenSource = new CancellationTokenSource(); object obj = null; string xaml = textEditor.Text; var insertParameter = new Tool.InsertParameterWindow(); if (insertParameter.Analyze(textEditor.Text) == true) { xaml = insertParameter.Xaml; } else { return; } try { obj = System.Xaml.XamlServices.Parse(xaml); } catch (Exception ex) { ReportManage.ErrReport(new RawlerBase(), "XAMLの形式がおかしいです" + ex.Message); } if (obj == null) { return; } if ((obj is Rawler.Tool.RawlerBase)==false) { ReportManage.ErrReport(new RawlerBase(), "キャストできませんでした。XAMLの形式がおかしいです"); } try { rawler = (obj as Rawler.Tool.RawlerBase); ReportManage.RowCount = 0; rawler.SetParent(); startDate = DateTime.Now; foreach (var item in rawler.GetConectAllRawler()) { item.BeginRunEvent += (o, arg) => { tokenSource.Token.ThrowIfCancellationRequested(); while (pause) { System.Threading.Thread.Sleep(1000); } }; } isBusy = true; Task.Factory.StartNew(() => rawler.Run(), tokenSource.Token).ContinueWith((t) => { StopWatch(); isBusy = false; }); } catch (OperationCanceledException oce) { ReportManage.ErrReport(new RawlerBase(), "キャンセルされました"); MessageBox.Show("キャンセルされました"); } catch (Exception ex) { ReportManage.ErrReport(new RawlerBase(), ex.Message); } }
private void button1_Click(object sender, RoutedEventArgs e) { if (isBusy) { MessageBox.Show("実行中です"); return; } tokenSource = new CancellationTokenSource(); object obj = null; string xaml = textEditor.Text; var insertParameter = new Tool.InsertParameterWindow(); if (insertParameter.Analyze(textEditor.Text) == true) { xaml = insertParameter.Xaml; } else { return; } try { obj = System.Xaml.XamlServices.Parse(xaml); } catch (Exception ex) { ReportManage.ErrReport(new RawlerBase(), "XAMLの形式がおかしいです" + ex.Message); } if (obj == null) { return; } if ((obj is Rawler.Tool.RawlerBase) == false) { ReportManage.ErrReport(new RawlerBase(), "キャストできませんでした。XAMLの形式がおかしいです"); } try { rawler = (obj as Rawler.Tool.RawlerBase); ReportManage.RowCount = 0; rawler.SetParent(); startDate = DateTime.Now; foreach (var item in rawler.GetConectAllRawler()) { item.BeginRunEvent += (o, arg) => { tokenSource.Token.ThrowIfCancellationRequested(); while (pause) { System.Threading.Thread.Sleep(1000); } }; } isBusy = true; Task.Factory.StartNew(() => rawler.Run(), tokenSource.Token).ContinueWith((t) => { StopWatch(); isBusy = false; }); } catch (OperationCanceledException oce) { ReportManage.ErrReport(new RawlerBase(), "キャンセルされました"); MessageBox.Show("キャンセルされました"); } catch (Exception ex) { ReportManage.ErrReport(new RawlerBase(), ex.Message); } }