Esempio n. 1
0
 public static void RegisterRoutes(RouteCollection routes)
 {
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
     //
     // -- add dynamic routes from Contensive add-ons and link-alias
     // -- these routes have no wildcards so add them first, before other routes
     //  --
     // -- the Contensive app can have any name, but the sitename included here as an option
     using (var cp = new  Contensive.Processor.CPClass(System.Web.Hosting.HostingEnvironment.SiteName)) {
         foreach (var kvp in cp.routeMap.routeDictionary)
         {
             try {
                 routes.MapRoute(
                     name: kvp.Value.virtualRoute,
                     url: kvp.Value.virtualRoute,
                     defaults: new { controller = "Home", action = "Contensive" }
                     );
             } catch (Exception ex) {
                 cp.Site.ErrorReport(ex, "Unexpected exception adding virtualRoute [" + kvp.Key + "]");
             }
         }
     }
     //
     routes.MapRoute(
         name: "Default",
         url: "{controller}/{action}/{id}",
         defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
         );
 }
 //
 //====================================================================================================
 /// <summary>
 /// run as single task from the cctasks table of an app, makred with a runnerGuid
 /// called from runTasks or from the cli in a different process
 /// when the task starts,
 /// saves the addons output to the task.filename
 /// </summary>
 public static void executeRunnerTasks(string appName, string runnerGuid)
 {
     try {
         using (var cp = new Contensive.Processor.CPClass(appName)) {
             try {
                 foreach (var task in DbBaseModel.createList <TaskModel>(cp, "(cmdRunner=" + DbController.encodeSQLText(runnerGuid) + ")and(datestarted is null)", "id"))
                 {
                     //
                     // -- trace log without core
                     LogController.log(cp.core, "taskRunner.runTask, runTask, task [" + task.name + "], cmdDetail [" + task.cmdDetail + "]", BaseClasses.CPLogBaseClass.LogLevel.Info);
                     //
                     DateTime dateStarted = cp.core.dateTimeNowMockable;
                     var      cmdDetail   = DeserializeObject <TaskModel.CmdDetailClass>(task.cmdDetail);
                     if (cmdDetail != null)
                     {
                         var addon = DbBaseModel.create <AddonModel>(cp, cmdDetail.addonId);
                         if (addon != null)
                         {
                             var context = new BaseClasses.CPUtilsBaseClass.addonExecuteContext {
                                 backgroundProcess     = true,
                                 addonType             = BaseClasses.CPUtilsBaseClass.addonContext.ContextSimple,
                                 argumentKeyValuePairs = cmdDetail.args,
                                 errorContextMessage   = "running task, addon [" + cmdDetail.addonId + "]"
                             };
                             string result = cp.core.addon.execute(addon, context);
                             if (!string.IsNullOrEmpty(result))
                             {
                                 //
                                 LogController.logTrace(cp.core, "executeRunnerTasks, result not empty, downloadId [" + task.resultDownloadId + "], result first 100 [" + (result.Length > 100 ? result.Substring(0, 100) : result) + "]");
                                 //
                                 // -- save output
                                 if (task.resultDownloadId > 0)
                                 {
                                     var download = DbBaseModel.create <DownloadModel>(cp, task.resultDownloadId);
                                     if (download != null)
                                     {
                                         //
                                         LogController.logTrace(cp.core, "executeRunnerTasks, download found, [id" + download.id + ", name:" + download.name + ", filename:" + download.filename + "]");
                                         //
                                         if (string.IsNullOrEmpty(download.name))
                                         {
                                             download.name = "Download";
                                         }
                                         download.resultMessage    = "Completed";
                                         download.filename.content = result;
                                         download.dateRequested    = dateStarted;
                                         download.dateCompleted    = cp.core.dateTimeNowMockable;
                                         download.save(cp);
                                     }
                                 }
                             }
                         }
                     }
                     task.dateCompleted = cp.core.dateTimeNowMockable;
                     DbBaseModel.delete <TaskModel>(cp, task.id);
                     //
                     // -- info log the task running - so info state will log for memory leaks
                     LogController.log(cp.core, "TaskRunner exit, task [" + task.name + "], cmdDetail [" + task.cmdDetail + "]", BaseClasses.CPLogBaseClass.LogLevel.Info);
                 }
             } catch (Exception exInner) {
                 LogController.log(cp.core, "TaskRunner exception, ex [" + exInner.ToString() + "]", BaseClasses.CPLogBaseClass.LogLevel.Error);
                 throw;
             }
         }
     } catch (Exception ex) {
         Console.WriteLine("Error: [" + ex + "]");
     }
 }
Esempio n. 3
0
 public ActionResult Contensive()
 {
     using (var cp = new Contensive.Processor.CPClass(System.Web.Hosting.HostingEnvironment.SiteName, System.Web.HttpContext.Current)) {
         return(Content(cp.executeRoute()));
     }
 }