public ResponseState Process(string data)
        {
            var applicationSettings = new ApplicationSettings
            {
                CanEdit = _editAuthorizer.Authorize(),
                DisableDocumentation = _docmahConfiguration.DocumentationConfiguration.Disabled,
            };

            var serializer = new JavaScriptSerializer();
            var applicationSettingsJson = serializer.Serialize(applicationSettings);

            return new ResponseState
            {
                Content = applicationSettingsJson,
                ContentType = ContentTypes.Json,
            };
        }
示例#2
0
        public string CreateFirstTimeHelpHtml()
        {
            var result = string.Empty;

            if (_memoryCache.Contains(_firstTimeHelpHtmlCacheKey))
                result = (string)_memoryCache.Get(_firstTimeHelpHtmlCacheKey);
            else
            {
                // Determine if content should be minified.
                var popupViewContent = _minifier.Minify(HtmlContent.FirstTimeView, HtmlContent.FirstTimeView_min);

                // Modify buttons per configuration settings.
                var hideHelpConfiguration = _docmahConfiguration.PopupViewerConfiguration.HidePopupButtonConfiguration;
                popupViewContent = popupViewContent.Replace("[HIDEHELPBUTTON]", CreateButtonHelp(hideHelpConfiguration.IsHidden, HtmlContent.HideHelpButton, hideHelpConfiguration.Text, hideHelpConfiguration.Description));
                var closeHelpConfiguration = _docmahConfiguration.PopupViewerConfiguration.ClosePopupButtonConfiguration;
                popupViewContent = popupViewContent.Replace("[CLOSEHELPBUTTON]", CreateButtonHelp(closeHelpConfiguration.IsHidden, HtmlContent.CloseHelpButton, closeHelpConfiguration.Text, closeHelpConfiguration.Description));

                // When injecting into other requests, the initialization scripts must be included.
                result += popupViewContent;

                // Attach jQueryUi CDN locations if not configured.
                var javaScriptDependencies = _docmahConfiguration.JsUrl;
                if (string.IsNullOrEmpty(javaScriptDependencies))
                {
                    result += string.Format("<script src='{0}' type='application/javascript'></script>", CdnUrls.jsJQuery);
                    result += string.Format("<script src='{0}' type='application/javascript'></script>", CdnUrls.jsJQueryUi);
                }

                result += _minifier.Minify(HtmlContent.FirstTimeViewInjectedScripts, HtmlContent.FirstTimeViewInjectedScripts_min);

                _memoryCache.Set(_firstTimeHelpHtmlCacheKey, result, new CacheItemPolicy());
            }

            // Begin reading request specific values.
            if (_editAuthorizer.Authorize())
            {
                result += _minifier.Minify(HtmlContent.FirstTimeEdit, HtmlContent.FirstTimeEdit_min);
            }

            var requestUrl = HttpContext.Current.Request.Url.AbsolutePath;
            var page = _firstTimeHelpRepository.ReadByUrl(requestUrl.Replace('*', '%'));
            UserPageSettings userPageSettings = null;

            if (null != page)
            {
                page.Bullets = _bulletRepository.ReadByPageId(page.Id);
                if (_httpContext.Request.IsAuthenticated)
                {
                    var userName = _httpContext.User.Identity.Name;
                    userPageSettings = _userPageSettingsRepository.Read(userName, page.Id);
                }
            }

            var serializer = new JavaScriptSerializer();
            var pageJson = serializer.Serialize(page);
            result = result.Replace("[PAGEJSON]", pageJson);

            var userPageSettingsJson = serializer.Serialize(userPageSettings);
            result = result.Replace("[USERPAGESETTINGSJSON]", userPageSettingsJson);

            // TODO: Refactor application settings creation into factory. Replace here and application settings request processor.
            var applicationSettings = new ApplicationSettings { CanEdit = _editAuthorizer.Authorize(), DisableDocumentation = _docmahConfiguration.DocumentationConfiguration.Disabled };
            var applicationSettingsJson = serializer.Serialize(applicationSettings);
            result = result.Replace("[APPLICATIONSETTINGSJSON]", applicationSettingsJson);

            return result;
        }