Beispiel #1
0
        protected override void DoHandleWork(WorkContext work)
        {
            var subHandler = m_Handlers.OrderedValues.FirstOrDefault(handler => handler.MakeMatch(work));

            if (subHandler == null)
            {
                throw HTTPStatusException.NotFound_404(StringConsts.NO_HANDLER_FOR_WORK_ERROR.Args(work.About));
            }

            subHandler.FilterAndHandleWork(work);
        }
Beispiel #2
0
        public void Feed(string portal, string ns, string block, Atom isolang, bool nocache = false, bool buffered = false)
        {
            ContentId id = default(ContentId);

            try
            {
                id = new ContentId(portal, ns, block);
            }
            catch (Exception error)
            {
                throw HTTPStatusException.BadRequest_400(error.Message);
            }

            var content = m_Cms.GetContentAsync(id, isolang, nocache.NoOrDefaultCache())
                          .GetAwaiter().GetResult();

            if (content == null)
            {
                throw HTTPStatusException.NotFound_404(id.ToString());
            }

            var compressionThreshold = App.ConfigRoot[SysConsts.CONFIG_WAVE_SECTION]
                                       .Of("cms-source-feeder-compressor-threshold-bytes").ValueAsInt(8000);

            var compress = (content.StringContent != null && content.StringContent.Length > compressionThreshold) ||
                           (content.BinaryContent != null && content.BinaryContent.Length > compressionThreshold);

            WorkContext.Response.Buffered          = buffered;
            WorkContext.Response.StatusCode        = 200;
            WorkContext.Response.StatusDescription = "Found CMS content";
            WorkContext.Response.ContentType       = compress ? CTP_COMPRESSED : CTP_UNCOMPRESSED;
            var httpStream = WorkContext.Response.GetDirectOutputStreamForWriting();

            if (compress)
            {
                using (var zipStream = new GZipStream(httpStream, CompressionLevel.Optimal))
                {
                    content.WriteToStream(zipStream);
                }
            }
            else
            {
                content.WriteToStream(httpStream);
            }
        }
Beispiel #3
0
        private (AppRemoteTerminal, Guid) get(string handle)
        {
            var guid = handle.AsGUID(Guid.Empty);

            if (guid == Guid.Empty)
            {
                throw HTTPStatusException.NotFound_404("Bad handle");
            }

            var result = App.ObjectStore.CheckOut(guid) as AppRemoteTerminal;

            if (result == null)
            {
                throw HTTPStatusException.NotFound_404("Bad terminal");
            }

            return(result, guid);
        }