コード例 #1
0
        public ActionResult Create(Instruction instruction)
        {
            if (ModelState.IsValid)
            {
                ManageSchedule(instruction);
                db.Instructions.Add(instruction);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(instruction);
        }
コード例 #2
0
 public ActionResult Edit(Instruction instruction)
 {
     if (ModelState.IsValid)
     {
         ManageSchedule(instruction);
         db.Entry(instruction).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(instruction);
 }
コード例 #3
0
ファイル: Crawler.cs プロジェクト: arturcp/ContentHunter
        private void SaveAndIndexResults(ContextResult context, Instruction instruction)
        {
            Crawler crawler = instruction.GetEngine();

            if (crawler.IsCustomSaved)
                crawler.CustomSave(context);
            else
            {
                List<CrawlerResult> toSave = new List<CrawlerResult>();
                foreach (var result in context.Results)
                {
                    if (!ContentExists(result.Url))
                    {
                        db.CrawlerResults.Add(result);
                        toSave.Add(result);
                    }
                }

                if (toSave.Count > 0)
                {
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                string p = validationError.PropertyName;
                                string e = validationError.ErrorMessage;
                                //Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                            }
                        }
                    }
                    Index(toSave);
                }
            }

            if (instruction.IsRecursive)
            {
                Instruction recursiveInstruction = (Instruction)instruction.Clone();
                recursiveInstruction.IsOriginal = false;
                foreach (string link in context.CandidatesToRecursion)
                {
                    recursiveInstruction.Url = link;
                    Execute(recursiveInstruction);
                }
            }
        }
コード例 #4
0
 private void ManageSchedule(Instruction instruction)
 {
     if (SafeConvert.ToBool(Request["schedule"]))
         instruction.Schedule();
     else
     {
         instruction.FrequencyUnit = 0;
         instruction.FrequencyValue = 0;
         instruction.ScheduledTo = null;
         instruction.Unschedule();
     }
 }
コード例 #5
0
ファイル: Crawler.cs プロジェクト: arturcp/ContentHunter
 private void InitializeInstructionExecution(Instruction instruction)
 {
     if (instruction.IsOriginal)
     {
         instruction.StartedAt = DateTime.Now;
         instruction.State = true;
         db.Entry(instruction).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
コード例 #6
0
ファイル: Crawler.cs プロジェクト: arturcp/ContentHunter
 private void FinalizeInstructionExecution(Instruction instruction)
 {
     if (instruction.IsOriginal)
     {
         instruction.FinishedAt = DateTime.Now;
         instruction.State = false;
         db.Entry(instruction).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
         }
         catch (DbEntityValidationException dbEx)
         {
             foreach (var validationErrors in dbEx.EntityValidationErrors)
             {
                 foreach (var validationError in validationErrors.ValidationErrors)
                 {
                     string p = validationError.PropertyName;
                     string e = validationError.ErrorMessage;
                     //Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                 }
             }
         }
     }
 }
コード例 #7
0
ファイル: Crawler.cs プロジェクト: arturcp/ContentHunter
 private ContextResult ExecuteByType(Instruction instruction)
 {
     this.VisitedLinks.Add(instruction.Url);
     Models.Instruction.InputType type = (Models.Instruction.InputType)instruction.Type;
     ContextResult output = null;
     if (type == Models.Instruction.InputType.Html)
         output = this.ParseHtml(instruction);
     else if (type == Models.Instruction.InputType.Rss)
         output = this.ParseRss(instruction);
     else if (type == Models.Instruction.InputType.Xml)
         output = this.ParseXml(instruction);
     return output;
 }
コード例 #8
0
ファイル: Crawler.cs プロジェクト: arturcp/ContentHunter
        private ContextResult Execute(Instruction instruction)
        {
            //cannot execute if it is not recurrent and it was already run
            ContextResult context = new ContextResult();

            if (instruction != null)
            {
                InitializeInstructionExecution(instruction);

                try
                {
                    context = ExecuteByType(instruction);
                }
                catch
                {
                    int i = 0;
                    //Log events
                }

                SaveAndIndexResults(context, instruction);
                FinalizeInstructionExecution(instruction);
            }

            return context;
        }
コード例 #9
0
ファイル: Crawler.cs プロジェクト: arturcp/ContentHunter
 public abstract ContextResult ParseXml(Instruction instruction);