// //============================================================================= /// <summary> /// A login form that can be added to any page. This is just form with no surrounding border, etc. /// </summary> /// <returns></returns> public static string getLoginForm(CoreController core, bool forceDefaultLoginForm = false) { string returnHtml = ""; try { int loginAddonId = 0; if (!forceDefaultLoginForm) { loginAddonId = core.siteProperties.getInteger("Login Page AddonID"); if (loginAddonId != 0) { // // -- Custom Login AddonModel addon = DbBaseModel.create <AddonModel>(core.cpParent, loginAddonId); CPUtilsBaseClass.addonExecuteContext executeContext = new CPUtilsBaseClass.addonExecuteContext { addonType = CPUtilsBaseClass.addonContext.ContextPage, errorContextMessage = "calling login form addon [" + loginAddonId + "] from internal method" }; returnHtml = core.addon.execute(addon, executeContext); if (string.IsNullOrEmpty(returnHtml)) { // // -- login successful, redirect back to this page (without a method) string QS = core.doc.refreshQueryString; QS = GenericController.modifyQueryString(QS, "method", ""); QS = GenericController.modifyQueryString(QS, "RequestBinary", ""); // return(core.webServer.redirect("?" + QS, "Login form success")); } } } if (loginAddonId == 0) { // // ----- When page loads, set focus on login username // returnHtml = getLoginForm_Default(core); } } catch (Exception ex) { LogController.logError(core, ex); throw; } return(returnHtml); }
// //============================================================================= /// <summary> /// Executes the current route. To determine the route: /// route can be from URL, or from routeOverride /// how to process route /// -- urlParameters - /urlParameter(0)/urlParameter(1)/etc. /// -- first try full url, then remove them from the left and test until last, try just urlParameter(0) /// ---- so url /a/b/c, with addon /a and addon /a/b -> would run addon /a/b /// /// </summary> /// <returns>The doc created by the default addon. (html, json, etc)</returns> public static string executeRoute(CoreController core, string routeOverride = "") { string result = ""; var sw = new Stopwatch(); sw.Start(); LogController.log(core, "CoreController executeRoute, enter", BaseClasses.CPLogBaseClass.LogLevel.Trace); try { if (core.appConfig != null) { // // -- test fix for 404 response during routing - could it be a response left over from processing before we are called core.webServer.setResponseStatus(WebServerController.httpResponseStatus200_Success); // // -- execute intercept methods first, like login, that run before the route that returns the page // -- intercept routes should be addons alos // // -- determine the route: try routeOverride string normalizedRoute = GenericController.normalizeRoute(routeOverride); if (string.IsNullOrEmpty(normalizedRoute)) { // // -- no override, try argument route (remoteMethodAddon=) normalizedRoute = GenericController.normalizeRoute(core.docProperties.getText(RequestNameRemoteMethodAddon)); if (string.IsNullOrEmpty(normalizedRoute)) { // // -- no override or argument, use the url as the route normalizedRoute = GenericController.normalizeRoute(core.webServer.requestPathPage.ToLowerInvariant()); } } // // -- legacy ajaxfn methods string AjaxFunction = core.docProperties.getText(RequestNameAjaxFunction); if (!string.IsNullOrEmpty(AjaxFunction)) { // // -- Need to be converted to Url parameter addons switch ((AjaxFunction)) { case ajaxGetFieldEditorPreferenceForm: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.GetFieldEditorPreference()).Execute(core.cpParent).ToString()); } case AjaxGetDefaultAddonOptionString: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.GetAjaxDefaultAddonOptionStringClass()).Execute(core.cpParent).ToString()); } case AjaxSetVisitProperty: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.SetAjaxVisitPropertyClass()).Execute(core.cpParent).ToString()); } case AjaxGetVisitProperty: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.GetAjaxVisitPropertyClass()).Execute(core.cpParent).ToString()); } case AjaxData: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.ProcessAjaxDataClass()).Execute(core.cpParent).ToString()); } case AjaxPing: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.GetOKClass()).Execute(core.cpParent).ToString()); } case AjaxOpenIndexFilter: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.OpenAjaxIndexFilterClass()).Execute(core.cpParent).ToString()); } case AjaxOpenIndexFilterGetContent: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.OpenAjaxIndexFilterGetContentClass()).Execute(core.cpParent).ToString()); } case AjaxCloseIndexFilter: { // // moved to Addons.AdminSite return((new Contensive.Processor.Addons.AdminSite.CloseAjaxIndexFilterClass()).Execute(core.cpParent).ToString()); } default: { // // -- unknown method, log warning return(string.Empty); } } } // // -- legacy email intercept methods if (core.docProperties.getInteger(rnEmailOpenFlag) > 0) { // // -- Process Email Open return((new Contensive.Processor.Addons.Primitives.OpenEmailClass()).Execute(core.cpParent).ToString()); } if (core.docProperties.getInteger(rnEmailClickFlag) > 0) { // // -- Process Email click, execute and continue (new Contensive.Processor.Addons.Primitives.ClickEmailClass()).Execute(core.cpParent).ToString(); } if (!string.IsNullOrWhiteSpace(core.docProperties.getText(rnEmailBlockRecipientEmail))) { // // -- Process Email block return((new Contensive.Processor.Addons.Primitives.BlockEmailClass()).Execute(core.cpParent).ToString()); } // // -- legacy form process methods string formType = core.docProperties.getText(core.docProperties.getText("ccformsn") + "type"); if (!string.IsNullOrEmpty(formType)) { // // set the meta content flag to show it is not needed for the head tag switch (formType) { case FormTypeAddonStyleEditor: { // result = (new Contensive.Processor.Addons.Primitives.ProcessAddonStyleEditorClass()).Execute(core.cpParent).ToString(); break; } case FormTypeAddonSettingsEditor: { // result = (new Contensive.Processor.Addons.Primitives.ProcessAddonSettingsEditorClass()).Execute(core.cpParent).ToString(); break; } case FormTypeSendPassword: { // result = (new Contensive.Processor.Addons.Primitives.processSendPasswordFormClass()).Execute(core.cpParent).ToString(); break; } case FormTypeLogin: case "l09H58a195": { // result = (new Contensive.Processor.Addons.Primitives.ProcessLoginDefaultClass()).Execute(core.cpParent).ToString(); break; } case FormTypeToolsPanel: { // result = (new Contensive.Processor.Addons.Primitives.processFormToolsPanelClass()).Execute(core.cpParent).ToString(); break; } case FormTypePageAuthoring: { // result = (new Contensive.Processor.Addons.Primitives.processFormQuickEditingClass()).Execute(core.cpParent).ToString(); break; } case FormTypeActiveEditor: { // result = (new Contensive.Processor.Addons.Primitives.ProcessActiveEditorClass()).Execute(core.cpParent).ToString(); break; } case FormTypeSiteStyleEditor: { // result = (new Contensive.Processor.Addons.Primitives.ProcessSiteStyleEditorClass()).Execute(core.cpParent).ToString(); break; } case FormTypeHelpBubbleEditor: { // result = (new Contensive.Processor.Addons.Primitives.processHelpBubbleEditorClass()).Execute(core.cpParent).ToString(); break; } case FormTypeJoin: { // result = (new Contensive.Processor.Addons.Primitives.processJoinFormClass()).Execute(core.cpParent).ToString(); break; } default: { break; } } } // // -- legacy methods= string HardCodedPage = core.docProperties.getText(RequestNameHardCodedPage); if (!string.IsNullOrEmpty(HardCodedPage)) { switch (GenericController.toLCase(HardCodedPage)) { case HardCodedPageLogout: { // // -- logout intercept (new Contensive.Processor.Addons.Primitives.ProcessLogoutMethodClass()).Execute(core.cpParent); // // -- redirect to the route without the method string routeWithoutQuery = modifyLinkQuery(core.webServer.requestUrlSource, "method", "", false); core.webServer.redirect(routeWithoutQuery, "Redirect to route without 'method' because login was successful."); return(string.Empty); } case HardCodedPageSendPassword: { // return((new Contensive.Processor.Addons.Primitives.ProcessSendPasswordMethodClass()).Execute(core.cpParent).ToString()); } case HardCodedPageResourceLibrary: { // return((new Contensive.Processor.Addons.Primitives.ProcessResourceLibraryMethodClass()).Execute(core.cpParent).ToString()); } case HardCodedPageLoginDefault: { // if (core.session.isAuthenticated) { // // -- if authenticated, redirect to the route without the method string routeWithoutQuery = modifyLinkQuery(core.webServer.requestUrlSource, "method", "", false); core.webServer.redirect(routeWithoutQuery, "Redirect to route without 'method' because login was successful."); return(string.Empty); } // // -- process the login method, or return the login form return((new Contensive.Processor.Addons.Primitives.ProcessLoginDefaultMethodClass()).Execute(core.cpParent).ToString()); } case HardCodedPageLogin: { // if (core.session.isAuthenticated) { // // -- if authenticated, redirect to the route without the method string routeWithoutQuery = modifyLinkQuery(core.webServer.requestUrlSource, "method", "", false); core.webServer.redirect(routeWithoutQuery, "Redirect to route without 'method' because login was successful."); return(string.Empty); } // // -- process the login method, or return the login form return((new Contensive.Processor.Addons.Primitives.ProcessLoginMethodClass()).Execute(core.cpParent).ToString()); } case HardCodedPageLogoutLogin: { // return((new Contensive.Processor.Addons.Primitives.ProcessLogoutLoginMethodClass()).Execute(core.cpParent).ToString()); } case HardCodedPageSiteExplorer: { // return((new Contensive.Processor.Addons.Primitives.ProcessSiteExplorerMethodClass()).Execute(core.cpParent).ToString()); } case HardCodedPageStatus: { // return((new Contensive.Processor.Addons.Diagnostics.StatusClass()).Execute(core.cpParent).ToString()); } case HardCodedPageRedirect: { // return((new Contensive.Processor.Addons.Primitives.ProcessRedirectMethodClass()).Execute(core.cpParent).ToString()); } case HardCodedPageExportAscii: { // return((new Contensive.Processor.Addons.Primitives.ProcessExportAsciiMethodClass()).Execute(core.cpParent).ToString()); } default: { break; } } } // // -- try route Dictionary (addons, admin, link forwards, link alias), from full route to first segment one at a time // -- so route /this/and/that would first test /this/and/that, then test /this/and, then test /this string routeTest = normalizedRoute; bool routeFound = false; int routeCnt = 100; do { routeFound = core.routeMap.routeDictionary.ContainsKey(routeTest); if (routeFound) { break; } if (routeTest.IndexOf("/") < 0) { break; } routeTest = routeTest.left(routeTest.LastIndexOf("/")); routeCnt -= 1; } while ((routeCnt > 0) && (!routeFound)); // // -- execute route if (routeFound) { RouteMapModel.RouteClass route = core.routeMap.routeDictionary[routeTest]; switch (route.routeType) { case RouteMapModel.RouteTypeEnum.admin: { // // -- admin site AddonModel addon = DbBaseModel.create <AddonModel>(core.cpParent, addonGuidAdminSite); if (addon == null) { LogController.logError(core, new GenericException("The admin site addon could not be found by guid [" + addonGuidAdminSite + "].")); return("The default admin site addon could not be found. Please run an upgrade on this application to restore default services (command line> cc -a appName -r )"); } else { return(core.addon.execute(addon, new CPUtilsBaseClass.addonExecuteContext { addonType = CPUtilsBaseClass.addonContext.ContextAdmin, errorContextMessage = "calling admin route [" + addonGuidAdminSite + "] during execute route method" })); } } case RouteMapModel.RouteTypeEnum.remoteMethod: { // // -- remote method AddonModel addon = core.addonCache.getAddonById(route.remoteMethodAddonId); if (addon == null) { LogController.logError(core, new GenericException("The addon for remoteMethodAddonId [" + route.remoteMethodAddonId + "] could not be opened.")); return(""); } else { CPUtilsBaseClass.addonExecuteContext executeContext = new CPUtilsBaseClass.addonExecuteContext { addonType = CPUtilsBaseClass.addonContext.ContextRemoteMethodJson, cssContainerClass = "", cssContainerId = "", hostRecord = new CPUtilsBaseClass.addonExecuteHostRecordContext { contentName = core.docProperties.getText("hostcontentname"), fieldName = "", recordId = core.docProperties.getInteger("HostRecordID") }, errorContextMessage = "calling remote method addon [" + route.remoteMethodAddonId + "] during execute route method" }; return(core.addon.execute(addon, executeContext)); } } case RouteMapModel.RouteTypeEnum.linkAlias: { // // - link alias // -- all the query string values have already been added to doc properties, so do not over write them. // -- consensus is that since the link alias (permalink, long-tail url, etc) comes first on the left, that the querystring should override // -- so http://www.mySite.com/My-Blog-Post?bid=9 means use the bid not the bid from the link-alias LinkAliasModel linkAlias = DbBaseModel.create <LinkAliasModel>(core.cpParent, route.linkAliasId); if (linkAlias != null) { // -- set the link alias page number, unless it has been overridden if (!core.docProperties.containsKey("bid")) { core.docProperties.setProperty("bid", linkAlias.pageId); } if (!string.IsNullOrWhiteSpace(linkAlias.queryStringSuffix)) { string[] keyValuePairs = linkAlias.queryStringSuffix.Split('&'); // -- iterate through all the key=value pairs foreach (var keyEqualsValue in keyValuePairs) { string[] keyValue = keyEqualsValue.Split('='); if (!string.IsNullOrEmpty(keyValue[0])) { if (!core.docProperties.containsKey(keyValue[0])) { if (keyValue.Length > 1) { core.docProperties.setProperty(keyValue[0], keyValue[1]); } else { core.docProperties.setProperty(keyValue[0], string.Empty); } } } } } } break; } case RouteMapModel.RouteTypeEnum.linkForward: { // // -- link forward LinkForwardModel linkForward = DbBaseModel.create <LinkForwardModel>(core.cpParent, route.linkForwardId); return(core.webServer.redirect(linkForward.destinationLink, "Link Forward #" + linkForward.id + ", " + linkForward.name)); } default: { break; } } } // // -- default route int defaultAddonId = 0; if (core.doc.domain != null) { defaultAddonId = core.doc.domain.defaultRouteId; } if (defaultAddonId == 0) { defaultAddonId = core.siteProperties.defaultRouteId; } if (defaultAddonId > 0) { // // -- default route is run if no other route is found, which includes the route=defaultPage (default.aspx) CPUtilsBaseClass.addonExecuteContext executeContext = new CPUtilsBaseClass.addonExecuteContext { addonType = CPUtilsBaseClass.addonContext.ContextPage, cssContainerClass = "", cssContainerId = "", hostRecord = new CPUtilsBaseClass.addonExecuteHostRecordContext { contentName = "", fieldName = "", recordId = 0 }, errorContextMessage = "calling default route addon [" + defaultAddonId + "] during execute route method" }; return(core.addon.execute(DbBaseModel.create <AddonModel>(core.cpParent, defaultAddonId), executeContext)); } // // -- no route LogController.logWarn(core, "executeRoute called with an unknown route [" + normalizedRoute + "], and no default route is set to handle it. Go to the admin site, open preferences and set a detault route. Typically this is Page Manager for websites or an authorization error for remote applications."); result = "<p>This site is not configured for website traffic. Please set the default route.</p>"; } } catch (Exception ex) { LogController.logError(core, ex); } finally { // if (core.doc.routeDictionaryChanges) { DefaultSite.configurationClass.loadRouteMap(cp))} LogController.log(core, "CoreController executeRoute, exit", BaseClasses.CPLogBaseClass.LogLevel.Trace); } return(result); }
// //============================================================================= /// <summary> /// editor for page content inline editing /// </summary> /// <param name="core"></param> /// <param name="rootPageId"></param> /// <param name="OrderByClause"></param> /// <param name="AllowPageList"></param> /// <param name="AllowReturnLink"></param> /// <param name="ArchivePages"></param> /// <param name="contactMemberID"></param> /// <param name="childListSortMethodId"></param> /// <param name="main_AllowChildListComposite"></param> /// <param name="ArchivePage"></param> /// <returns></returns> internal static string getQuickEditing(CoreController core) { string result = ""; try { int childListSortMethodId = core.doc.pageController.page.childListSortMethodId; int contactMemberId = core.doc.pageController.page.contactMemberId; int rootPageId = core.doc.pageController.pageToRootList.Last().id; core.html.addStyleLink("" + cdnPrefix + "quickEditor/styles.css", "Quick Editor"); // // -- First Active Record - Output Quick Editor form Models.Domain.ContentMetadataModel cdef = Models.Domain.ContentMetadataModel.createByUniqueName(core, PageContentModel.tableMetadata.contentName); var pageContentTable = DbBaseModel.create <TableModel>(core.cpParent, cdef.id); var editLock = WorkflowController.getEditLock(core, pageContentTable.id, core.doc.pageController.page.id); WorkflowController.recordWorkflowStatusClass authoringStatus = WorkflowController.getWorkflowStatus(core, PageContentModel.tableMetadata.contentName, core.doc.pageController.page.id); PermissionController.UserContentPermissions userContentPermissions = PermissionController.getUserContentPermissions(core, cdef); bool AllowMarkReviewed = DbBaseModel.containsField <PageContentModel>("DateReviewed"); string OptionsPanelAuthoringStatus = core.session.getAuthoringStatusMessage(false, editLock.isEditLocked, editLock.editLockByMemberName, encodeDate(editLock.editLockExpiresDate), authoringStatus.isWorkflowApproved, authoringStatus.workflowApprovedMemberName, authoringStatus.isWorkflowSubmitted, authoringStatus.workflowSubmittedMemberName, authoringStatus.isWorkflowDeleted, authoringStatus.isWorkflowInserted, authoringStatus.isWorkflowModified, authoringStatus.workflowModifiedByMemberName); // // Set Editing Authoring Control // WorkflowController.setEditLock(core, pageContentTable.id, core.doc.pageController.page.id); // // SubPanel: Authoring Status // string leftButtonCommaList = ""; leftButtonCommaList = leftButtonCommaList + "," + ButtonCancel; if (userContentPermissions.allowSave) { leftButtonCommaList = leftButtonCommaList + "," + ButtonSave + "," + ButtonOK; } if (userContentPermissions.allowDelete && (core.doc.pageController.pageToRootList.Count == 1)) { // // -- allow delete and not root page leftButtonCommaList = leftButtonCommaList + "," + ButtonDelete; } if (userContentPermissions.allowAdd) { leftButtonCommaList = leftButtonCommaList + "," + ButtonAddChildPage; } int page_ParentId = 0; if ((page_ParentId != 0) && userContentPermissions.allowAdd) { leftButtonCommaList = leftButtonCommaList + "," + ButtonAddSiblingPage; } if (AllowMarkReviewed) { leftButtonCommaList = leftButtonCommaList + "," + ButtonMarkReviewed; } if (!string.IsNullOrEmpty(leftButtonCommaList)) { leftButtonCommaList = leftButtonCommaList.Substring(1); leftButtonCommaList = core.html.getPanelButtons(leftButtonCommaList); } if (!core.doc.userErrorList.Count.Equals(0)) { result += "" + "\r<tr>" + cr2 + "<td colspan=2 class=\"qeRow\"><div class=\"qeHeadCon\">" + ErrorController.getUserError(core) + "</div></td>" + "\r</tr>"; } if (!userContentPermissions.allowSave) { result += "" + "\r<tr>" + cr2 + "<td colspan=\"2\" class=\"qeRow\">" + getQuickEditingBody(core, PageContentModel.tableMetadata.contentName, "", true, true, rootPageId, !userContentPermissions.allowSave, true, PageContentModel.tableMetadata.contentName, false, contactMemberId) + "</td>" + "\r</tr>"; } else { result += "" + "\r<tr>" + cr2 + "<td colspan=\"2\" class=\"qeRow\">" + getQuickEditingBody(core, PageContentModel.tableMetadata.contentName, "", true, true, rootPageId, !userContentPermissions.allowSave, true, PageContentModel.tableMetadata.contentName, false, contactMemberId) + "</td>" + "\r</tr>"; } result += "\r<tr>" + cr2 + "<td class=\"qeRow qeLeft\" style=\"padding-top:10px;\">Name</td>" + cr2 + "<td class=\"qeRow qeRight\">" + HtmlController.inputText_Legacy(core, "name", core.doc.pageController.page.name, 1, 0, "", false, !userContentPermissions.allowSave) + "</td>" + "\r</tr>" + ""; string pageList = " (there are no parent pages)"; // // ----- Parent pages // if (core.doc.pageController.pageToRootList.Count > 1) { pageList = "<ul class=\"qeListUL\"><li class=\"qeListLI\">Current Page</li></ul>"; foreach (PageContentModel testPage in Enumerable.Reverse(core.doc.pageController.pageToRootList)) { string pageCaption = testPage.name; if (string.IsNullOrEmpty(pageCaption)) { pageCaption = "no name #" + GenericController.encodeText(testPage.id); } pageCaption = "<a href=\"" + PageContentController.getPageLink(core, testPage.id, "") + "\">" + pageCaption + "</a>"; pageList = "<ul class=\"qeListUL\"><li class=\"qeListLI\">" + pageCaption + pageList + "</li></ul>"; } } result += "" + "\r<tr>" + cr2 + "<td class=\"qeRow qeLeft\" style=\"padding-top:26px;\">Parent Pages</td>" + cr2 + "<td class=\"qeRow qeRight\"><div class=\"qeListCon\">" + pageList + "</div></td>" + "\r</tr>"; // // ----- Child pages // AddonModel addon = DbBaseModel.create <AddonModel>(core.cpParent, addonGuidChildList); CPUtilsBaseClass.addonExecuteContext executeContext = new CPUtilsBaseClass.addonExecuteContext { addonType = CPUtilsBaseClass.addonContext.ContextPage, hostRecord = new CPUtilsBaseClass.addonExecuteHostRecordContext { contentName = PageContentModel.tableMetadata.contentName, fieldName = "", recordId = core.doc.pageController.page.id }, argumentKeyValuePairs = GenericController.convertQSNVAArgumentstoDocPropertiesList(core, core.doc.pageController.page.childListInstanceOptions), instanceGuid = PageChildListInstanceId, errorContextMessage = "calling child page addon in quick editing editor" }; pageList = core.addon.execute(addon, executeContext); if (GenericController.strInstr(1, pageList, "<ul", 1) == 0) { pageList = "(there are no child pages)"; } result += "\r<tr>" + cr2 + "<td class=\"qeRow qeLeft\" style=\"padding-top:36px;\">Child Pages</td>" + cr2 + "<td class=\"qeRow qeRight\"><div class=\"qeListCon\">" + pageList + "</div></td>" + "\r</tr>"; result = "" + "\r<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">" + GenericController.nop(result) + "\r</table>"; result = "" + leftButtonCommaList + result + leftButtonCommaList; result = core.html.getPanel(result); // // Form Wrapper // result += "" + HtmlController.inputHidden("Type", FormTypePageAuthoring) + HtmlController.inputHidden("ID", core.doc.pageController.page.id) + HtmlController.inputHidden("ContentName", PageContentModel.tableMetadata.contentName); result = HtmlController.formMultipart(core, result, core.webServer.requestQueryString, "", "ccForm"); result = "<div class=\"ccCon\">" + result + "</div>"; } catch (Exception ex) { LogController.logError(core, ex); } return(result); }
// //================================================================================================================= /// <summary> /// convert a single command in the command formats to call the execute /// </summary> private static string executeSingleCommand(CoreController core, string cmdSrc, CPUtilsBaseClass.addonContext Context) { try { // // accumulator gets the result of each cmd, then is passed to the next command to filter List <object> cmdCollection = null; Dictionary <string, object> cmdDef = null; Dictionary <string, object> cmdArgDef = new Dictionary <string, object>(); var json = new System.Web.Script.Serialization.JavaScriptSerializer(); // cmdSrc = cmdSrc.Trim(' '); string whiteChrs = Environment.NewLine + "\t "; bool trimming; do { trimming = false; int trimLen = cmdSrc.Length; if (trimLen > 0) { string leftChr = cmdSrc.left(1); string rightChr = cmdSrc.Substring(cmdSrc.Length - 1); if (GenericController.strInstr(1, whiteChrs, leftChr) != 0) { cmdSrc = cmdSrc.Substring(1); trimming = true; } if (GenericController.strInstr(1, whiteChrs, rightChr) != 0) { cmdSrc = cmdSrc.left(cmdSrc.Length - 1); trimming = true; } } } while (trimming); string CmdAccumulator = ""; if (!string.IsNullOrEmpty(cmdSrc)) { Dictionary <string, object> .KeyCollection dictionaryKeys = null; object itemObject = null; object itemVariant = null; Dictionary <string, object> cmdObject = null; // cmdCollection = new List <object>(); if ((cmdSrc.left(1) == "{") && (cmdSrc.Substring(cmdSrc.Length - 1) == "}")) { // // JSON is a single command in the form of an object, like: ( "import" : "test.html" ) // Dictionary <string, object> cmdDictionary; try { cmdDictionary = json.Deserialize <Dictionary <string, object> >(cmdSrc); } catch (Exception ex) { LogController.logError(core, ex); throw; } // dictionaryKeys = cmdDictionary.Keys; foreach (string KeyWithinLoop in dictionaryKeys) { if (cmdDictionary[KeyWithinLoop] != null) { cmdObject = new Dictionary <string, object>(); itemObject = cmdDictionary[KeyWithinLoop]; cmdObject.Add(KeyWithinLoop, itemObject); cmdCollection.Add(cmdObject); } else { cmdObject = new Dictionary <string, object>(); itemVariant = cmdDictionary[KeyWithinLoop]; cmdObject.Add(KeyWithinLoop, itemVariant); cmdCollection.Add(cmdObject); } } } else if ((cmdSrc.left(1) == "[") && (cmdSrc.Substring(cmdSrc.Length - 1) == "]")) { // // JSON is a command list in the form of an array, like: [ "clear" , { "import": "test.html" },{ "open" : "myfile.txt" }] // cmdCollection = json.Deserialize <List <object> >(cmdSrc); } else { // // a single text command without JSON wrapper, like // open myfile.html // open "myfile.html" // "open" "myfile.html" // "content box" // all other posibilities are syntax errors // string cmdText = cmdSrc.Trim(' '); string cmdArg = ""; if (cmdText.left(1) == "\"") { // // cmd is quoted // "open" // "Open" file // "Open" "file" // int Pos = GenericController.strInstr(2, cmdText, "\""); if (Pos <= 1) { throw new GenericException("Error parsing content command [" + cmdSrc + "], expected a close quote around position " + Pos); } else { if (Pos == cmdText.Length) { // // cmd like "open" // cmdArg = ""; cmdText = cmdText.Substring(1, Pos - 2); } else if (cmdText.Substring(Pos, 1) != " ") { // // syntax error, must be a space between cmd and argument // throw new GenericException("Error parsing content command [" + cmdSrc + "], expected a space between command and argument around position " + Pos); } else { cmdArg = (cmdText.Substring(Pos)).Trim(' '); cmdText = cmdText.Substring(1, Pos - 2); } } } else { // // no quotes, can be // open // open file // int Pos = GenericController.strInstr(1, cmdText, " "); if (Pos > 0) { cmdArg = cmdSrc.Substring(Pos); cmdText = (cmdSrc.left(Pos - 1)).Trim(' '); } } if (cmdArg.left(1) == "\"") { // // cmdarg is quoted // int Pos = GenericController.strInstr(2, cmdArg, "\""); if (Pos <= 1) { throw new GenericException("Error parsing JSON command list, expected a quoted command argument, command list [" + cmdSrc + "]"); } else { cmdArg = cmdArg.Substring(1, Pos - 2); } } if ((cmdArg.left(1) == "{") && (cmdArg.Substring(cmdArg.Length - 1) == "}")) { // // argument is in the form of an object, like: ( "text name": "my text" ) // object cmdDictionaryOrCollection = json.Deserialize <object>(cmdArg); string cmdDictionaryOrCollectionTypeName = cmdDictionaryOrCollection.GetType().FullName.ToLowerInvariant(); if (cmdDictionaryOrCollectionTypeName.left(37) != "system.collections.generic.dictionary") { throw new GenericException("Error parsing JSON command argument list, expected a single command, command list [" + cmdSrc + "]"); } else { // // create command array of one command // cmdCollection.Add(cmdDictionaryOrCollection); } cmdDef = new Dictionary <string, object> { { cmdText, cmdDictionaryOrCollection } }; cmdCollection = new List <object> { cmdDef }; } else { // // command and arguments are strings // cmdDef = new Dictionary <string, object> { { cmdText, cmdArg } }; cmdCollection = new List <object> { cmdDef }; } } // // execute the commands in the JSON cmdCollection // foreach (object cmd in cmdCollection) { // // repeat for all commands in the collection: // convert each command in the command array to a cmd string, and a cmdArgDef dictionary // each cmdStringOrDictionary is a command. It may be: // A - "command" // B - { "command" } // C - { "command" : "single-default-argument" } // D - { "command" : { "name" : "The Name"} } // E - { "command" : { "name" : "The Name" , "secondArgument" : "secondValue" } } // string cmdTypeName = cmd.GetType().FullName.ToLowerInvariant(); string cmdText = ""; if (cmdTypeName == "system.string") { // // case A & B, the cmdDef is a string // cmdText = (string)cmd; cmdArgDef = new Dictionary <string, object>(); } else if (cmdTypeName.left(37) == "system.collections.generic.dictionary") { // // cases C-E, (0).key=cmd, (0).value = argument (might be string or object) // cmdDef = (Dictionary <string, object>)cmd; if (cmdDef.Count != 1) { // // syntax error // } else { string cmdDefKey = cmdDef.Keys.First(); string cmdDefValueTypeName = cmdDef[cmdDefKey].GetType().FullName.ToLowerInvariant(); // // command is the key for these cases // cmdText = cmdDefKey; if (cmdDefValueTypeName == "system.string") { // // command definition with default argument // cmdArgDef = new Dictionary <string, object> { { "default", cmdDef[cmdDefKey] } }; } else if ((cmdDefValueTypeName == "dictionary") || (cmdDefValueTypeName == "dictionary(of string,object)") || (cmdTypeName.left(37) == "system.collections.generic.dictionary")) { cmdArgDef = (Dictionary <string, object>)cmdDef[cmdDefKey]; } else { // // syntax error, bad command // throw new GenericException("Error parsing JSON command list, , command list [" + cmdSrc + "]"); } } } else { // // syntax error // throw new GenericException("Error parsing JSON command list, , command list [" + cmdSrc + "]"); } // // execute the cmd with cmdArgDef dictionary // switch (GenericController.toLCase(cmdText)) { case "textbox": { // // Opens a textbox addon (patch for text box name being "text name" so it requies json)copy content record // // arguments // name: copy content record // default // name // CmdAccumulator = ""; string ArgName = ""; foreach (KeyValuePair <string, object> kvp in cmdArgDef) { switch (kvp.Key.ToLowerInvariant()) { case "name": case "default": ArgName = (string)kvp.Value; break; } } if (!string.IsNullOrEmpty(ArgName)) { CmdAccumulator = core.html.getContentCopy(ArgName, "copy content", core.session.user.id, true, core.session.isAuthenticated); } break; } case "opencopy": { // // Opens a copy content record // // arguments // name: layout record name // default // name // CmdAccumulator = ""; string ArgName = ""; foreach (KeyValuePair <string, object> kvp in cmdArgDef) { switch (kvp.Key.ToLowerInvariant()) { case "name": case "default": ArgName = (string)kvp.Value; break; } } if (!string.IsNullOrEmpty(ArgName)) { CmdAccumulator = core.html.getContentCopy(ArgName, "copy content", core.session.user.id, true, core.session.isAuthenticated); } break; } case "openlayout": { // // Opens a layout record // // arguments // name: layout record name // default // name // CmdAccumulator = ""; string ArgName = ""; foreach (KeyValuePair <string, object> kvp in cmdArgDef) { switch (kvp.Key.ToLowerInvariant()) { case "name": case "default": ArgName = (string)kvp.Value; break; } } if (!string.IsNullOrEmpty(ArgName)) { DataTable dt = core.db.executeQuery("select layout from ccLayouts where name=" + DbController.encodeSQLText(ArgName)); if (dt != null) { CmdAccumulator = GenericController.encodeText(dt.Rows[0]["layout"]); } dt.Dispose(); } break; } case "open": { // // Opens a file in the wwwPath // // arguments // name: filename // default // name // CmdAccumulator = ""; string ArgName = ""; foreach (KeyValuePair <string, object> kvp in cmdArgDef) { switch (kvp.Key.ToLowerInvariant()) { case "name": case "default": ArgName = (string)kvp.Value; break; } } if (!string.IsNullOrEmpty(ArgName)) { CmdAccumulator = core.wwwFiles.readFileText(ArgName); } break; } case "userproperty": case "user": { CmdAccumulator = ""; string ArgName = ""; foreach (KeyValuePair <string, object> kvp in cmdArgDef) { switch (kvp.Key.ToLowerInvariant()) { case "name": case "default": ArgName = (string)kvp.Value; break; } } if (!string.IsNullOrEmpty(ArgName)) { CmdAccumulator = core.userProperty.getText(ArgName, ""); } break; } case "siteproperty": case "site": { // // returns a site property // // arguments // name: the site property name // default argument // name // CmdAccumulator = ""; string ArgName = ""; foreach (KeyValuePair <string, object> kvp in cmdArgDef) { switch (kvp.Key.ToLowerInvariant()) { case "name": case "default": { ArgName = (string)kvp.Value; break; } default: { // do nothing break; } } } if (!string.IsNullOrEmpty(ArgName)) { CmdAccumulator = core.siteProperties.getText(ArgName, ""); } break; } case "runaddon": case "executeaddon": case "addon": { // // execute an add-on // string addonName = ""; Dictionary <string, string> addonArgDict = new Dictionary <string, string>(); foreach (KeyValuePair <string, object> kvp in cmdArgDef) { if (kvp.Key.ToLowerInvariant().Equals("addon")) { addonName = kvp.Value.ToString(); } else { addonArgDict.Add(kvp.Key, kvp.Value.ToString()); } } addonArgDict.Add("cmdAccumulator", CmdAccumulator); AddonModel addon = AddonModel.createByUniqueName(core.cpParent, addonName); var executeContext = new Contensive.BaseClasses.CPUtilsBaseClass.addonExecuteContext { addonType = Context, cssContainerClass = "", cssContainerId = "", hostRecord = new Contensive.BaseClasses.CPUtilsBaseClass.addonExecuteHostRecordContext { contentName = "", fieldName = "", recordId = 0 }, argumentKeyValuePairs = addonArgDict, errorContextMessage = "calling Addon [" + addonName + "] during content cmd execution" }; if (addon == null) { LogController.logError(core, new GenericException("Add-on [" + addonName + "] could not be found executing command in content [" + cmdSrc + "]")); } else { CmdAccumulator = core.addon.execute(addon, executeContext); } break; } default: { // // execute an add-on // string addonName = cmdText; Dictionary <string, string> addonArgDict = new Dictionary <string, string>(); foreach (KeyValuePair <string, object> kvp in cmdArgDef) { addonArgDict.Add(kvp.Key, kvp.Value.ToString()); } addonArgDict.Add("cmdAccumulator", CmdAccumulator); var executeContext = new CPUtilsBaseClass.addonExecuteContext { addonType = Context, cssContainerClass = "", cssContainerId = "", hostRecord = new CPUtilsBaseClass.addonExecuteHostRecordContext { contentName = "", fieldName = "", recordId = 0 }, argumentKeyValuePairs = addonArgDict, errorContextMessage = "calling Addon [" + addonName + "] during content cmd execution" }; AddonModel addon = AddonModel.createByUniqueName(core.cpParent, addonName); CmdAccumulator = core.addon.execute(addon, executeContext); break; } } } } // return(CmdAccumulator); } catch (Exception ex) { LogController.logError(core, ex); throw; } }