/// <summary> /// 直近の上流に指定の型があったら取得する。 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T GetUpperRawler <T>() where T : RawlerBase { T result = null; RawlerBase rawler = this.Parent; if (rawler != null) { while (true) { if (rawler is T) { result = rawler as T; break; } else if (rawler.Parent == null) { break; } else { rawler = rawler.Parent; } } } return(result); }
public RawlerBase GetUpperInterface <T>() { bool flag = false; RawlerBase rawler = this.Parent; while (true) { if (rawler == null) { break; } if (rawler is T) { flag = true; break; } else if (rawler.Parent == null) { break; } else { rawler = rawler.Parent; } } if (flag) { return(rawler); } else { return(null); } }
/// <summary> /// 指定したキーで上流のKeyValueStoreから値を取得する。 /// </summary> /// <param name="rawler"></param> /// <param name="key"></param> /// <returns></returns> public static string GetValueByKey(RawlerBase rawler, string key) { KeyValueStore[] r = null; if (ancestorKeyValueStoreDic.ContainsKey(rawler)) { ancestorKeyValueStoreDic[rawler].TryGetTarget(out r); } if (r == null) { r = rawler.GetAncestorRawler().OfType <KeyValueStore>().ToArray(); if (ancestorKeyValueStoreDic.ContainsKey(rawler)) { ancestorKeyValueStoreDic[rawler].SetTarget(r); } else { ancestorKeyValueStoreDic.Add(rawler, new WeakReference <KeyValueStore[]>(r)); } } string val = null; foreach (var item in r) { if (item.dic.ContainsKey(key)) { val = item.dic[key]; break; } } if (val == null) { ReportManage.ErrReport(rawler, "key:" + key + "が見つかりません"); } return(val); }
/// <summary> /// {key} という記法で上流のKeyValueの値を取得する。 /// </summary> /// <param name="text"></param> /// <param name="rawler"></param> /// <returns></returns> public static string Convert(this string text, RawlerBase rawler) { if (text == null) { return(null); } else { return(GetConvertStr(text, rawler)); // var text2 = text.Replace("[[", "&(").Replace("]]", "&)"); //// System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"\[\w*\]"); // foreach (var item in r.Matches(text).OfType<System.Text.RegularExpressions.Match>()) // { // var key = item.Value.Replace("[", "").Replace("]", ""); // var key1 = HeaderConvert(key, rawler); // if(key1.Length==0) // { // var val = KeyValueStore.GetValueByKey(rawler, key); // if (val.Length > 0) // { // text2 = text2.Replace(item.Value, val); // } // } // else // { // text2 = text2.Replace(item.Value, key1); // } // } // return text2.Replace("&(", "[").Replace("&)", "]"); } }
private static void AddReportEventArgs(RawlerBase sender, ReportEvnetArgs args) { if (sender != null) { var reportStock = sender.GetUpperRawler <ReportStock>(); if (reportStock != null) { reportStock.AddReport(args); return; } } if (args.IsErr) { if (stockErrReport) { reportList.Add(args); } } else { if (stockReport) { reportList.Add(args); } } }
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); }
/// <summary> /// クローンを作る /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parent"></param> /// <returns></returns> public virtual T Clone <T>(RawlerBase parent) where T : RawlerBase, new() { T clone = new T(); RawlerLib.ObjectLib.FildCopy(this as T, clone); clone.SetParent(parent); CloneEvent(clone); clone.Children.Clear(); foreach (var item in clone.GetType().GetProperties()) { if (item.PropertyType.IsSubclassOf(typeof(RawlerBase))) { var r = item.GetValue(this as T, null) as RawlerBase; item.SetValue(clone, r.Clone(), null); } //else if(item.PropertyType == typeof(RawlerCollection)) //{ // var col = item.GetValue(clone, null) as RawlerCollection; // col.Clear(); // foreach (var item2 in item.GetValue(this as T,null) as RawlerCollection) // { // col.Add(item2); // } //} } foreach (var item in this.Children) { var child = item.Clone(clone); clone.AddChildren(child); } return(clone); }
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); }
/// <summary> /// Dispose() /// </summary> public virtual void Dispose() { this.text = null; this.parent = null; this.children = null; this.commnet = null; this.preTree = null; }
protected string GetFileName() { if (FileNameTree != null) { return(RawlerBase.GetText(this.GetText(), FileNameTree, this)); } return(this.FileName.Convert(this)); }
public override T Clone <T>(RawlerBase parent) { var obj = base.Clone <T>(parent); if (obj is RawlerMultiBase) { (obj as RawlerMultiBase).Query = this.Query.Clone(); } return(obj); }
public ReportEvnetArgs(RawlerBase sender, string message, bool returncode, bool isErr) : base() { // this.Sender = sender; this.Message = message; this.IsErr = isErr; this.DateTime = DateTime.Now; this.Visible = true; this.ReturnCode = returncode; }
public static string GetText(string text, RawlerBase rawler) { Document doc = new Document(); doc.SetText(text); rawler.SetParent(doc); var last = rawler.GetDescendantRawler().Last(); rawler.Run(); return(last.Text); }
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))); } }
private static string GetTopComment(RawlerBase sender) { if (visbleTopObjectComment) { return(sender.GetAncestorRawler().Last().Comment + ":"); } else { return(string.Empty); } }
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); } }
/// <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); } }
/// <summary> /// AddDataRowの共通呼び出し。 /// </summary> /// <param name="rawler"></param> /// <param name="datarow"></param> public static void AddDataRow(RawlerBase rawler, DataRowObject datarow) { var r = (IDataRows)rawler.GetUpperInterface <IDataRows>(); if (r != null) { r.AddDataRow(datarow); } else { ReportManage.ErrUpperNotFound <IDataRows>(rawler); } }
public override void Run(bool runChildren) { try { RawlerBase rawler = (RawlerBase)XamlServices.Load(FileName.Convert(this)); rawler.SetParent(this); rawler.Run(); } catch (Exception ex) { ReportManage.ErrReport(this, ex.ToString()); } }
/// <summary> /// DataWriteの共通呼び出し /// </summary> /// <param name="rawler"></param> /// <param name="attribute"></param> /// <param name="value"></param> /// <param name="type"></param> /// <param name="attributeType"></param> public static void DataWrite(RawlerBase rawler, string attribute, string value, DataWriteType type, DataAttributeType attributeType) { var d = (IData)rawler.GetUpperInterface <IData>(); if (d != null) { d.DataWrite(attribute, value, type, attributeType); } else { ReportManage.ErrUpperNotFound <IData>(rawler); } }
public static void Report(RawlerBase sender, string message, bool returncode) { ReportEvnetArgs args = new ReportEvnetArgs(sender, GetTopComment(sender) + message, returncode); AddReportEventArgs(sender, args); if (message.Contains("NextDataRow")) { RowCount++; } else { ReportEvnet?.Invoke(sender, args); } }
/// <summary> /// 指定したキーが上流のKeyValueStoreにあるかを調べる /// </summary> /// <param name="rawler"></param> /// <param name="keys"></param> /// <returns></returns> public static bool ContainsKey(RawlerBase rawler, params string[] keys) { var r = rawler.GetUpperRawler <KeyValueStore>(); if (r != null) { return(keys.All((n) => r.dic.ContainsKey(n))); } else { ReportManage.ErrUpperNotFound <KeyValueStore>(rawler); } return(false); }
/// <summary> /// Errをレポートする。 /// </summary> /// <param name="sender"></param> /// <param name="err"></param> public static void ErrReport(RawlerBase sender, string err) { ReportEvnetArgs args; if (sender != null) { args = new ReportEvnetArgs(sender, GetTopComment(sender) + "ERR:" + sender.GetType().Name + ":" + err, true, true); } else { args = new ReportEvnetArgs(sender, GetTopComment(sender) + "ERR:" + err, true, true); } AddReportEventArgs(sender, args); ErrReportEvent?.Invoke(sender, args); }
/// <summary> /// クローンを作る /// </summary> /// <param name="parent"></param> /// <returns></returns> public virtual RawlerBase Clone(RawlerBase parent) { RawlerBase clone = new RawlerBase(); RawlerLib.ObjectLib.FildCopy(this, clone); clone.SetParent(parent); CloneEvent(clone); clone.Children.Clear(); foreach (var item in this.Children) { var child = item.Clone(clone); clone.AddChildren(child); } return(clone); }
/// <summary> /// クローンを作る。 /// </summary> /// <param name="parent"></param> /// <returns></returns> public override RawlerBase Clone(RawlerBase parent) { return(base.Clone <GetScriptVariable>(parent)); //var clone = new GetScriptVariable(); //RawlerLib.ObjectLib.FildCopy(this, clone); //clone.SetParent(parent); //this.CloneEvent(clone); //clone.children.Clear(); //foreach (var item in this.Children) //{ // var child = item.Clone(clone); // clone.AddChildren(child); //} //return clone; }
/// <summary> /// 自身を含む、すべての祖先を取得する。 /// </summary> /// <returns></returns> public IEnumerable <RawlerBase> GetAncestorRawler() { List <RawlerBase> list = new List <RawlerBase>(); Queue <RawlerBase> queueRawler = new Queue <RawlerBase>(); queueRawler.Enqueue(this); while (queueRawler.Count > 0) { RawlerBase tmp = queueRawler.Dequeue(); list.Add(tmp); if (tmp.Parent != null) { queueRawler.Enqueue(tmp.Parent); } } return(list); }
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); } }
/// <summary> /// 自身を含む、すべての子、孫を取得する。 /// </summary> /// <returns></returns> public IEnumerable <RawlerBase> GetDescendantRawler() { List <RawlerBase> list = new List <RawlerBase>(); Queue <RawlerBase> queueRawler = new Queue <RawlerBase>(); queueRawler.Enqueue(this); while (queueRawler.Count > 0) { RawlerBase tmp = queueRawler.Dequeue(); list.Add(tmp); foreach (var item in tmp.Children) { queueRawler.Enqueue(item); } } return(list); }
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); } } }
/// <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); }