Exemplo n.º 1
0
 //
 //====================================================================================================
 /// <summary>
 /// Add a user to a group with an expiration date
 /// </summary>
 /// <param name="core"></param>
 /// <param name="group"></param>
 /// <param name="user"></param>
 /// <param name="dateExpires"></param>
 public static void addUser(CoreController core, GroupModel group, PersonModel user, DateTime dateExpires)
 {
     try {
         var ruleList = DbBaseModel.createList <MemberRuleModel>(core.cpParent, "(MemberID=" + user.id.ToString() + ")and(GroupID=" + group.id.ToString() + ")");
         if (ruleList.Count == 0)
         {
             // -- add new rule
             var rule = DbBaseModel.addDefault <MemberRuleModel>(core.cpParent, Models.Domain.ContentMetadataModel.getDefaultValueDict(core, "groups"));
             rule.groupId     = group.id;
             rule.memberId    = user.id;
             rule.dateExpires = dateExpires;
             rule.save(core.cpParent);
             return;
         }
         // at least one rule found, set expire date, delete the rest
         var ruleFirst = ruleList.First();
         if (ruleFirst.dateExpires != dateExpires)
         {
             ruleFirst.dateExpires = dateExpires;
             ruleFirst.save(core.cpParent);
         }
         if (ruleList.Count > 1)
         {
             foreach (var rule in ruleList)
             {
                 if (!rule.Equals(ruleFirst))
                 {
                     DbBaseModel.delete <MemberRuleModel>(core.cpParent, rule.id);
                 }
             }
         }
     } catch (Exception ex) {
         LogController.logError(core, ex);
     }
 }
 //
 //====================================================================================================
 /// <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 + "]");
     }
 }
Exemplo n.º 3
0
 //
 //====================================================================================================
 //
 public override void DeleteContent(string contentName)
 {
     DbBaseModel.delete <ContentModel>(cp, ContentMetadataModel.getContentId(cp.core, contentName));
 }
Exemplo n.º 4
0
 //====================================================================================================
 /// <summary>
 /// dispose.
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         this.disposed = true;
         if (disposing)
         {
             //
             // call .dispose for managed objects
             //
             // ----- Block all output from underlying routines
             //
             doc.blockExceptionReporting = true;
             doc.continueProcessing      = false;
             //
             // content server object is valid
             //
             if (serverConfig != null)
             {
                 if (appConfig != null)
                 {
                     if (appConfig.appStatus == AppConfigBaseModel.AppStatusEnum.ok)
                     {
                         if (deleteSessionOnExit)
                         {
                             if ((session != null))
                             {
                                 if ((session.visit != null) && (session.visit.id > 0))
                                 {
                                     //
                                     // -- delete visit
                                     visitProperty.deleteAll(session.user.id);
                                     DbBaseModel.delete <VisitModel>(cpParent, session.visit.id);
                                     //
                                     // -- delete viewing
                                     DbBaseModel.deleteRows <ViewingModel>(cpParent, "(visitId=" + session.visit.id + ")");
                                 }
                                 if ((session.visitor != null) && (session.visitor.id > 0))
                                 {
                                     //
                                     // -- delete visitor
                                     visitorProperty.deleteAll(session.user.id);
                                     DbBaseModel.delete <VisitorModel>(cpParent, session.visit.id);
                                 }
                             }
                         }
                         if (!deleteSessionOnExit && siteProperties.allowVisitTracking)
                         {
                             //
                             // If visit tracking, save the viewing record
                             //
                             string ViewingName = ((string)(session.visit.id + "." + session.visit.pageVisits)).left(10);
                             int    PageId      = 0;
                             if (_doc != null)
                             {
                                 if (doc.pageController.page != null)
                                 {
                                     PageId = doc.pageController.page.id;
                                 }
                             }
                             //
                             // -- convert requestForm to a name=value string for Db storage
                             string requestFormSerialized = GenericController.convertNameValueDictToREquestString(webServer.requestForm);
                             string pagetitle             = "";
                             if (!doc.htmlMetaContent_TitleList.Count.Equals(0))
                             {
                                 pagetitle = doc.htmlMetaContent_TitleList[0].content;
                             }
                             string sql = "insert into ccviewings ("
                                          + "Name,VisitId,MemberID,Host,Path,Page,QueryString,Form,Referer,DateAdded,StateOK,pagetime,Active,RecordID,ExcludeFromAnalytics,pagetitle,ccguid"
                                          + ")values("
                                          + " " + DbController.encodeSQLText(ViewingName)
                                          + "," + session.visit.id.ToString()
                                          + "," + session.user.id.ToString()
                                          + "," + DbController.encodeSQLText(webServer.requestDomain)
                                          + "," + DbController.encodeSQLText(webServer.requestPath)
                                          + "," + DbController.encodeSQLText(webServer.requestPage)
                                          + "," + DbController.encodeSQLText(webServer.requestQueryString.left(255))
                                          + "," + DbController.encodeSQLText(requestFormSerialized.left(255))
                                          + "," + DbController.encodeSQLText(webServer.requestReferrer.left(255))
                                          + "," + DbController.encodeSQLDate(doc.profileStartTime)
                                          + "," + DbController.encodeSQLBoolean(session.visitStateOk)
                                          + "," + doc.appStopWatch.ElapsedMilliseconds.ToString()
                                          + ",1"
                                          + "," + PageId.ToString()
                                          + "," + DbController.encodeSQLBoolean(webServer.pageExcludeFromAnalytics)
                                          + "," + DbController.encodeSQLText(pagetitle)
                                          + "," + DbController.encodeSQLText(doc.docGuid);
                             sql += ");";
                             Task.Run(() => db.executeNonQueryAsync(sql));
                         }
                     }
                 }
             }
             //
             // ----- dispose objects created here
             //
             if (_addon != null)
             {
                 _addon.Dispose();
                 _addon = null;
             }
             //
             if (_db != null)
             {
                 _db.Dispose();
                 _db = null;
             }
             //
             if (_cache != null)
             {
                 _cache.Dispose();
                 _cache = null;
             }
             //
             if (_db != null)
             {
                 _db.Dispose();
                 _db = null;
             }
             //
             _siteProperties  = null;
             _domains         = null;
             _docProperties   = null;
             _webServer       = null;
             _visitProperty   = null;
             _visitorProperty = null;
             _userProperty    = null;
         }
         //
         // cleanup non-managed objects
         //
     }
 }