public async Task<YieldStreamResults> SetResultAsync(StreamResult response, CancellationToken token = default)
        {
            var enumerator = new YieldStreamResults(_session, response, _isQueryStream, isTimeSeriesStream: false, isAsync: true, _statistics, token);
            await enumerator.InitializeAsync().ConfigureAwait(false);

            return enumerator;
        }
        public IEnumerator<BlittableJsonReaderObject> SetResult(StreamResult response)
        {
            var enumerator = new YieldStreamResults(_session, response, _isQueryStream, isTimeSeriesStream: false, isAsync: false, _statistics);
            enumerator.Initialize();

            return enumerator;
        }
        internal async Task<YieldStreamResults> SetResultForTimeSeriesAsync(StreamResult response)
        {
            var enumerator = new YieldStreamResults(_session, response, _isQueryStream, isTimeSeriesStream: true, isAsync: true, _statistics);
            await enumerator.InitializeAsync().ConfigureAwait(false);

            return enumerator;
        }
        internal YieldStreamResults SetResultForTimeSeries(StreamResult response)
        {
            var enumerator = new YieldStreamResults(_session, response, _isQueryStream, isTimeSeriesStream: true, isAsync: false, _statistics);
            enumerator.Initialize();

            return enumerator;
        }
Beispiel #5
0
            protected override void SetCurrent()
            {
                var ravenJObject = enumerator.Current;

                query.InvokeAfterStreamExecuted(ref ravenJObject);

                var    meta = ravenJObject.Value <RavenJObject>(Constants.Metadata);
                string key  = null;
                Etag   etag = null;

                if (meta != null)
                {
                    key = meta.Value <string>("@id") ??
                          meta.Value <string>(Constants.DocumentIdFieldName) ??
                          ravenJObject.Value <string>(Constants.DocumentIdFieldName);

                    var value = meta.Value <string>("@etag");
                    if (value != null)
                    {
                        etag = Etag.Parse(value);
                    }
                }

                Current = new StreamResult <T>
                {
                    Document = queryOperation.Deserialize <T>(ravenJObject),
                    Etag     = etag,
                    Key      = key,
                    Metadata = meta
                };
            }
Beispiel #6
0
        public StreamResult GetVideo()
        {
            try
            {
                StreamFile sf = new StreamFile();
                bool       containHeaderInfo = HttpContext.Request.Headers.ContainsKey("Accept");

                if (containHeaderInfo)
                {
                    Microsoft.Extensions.Primitives.StringValues headers;
                    if (HttpContext.Request.Headers.TryGetValue("Accept", out headers))
                    {
                        // Check for vide and wild card. Only firefox had the actual video type
                        if (headers.ToString().Contains("video") || headers.ToString().Contains("*/*"))
                        {
                            StreamResult sr = sf.GetVideoStream();
                            return((sr == null) ? sf.GetEmptyStream() : sr);
                        }
                    }
                }

                return(sf.GetEmptyStream());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>test xml generation</summary>
        /// <exception cref="Javax.Xml.Parsers.ParserConfigurationException"/>
        /// <exception cref="System.Exception"></exception>
        public virtual void TestQueueConfigurationParser()
        {
            JobQueueInfo info       = new JobQueueInfo("root", "rootInfo");
            JobQueueInfo infoChild1 = new JobQueueInfo("child1", "child1Info");
            JobQueueInfo infoChild2 = new JobQueueInfo("child2", "child1Info");

            info.AddChild(infoChild1);
            info.AddChild(infoChild2);
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.NewInstance();
            DocumentBuilder        builder           = docBuilderFactory.NewDocumentBuilder();
            Document document = builder.NewDocument();
            // test QueueConfigurationParser.getQueueElement
            Element e = QueueConfigurationParser.GetQueueElement(document, info);
            // transform result to string for check
            DOMSource          domSource   = new DOMSource(e);
            StringWriter       writer      = new StringWriter();
            StreamResult       result      = new StreamResult(writer);
            TransformerFactory tf          = TransformerFactory.NewInstance();
            Transformer        transformer = tf.NewTransformer();

            transformer.Transform(domSource, result);
            string str = writer.ToString();

            NUnit.Framework.Assert.IsTrue(str.EndsWith("<queue><name>root</name><properties/><state>running</state><queue><name>child1</name><properties/><state>running</state></queue><queue><name>child2</name><properties/><state>running</state></queue></queue>"
                                                       ));
        }
Beispiel #8
0
        public void SetUp()
        {
            // Create a response object and get the binary representation of it
            var streamUpdate = new StreamUpdate();

            var result1 = new ProcedureResult();

            result1.Error = new Error("Foo", string.Empty);

            var streamResult1 = new StreamResult();

            streamResult1.Id     = 1263;
            streamResult1.Result = result1;

            var result2 = new ProcedureResult();

            result2.Error = new Error("Bar", string.Empty);

            var streamResult2 = new StreamResult();

            streamResult2.Id     = 3443;
            streamResult2.Result = result2;

            streamUpdate.Results.Add(streamResult1);
            streamUpdate.Results.Add(streamResult2);

            expectedUpdate = streamUpdate;
            using (var stream = new MemoryStream()) {
                expectedUpdate.ToProtobufMessage().WriteDelimitedTo(stream);
                updateBytes = stream.ToArray();
            }
        }
Beispiel #9
0
        public void UpdateChannel(IChannel p_channel)
        {
            string       uri    = String.Format(Get_STREAM_RESULT, p_channel.Username);
            string       json   = Utility.GetJson(uri);
            StreamResult result = ModelFactory.GetStreamResult(json);

            try
            {
                if (result != null && result.stream != null)
                {
                    p_channel.Game    = result.stream.game;
                    p_channel.Title   = result.stream.channel.status;
                    p_channel.Viewers = result.stream.viewers;
                    p_channel.Status  = Status.Online;
                }
                else
                {
                    p_channel.Game    = String.Empty;
                    p_channel.Title   = String.Empty;
                    p_channel.Viewers = null;
                    p_channel.Status  = Status.Offline;
                }
            }
            catch (Exception ex)
            {
                Utility.LogTrace(ex.Message + " in " + MethodBase.GetCurrentMethod());
            }
        }
Beispiel #10
0
        /// <summary>
        /// Transforms a <seealso cref="DomDocument"/> to XML output.
        /// </summary>
        /// <param name="document">  the DOM document to transform </param>
        /// <param name="result">  the <seealso cref="StreamResult"/> to write to </param>
        public static void transformDocumentToXml(DomDocument document, StreamResult result)
        {
            TransformerFactory transformerFactory = TransformerFactory.newInstance();

            try
            {
                Transformer transformer = transformerFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

                lock (document)
                {
                    transformer.transform(document.DomSource, result);
                }
            }
            catch (TransformerConfigurationException e)
            {
                throw new ModelIoException("Unable to create a transformer for the model", e);
            }
            catch (TransformerException e)
            {
                throw new ModelIoException("Unable to transform model to xml", e);
            }
        }
Beispiel #11
0
        private void Wt_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            BackgroundWorker wt     = sender as BackgroundWorker;
            StreamResult     result = e.Result as StreamResult;

            _logger.LogInformation($"RunWorkerCompleted: {result?.ErrorMessage}");
        }
        private StreamResult <T> CreateStreamResult <T>(BlittableJsonReaderObject res)
        {
            string key  = null;
            long?  etag = null;
            BlittableJsonReaderObject metadata;

            if (res.TryGet(Constants.Metadata.Key, out metadata))
            {
                if (metadata.TryGet(Constants.Metadata.Id, out key) == false)
                {
                    throw new ArgumentException();
                }
                if (metadata.TryGet(Constants.Metadata.Etag, out etag) == false)
                {
                    throw new ArgumentException();
                }
            }
            var entity      = ConvertToEntity(typeof(T), key, res);
            var stremResult = new StreamResult <T>
            {
                Etag     = etag,
                Key      = key,
                Document = (T)entity,
                Metadata = new MetadataAsDictionary(metadata)
            };

            return(stremResult);
        }
Beispiel #13
0
 public YieldStreamResults(InMemoryDocumentSessionOperations session, StreamResult stream, bool isQueryStream)
 {
     _response         = stream;
     _peepingTomStream = new PeepingTomStream(_response.Stream, session.Context);
     _session          = session;
     _isQueryStream    = isQueryStream;
 }
Beispiel #14
0
        public void WriteResponseWithRange()
        {
            var stream = new MemoryStream(Encoding.UTF8.GetBytes("test contents"));

            using (var result = new StreamResult(stream, Pair.Create <long?, long?>(5, 11)))
            {
                var contextMock = new HttpContextMock();
                result.WriteResponse(contextMock.response);
                Assert.Equals(contextMock.response.StatusCode, 206);
                Assert.Equals(contextMock.response.ContentType, "application/octet-stream");
                Assert.Equals(contextMock.response.headers["Accept-Ranges"][0], "bytes");
                Assert.Equals(contextMock.response.headers["Content-Range"][0], "5-11/13");
                Assert.Equals(contextMock.response.GetContentsFromBody(), "content");
            }

            stream = new MemoryStream(Encoding.UTF8.GetBytes("test contents"));
            using (var result = new StreamResult(stream, Pair.Create <long?, long?>(5, null)))
            {
                var contextMock = new HttpContextMock();
                result.WriteResponse(contextMock.response);
                Assert.Equals(contextMock.response.StatusCode, 206);
                Assert.Equals(contextMock.response.ContentType, "application/octet-stream");
                Assert.Equals(contextMock.response.headers["Accept-Ranges"][0], "bytes");
                Assert.Equals(contextMock.response.headers["Content-Range"][0], "5-12/13");
                Assert.Equals(contextMock.response.GetContentsFromBody(), "contents");
            }
        }
        public void Test2()
        {
            string requestText = @"
GET http://www.fish-web-demo.com/Ajax/test/DataTypeTest/Input_string_ToUpper.aspx?input=fish HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 OPR/31.0.1889.174
";

            using (WebContext context = WebContext.FromRawText(requestText)) {
                context.Response.EnableOutputStream();

                byte[] buffer = System.Text.Encoding.Unicode.GetBytes("中文汉字");

                // 注意:这个文件名中,有些字符是操作系统不允许的,它们将会变成_
                string       filename     = "中文 汉字,无乱码~`!@#$%^&*()_-+-=[]{}|:;',.<>?¥◆≠∞µαβπ™■.dat";
                StreamResult streamResult = new StreamResult(buffer, "text/test", filename);

                streamResult.Ouput(context.HttpContext);

                // 获取编码后的文件名标头
                string header = context.Response.GetCustomHeader("Content-Disposition");

                // TODO: 现在拿到编码后的文件名了,但是不知道该如何断言,暂时先不做判断。

                Assert.AreEqual("text/test", context.HttpContext.Response.ContentType);
            }
        }
            public async ValueTask <bool> MoveNextAsync()
            {
                _prev?.Dispose(); // dispose the previous instance

                var isProjectInto = _query?.IsProjectInto ?? false;

                while (true)
                {
                    var next = _enumerator.MoveNextAsync();
                    if (next.IsCompleted)
                    {
                        if (next.Result == false)
                        {
                            return(false);
                        }
                    }
                    else if (await next.AsTask().WithCancellation(_token).ConfigureAwait(false) == false)
                    {
                        return(false);
                    }

                    _prev = _enumerator.Current;

                    _query?.InvokeAfterStreamExecuted(_enumerator.Current);

                    Current = CreateStreamResult(_enumerator.Current, isProjectInto);
                    return(true);
                }
            }
Beispiel #17
0
        /// <summary>
        /// Converts a <seealso cref="DomDocument"/> to its String representation
        /// </summary>
        /// <param name="document">  the XML document to convert </param>
        public static string convertXmlDocumentToString(DomDocument document)
        {
            StringWriter stringWriter = new StringWriter();
            StreamResult result       = new StreamResult(stringWriter);

            transformDocumentToXml(document, result);
            return(stringWriter.ToString());
        }
Beispiel #18
0
 /// <summary>
 /// Construct a stream.
 /// </summary>
 protected Stream()
 {
     StreamResult = new StreamResult();
     Started      = false;
     rate         = 0;
     delay        = 0;
     timer        = new Stopwatch();
 }
Beispiel #19
0
        public static Schema.KRPC.StreamResult ToProtobufMessage(this StreamResult streamResult)
        {
            var result = new Schema.KRPC.StreamResult();

            result.Id     = streamResult.Id;
            result.Result = streamResult.Result.ToProtobufMessage();
            return(result);
        }
Beispiel #20
0
        public void EnsureIsAcceptable(string indexName, StreamResult result)
        {
            if (result != null)
                return;

            if (indexName != null)
                IndexDoesNotExistException.ThrowFor(indexName);
        }
Beispiel #21
0
        public IEnumerator <BlittableJsonReaderObject> SetResult(StreamResult response)
        {
            if (response == null)
            {
                throw new InvalidOperationException("The index does not exists, failed to stream results");
            }

            var state = new JsonParserState();

            JsonOperationContext.ManagedPinnedBuffer buffer;

            using (response.Response)
                using (response.Stream)
                    using (var parser = new UnmanagedJsonParser(_session.Context, state, "stream contents"))
                        using (_session.Context.GetManagedBuffer(out buffer))
                            using (var peepingTomStream = new PeepingTomStream(response.Stream, _session.Context))
                            {
                                if (UnmanagedJsonParserHelper.Read(peepingTomStream, parser, state, buffer) == false)
                                {
                                    UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                                }

                                if (state.CurrentTokenType != JsonParserToken.StartObject)
                                {
                                    UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                                }


                                if (_isQueryStream)
                                {
                                    HandleStreamQueryStats(_session.Context, response, parser, state, buffer, _statistics);
                                }

                                var property = UnmanagedJsonParserHelper.ReadString(_session.Context, peepingTomStream, parser, state, buffer);
                                if (string.Equals(property, "Results") == false)
                                {
                                    UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                                }

                                foreach (var result in UnmanagedJsonParserHelper.ReadArrayToMemory(_session.Context, peepingTomStream, parser, state, buffer))
                                {
                                    yield return(result);
                                }

                                if (UnmanagedJsonParserHelper.Read(peepingTomStream, parser, state, buffer) == false)
                                {
                                    UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                                }

                                if (state.CurrentTokenType != JsonParserToken.EndObject)
                                {
                                    UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                                }
                            }
        }
Beispiel #22
0
        public static void G15_StreamingAPI()
        {
            /*
             * Be aware that the results returned by the Stream() method are not tracked by session and, therefore, will not
             * be automatically saved if modified. Also, the Stream() method uses RavenDB's export facility which snapshots the
             * results when export starts. If a document in the result is added or deleted while the results are streaming, this
             * change will not be reflcted in the results.
             *
             * It also consumes less memory than a Query executed not through the Streaming API, it's due to the fact that in this
             * session doesn't track the result documents in memory. So for memory sensitive systems this may make sense.
             * Although it requires less memory, it's also about 1.5 times slower than a regular query.
             *
             * A drawback (probably one of the drawbacks) that I noticed is that it doesn't respect DocumentStore caching, the results
             * are always retrieved from the server
             */
            using (var session = Store.Documents.OpenSession())
            {
                int page     = 2,
                    pageSize = 10;

                IQueryable <Order> query = session.Query <Order>("Orders/Totals")
                                           .Skip((page - 1) * pageSize)
                                           .Take(pageSize)
                                           .Where(x => x.Employee == "employees/1");

                QueryHeaderInformation queryHeaderInformation;
                IEnumerator <StreamResult <Order> > results = session.Advanced.Stream(query, out queryHeaderInformation);

                List <Order> orders = new List <Order>();
                while (results.MoveNext())
                {
                    StreamResult <Order> employee = results.Current;
                    orders.Add(employee.Document);
                }
            }


            /*
             * Another way, using the StartsWith syntax
             */
            using (var session = Store.Documents.OpenSession())
            {
                RavenPagingInformation ravenPagingInformation = new RavenPagingInformation();
                IEnumerator <StreamResult <Order> > results   = session.Advanced
                                                                .Stream <Order>("orders/", "8?", 0, 128, ravenPagingInformation, null);

                List <Order> orders = new List <Order>();
                while (results.MoveNext())
                {
                    StreamResult <Order> employee = results.Current;
                    orders.Add(employee.Document);
                }
            }
        }
        public void Test1()
        {
            // 测试 StreamResult的构造函数传递,及contentType的默认设置

            byte[]       buffer       = System.Text.Encoding.Unicode.GetBytes("中文汉字");
            StreamResult streamResult = new StreamResult(buffer);

            string actual = streamResult.GetValue("_contentType").ToString();

            Assert.AreEqual("application/octet-stream", actual);
        }
Beispiel #24
0
        public void WriteResponse()
        {
            var stream = new MemoryStream(Encoding.UTF8.GetBytes("test contents"));

            using (var result = new StreamResult(stream)) {
                var contextMock = new HttpContextMock();
                result.WriteResponse(contextMock.response);
                Assert.Equals(contextMock.response.StatusCode, 200);
                Assert.Equals(contextMock.response.ContentType, "application/octet-stream");
                Assert.Equals(contextMock.response.GetContentsFromBody(), "test contents");
            }
        }
Beispiel #25
0
        public StreamResult GetStreamInfo()
        {
            var streamresult = new StreamResult()
            {
            };
            var keyValueStreamUrl     = db.AppConfigs.Where(e => e.AppConfigKey == "STREAMURL").FirstOrDefault().AppConfigValue;
            var keyValueStreamUrlTime = db.AppConfigs.Where(e => e.AppConfigKey == "STREAMURLTIME").FirstOrDefault().AppConfigValue;

            streamresult.url      = keyValueStreamUrl;
            streamresult.startsAt = keyValueStreamUrlTime;
            return(streamresult);
        }
Beispiel #26
0
 public YieldStreamResults(InMemoryDocumentSessionOperations session, StreamResult response, bool isQueryStream, bool isTimeSeriesStream, bool isAsync, StreamQueryStatistics streamQueryStatistics, CancellationToken token = default)
 {
     _response                         = response ?? throw new InvalidOperationException("The index does not exists, failed to stream results");
     _peepingTomStream                 = new PeepingTomStream(_response.Stream, session.Context);
     _session                          = session;
     _isQueryStream                    = isQueryStream;
     _isAsync                          = isAsync;
     _streamQueryStatistics            = streamQueryStatistics;
     _maxDocsCountOnCachedRenewSession = session._maxDocsCountOnCachedRenewSession;
     _token = token;
     _isTimeSeriesStream = isTimeSeriesStream;
 }
Beispiel #27
0
            protected override void SetCurrent()
            {
                var document = SerializationHelper.RavenJObjectToJsonDocument(enumerator.Current);

                Current = new StreamResult <T>
                {
                    Document = (T)parent.ConvertToEntity(typeof(T), document.Key, document.DataAsJson, document.Metadata),
                    Etag     = document.Etag,
                    Key      = document.Key,
                    Metadata = document.Metadata
                };
            }
Beispiel #28
0
        public void Put(StreamResult result)
        {
            lock (mutex)
            {
                queue.Add(result);

                // Checking part when put it in queue
                if (result.PartIndex == totalWriteCount)
                {
                    eventWaitHandle.Set();
                }
            }
        }
Beispiel #29
0
            public YieldStreamResults(InMemoryDocumentSessionOperations session, StreamResult response, bool isQueryStream, bool isAsync, StreamQueryStatistics streamQueryStatistics)
            {
                if (response == null)
                {
                    throw new InvalidOperationException("The index does not exists, failed to stream results");
                }

                _response              = response;
                _peepingTomStream      = new PeepingTomStream(_response.Stream, session.Context);
                _session               = session;
                _isQueryStream         = isQueryStream;
                _isAsync               = isAsync;
                _streamQueryStatistics = streamQueryStatistics;
            }
Beispiel #30
0
            private static void HandleStreamQueryStats(JsonOperationContext context, StreamResult response, UnmanagedJsonParser parser, JsonParserState state, JsonOperationContext.MemoryBuffer buffer, StreamQueryStatistics streamQueryStatistics = null)
            {
                using (var peepingTomStream = new PeepingTomStream(response.Stream, context))
                {
                    var property = UnmanagedJsonParserHelper.ReadString(context, peepingTomStream, parser, state, buffer);
                    if (string.Equals(property, nameof(StreamQueryStatistics.ResultEtag)) == false)
                        UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                    var resultEtag = UnmanagedJsonParserHelper.ReadLong(context, peepingTomStream, parser, state, buffer);

                    property = UnmanagedJsonParserHelper.ReadString(context, peepingTomStream, parser, state, buffer);
                    if (string.Equals(property, nameof(StreamQueryStatistics.IsStale)) == false)
                        UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);

                    if (UnmanagedJsonParserHelper.Read(peepingTomStream, parser, state, buffer) == false)
                        UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);

                    if (state.CurrentTokenType != JsonParserToken.False && state.CurrentTokenType != JsonParserToken.True)
                        UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                    var isStale = state.CurrentTokenType != JsonParserToken.False;

                    property = UnmanagedJsonParserHelper.ReadString(context, peepingTomStream, parser, state, buffer);
                    if (string.Equals(property, nameof(StreamQueryStatistics.IndexName)) == false)
                        UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                    var indexName = UnmanagedJsonParserHelper.ReadString(context, peepingTomStream, parser, state, buffer);

                    property = UnmanagedJsonParserHelper.ReadString(context, peepingTomStream, parser, state, buffer);
                    if (string.Equals(property, nameof(StreamQueryStatistics.TotalResults)) == false)
                        UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                    var totalResults = (int)UnmanagedJsonParserHelper.ReadLong(context, peepingTomStream, parser, state, buffer);

                    property = UnmanagedJsonParserHelper.ReadString(context, peepingTomStream, parser, state, buffer);
                    if (string.Equals(property, nameof(StreamQueryStatistics.IndexTimestamp)) == false)
                        UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                    var indexTimestamp = UnmanagedJsonParserHelper.ReadString(context, peepingTomStream, parser, state, buffer);

                    if (streamQueryStatistics == null)
                        return;

                    streamQueryStatistics.IndexName = indexName;
                    streamQueryStatistics.IsStale = isStale;
                    streamQueryStatistics.TotalResults = totalResults;
                    streamQueryStatistics.ResultEtag = resultEtag;

                    if (DateTime.TryParseExact(indexTimestamp, "o", CultureInfo.InvariantCulture,
                        DateTimeStyles.RoundtripKind, out DateTime timeStamp) == false)
                        UnmanagedJsonParserHelper.ThrowInvalidJson(peepingTomStream);
                    streamQueryStatistics.IndexTimestamp = timeStamp;
                }
            }
        public StreamResult PhotoData(Guid id)
        {
            if (Session["photoPreview"] == null)
              {
            Response.StatusCode = 400;
            Response.End();
              }

              Dictionary<Guid, Bitmap> photos = (Dictionary<Guid, Bitmap>)Session["photoPreview"];

              StreamResult result = new StreamResult { ContentType = "image/jpeg" };
              photos[id].Save(result.Stream, ImageFormat.Jpeg);
              result.Stream.Position = 0;

              return result;
        }
Beispiel #32
0
        private void ExecuteContentFile(IContext context)
        {
            string contentType;
            if (ContentType != null)
                contentType = ContentType;
            else
            {
                string extension = System.IO.Path.GetExtension(ContentFile);
                contentType = MimeTypes.FromExtension(extension);
            }

            if (System.IO.Path.IsPathRooted(ContentFile))
            {
                if (!System.IO.File.Exists(ContentFile))
                    throw new HttpException((int)HttpStatusCode.NotFound, string.Format("Resource '{0}' not found.", ContentFile));

                var result = new FilePathResult(ContentFile, contentType);
                if (!string.IsNullOrEmpty(FileDownloadName))
                    result.FileDownloadName = FileDownloadName;

                ExecuteFileResult(context, result);
            }
            else
            {
                string resourceLocation = context.Page.GetResourceLocation(ContentFile);
                if (!_resourceProvider.ResourceExists(resourceLocation))
                    throw new HttpException((int)HttpStatusCode.NotFound, string.Format("Resource '{0}' not found.", resourceLocation));

                using (var contentStream = _resourceProvider.OpenResource(resourceLocation))
                {
                    var result = new StreamResult(contentStream, contentType);
                    if (!string.IsNullOrEmpty(FileDownloadName))
                        result.FileDownloadName = FileDownloadName;

                    ExecuteFileResult(context, result);
                }
            }
        }