示例#1
0
 public async  override Task Run (IJubenRunningControler  runningMen,   Action completed, string logTitle)
 {
    await  base.Run(runningMen, completed,logTitle);
    runningMen.CallScript(GetScript());
    if(completed != null)
     completed(); 
 }
示例#2
0
        public async  override Task Run (IJubenRunningControler runningMen,  Action completed, string logTitle)
        {
           await base.Run(runningMen, null,logTitle );
            
            try
            {
                var doc = runningMen.GetHtmlDocument();
           
               //var ex = (System.Runtime.InteropServices.Expando.IExpando)doc;
               //var proName =  string.Format("TakeValue_{0}", this.GetHashCode());
               //var piform = ex.AddProperty(proName);
               //piform.SetValue(browser.Document , this, null);
               //var fullScript = string.Format(@"function TakeData{2}() {{ {1}  }} document.{0}.Value = TakeData{2}();", proName, Script, runningMen.GetHashCode());
               //browser.CallScript(fullScript);

               var proName = string.Format("TakeValue_{0}", this.GetHashCode());
               var script = string.Format(@"function TakeData{2}() {{ {1}  }} 
document.{0} = TakeData{2}();", proName, Script, runningMen.GetHashCode());
                 
                runningMen.RecordLog(logTitle +  this.ToString() + "\t" + script , LogLevel.Debug);
                runningMen.CallScript(script);
               var value = doc.GetType().InvokeMember(proName, BindingFlags.GetProperty, null, doc, new object[] { });
                if(IsSummarize)
                {
                    var oldValue = runningMen.GetValue(Key);
                    int oldCount = string.IsNullOrEmpty(runningMen.GetValue(Key))?0: Convert.ToInt32(oldValue);
                    oldCount += Convert.ToInt32(value);
                    runningMen.SetValue(Key, oldCount.ToString());
                }else
                    runningMen.SetValue(Key, value == null ?"" : value.ToString());
 
                    runningMen.RecordLog( string.Format( "提取到[{0}]={1}",Key,value), LogLevel.Info);
               
            } catch(Exception e)
            {
                runningMen.RecordLog(string.Format("提取[{0}]异常:{1}", Key, e), LogLevel.Error); 
                throw;
            }

           completed();
 
        }