Exemplo n.º 1
0
        public async Task SetCacheAsync(IEditablePageViewModel vm, PageActionRoutingState state)
        {
            var siteViewerMode     = state.VisualEditorMode;
            var publishStatusQuery = state.VisualEditorMode.ToPublishStatusQuery();
            var pageVersions       = state.PageRoutingInfo.PageRoute.Versions;

            // Force a viewer mode
            if (siteViewerMode == VisualEditorMode.Any)
            {
                var version = state.PageRoutingInfo.GetVersionRoute(
                    state.InputParameters.IsEditingCustomEntity,
                    state.VisualEditorMode.ToPublishStatusQuery(),
                    state.InputParameters.VersionId);

                switch (version.WorkFlowStatus)
                {
                case WorkFlowStatus.Draft:
                    siteViewerMode = VisualEditorMode.Draft;
                    break;

                case WorkFlowStatus.Published:
                    siteViewerMode = VisualEditorMode.Live;
                    break;

                default:
                    throw new InvalidOperationException("WorkFlowStatus." + version.WorkFlowStatus + " is not valid for VisualEditorMode.Any");
                }
            }

            var pageResponseData = new PageResponseData();

            pageResponseData.Page                      = vm;
            pageResponseData.VisualEditorMode          = siteViewerMode;
            pageResponseData.PageRoutingInfo           = state.PageRoutingInfo;
            pageResponseData.HasDraftVersion           = state.PageRoutingInfo.GetVersionRoute(state.InputParameters.IsEditingCustomEntity, PublishStatusQuery.Draft, null) != null;
            pageResponseData.Version                   = state.PageRoutingInfo.GetVersionRoute(state.InputParameters.IsEditingCustomEntity, publishStatusQuery, state.InputParameters.VersionId);
            pageResponseData.CofoundryAdminUserContext = state.CofoundryAdminUserContext;

            var customEntityDefinitionCode = state.PageRoutingInfo.PageRoute.CustomEntityDefinitionCode;

            if (!string.IsNullOrEmpty(customEntityDefinitionCode))
            {
                var definitionQuery = new GetCustomEntityDefinitionSummaryByCodeQuery(customEntityDefinitionCode);
                pageResponseData.CustomEntityDefinition = await _queryExecutor.ExecuteAsync(definitionQuery);
            }

            if (state.InputParameters.IsEditingCustomEntity)
            {
                pageResponseData.PageVersion = pageVersions.GetVersionRouting(PublishStatusQuery.Latest);
            }
            else
            {
                pageResponseData.PageVersion = pageVersions.GetVersionRouting(publishStatusQuery, state.InputParameters.VersionId);
            }

            _pageRenderDataCache.Set(pageResponseData);
        }
Exemplo n.º 2
0
        public void SetCache(IEditablePageViewModel vm, PageActionRoutingState state)
        {
            var siteViewerMode      = state.VisualEditorMode;
            var workFlowStatusQuery = state.VisualEditorMode.ToWorkFlowStatusQuery();
            var pageVersions        = state.PageRoutingInfo.PageRoute.Versions;

            // Force a viewer mode
            if (siteViewerMode == VisualEditorMode.Any)
            {
                var version = state.PageRoutingInfo.GetVersionRoute(
                    state.InputParameters.IsEditingCustomEntity,
                    state.VisualEditorMode.ToWorkFlowStatusQuery(),
                    state.InputParameters.VersionId);

                switch (version.WorkFlowStatus)
                {
                case WorkFlowStatus.Draft:
                    siteViewerMode = VisualEditorMode.Draft;
                    break;

                case WorkFlowStatus.Published:
                    siteViewerMode = VisualEditorMode.Live;
                    break;

                default:
                    throw new ApplicationException("WorkFlowStatus." + version.WorkFlowStatus + " is not valid for VisualEditorMode.Any");
                }
            }

            var pageResponseData = new PageResponseData();

            pageResponseData.Page                = vm;
            pageResponseData.VisualEditorMode    = siteViewerMode;
            pageResponseData.PageRoutingInfo     = state.PageRoutingInfo;
            pageResponseData.HasDraftVersion     = state.PageRoutingInfo.GetVersionRoute(state.InputParameters.IsEditingCustomEntity, WorkFlowStatusQuery.Draft, null) != null;
            pageResponseData.Version             = state.PageRoutingInfo.GetVersionRoute(state.InputParameters.IsEditingCustomEntity, workFlowStatusQuery, state.InputParameters.VersionId);
            pageResponseData.IsCustomEntityRoute = pageResponseData.Version is CustomEntityVersionRoute;

            if (!string.IsNullOrEmpty(state.PageRoutingInfo.PageRoute.CustomEntityDefinitionCode))
            {
                pageResponseData.CustomEntityDefinition = _queryExecutor.GetById <CustomEntityDefinitionSummary>(state.PageRoutingInfo.PageRoute.CustomEntityDefinitionCode);
            }

            if (state.InputParameters.IsEditingCustomEntity)
            {
                pageResponseData.PageVersion = pageVersions.GetVersionRouting(WorkFlowStatusQuery.Latest);
            }
            else
            {
                pageResponseData.PageVersion = pageVersions.GetVersionRouting(workFlowStatusQuery, state.InputParameters.VersionId);
            }

            _pageRenderDataCache.Set(pageResponseData);
        }