public ActionResult Create(Instruction instruction) { if (ModelState.IsValid) { ManageSchedule(instruction); db.Instructions.Add(instruction); db.SaveChanges(); return RedirectToAction("Index"); } return View(instruction); }
public ActionResult Edit(Instruction instruction) { if (ModelState.IsValid) { ManageSchedule(instruction); db.Entry(instruction).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(instruction); }
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); } } }
private void ManageSchedule(Instruction instruction) { if (SafeConvert.ToBool(Request["schedule"])) instruction.Schedule(); else { instruction.FrequencyUnit = 0; instruction.FrequencyValue = 0; instruction.ScheduledTo = null; instruction.Unschedule(); } }
private void InitializeInstructionExecution(Instruction instruction) { if (instruction.IsOriginal) { instruction.StartedAt = DateTime.Now; instruction.State = true; db.Entry(instruction).State = EntityState.Modified; db.SaveChanges(); } }
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); } } } } }
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; }
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; }
public abstract ContextResult ParseXml(Instruction instruction);