Example #1
0
        public override void Run(bool runChildren)
        {
            string t = string.Empty;

            if (string.IsNullOrEmpty(Value))
            {
                t = GetText();
            }
            else
            {
                t = Value;
            }
            if (Header != null)
            {
                t = Header + t;
            }
            if (HeaderTree != null)
            {
                t = RawlerBase.GetText(this.Parent.Text, HeaderTree, this.Parent) + t;
            }
            if (Footer != null)
            {
                t = t + Footer;
            }
            if (FooterTree != null)
            {
                t = t + RawlerBase.GetText(this.Parent.Text, FooterTree, this.Parent);
            }
            SetText(t);
            base.Run(runChildren);
        }
Example #2
0
        public override void Run(bool runChildren)
        {
            string group = string.Empty;

            if (GroupTree != null && this.Parent != null)
            {
                GroupTree.SetParent();
                group = RawlerBase.GetText(this.Parent.Text, GroupTree, this);
            }
            else
            {
                if (GroupName != null)
                {
                    group = GroupName;
                }
            }
            int num = 1;

            if (AddNumTree != null && this.Parent != null)
            {
                int.TryParse(RawlerBase.GetText(this.Parent.Text, AddNumTree, this), out num);
            }

            var c = this.GetAncestorRawler().Where(n => n is CountData);

            if (c.Count() > 0)
            {
                ((CountData)c.First()).AddCount(group, GetText(), num);
            }
            else
            {
                ReportManage.ErrReport(this, "上流にCountDataがありません");
            }
            base.Run(runChildren);
        }
Example #3
0
 protected string GetFileName()
 {
     if (FileNameTree != null)
     {
         return(RawlerBase.GetText(this.GetText(), FileNameTree, this));
     }
     return(this.FileName.Convert(this));
 }
Example #4
0
 public override IEnumerable <string> Query(IEnumerable <string> list)
 {
     if (KeyTree == null)
     {
         return(list.OrderBy(n => n));
     }
     else
     {
         return(list.OrderBy(n => RawlerBase.GetText(n, KeyTree)));
     }
 }
Example #5
0
 /// <summary>
 /// 指定したテキストをPreTreeにかける。
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 protected string GetText(string preText)
 {
     if (preTree != null)
     {
         return(RawlerBase.GetText(preText, PreTree));
     }
     else
     {
         return(preText);
     }
 }
Example #6
0
 public async Task AddReport(ReportEvnetArgs ea)
 {
     if (ea.IsErr && ErrReportTree != null)
     {
         await Task.Run(() => RawlerBase.GetText(ea.DateTime.ToFileTimeUtc() + "\t" + ea.Message, ErrReportTree, this));
     }
     if (isStock && ea.IsErr)
     {
         reportList.Add(ea);
     }
 }
Example #7
0
        public override IEnumerable <string> Query(IEnumerable <string> list)
        {
            var root = this.GetRoot().Rawler;

            if (SelectTree != null)
            {
                foreach (var item in list)
                {
                    yield return(RawlerBase.GetText(item, SelectTree, root));
                }
            }
            else
            {
                ReportManage.ErrReport(root, "SelectTreeがありません");
                //  yield return base.Query(list);
            }
        }
Example #8
0
 private IEnumerable <string> Convert(IEnumerable <string> list)
 {
     if (ConvertTree != null)
     {
         ConvertTree.SetParent(this.Parent);
         foreach (var item in list)
         {
             yield return(RawlerBase.GetText(item, ConvertTree, this.Parent));
         }
     }
     else
     {
         foreach (var item in list)
         {
             yield return(item);
         }
     }
 }
Example #9
0
        public override void Run(bool runChildren)
        {
            string t = string.Empty;

            if (string.IsNullOrEmpty(Value))
            {
                t = GetText();
            }
            else
            {
                t = Value;
            }
            try
            {
                var dir  = System.IO.Path.GetDirectoryName(t) + "\\";
                var file = System.IO.Path.GetFileNameWithoutExtension(t);
                var ext  = System.IO.Path.GetExtension(t);
                t = file;
                if (Header != null)
                {
                    t = Header + t;
                }
                if (HeaderTree != null)
                {
                    t = RawlerBase.GetText(this.Parent.Text, HeaderTree, this.Parent) + t;
                }
                if (Footer != null)
                {
                    t = t + Footer;
                }
                if (FooterTree != null)
                {
                    t = t + RawlerBase.GetText(this.Parent.Text, FooterTree, this.Parent);
                }
                t = dir + t + ext;
            }
            catch
            {
                ReportManage.ErrReport(this, "File名として不正です。");
            }

            SetText(t);
            base.Run(runChildren);
        }
Example #10
0
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            var    list = this.GetAncestorRawler().OfType <Page>();
            string key  = this.Key;

            if (KeyTree != null)
            {
                key = RawlerBase.GetText(this.Parent.Text, KeyTree, this.Parent);
            }
            else
            {
                key = key.Convert(this);
            }
            if (list.Any())
            {
                if (string.IsNullOrEmpty(Value))
                {
                    if (AddType == AddInputParameterType.replece)
                    {
                        list.First().ReplaceParameter(key, GetText());
                    }
                    else
                    {
                        list.First().AddParameter(key, GetText());
                    }
                }
                else
                {
                    if (AddType == AddInputParameterType.replece)
                    {
                        list.First().ReplaceParameter(key, Value.Convert(this));
                    }
                    else
                    {
                        list.First().AddParameter(key, Value.Convert(this));
                    }
                }
            }
            else
            {
                ReportManage.ErrReport(this, "上流にPageが必要です。");
            }
            base.Run(runChildren);
        }
Example #11
0
 /// <summary>
 /// PreTreeを通したあとのText
 /// </summary>
 /// <returns></returns>
 protected string GetText()
 {
     if (this.Parent != null)
     {
         if (preTree != null)
         {
             preTree.SetParent();
             return(RawlerBase.GetText(this.Parent.Text, PreTree, this.Parent));
         }
         else
         {
             return(this.Parent.Text);
         }
     }
     else
     {
         return(this.text);
     }
 }
Example #12
0
        public override void Run(bool runChildren)
        {
            var file = this.GetUpperRawler <TsvReadLines>();

            if (file != null)
            {
                string columnName = this.ColumnName.Convert(this);
                if (this.ColumnNameTree != null)
                {
                    columnName = RawlerBase.GetText(GetText(), ColumnNameTree, this);
                }
                if (string.IsNullOrEmpty(columnName) == false)
                {
                    if (file.ColumnNameDic.ContainsKey(columnName))
                    {
                        var i = file.ColumnNameDic[columnName];

                        var d = file.Text.Split('\t');
                        if (d.Length > i)
                        {
                            SetText(d[i]);
                        }
                        else
                        {
                            SetText(Default);
                        }
                    }
                    else
                    {
                        ReportManage.ErrReport(this, "該当するキーがありません:" + columnName);
                    }
                }
                else
                {
                    ReportManage.ErrReport(this, "ColumnNameが空です。");
                }
            }
            else
            {
                ReportManage.ErrReport(this, "GetTsvValue の上流にTsvReadLinesがありません");
            }
            base.Run(runChildren);
        }
Example #13
0
 private IEnumerable <TextPair <T> > Convert <T>(IEnumerable <TextPair <T> > list, Func <T, string> textFunc)
 {
     if (ConvertTree != null)
     {
         ConvertTree.SetParent(this.Parent);
         foreach (var item in list)
         {
             item.Text = RawlerBase.GetText(item.Text, ConvertTree, this.Parent);
             yield return(item);
             //yield return RawlerBase.GetText(item, ConvertTree, this.Parent);
         }
     }
     else
     {
         foreach (var item in list)
         {
             yield return(item);
         }
     }
 }
Example #14
0
        public override void Run(bool runChildren)
        {
            try
            {
                string fileName = this.FileName.Convert(this);
                if (FileNameTree != null)
                {
                    FileNameTree.SetParent();
                    FileNameTree.SetParent(this);
                    fileName = RawlerBase.GetText(GetText(), FileNameTree, this);
                }
                if (string.IsNullOrEmpty(fileName))
                {
                    if (string.IsNullOrEmpty(fileName))
                    {
                        ReportManage.ErrReport(this, "FileNameが空です。");
                        return;
                    }
                }

                baseFileName    = fileName;
                currentFileName = fileName;
                FileInit(fileName);

                base.Run(runChildren);
                endAction?.Invoke();
            }
            catch (Exception e)
            {
                ReportManage.ErrReport(this, e.Message);
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Close();
                    streamWriter.Dispose();
                }
            }
        }
Example #15
0
        public override void Run(bool runChildren)
        {
            string path = string.Empty;

            if (workFolderType == Tool.SpecialFolder.MyDocuments)
            {
                path = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            }
            if (workFolderType == Tool.SpecialFolder.Desktop)
            {
                path = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            }

            string folder = null;


            if (FolderNameTree != null)
            {
                folder = RawlerBase.GetText(this.GetText(), FolderNameTree, this);
            }
            else
            {
                folder = FolderName;
            }

            if (folder == null || folder.Length == 0)
            {
                ReportManage.ErrReport(this, "CreateFolderのFolderNameがありません");
            }
            else
            {
                path = System.IO.Path.Combine(path, folder);
                if (System.IO.Directory.Exists(path) == false)
                {
                    System.IO.Directory.CreateDirectory(path);
                }
            }
            base.Run(runChildren);
        }
Example #16
0
        protected async Task <bool> ReadPage(string url)
        {
            var client = GetWebClient();

            if (MethodType == MethodType.GET)
            {
                this.text = await client.HttpGet(url, null, tmpReferer);
            }
            else if (MethodType == MethodType.POST)
            {
                parameterDic.Clear();
                if (InputParameterTree != null)
                {
                    RawlerBase.GetText(GetText(), InputParameterTree, this);
                }
                List <KeyValue> list = new List <KeyValue>();
                foreach (var item in parameterDic)
                {
                    list.Add(new KeyValue()
                    {
                        Key = item.Key, Value = item.Value
                    });
                }
                this.text = await client.HttpPost(url, list, tmpReferer);
            }

            this.currentUrl = url;
            this.pastUrl    = this.currentUrl;

            if (this.Text.Length > 0)
            {
                return(true);
            }
            else
            {
                if (client.ErrMessage.Contains("503") || client.ErrMessage.Contains("500"))
                {
                    ReportManage.Report(this, "待機します", true, true);
                    await Task.Delay(new TimeSpan(0, 0, 30));

                    urlStack.Push(url);
                }
                else
                {
                    if (visbleErr)
                    {
                        ReportManage.ErrReport(this, url + "の読み込みに失敗しました。");
                    }
                    if (ErrorEvent != null)
                    {
                        ErrorEvent(this, new EventArgs());
                    }
                    if (ErrEventTree != null)
                    {
                        ErrEventTree.SetParent();
                        Document d = new Document()
                        {
                            TextValue = client.ErrMessage
                        };
                        d.SetParent(this);
                        d.AddChildren(ErrEventTree);
                        d.Run();
                    }
                }
                return(false);
            }
        }
Example #17
0
        //public new void Run()
        //{
        //    Run(true);
        //}

        /// <summary>
        /// 実行
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            string txt = string.Empty;

            if (Value == null || Value.Length == 0)
            {
                txt = GetText();
            }
            else
            {
                txt = Value.Convert(this);
            }
            if (useHtmlDecode)
            {
                txt = System.Net.WebUtility.HtmlDecode(txt);
            }

            string attribute = string.Empty;

            if (this.Attribute == null && attributeTree != null)
            {
                if (this.Parent != null)
                {
                    attribute = RawlerBase.GetText(this.Parent.Text, attributeTree, this);
                }
            }
            else if (this.Attribute != null)
            {
                attribute = this.Attribute.Convert(this);
            }

            Data.DataWrite(this, attribute, txt, writeType, AttributeType);

            //IData data = null;

            //IRawler current = this.Parent;
            //while (current != null)
            //{
            //    if (current is IData)
            //    {
            //        data = current as IData;
            //        break;
            //    }
            //    current = current.Parent;
            //}
            //if (data != null)
            //{
            //    string txt = string.Empty;
            //    if (Value == null || Value.Length == 0)
            //    {
            //        txt = GetText();
            //    }
            //    else
            //    {
            //        txt = Value;
            //    }
            //    if (useHtmlDecode)
            //    {
            //        txt = System.Net.WebUtility.HtmlDecode(txt);
            //    }

            //    if (this.Attribute == null && attributeTree != null)
            //    {
            //        string tmpAttributeText = string.Empty;
            //        if (this.Parent != null)
            //        {
            //            tmpAttributeText = RawlerBase.GetText(this.Parent.Text, attributeTree,this);

            //        }
            //        data.DataWrite(tmpAttributeText, txt, writeType,AttributeType);

            //    }
            //    else
            //    {
            //        if (this.Attribute != null)
            //        {
            //            data.DataWrite(this.Attribute, txt, writeType,AttributeType);
            //        }
            //        else
            //        {
            //            data.DataWrite(string.Empty, txt, writeType, AttributeType);
            //        }
            //    }

            //    //if (this.AttributeObjectName != null && this.AttributeObjectName.Length>0)
            //    //{
            //    //    var list = this.GetConectAllRawler().Where(n => n.Name == this.AttributeObjectName);
            //    //    if (list.Count() > 0)
            //    //    {
            //    //        data.DataWrite(list.First().Text, txt,writeType);
            //    //    }
            //    //    else
            //    //    {
            //    //        ReportManage.ErrReport(this, "AttributeObjectNameの指定が不正です。オブジェクトが見つかりませんでした。");
            //    //    }
            //    //}

            //}
            //else
            //{
            //    ReportManage.ErrReport(this,"書き込み先のDataオブジェクトが見つかりません。");
            //}
            this.RunChildren(runChildren);
        }