示例#1
0
        public IActionResult CreateAddons(AddonModel model, IFormFile AddonImage)
        {
            byte[] addonbytes;
            using (var ms = new MemoryStream())
            {
                AddonImage.CopyTo(ms);
                addonbytes = ms.ToArray();
            }

            Addon addon = null;

            addon = new Addon
            {
                AddonName   = model.AddonName,
                Price       = model.Price,
                Description = model.Description,
                AddonImage  = addonbytes,
                Status      = model.Status
            };
            _addonService.InsertAddon(addon);

            AddNotification(NotificationMessage.TitleSuccess, NotificationMessage.msgAddAddon, NotificationMessage.TypeSuccess);


            return(RedirectToAction("ListAddons"));
        }
示例#2
0
 public override string ExecuteAddonAsProcess(string addonIDGuidOrName)
 {
     try {
         AddonModel addon = null;
         if (addonIDGuidOrName.isNumeric())
         {
             addon = cp.core.addonCache.getAddonById(EncodeInteger(addonIDGuidOrName));
         }
         else if (GenericController.isGuid(addonIDGuidOrName))
         {
             addon = cp.core.addonCache.getAddonByGuid(addonIDGuidOrName);
         }
         else
         {
             addon = cp.core.addonCache.getAddonByName(addonIDGuidOrName);
         }
         if (addon != null)
         {
             cp.core.addon.executeAsync(addon);
         }
     } catch (Exception ex) {
         LogController.logError(cp.core, ex);
     }
     return(string.Empty);
 }
示例#3
0
        //
        //====================================================================================================
        /// <summary>
        /// getFieldEditorPreference remote method
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            string result = "";

            try {
                CoreController core = ((CPClass)cp).core;
                //
                core.doc.addRefreshQueryString(RequestNameHardCodedPage, HardCodedPageSiteExplorer);
                string LinkObjectName = core.docProperties.getText("LinkObjectName");
                if (!string.IsNullOrEmpty(LinkObjectName))
                {
                    //
                    // Open a page compatible with a dialog
                    //
                    core.doc.addRefreshQueryString("LinkObjectName", LinkObjectName);
                    core.html.addTitle("Site Explorer");
                    core.doc.setMetaContent(0, 0);
                    string copy = core.addon.execute(AddonModel.createByUniqueName(core.cpParent, "Site Explorer"), new CPUtilsBaseClass.addonExecuteContext {
                        addonType           = CPUtilsBaseClass.addonContext.ContextPage,
                        errorContextMessage = "processing site explorer response"
                    });
                    core.html.addScriptCode_onLoad("document.body.style.overflow='scroll';", "Site Explorer");
                    string htmlBodyTag = "<body class=\"container-fluid ccBodyAdmin ccCon\" style=\"overflow:scroll\">";
                    string htmlBody    = ""
                                         + GenericController.nop(core.html.getPanelHeader("Contensive Site Explorer")) + "\r<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td>"
                                         + GenericController.nop(copy) + "\r</td></tr></table>"
                                         + "";
                    result = core.html.getHtmlDoc(htmlBody, htmlBodyTag, false, false);
                    core.doc.continueProcessing = false;
                }
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex);
            }
            return(result);
        }
        //
        //====================================================================================================
        /// <summary>
        /// getFieldEditorPreference remote method
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            string result = "";

            try {
                CoreController core = ((CPClass)cp).core;
                //
                // save custom styles
                if (core.session.isAuthenticatedAdmin())
                {
                    int addonId = core.docProperties.getInteger("AddonID");
                    if (addonId > 0)
                    {
                        AddonModel styleAddon = DbBaseModel.create <AddonModel>(core.cpParent, addonId);
                        if (styleAddon.stylesFilename.content != core.docProperties.getText("CustomStyles"))
                        {
                            styleAddon.stylesFilename.content = core.docProperties.getText("CustomStyles");
                            styleAddon.save(core.cpParent);
                            //
                            // Clear Caches
                            //
                            DbBaseModel.invalidateCacheOfRecord <AddonModel>(core.cpParent, addonId);
                        }
                    }
                }
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex);
            }
            return(result);
        }
        //
        // ====================================================================================================

        public static string get(CPBaseClass cp, PageTemplateModel template)
        {
            try {
                string addonList = "";
                foreach (var rule in DbBaseModel.createList <AddonTemplateRuleModel>(cp, "(templateId=" + template.id + ")"))
                {
                    AddonModel addon = DbBaseModel.create <AddonModel>(cp, rule.addonId);
                    if (addon != null)
                    {
                        addonList += System.Environment.NewLine + "\t\t" + "<IncludeAddon name=\"" + addon.name + "\" guid=\"" + addon.ccguid + "\" />";
                    }
                }
                return(""
                       + System.Environment.NewLine + "\t" + "<Template"
                       + " name=\"" + System.Net.WebUtility.HtmlEncode(template.name) + "\""
                       + " guid=\"" + template.ccguid + "\""
                       + " issecure=\"" + GenericController.getYesNo(template.isSecure) + "\""
                       + " >"
                       + addonList
                       + System.Environment.NewLine + "\t\t" + "<BodyHtml>" + ExportController.tabIndent(cp, ExportController.EncodeCData(template.bodyHTML)) + "</BodyHtml>"
                       + System.Environment.NewLine + "\t" + "</Template>");
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex, "GetAddonNode");
                return(string.Empty);
            }
        }
        public IActionResult AddNewAddons(AddonModel model)
        {
            ResultModel resultModel = new ResultModel();

            try
            {
                Addon addon = null;
                addon = new Addon
                {
                    AddonName   = model.AddonName,
                    Price       = Convert.ToDecimal(model.Price),
                    Description = model.Description,
                    //AddonImage = addonbytes,
                    Status = model.Status
                };
                _addonServices.InsertAddon(addon);

                resultModel.Message  = ValidationMessages.Success;
                resultModel.Status   = 1;
                resultModel.Response = addon;
            }
            catch (Exception exp)
            {
                resultModel.Message  = exp.ToString();
                resultModel.Status   = 0;
                resultModel.Response = null;
            }

            return(Ok(resultModel));
        }
示例#7
0
        public ProductModel()
        {
            ProductTypeInfo           = new ProductTypeModel();
            this.AvailableProductType = new List <SelectListItem>();

            AddonInfo           = new AddonModel();
            this.AvailableAddon = new List <SelectListItem>();
        }
示例#8
0
 private void DeleteCmd_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     for (int index = LvAddons.SelectedItems.Count - 1; index >= 0; index--)
     {
         AddonModel item = (AddonModel)LvAddons.SelectedItems[index];
         if (DeleteAddon(Path.Combine(item.Path, item.Id)))
         {
             _addonList.Remove(item);
         }
     }
 }
示例#9
0
        public Window7()
        {
            InitializeComponent();
            PopulateAddons();
            DataContext          = new AddonModel();
            LvAddons.ItemsSource = _addonList;
            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(LvAddons.ItemsSource);

            view.Filter = UserFilter;
            TbSearch.Focus();
            Shared.ShowSnackBar(MainSnackbar);
        }
示例#10
0
 //
 //====================================================================================================
 /// <summary>
 /// add an addon to the internal store
 /// </summary>
 /// <param name="core"></param>
 /// <param name="addon"></param>
 private void add(CoreController core, AddonModel addon)
 {
     if (!dictIdAddon.ContainsKey(addon.id))
     {
         dictIdAddon.Add(addon.id, addon);
         if (string.IsNullOrEmpty(addon.ccguid))
         {
             addon.ccguid = GenericController.getGUID();
             addon.save(core.cpParent);
         }
         if (!dictGuidId.ContainsKey(addon.ccguid.ToLowerInvariant()))
         {
             dictGuidId.Add(addon.ccguid.ToLowerInvariant(), addon.id);
             if (string.IsNullOrEmpty(addon.name.Trim()))
             {
                 addon.name = "addon " + addon.id.ToString();
                 addon.save(core.cpParent);
             }
             if (!dictNameId.ContainsKey(addon.name.ToLowerInvariant()))
             {
                 dictNameId.Add(addon.name.ToLowerInvariant(), addon.id);
             }
         }
     }
     if ((addon.onBodyEnd) && (!onBodyEndIdList.Contains(addon.id)))
     {
         onBodyEndIdList.Add(addon.id);
     }
     if ((addon.onBodyStart) && (!onBodyStartIdList.Contains(addon.id)))
     {
         onBodyStartIdList.Add(addon.id);
     }
     if ((addon.onNewVisitEvent) && (!onNewVisitIdList.Contains(addon.id)))
     {
         onNewVisitIdList.Add(addon.id);
     }
     if ((addon.onPageEndEvent) && (!OnPageEndIdList.Contains(addon.id)))
     {
         OnPageEndIdList.Add(addon.id);
     }
     if ((addon.onPageStartEvent) && (!OnPageStartIdList.Contains(addon.id)))
     {
         OnPageStartIdList.Add(addon.id);
     }
     if ((addon.remoteMethod) && (!remoteMethodIdList.Contains(addon.id)))
     {
         remoteMethodIdList.Add(addon.id);
     }
     if (!string.IsNullOrWhiteSpace(addon.robotsTxt))
     {
         robotsTxt += Environment.NewLine + addon.robotsTxt;
     }
 }
示例#11
0
        public virtual IActionResult EditAddons(AddonModel admodel, bool continueEditing, IFormFile AddonImage)
        {
            try
            {
                byte[] addonbytes = null;
                using (var ms = new MemoryStream())
                {
                    try
                    {
                        AddonImage.CopyTo(ms);
                        addonbytes = ms.ToArray();
                    }
                    catch { }
                }

                var addon = _addonService.GetAddonById(admodel.Id);

                if (addon == null || addon.Deleted)
                {
                    //No producttype found with the specified id
                    return(RedirectToAction("ListAddons"));
                }

                addon.AddonName   = admodel.AddonName;
                addon.Price       = admodel.Price;
                addon.Description = admodel.Description;
                if (addonbytes == null)
                {
                    addon.AddonImage = addon.AddonImage;
                }
                else
                {
                    addon.AddonImage = addonbytes;
                }

                addon.Status = admodel.Status;

                _addonService.UpdateAddon(addon);
                AddNotification(NotificationMessage.TitleSuccess, NotificationMessage.msgEditAddon, NotificationMessage.TypeSuccess);
                return(RedirectToAction("ListAddons"));
            }
            catch (Exception e)
            {
                AddNotification(NotificationMessage.TypeError, NotificationMessage.ErrormsgEditAddon, NotificationMessage.TypeError);

                return(View(e));
            }
        }
示例#12
0
 //
 //====================================================================================================
 /// <summary>
 /// executes an addon with the name or guid provided, in the context specified.
 /// </summary>
 /// <param name="addonNameOrGuid"></param>
 /// <param name="addonContext"></param>
 /// <returns></returns>
 public string executeAddon(string addonNameOrGuid, CPUtilsBaseClass.addonContext addonContext = CPUtilsBaseClass.addonContext.ContextSimple)
 {
     try {
         if (GenericController.isGuid(addonNameOrGuid))
         {
             //
             // -- call by guid
             AddonModel addon = DbBaseModel.create <AddonModel>(core.cpParent, addonNameOrGuid);
             if (addon == null)
             {
                 throw new GenericException("Addon [" + addonNameOrGuid + "] could not be found.");
             }
             else
             {
                 return(core.addon.execute(addon, new CPUtilsBaseClass.addonExecuteContext {
                     addonType = addonContext,
                     errorContextMessage = "external call to execute addon [" + addonNameOrGuid + "]"
                 }));
             }
         }
         else
         {
             AddonModel addon = AddonModel.createByUniqueName(core.cpParent, addonNameOrGuid);
             if (addon != null)
             {
                 //
                 // -- call by name
                 return(core.addon.execute(addon, new CPUtilsBaseClass.addonExecuteContext {
                     addonType = addonContext,
                     errorContextMessage = "external call to execute addon [" + addonNameOrGuid + "]"
                 }));
             }
             else if (addonNameOrGuid.isNumeric())
             {
                 //
                 // -- compatibility - call by id
                 return(executeAddon(GenericController.encodeInteger(addonNameOrGuid), addonContext));
             }
             else
             {
                 throw new GenericException("Addon [" + addonNameOrGuid + "] could not be found.");
             }
         }
     } catch (Exception ex) {
         Site.ErrorReport(ex);
     }
     return(string.Empty);
 }
示例#13
0
        //
        //=============================================================================
        /// <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);
        }
示例#14
0
 //
 //====================================================================================================
 /// <summary>
 /// executes an addon with the id provided, in the context specified.
 /// </summary>
 /// <param name="addonId"></param>
 /// <param name="addonContext"></param>
 /// <returns></returns>
 public string executeAddon(int addonId, Contensive.BaseClasses.CPUtilsBaseClass.addonContext addonContext = Contensive.BaseClasses.CPUtilsBaseClass.addonContext.ContextSimple)
 {
     try {
         AddonModel addon = DbBaseModel.create <AddonModel>(core.cpParent, addonId);
         if (addon == null)
         {
             throw new GenericException("Addon [#" + addonId.ToString() + "] could not be found.");
         }
         else
         {
             return(core.addon.execute(addon, new CPUtilsBaseClass.addonExecuteContext {
                 addonType = addonContext,
                 errorContextMessage = "external call to execute addon [" + addonId + "]"
             }));
         }
     } catch (Exception ex) {
         Site.ErrorReport(ex);
     }
     return(string.Empty);
 }
        //
        //=============================================================================
        //   Print the manual query form
        //=============================================================================
        //
        private string GetForm_WebsiteFileManager(CoreController core)
        {
            string result = "";

            try {
                string     InstanceOptionString = "AdminLayout=1&filesystem=website files";
                AddonModel addon   = DbBaseModel.create <AddonModel>(core.cpParent, "{B966103C-DBF4-4655-856A-3D204DEF6B21}");
                string     Content = core.addon.execute(addon, new BaseClasses.CPUtilsBaseClass.addonExecuteContext {
                    addonType             = Contensive.BaseClasses.CPUtilsBaseClass.addonContext.ContextAdmin,
                    argumentKeyValuePairs = GenericController.convertQSNVAArgumentstoDocPropertiesList(core, InstanceOptionString),
                    instanceGuid          = "-2",
                    errorContextMessage   = "executing File Manager within website file manager"
                });
                string Description = "Manage files and folders within the Website's file area.";
                string ButtonList  = ButtonApply + "," + ButtonCancel;
                result = AdminUIController.getToolBody(core, "Website File Manager", ButtonList, "", false, false, Description, "", 0, Content);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
示例#16
0
        private async void DeleteCmd_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            int selCount = LvAddons.SelectedItems.Count;

            if (selCount > 20)
            {
                object result = await DialogHost.Show(
                    new GenYesNoUc($"Are you sure you want to delete {selCount} items?"), "RootDialog");

                if (result == null || result.ToString() != "Y")
                {
                    return;
                }
            }

            if (Process.GetProcessesByName("chrome").Length > 0)
            {
                object result = await DialogHost.Show(new ChromeProcessUc(), "RootDialog");

                if (result == null || result.ToString() != "Y")
                {
                    return;
                }
                CustomProc.KillAllProc("chrome");
            }

            for (int index = selCount - 1; index >= 0; index--)
            {
                AddonModel item = (AddonModel)LvAddons.SelectedItems[index];
                try
                {
                    Directory.Delete(Path.Combine(item.Path, item.Id), true);
                    _addonList.Remove(item);
                }
                catch
                {
                    //ignored
                }
            }
        }
示例#17
0
        public virtual IActionResult EditAddons(int id)
        {
            var addon = _addonService.GetAddonById(id);

            if (addon == null || addon.Deleted)
            {
                //No producttype found with the specified id
                return(RedirectToAction("ListAddons"));
            }

            //var model = new ProductTypeModel();
            var model = new AddonModel
            {
                AddonName   = addon.AddonName,
                Price       = addon.Price,
                Description = addon.Description,
                AddonImage  = addon.AddonImage,
                Status      = addon.Status,
            };


            return(View(model));
        }
示例#18
0
        public IActionResult AddNewAddonsByImage(AddonModel model, IFormFile AddonImage)
        {
            ResultModel resultModel = new ResultModel();

            try
            {
                byte[] addonbytes;
                using (var ms = new MemoryStream())
                {
                    AddonImage.CopyTo(ms);
                    addonbytes = ms.ToArray();
                }

                Addon addon = null;
                addon = new Addon
                {
                    AddonName   = model.AddonName,
                    Price       = Convert.ToDecimal(model.Price),
                    Description = model.Description,
                    AddonImage  = addonbytes,
                    Status      = model.Status
                };
                _addonServices.InsertAddon(addon);

                resultModel.Message  = ValidationMessages.Success;
                resultModel.Status   = 1;
                resultModel.Response = addon;
            }
            catch (Exception exp)
            {
                resultModel.Message  = exp.ToString();
                resultModel.Status   = 0;
                resultModel.Response = null;
            }

            return(Ok(resultModel));
        }
示例#19
0
        //
        //=============================================================================
        /// <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);
        }
示例#20
0
        //
        //=============================================================================
        /// <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 = "&nbsp;(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);
        }
示例#21
0
        public static string getEditorRow(CoreController core, ContentFieldMetadataModel field, AdminDataModel adminData, EditorEnvironmentModel editorEnv)
        {
            string whyReadOnlyMsg = "";

            Models.EditRecordModel editRecord = adminData.editRecord;
            object fieldValueObject           = editRecord.fieldsLc[field.nameLc].value;
            string fieldValue_text            = encodeText(fieldValueObject);
            int    fieldRows    = 1;
            string fieldHtmlId  = field.nameLc + field.id.ToString();
            string fieldCaption = field.caption;

            if (field.uniqueName)
            {
                fieldCaption = "&nbsp;**" + fieldCaption;
            }
            else
            {
                if (field.nameLc.ToLowerInvariant() == "email")
                {
                    if ((adminData.adminContent.tableName.ToLowerInvariant() == "ccmembers") && ((core.siteProperties.getBoolean("allowemaillogin", false))))
                    {
                        fieldCaption = "&nbsp;***" + fieldCaption;
                        editorEnv.needUniqueEmailMessage = true;
                    }
                }
            }
            if (field.required)
            {
                fieldCaption = "&nbsp;*" + fieldCaption;
            }
            adminData.formInputCount = adminData.formInputCount + 1;
            bool fieldForceReadOnly = false;

            //
            // Read only Special Cases
            if (editorEnv.isRootPage)
            {
                //
                // -- page content metadata, these are the special fields
                switch (GenericController.toLCase(field.nameLc))
                {
                case "active": {
                    //
                    // if active, it is read only -- if inactive, let them set it active.
                    fieldForceReadOnly = encodeBoolean(fieldValueObject);
                    if (fieldForceReadOnly)
                    {
                        whyReadOnlyMsg = "&nbsp;(disabled because you can not mark the landing page inactive)";
                    }
                    break;
                }

                case "dateexpires":
                case "pubdate":
                case "datearchive":
                case "blocksection":
                case "archiveparentid":
                case "hidemenu": {
                    //
                    // These fields are read only on landing pages
                    fieldForceReadOnly = true;
                    whyReadOnlyMsg     = "&nbsp;(disabled for the landing page)";
                    break;
                }

                case "allowinmenus":
                case "allowinchildlists": {
                    fieldValueObject   = "1";
                    fieldForceReadOnly = true;
                    whyReadOnlyMsg     = "&nbsp;(disabled for root pages)";
                }
                break;

                default: {
                    // do nothing
                    break;
                }
                }
            }
            //
            // Special Case - ccemail table Alloweid should be disabled if siteproperty AllowLinkLogin is false
            //
            if (GenericController.toLCase(adminData.adminContent.tableName) == "ccemail" && GenericController.toLCase(field.nameLc) == "allowlinkeid")
            {
                if (!(core.siteProperties.getBoolean("AllowLinkLogin", true)))
                {
                    fieldValueObject   = "0";
                    fieldForceReadOnly = true;
                    fieldValue_text    = "0";
                }
            }
            string     EditorString   = "";
            bool       editorReadOnly = (editorEnv.record_readOnly || field.readOnly || (editRecord.id != 0 && field.notEditable) || (fieldForceReadOnly));
            AddonModel editorAddon    = null;
            int        fieldTypeDefaultEditorAddonId = 0;
            var        fieldEditor = adminData.fieldTypeEditors.Find(x => (x.fieldTypeId == (int)field.fieldTypeId));

            if (fieldEditor != null)
            {
                fieldTypeDefaultEditorAddonId = (int)fieldEditor.editorAddonId;
                editorAddon = DbBaseModel.create <AddonModel>(core.cpParent, fieldTypeDefaultEditorAddonId);
            }
            bool useEditorAddon = false;

            if (editorAddon != null)
            {
                //
                //--------------------------------------------------------------------------------------------
                // ----- Custom Editor
                //--------------------------------------------------------------------------------------------
                //
                core.docProperties.setProperty("editorName", field.nameLc);
                core.docProperties.setProperty("editorValue", fieldValue_text);
                core.docProperties.setProperty("editorFieldId", field.id);
                core.docProperties.setProperty("editorFieldType", (int)field.fieldTypeId);
                core.docProperties.setProperty("editorReadOnly", editorReadOnly);
                core.docProperties.setProperty("editorWidth", "");
                core.docProperties.setProperty("editorHeight", "");
                if (field.fieldTypeId.isOneOf(CPContentBaseClass.FieldTypeIdEnum.HTML, CPContentBaseClass.FieldTypeIdEnum.HTMLCode, CPContentBaseClass.FieldTypeIdEnum.FileHTML, CPContentBaseClass.FieldTypeIdEnum.FileHTMLCode))
                {
                    //
                    // include html related arguments
                    core.docProperties.setProperty("editorAllowActiveContent", "1");
                    core.docProperties.setProperty("editorAddonList", editorEnv.editorAddonListJSON);
                    core.docProperties.setProperty("editorStyles", editorEnv.styleList);
                    core.docProperties.setProperty("editorStyleOptions", editorEnv.styleOptionList);
                }
                EditorString = core.addon.execute(editorAddon, new BaseClasses.CPUtilsBaseClass.addonExecuteContext {
                    addonType           = BaseClasses.CPUtilsBaseClass.addonContext.ContextEditor,
                    errorContextMessage = "field editor id:" + editorAddon.id
                });
                useEditorAddon = !string.IsNullOrEmpty(EditorString);
                if (useEditorAddon)
                {
                    //
                    // -- editor worked
                    editorEnv.formFieldList += "," + field.nameLc;
                }
                else
                {
                    //
                    // -- editor failed, determine if it is missing (or inactive). If missing, remove it from the members preferences
                    using (var csData = new CsModel(core)) {
                        if (!csData.openSql("select id from ccaggregatefunctions where id=" + editorAddon.id))
                        {
                            //
                            // -- missing, not just inactive
                            EditorString = "";
                            //
                            // load user's editor preferences to fieldEditorPreferences() - this is the editor this user has picked when there are >1
                            //   fieldId:addonId,fieldId:addonId,etc
                            //   with custom FancyBox form in edit window with button "set editor preference"
                            //   this button causes a 'refresh' action, reloads fields with stream without save
                            //
                            string tmpList  = core.userProperty.getText("editorPreferencesForContent:" + adminData.adminContent.id, "");
                            int    PosStart = GenericController.strInstr(1, "," + tmpList, "," + field.id + ":");
                            if (PosStart > 0)
                            {
                                int PosEnd = GenericController.strInstr(PosStart + 1, "," + tmpList, ",");
                                if (PosEnd == 0)
                                {
                                    tmpList = tmpList.left(PosStart - 1);
                                }
                                else
                                {
                                    tmpList = tmpList.left(PosStart - 1) + tmpList.Substring(PosEnd - 1);
                                }
                                core.userProperty.setProperty("editorPreferencesForContent:" + adminData.adminContent.id, tmpList);
                            }
                        }
                    }
                }
            }
            //
            // -- style for editor wrapper used to limit the width of some editors like integer
            string editorWrapperSyle = "";

            if (!useEditorAddon)
            {
                bool IsEmptyList = false;
                //string NonEncodedLink = null;
                //string EncodedLink = null;
                //
                // if custom editor not used or if it failed
                //
                if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.Redirect)
                {
                    //
                    // ----- Default Editor, Redirect fields (the same for normal/readonly/spelling)

                    EditorString = AdminUIEditorController.getRedirectEditor(core, field, adminData, editRecord, fieldValue_text, editorReadOnly, fieldHtmlId, field.required);
                    //string RedirectPath = core.appConfig.adminRoute;
                    //if (field.redirectPath != "") {
                    //    RedirectPath = field.redirectPath;
                    //}
                    //RedirectPath = RedirectPath + "?" + RequestNameTitleExtension + "=" + GenericController.encodeRequestVariable(" For " + editRecord.nameLc + adminData.titleExtension) + "&" + RequestNameAdminDepth + "=" + (adminData.ignore_legacyMenuDepth + 1) + "&wl0=" + field.redirectId + "&wr0=" + editRecord.id;
                    //if (field.redirectContentId != 0) {
                    //    RedirectPath = RedirectPath + "&cid=" + field.redirectContentId;
                    //} else {
                    //    RedirectPath = RedirectPath + "&cid=" + ((editRecord.contentControlId.Equals(0)) ? adminData.adminContent.id : editRecord.contentControlId);
                    //}
                    //if (editRecord.id == 0) {
                    //    EditorString += ("[available after save]");
                    //} else {
                    //    RedirectPath = GenericController.strReplace(RedirectPath, "'", "\\'");
                    //    EditorString += ("<a href=\"#\"");
                    //    EditorString += (" onclick=\" window.open('" + RedirectPath + "', '_blank', 'scrollbars=yes,toolbar=no,status=no,resizable=yes'); return false;\"");
                    //    EditorString += (">");
                    //    EditorString += ("Open in New Window</A>");
                    //}
                }
                else if (editorReadOnly)
                {
                    //
                    //--------------------------------------------------------------------------------------------
                    // ----- Display fields as read only
                    //--------------------------------------------------------------------------------------------
                    //
                    if (!string.IsNullOrEmpty(whyReadOnlyMsg))
                    {
                        whyReadOnlyMsg = "<span class=\"ccDisabledReason\">" + whyReadOnlyMsg + "</span>";
                    }
                    switch (field.fieldTypeId)
                    {
                    case CPContentBaseClass.FieldTypeIdEnum.Text:
                    case CPContentBaseClass.FieldTypeIdEnum.Link:
                    case CPContentBaseClass.FieldTypeIdEnum.ResourceLink: {
                        //
                        // ----- Text Type
                        EditorString            += AdminUIEditorController.getTextEditor(core, field.nameLc, fieldValue_text, editorReadOnly, fieldHtmlId);
                        editorEnv.formFieldList += "," + field.nameLc;
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Boolean: {
                        //
                        // ----- Boolean ReadOnly
                        EditorString            += AdminUIEditorController.getBooleanEditor(core, field.nameLc, GenericController.encodeBoolean(fieldValueObject), editorReadOnly, fieldHtmlId);
                        editorEnv.formFieldList += "," + field.nameLc;
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Lookup: {
                        //
                        // ----- Lookup, readonly
                        if (field.lookupContentId != 0)
                        {
                            EditorString             = AdminUIEditorController.getLookupContentEditor(core, field.nameLc, GenericController.encodeInteger(fieldValueObject), field.lookupContentId, ref IsEmptyList, editorReadOnly, fieldHtmlId, whyReadOnlyMsg, field.required, "");
                            editorEnv.formFieldList += "," + field.nameLc;
                            editorWrapperSyle        = "max-width:400px";
                        }
                        else if (field.lookupList != "")
                        {
                            EditorString             = AdminUIEditorController.getLookupListEditor(core, field.nameLc, encodeInteger(fieldValueObject), field.lookupList.Split(',').ToList(), editorReadOnly, fieldHtmlId, whyReadOnlyMsg, field.required);
                            editorEnv.formFieldList += "," + field.nameLc;
                            editorWrapperSyle        = "max-width:400px";
                        }
                        else
                        {
                            //
                            // -- log exception but dont throw
                            LogController.logWarn(core, new GenericException("Field [" + adminData.adminContent.name + "." + field.nameLc + "] is a Lookup field, but no LookupContent or LookupList has been configured"));
                            EditorString += "[Selection not configured]";
                        }
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Date: {
                        //
                        // ----- date, readonly
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getDateTimeEditor(core, field.nameLc, encodeDate(fieldValueObject), editorReadOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.MemberSelect: {
                        //
                        // ----- Member Select ReadOnly
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getMemberSelectEditor(core, field.nameLc, encodeInteger(fieldValueObject), field.memberSelectGroupId_get(core), field.memberSelectGroupName_get(core), editorReadOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.ManyToMany: {
                        //
                        //   Placeholder
                        EditorString = AdminUIEditorController.getManyToManyEditor(core, field, "field" + field.id, fieldValue_text, editRecord.id, editorReadOnly, whyReadOnlyMsg);
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Currency: {
                        //
                        // ----- Currency ReadOnly
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += (HtmlController.inputCurrency(core, field.nameLc, encodeNumber(fieldValue_text), fieldHtmlId, "text form-control", editorReadOnly, false));
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Float: {
                        //
                        // ----- double/number/float
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += (HtmlController.inputNumber(core, field.nameLc, encodeNumber(fieldValue_text), fieldHtmlId, "text form-control", editorReadOnly, false));
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.AutoIdIncrement:
                    case CPContentBaseClass.FieldTypeIdEnum.Integer: {
                        //
                        // ----- Others that simply print
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += (HtmlController.inputInteger(core, field.nameLc, encodeInteger(fieldValue_text), fieldHtmlId, "text form-control", editorReadOnly, false));
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.HTMLCode:
                    case CPContentBaseClass.FieldTypeIdEnum.FileHTMLCode: {
                        //
                        // edit html as html (see the code)
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += HtmlController.inputHidden(field.nameLc, fieldValue_text);
                        fieldRows     = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                        EditorString += HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, fieldRows, -1, fieldHtmlId, false, editorReadOnly, "form-control");
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.HTML:
                    case CPContentBaseClass.FieldTypeIdEnum.FileHTML: {
                        //
                        // ----- HTML types readonly
                        if (field.htmlContent)
                        {
                            //
                            // edit html as html (see the code)
                            editorEnv.formFieldList += "," + field.nameLc;
                            EditorString            += HtmlController.inputHidden(field.nameLc, fieldValue_text);
                            fieldRows     = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                            EditorString += HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, fieldRows, -1, fieldHtmlId, false, editorReadOnly, "form-control");
                        }
                        else
                        {
                            //
                            // edit html as wysiwyg readonly
                            editorEnv.formFieldList += "," + field.nameLc;
                            EditorString            += AdminUIEditorController.getHtmlEditor(core, field.nameLc, fieldValue_text, editorEnv.editorAddonListJSON, editorEnv.styleList, editorEnv.styleOptionList, editorReadOnly, fieldHtmlId);
                        }
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.LongText:
                    case CPContentBaseClass.FieldTypeIdEnum.FileText: {
                        //
                        // ----- LongText, TextFile
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += HtmlController.inputHidden(field.nameLc, fieldValue_text);
                        fieldRows     = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                        EditorString += HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, fieldRows, -1, fieldHtmlId, false, editorReadOnly, " form-control");
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.File: {
                        //
                        // ----- File ReadOnly
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getFileEditor(core, field.nameLc, fieldValue_text, field.readOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.FileImage: {
                        //
                        // ----- Image ReadOnly
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getImageEditor(core, field.nameLc, fieldValue_text, field.readOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        break;
                    }

                    default: {
                        //
                        // ----- Legacy text type -- not used unless something was missed
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += HtmlController.inputHidden(field.nameLc, fieldValue_text);
                        if (field.password)
                        {
                            //
                            // Password forces simple text box
                            EditorString += HtmlController.inputText_Legacy(core, field.nameLc, "*****", 0, 0, fieldHtmlId, true, true, "password form-control");
                        }
                        else if (!field.htmlContent)
                        {
                            //
                            // not HTML capable, textarea with resizing
                            if ((field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.Text) && (fieldValue_text.IndexOf("\n") == -1) && (fieldValue_text.Length < 40))
                            {
                                //
                                // text field shorter then 40 characters without a CR
                                EditorString += HtmlController.inputText_Legacy(core, field.nameLc, fieldValue_text, 1, 0, fieldHtmlId, false, true, "text form-control");
                            }
                            else
                            {
                                //
                                // longer text data, or text that contains a CR
                                EditorString += HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, 10, -1, fieldHtmlId, false, true, " form-control");
                            }
                        }
                        else if (field.htmlContent)
                        {
                            //
                            // HTMLContent true, and prefered
                            fieldRows     = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".PixelHeight", 500));
                            EditorString += core.html.getFormInputHTML(field.nameLc, fieldValue_text, "500", "", false, true, editorEnv.editorAddonListJSON, editorEnv.styleList, editorEnv.styleOptionList);
                            EditorString  = "<div style=\"width:95%\">" + EditorString + "</div>";
                        }
                        else
                        {
                            //
                            // HTMLContent true, but text editor selected
                            fieldRows     = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                            EditorString += HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, fieldRows, -1, fieldHtmlId, false, editorReadOnly);
                        }
                        break;
                    }
                    }
                }
                else
                {
                    //
                    // -- Not Read Only - Display fields as form elements to be modified
                    switch (field.fieldTypeId)
                    {
                    case CPContentBaseClass.FieldTypeIdEnum.Text: {
                        //
                        // ----- Text Type
                        if (field.password)
                        {
                            EditorString += AdminUIEditorController.getPasswordEditor(core, field.nameLc, fieldValue_text, false, fieldHtmlId);
                        }
                        else
                        {
                            EditorString += AdminUIEditorController.getTextEditor(core, field.nameLc, fieldValue_text, false, fieldHtmlId);
                        }
                        editorEnv.formFieldList += "," + field.nameLc;
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Boolean: {
                        //
                        // ----- Boolean
                        EditorString            += AdminUIEditorController.getBooleanEditor(core, field.nameLc, encodeBoolean(fieldValueObject), false, fieldHtmlId);
                        editorEnv.formFieldList += "," + field.nameLc;
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Lookup: {
                        //
                        // ----- Lookup
                        if (field.lookupContentId != 0)
                        {
                            EditorString             = AdminUIEditorController.getLookupContentEditor(core, field.nameLc, encodeInteger(fieldValueObject), field.lookupContentId, ref IsEmptyList, field.readOnly, fieldHtmlId, whyReadOnlyMsg, field.required, "");
                            editorEnv.formFieldList += "," + field.nameLc;
                            editorWrapperSyle        = "max-width:400px";
                        }
                        else if (field.lookupList != "")
                        {
                            EditorString             = AdminUIEditorController.getLookupListEditor(core, field.nameLc, encodeInteger(fieldValueObject), field.lookupList.Split(',').ToList(), field.readOnly, fieldHtmlId, whyReadOnlyMsg, field.required);
                            editorEnv.formFieldList += "," + field.nameLc;
                            editorWrapperSyle        = "max-width:400px";
                        }
                        else
                        {
                            //
                            // -- log exception but dont throw
                            LogController.logWarn(core, new GenericException("Field [" + adminData.adminContent.name + "." + field.nameLc + "] is a Lookup field, but no LookupContent or LookupList has been configured"));
                            EditorString += "[Selection not configured]";
                        }
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Date: {
                        //
                        // ----- Date
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getDateTimeEditor(core, field.nameLc, GenericController.encodeDate(fieldValueObject), field.readOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.MemberSelect: {
                        //
                        // ----- Member Select
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getMemberSelectEditor(core, field.nameLc, encodeInteger(fieldValueObject), field.memberSelectGroupId_get(core), field.memberSelectGroupName_get(core), field.readOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.ManyToMany: {
                        //
                        //   Placeholder
                        EditorString = AdminUIEditorController.getManyToManyEditor(core, field, "field" + field.id, fieldValue_text, editRecord.id, false, whyReadOnlyMsg);
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.File: {
                        //
                        // ----- File
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getFileEditor(core, field.nameLc, fieldValue_text, field.readOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.FileImage: {
                        //
                        // ----- Image ReadOnly
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getImageEditor(core, field.nameLc, fieldValue_text, field.readOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Currency: {
                        //
                        // ----- currency
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += AdminUIEditorController.getCurrencyEditor(core, field.nameLc, encodeNumberNullable(fieldValueObject), field.readOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Float: {
                        //
                        // ----- double/number/float
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += AdminUIEditorController.getNumberEditor(core, field.nameLc, encodeNumberNullable(fieldValueObject), field.readOnly, fieldHtmlId, field.required, whyReadOnlyMsg);
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.AutoIdIncrement:
                    case CPContentBaseClass.FieldTypeIdEnum.Integer: {
                        //
                        // ----- Others that simply print
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString            += (HtmlController.inputInteger(core, field.nameLc, encodeIntegerNullable(fieldValue_text), fieldHtmlId, "text form-control", editorReadOnly, false));
                        editorWrapperSyle        = "max-width:400px";
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.Link: {
                        //
                        // ----- Link (href value
                        //
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getLinkEditor(core, field.nameLc, fieldValue_text, editorReadOnly, fieldHtmlId, field.required);
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.ResourceLink: {
                        //
                        // ----- Resource Link (src value)
                        //
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getLinkEditor(core, field.nameLc, fieldValue_text, editorReadOnly, fieldHtmlId, field.required);
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.HTMLCode:
                    case CPContentBaseClass.FieldTypeIdEnum.FileHTMLCode: {
                        //
                        // View the content as Html, not wysiwyg
                        editorEnv.formFieldList += "," + field.nameLc;
                        EditorString             = AdminUIEditorController.getHtmlCodeEditor(core, field.nameLc, fieldValue_text, editorReadOnly, fieldHtmlId);
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.HTML:
                    case CPContentBaseClass.FieldTypeIdEnum.FileHTML: {
                        //
                        // content is html
                        editorEnv.formFieldList += "," + field.nameLc;
                        if (field.htmlContent)
                        {
                            //
                            // View the content as Html, not wysiwyg
                            EditorString = AdminUIEditorController.getHtmlCodeEditor(core, field.nameLc, fieldValue_text, editorReadOnly, fieldHtmlId);
                        }
                        else
                        {
                            //
                            // wysiwyg editor
                            EditorString = AdminUIEditorController.getHtmlEditor(core, field.nameLc, fieldValue_text, editorEnv.editorAddonListJSON, editorEnv.styleList, editorEnv.styleOptionList, editorReadOnly, fieldHtmlId);
                        }
                        //
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.LongText:
                    case CPContentBaseClass.FieldTypeIdEnum.FileText: {
                        //
                        // -- Long Text, use text editor
                        editorEnv.formFieldList += "," + field.nameLc;
                        fieldRows    = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                        EditorString = HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, fieldRows, -1, fieldHtmlId, false, false, "text form-control");
                        //
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.FileCSS: {
                        //
                        // ----- CSS field
                        editorEnv.formFieldList += "," + field.nameLc;
                        fieldRows    = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                        EditorString = HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, fieldRows, -1, fieldHtmlId, false, false, "styles form-control");
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.FileJavascript: {
                        //
                        // ----- Javascript field
                        editorEnv.formFieldList += "," + field.nameLc;
                        fieldRows    = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                        EditorString = HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, fieldRows, -1, fieldHtmlId, false, false, "text form-control");
                        //
                        break;
                    }

                    case CPContentBaseClass.FieldTypeIdEnum.FileXML: {
                        //
                        // ----- xml field
                        editorEnv.formFieldList += "," + field.nameLc;
                        fieldRows    = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                        EditorString = HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, fieldRows, -1, fieldHtmlId, false, false, "text form-control");
                        //
                        break;
                    }

                    default: {
                        //
                        // ----- Legacy text type -- not used unless something was missed
                        //
                        editorEnv.formFieldList += "," + field.nameLc;
                        if (field.password)
                        {
                            //
                            // Password forces simple text box
                            EditorString = HtmlController.inputText_Legacy(core, field.nameLc, fieldValue_text, -1, -1, fieldHtmlId, true, false, "password form-control");
                        }
                        else if (!field.htmlContent)
                        {
                            //
                            // not HTML capable, textarea with resizing
                            //
                            if ((field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.Text) && (fieldValue_text.IndexOf("\n", StringComparison.InvariantCulture) == -1) && (fieldValue_text.Length < 40))
                            {
                                //
                                // text field shorter then 40 characters without a CR
                                //
                                EditorString = HtmlController.inputText_Legacy(core, field.nameLc, fieldValue_text, 1, -1, fieldHtmlId, false, false, "text form-control");
                            }
                            else
                            {
                                //
                                // longer text data, or text that contains a CR
                                //
                                EditorString = HtmlController.inputTextarea(core, field.nameLc, fieldValue_text, 10, -1, fieldHtmlId, false, false, "text form-control");
                            }
                        }
                        else if (field.htmlContent)
                        {
                            //
                            // HTMLContent true, and prefered
                            //
                            if (string.IsNullOrEmpty(fieldValue_text))
                            {
                                //
                                // editor needs a starting p tag to setup correctly
                                //
                                fieldValue_text = HTMLEditorDefaultCopyNoCr;
                            }
                            fieldRows     = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".PixelHeight", 500));
                            EditorString += core.html.getFormInputHTML(field.nameLc, fieldValue_text, "500", "", false, true, editorEnv.editorAddonListJSON, editorEnv.styleList, editorEnv.styleOptionList);
                            EditorString  = "<div style=\"width:95%\">" + EditorString + "</div>";
                        }
                        else
                        {
                            //
                            // HTMLContent true, but text editor selected
                            fieldRows    = (core.userProperty.getInteger(adminData.adminContent.name + "." + field.nameLc + ".RowHeight", 10));
                            EditorString = HtmlController.inputTextarea(core, field.nameLc, HtmlController.encodeHtml(fieldValue_text), fieldRows, -1, fieldHtmlId, false, false, "text");
                        }
                        break;
                    }
                    }
                }
            }
            //
            // assemble the editor row
            return(AdminUIController.getEditRow(core, EditorString, fieldCaption, field.helpDefault, field.required, false, fieldHtmlId, editorWrapperSyle));
        }
示例#22
0
        //
        // ====================================================================================================
        /// <summary>
        /// create the colleciton zip file and return the pathFilename in the Cdn
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="collectionId"></param>
        /// <returns></returns>
        public static string createCollectionZip_returnCdnPathFilename(CPBaseClass cp, AddonCollectionModel collection)
        {
            string cdnExportZip_Filename = "";

            try {
                if ((collection == null))
                {
                    //
                    // -- exit with error
                    cp.UserError.Add("The collection you selected could not be found");
                    return(string.Empty);
                }
                using (CPCSBaseClass CS = cp.CSNew()) {
                    CS.OpenRecord("Add-on Collections", collection.id);
                    if (!CS.OK())
                    {
                        //
                        // -- exit with error
                        cp.UserError.Add("The collection you selected could not be found");
                        return(string.Empty);
                    }
                    string collectionXml  = "<?xml version=\"1.0\" encoding=\"windows-1252\"?>";
                    string CollectionGuid = CS.GetText("ccGuid");
                    if (CollectionGuid == "")
                    {
                        CollectionGuid = cp.Utils.CreateGuid();
                        CS.SetField("ccGuid", CollectionGuid);
                    }
                    string onInstallAddonGuid = "";
                    if ((CS.FieldOK("onInstallAddonId")))
                    {
                        int onInstallAddonId = CS.GetInteger("onInstallAddonId");
                        if ((onInstallAddonId > 0))
                        {
                            AddonModel addon = AddonModel.create <AddonModel>(cp, onInstallAddonId);
                            if ((addon != null))
                            {
                                onInstallAddonGuid = addon.ccguid;
                            }
                        }
                    }
                    string CollectionName = CS.GetText("name");
                    collectionXml        += System.Environment.NewLine + "<Collection";
                    collectionXml        += " name=\"" + CollectionName + "\"";
                    collectionXml        += " guid=\"" + CollectionGuid + "\"";
                    collectionXml        += " system=\"" + GenericController.getYesNo(CS.GetBoolean("system")) + "\"";
                    collectionXml        += " updatable=\"" + GenericController.getYesNo(CS.GetBoolean("updatable")) + "\"";
                    collectionXml        += " blockNavigatorNode=\"" + GenericController.getYesNo(CS.GetBoolean("blockNavigatorNode")) + "\"";
                    collectionXml        += " onInstallAddonGuid=\"" + onInstallAddonGuid + "\"";
                    collectionXml        += ">";
                    cdnExportZip_Filename = encodeFilename(cp, CollectionName + ".zip");
                    List <string> tempPathFileList = new List <string>();
                    string        tempExportPath   = "CollectionExport" + Guid.NewGuid().ToString() + @"\";
                    //
                    // --resource executable files
                    string        wwwFileList          = CS.GetText("wwwFileList");
                    string        ContentFileList      = CS.GetText("ContentFileList");
                    List <string> execFileList         = ExportResourceListController.getResourceFileList(cp, CS.GetText("execFileList"), CollectionGuid);
                    string        execResourceNodeList = ExportResourceListController.getResourceNodeList(cp, execFileList, CollectionGuid, tempPathFileList, tempExportPath);
                    //
                    // helpLink
                    //
                    if (CS.FieldOK("HelpLink"))
                    {
                        collectionXml += System.Environment.NewLine + "\t" + "<HelpLink>" + System.Net.WebUtility.HtmlEncode(CS.GetText("HelpLink")) + "</HelpLink>";
                    }
                    //
                    // Help
                    //
                    collectionXml += System.Environment.NewLine + "\t" + "<Help>" + System.Net.WebUtility.HtmlEncode(CS.GetText("Help")) + "</Help>";
                    //
                    // Addons
                    //
                    string IncludeSharedStyleGuidList = "";
                    string IncludeModuleGuidList      = "";
                    foreach (var addon in DbBaseModel.createList <AddonModel>(cp, "collectionid=" + collection.id))
                    {
                        //
                        // -- style sheet is in the wwwroot
                        if (!string.IsNullOrEmpty(addon.stylesLinkHref))
                        {
                            string filename = addon.stylesLinkHref.Replace("/", "\\");
                            if (filename.Substring(0, 1).Equals(@"\"))
                            {
                                filename = filename.Substring(1);
                            }
                            if (!cp.WwwFiles.FileExists(filename))
                            {
                                cp.WwwFiles.Save(filename, @"/* css file created as exported for addon [" + addon.name + "], collection [" + collection.name + "] in site [" + cp.Site.Name + "] */");
                            }
                            wwwFileList += System.Environment.NewLine + addon.stylesLinkHref;
                        }
                        //
                        // -- js is in the wwwroot
                        if (!string.IsNullOrEmpty(addon.jsHeadScriptSrc))
                        {
                            string filename = addon.jsHeadScriptSrc.Replace("/", "\\");
                            if (filename.Substring(0, 1).Equals(@"\"))
                            {
                                filename = filename.Substring(1);
                            }
                            if (!cp.WwwFiles.FileExists(filename))
                            {
                                cp.WwwFiles.Save(filename, @"// javascript file created as exported for addon [" + addon.name + "], collection [" + collection.name + "] in site [" + cp.Site.Name + "]");
                            }
                            wwwFileList += System.Environment.NewLine + addon.jsHeadScriptSrc;
                        }
                        collectionXml += ExportAddonController.getAddonNode(cp, addon.id, ref IncludeModuleGuidList, ref IncludeSharedStyleGuidList);
                    }
                    //
                    // Layouts
                    foreach (var layout in DbBaseModel.createList <LayoutModel>(cp, "(installedByCollectionId=" + collection.id + ")"))
                    {
                        collectionXml += ExportLayoutController.get(cp, layout);
                    }
                    //
                    // Templates
                    foreach (var template in DbBaseModel.createList <PageTemplateModel>(cp, "(collectionId=" + collection.id + ")"))
                    {
                        collectionXml += ExportTemplateController.get(cp, template);
                    }
                    //
                    // Data Records
                    string DataRecordList = CS.GetText("DataRecordList");
                    collectionXml += ExportDataRecordController.getNodeList(cp, DataRecordList, tempPathFileList, tempExportPath);
                    //
                    // CDef
                    foreach (Contensive.Models.Db.ContentModel content in createListFromCollection(cp, collection.id))
                    {
                        if ((string.IsNullOrEmpty(content.ccguid)))
                        {
                            content.ccguid = cp.Utils.CreateGuid();
                            content.save(cp);
                        }
                        XmlController xmlTool = new XmlController(cp);
                        string        Node    = xmlTool.GetXMLContentDefinition3(content.name);
                        //
                        // remove the <collection> top node
                        //
                        int Pos = Strings.InStr(1, Node, "<cdef", CompareMethod.Text);
                        if (Pos > 0)
                        {
                            Node = Strings.Mid(Node, Pos);
                            Pos  = Strings.InStr(1, Node, "</cdef>", CompareMethod.Text);
                            if (Pos > 0)
                            {
                                Node           = Strings.Mid(Node, 1, Pos + 6);
                                collectionXml += System.Environment.NewLine + "\t" + Node;
                            }
                        }
                    }
                    //
                    // Scripting Modules
                    if (IncludeModuleGuidList != "")
                    {
                        string[] Modules = Strings.Split(IncludeModuleGuidList, System.Environment.NewLine);
                        for (var Ptr = 0; Ptr <= Information.UBound(Modules); Ptr++)
                        {
                            string ModuleGuid = Modules[Ptr];
                            if (ModuleGuid != "")
                            {
                                using (CPCSBaseClass CS2 = cp.CSNew()) {
                                    CS2.Open("Scripting Modules", "ccguid=" + cp.Db.EncodeSQLText(ModuleGuid));
                                    if (CS2.OK())
                                    {
                                        string Code = CS2.GetText("code").Trim();
                                        Code           = EncodeCData(Code);
                                        collectionXml += System.Environment.NewLine + "\t" + "<ScriptingModule Name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\" guid=\"" + ModuleGuid + "\">" + Code + "</ScriptingModule>";
                                    }
                                    CS2.Close();
                                }
                            }
                        }
                    }
                    //
                    // shared styles
                    string[] recordGuids;
                    string   recordGuid;
                    if ((IncludeSharedStyleGuidList != ""))
                    {
                        recordGuids = Strings.Split(IncludeSharedStyleGuidList, System.Environment.NewLine);
                        for (var Ptr = 0; Ptr <= Information.UBound(recordGuids); Ptr++)
                        {
                            recordGuid = recordGuids[Ptr];
                            if (recordGuid != "")
                            {
                                using (CPCSBaseClass CS2 = cp.CSNew()) {
                                    CS2.Open("Shared Styles", "ccguid=" + cp.Db.EncodeSQLText(recordGuid));
                                    if (CS2.OK())
                                    {
                                        collectionXml += System.Environment.NewLine + "\t" + "<SharedStyle"
                                                         + " Name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\""
                                                         + " guid=\"" + recordGuid + "\""
                                                         + " alwaysInclude=\"" + CS2.GetBoolean("alwaysInclude") + "\""
                                                         + " prefix=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("prefix")) + "\""
                                                         + " suffix=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("suffix")) + "\""
                                                         + " sortOrder=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("sortOrder")) + "\""
                                                         + ">"
                                                         + EncodeCData(CS2.GetText("styleFilename").Trim())
                                                         + "</SharedStyle>";
                                    }
                                    CS2.Close();
                                }
                            }
                        }
                    }
                    //
                    // Import Collections
                    {
                        string Node = "";
                        using (CPCSBaseClass CS3 = cp.CSNew()) {
                            if (CS3.Open("Add-on Collection Parent Rules", "parentid=" + collection.id))
                            {
                                do
                                {
                                    using (CPCSBaseClass CS2 = cp.CSNew()) {
                                        if (CS2.OpenRecord("Add-on Collections", CS3.GetInteger("childid")))
                                        {
                                            string Guid = CS2.GetText("ccGuid");
                                            if (Guid == "")
                                            {
                                                Guid = cp.Utils.CreateGuid();
                                                CS2.SetField("ccGuid", Guid);
                                            }

                                            Node = Node + System.Environment.NewLine + "\t" + "<ImportCollection name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\">" + Guid + "</ImportCollection>";
                                        }

                                        CS2.Close();
                                    }

                                    CS3.GoNext();
                                }while (CS3.OK());
                            }
                            CS3.Close();
                        }
                        collectionXml += Node;
                    }
                    //
                    // wwwFileList
                    if (wwwFileList != "")
                    {
                        string[] Files = Strings.Split(wwwFileList, System.Environment.NewLine);
                        for (int Ptr = 0; Ptr <= Information.UBound(Files); Ptr++)
                        {
                            string pathFilename = Files[Ptr];
                            if (pathFilename != "")
                            {
                                pathFilename = Strings.Replace(pathFilename, @"\", "/");
                                string path     = "";
                                string filename = pathFilename;
                                int    Pos      = Strings.InStrRev(pathFilename, "/");
                                if (Pos > 0)
                                {
                                    filename = Strings.Mid(pathFilename, Pos + 1);
                                    path     = Strings.Mid(pathFilename, 1, Pos - 1);
                                }
                                string fileExtension = System.IO.Path.GetExtension(filename);
                                pathFilename = Strings.Replace(pathFilename, "/", @"\");
                                if (tempPathFileList.Contains(tempExportPath + filename))
                                {
                                    //
                                    // -- the path already has a file with this name
                                    cp.UserError.Add("There was an error exporting this collection because there were multiple files with the same filename [" + filename + "]");
                                }
                                else if (fileExtension.ToUpperInvariant().Equals(".ZIP"))
                                {
                                    //
                                    // -- zip files come from the collection folder
                                    CoreController core           = ((CPClass)cp).core;
                                    string         addonPath      = AddonController.getPrivateFilesAddonPath();
                                    string         collectionPath = CollectionFolderController.getCollectionConfigFolderPath(core, collection.ccguid);
                                    if (!cp.PrivateFiles.FileExists(addonPath + collectionPath + filename))
                                    {
                                        //
                                        // - not there
                                        cp.UserError.Add("There was an error exporting this collection because the zip file [" + pathFilename + "] was not found in the collection path [" + collectionPath + "].");
                                    }
                                    else
                                    {
                                        //
                                        // -- copy file from here
                                        cp.PrivateFiles.Copy(addonPath + collectionPath + filename, tempExportPath + filename, cp.TempFiles);
                                        tempPathFileList.Add(tempExportPath + filename);
                                        collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(filename) + "\" type=\"www\" path=\"" + System.Net.WebUtility.HtmlEncode(path) + "\" />";
                                    }
                                }
                                else if ((!cp.WwwFiles.FileExists(pathFilename)))
                                {
                                    cp.UserError.Add("There was an error exporting this collection because the www file [" + pathFilename + "] was not found.");
                                }
                                else
                                {
                                    cp.WwwFiles.Copy(pathFilename, tempExportPath + filename, cp.TempFiles);
                                    tempPathFileList.Add(tempExportPath + filename);
                                    collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(filename) + "\" type=\"www\" path=\"" + System.Net.WebUtility.HtmlEncode(path) + "\" />";
                                }
                            }
                        }
                    }
                    //
                    // ContentFileList
                    //
                    if (true)
                    {
                        if (ContentFileList != "")
                        {
                            string[] Files = Strings.Split(ContentFileList, System.Environment.NewLine);
                            for (var Ptr = 0; Ptr <= Information.UBound(Files); Ptr++)
                            {
                                string PathFilename = Files[Ptr];
                                if (PathFilename != "")
                                {
                                    PathFilename = Strings.Replace(PathFilename, @"\", "/");
                                    string Path     = "";
                                    string Filename = PathFilename;
                                    int    Pos      = Strings.InStrRev(PathFilename, "/");
                                    if (Pos > 0)
                                    {
                                        Filename = Strings.Mid(PathFilename, Pos + 1);
                                        Path     = Strings.Mid(PathFilename, 1, Pos - 1);
                                    }
                                    if (tempPathFileList.Contains(tempExportPath + Filename))
                                    {
                                        cp.UserError.Add("There was an error exporting this collection because there were multiple files with the same filename [" + Filename + "]");
                                    }
                                    else if ((!cp.CdnFiles.FileExists(PathFilename)))
                                    {
                                        cp.UserError.Add("There was an error exporting this collection because the cdn file [" + PathFilename + "] was not found.");
                                    }
                                    else
                                    {
                                        cp.CdnFiles.Copy(PathFilename, tempExportPath + Filename, cp.TempFiles);
                                        tempPathFileList.Add(tempExportPath + Filename);
                                        collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(Filename) + "\" type=\"content\" path=\"" + System.Net.WebUtility.HtmlEncode(Path) + "\" />";
                                    }
                                }
                            }
                        }
                    }
                    //
                    // ExecFileListNode
                    //
                    collectionXml += execResourceNodeList;
                    //
                    // Other XML
                    //
                    string OtherXML;
                    OtherXML = CS.GetText("otherxml");
                    if (Strings.Trim(OtherXML) != "")
                    {
                        collectionXml += System.Environment.NewLine + OtherXML;
                    }
                    collectionXml += System.Environment.NewLine + "</Collection>";
                    CS.Close();
                    string tempExportXml_Filename = encodeFilename(cp, CollectionName + ".xml");
                    //
                    // Save the installation file and add it to the archive
                    //
                    cp.TempFiles.Save(tempExportPath + tempExportXml_Filename, collectionXml);
                    if (!tempPathFileList.Contains(tempExportPath + tempExportXml_Filename))
                    {
                        tempPathFileList.Add(tempExportPath + tempExportXml_Filename);
                    }
                    string tempExportZip_Filename = encodeFilename(cp, CollectionName + ".zip");
                    //
                    // -- zip up the folder to make the collection zip file in temp filesystem
                    zipTempCdnFile(cp, tempExportPath + tempExportZip_Filename, tempPathFileList);
                    //
                    // -- copy the collection zip file to the cdn filesystem as the download link
                    cp.TempFiles.Copy(tempExportPath + tempExportZip_Filename, cdnExportZip_Filename, cp.CdnFiles);
                    //
                    // -- delete the temp folder
                    cp.TempFiles.DeleteFolder(tempExportPath);
                }
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex);
            }
            return(cdnExportZip_Filename);
        }
        //
        //=================================================================================================================
        /// <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;
            }
        }
示例#24
0
        //
        //====================================================================================================
        /// <summary>
        /// execute vb script
        /// </summary>
        /// <param name="addon"></param>
        /// <param name="Code"></param>
        /// <param name="EntryPoint"></param>
        /// <param name="ScriptingTimeout"></param>
        /// <param name="ScriptName"></param>
        /// <returns></returns>
        public static string execute_Script_VBScript(CoreController core, ref AddonModel addon)
        {
            string returnText = "";

            try {
                // todo - move locals
                using (var engine = new Microsoft.ClearScript.Windows.VBScriptEngine()) {
                    //var engine = new Microsoft.ClearScript.Windows.VBScriptEngine(Microsoft.ClearScript.Windows.WindowsScriptEngineFlags.EnableDebugging);
                    string entryPoint = addon.scriptingEntryPoint;
                    if (string.IsNullOrEmpty(entryPoint))
                    {
                        //
                        // -- compatibility mode, if no entry point given, if the code starts with "function myFuncton()" and add "call myFunction()"
                        int pos = addon.scriptingCode.IndexOf("function", StringComparison.CurrentCultureIgnoreCase);
                        if (pos >= 0)
                        {
                            entryPoint = addon.scriptingCode.Substring(pos + 9);
                            pos        = entryPoint.IndexOf("\r");
                            if (pos > 0)
                            {
                                entryPoint = entryPoint.Substring(0, pos);
                            }
                            pos = entryPoint.IndexOf("\n");
                            if (pos > 0)
                            {
                                entryPoint = entryPoint.Substring(0, pos);
                            }
                            pos = entryPoint.IndexOf("(");
                            if (pos > 0)
                            {
                                entryPoint = entryPoint.Substring(0, pos);
                            }
                        }
                    }
                    else
                    {
                        //
                        // -- etnry point provided, remove "()" if included and add to code
                        int pos = entryPoint.IndexOf("(");
                        if (pos > 0)
                        {
                            entryPoint = entryPoint.Substring(0, pos);
                        }
                    }
                    //
                    // -- adding cclib
                    try {
                        MainCsvScriptCompatibilityClass mainCsv = new MainCsvScriptCompatibilityClass(core);
                        engine.AddHostObject("ccLib", mainCsv);
                    } catch (Microsoft.ClearScript.ScriptEngineException ex) {
                        string errorMessage = getScriptEngineExceptionMessage(ex, "Adding cclib compatibility object ");
                        LogController.logError(core, ex, errorMessage);
                        throw new GenericException(errorMessage, ex);
                    } catch (Exception ex) {
                        LogController.logError(core, ex);
                        throw;
                    }
                    //
                    // -- adding cp
                    try {
                        engine.AddHostObject("cp", core.cpParent);
                    } catch (Microsoft.ClearScript.ScriptEngineException ex) {
                        string errorMessage = getScriptEngineExceptionMessage(ex, "Adding cp object ");
                        LogController.logError(core, ex, errorMessage);
                        throw new GenericException(errorMessage, ex);
                    } catch (Exception ex) {
                        LogController.logError(core, ex);
                        throw;
                    }
                    //
                    // -- execute code
                    try {
                        engine.Execute(addon.scriptingCode);
                        object returnObj = engine.Evaluate(entryPoint);
                        if (returnObj != null)
                        {
                            if (returnObj.GetType() == typeof(String))
                            {
                                returnText = (String)returnObj;
                            }
                        }
                    } catch (Microsoft.ClearScript.ScriptEngineException ex) {
                        string errorMessage = getScriptEngineExceptionMessage(ex, "executing script ");
                        LogController.logError(core, ex, errorMessage);
                        throw new GenericException(errorMessage, ex);
                    } catch (Exception ex) {
                        string addonDescription = AddonController.getAddonDescription(core, addon);
                        string errorMessage     = "Error executing addon script, " + addonDescription;
                        throw new GenericException(errorMessage, ex);
                    }
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnText);
        }