コード例 #1
0
ファイル: PublicationEx.cs プロジェクト: crui3er/Stl.Fusion
        public static void Publish(this HttpActionContext httpContext, IPublication publication)
        {
            using var _ = publication.Use();
            var publicationState = publication.State;
            var computed         = publicationState.Computed;
            var isConsistent     = computed.IsConsistent();

            // If exception occurred, response is empty, and we can not assign publication header.
            // If JsonifyAttribute is used, it will do it.
            var responseHeaders = httpContext.Response?.Headers;

            if (responseHeaders != null && responseHeaders.Contains(FusionHeaders.Publication))
            {
                throw Errors.AlreadyPublished();
            }
            var psi = new PublicationStateInfo(publication.Ref, computed.Version, isConsistent);

            var items = httpContext.GetItems();

            items[typeof(IPublicationState)]    = publicationState;
            items[typeof(PublicationStateInfo)] = psi;

            if (responseHeaders != null)
            {
                responseHeaders.AddPublicationStateInfoHeader(psi);
            }
        }
コード例 #2
0
    public static void Publish(this HttpContext httpContext, IPublication publication)
    {
        using var _ = publication.Use();
        var publicationState = publication.State;
        var computed         = publicationState.Computed;
        var isConsistent     = computed.IsConsistent();

        var responseHeaders = httpContext.Response.Headers;

        if (responseHeaders.ContainsKey(FusionHeaders.Publication))
        {
            throw Errors.AlreadyPublished();
        }
        var psi = new PublicationStateInfo(publication.Ref, computed.Version, isConsistent);

        httpContext.Items[typeof(IPublicationState)]    = publicationState;
        httpContext.Items[typeof(PublicationStateInfo)] = psi;
        responseHeaders[FusionHeaders.Publication]      = JsonConvert.SerializeObject(psi);
    }