Exemplo n.º 1
0
        internal void SaveResponseInfo(HttpResponseMessage partialDownload, bool continueDownload)
        {
            if (partialDownload != null)
            {
#if NET35
                var len = partialDownload.ContentLength == -1 ? null : (long?)partialDownload.ContentLength;
#else
                var len = partialDownload.Content.Headers.ContentLength;
#endif
                if (len != null)
                {
                    Size = new FileSize(len.Value);
                }

// HACK: ignore content disposition in .net 35
#if !NET35
                var contentDisposition = partialDownload.Content.Headers.ContentDisposition;
                if (contentDisposition != null)
                {
                    contentDispositionFileName = contentDisposition.FileName;
                }
#endif

                contentTypeExtension = HttpUtils.GetFileExtensionFromMime(
#if NET35
                    HttpUtils.GetMimeFromContentType(partialDownload.Headers["Content-Type"])
#else
                    partialDownload.Content.Headers.ContentType?.MediaType
#endif
                    );

                if (continueDownload && (manager == null || !manager.IsAlive))
                {
                    this.partialDownload = partialDownload;
                    manager = new MediaStreamManager(GetResponseAsync, true);
                }
                else
                {
                    partialDownload.AbortAndDispose();
                }
                OnChanged();
            }
        }
Exemplo n.º 2
0
        internal void SaveResponseInfo(HttpResponseMessage partialDownload, bool continueDownload)
        {
            if (partialDownload != null)
            {
#if NET35
                var len = partialDownload.ContentLength == -1 ? null : (long?)partialDownload.ContentLength;
#else
                var len = partialDownload.Content.Headers.ContentLength;
#endif
                if (len != null) Size = new FileSize(len.Value);

// HACK: ignore content disposition in .net 35
#if !NET35
                var contentDisposition = partialDownload.Content.Headers.ContentDisposition;
                if (contentDisposition != null) contentDispositionFileName = contentDisposition.FileName;
#endif

                contentTypeExtension = HttpUtils.GetFileExtensionFromMime(
#if NET35
                    HttpUtils.GetMimeFromContentType(partialDownload.Headers["Content-Type"])
#else
                    partialDownload.Content.Headers.ContentType?.MediaType
#endif
                );

                if (continueDownload && (manager == null || !manager.IsAlive))
                {
                    this.partialDownload = partialDownload;
                    manager = new MediaStreamManager(GetResponseAsync, true);
                }
                else
                {
                    partialDownload.AbortAndDispose();
                }
                OnChanged();
            }
        }
Exemplo n.º 3
0
        internal void SaveResponseInfo(HttpResponseMessage partialDownload, bool?continueDownload)
        {
            if (partialDownload != null)
            {
#if NET35
                var len = partialDownload.ContentLength == -1 ? null : (long?)partialDownload.ContentLength;
#else
                var len = partialDownload.Content.Headers.ContentLength;
#endif
                if (len != null)
                {
                    Size = new FileSize(len.Value);
                }

#if !WEBCLIENT
                var lastModified = partialDownload.Content.Headers.LastModified?.UtcDateTime;
                if (partialDownload.Headers.TryGetValues("Memento-Datetime", out var k))
                {
                    if (DateTimeOffset.TryParse(k.First(), CultureInfo.InvariantCulture, DateTimeStyles.None, out var m))
                    {
                        if (lastModified == null || m.UtcDateTime < lastModified)
                        {
                            lastModified = m.UtcDateTime;
                        }
                    }
                }

                if (lastModified != null)
                {
                    LastModified = lastModified;
                }
#endif

                // HACK: ignore content disposition in .net 35
#if !NET35
                var contentDisposition = partialDownload.Content.Headers.ContentDisposition;
                if (contentDisposition != null)
                {
                    contentDispositionFileName = contentDisposition.FileName;
                }
#endif

                contentTypeExtension = HttpUtils.GetFileExtensionFromMime(
#if NET35
                    HttpUtils.GetMimeFromContentType(partialDownload.Headers["Content-Type"])
#else
                    partialDownload.Content.Headers.ContentType?.MediaType
#endif
                    );

                if (continueDownload != null)
                {
                    if (continueDownload == true && (manager == null || !manager.IsAlive))
                    {
                        this.partialDownload = partialDownload;
                        manager = new MediaStreamManager(GetResponseAsync, true);
                    }
                    else
                    {
                        partialDownload.AbortAndDispose();
                    }
                }
                OnChanged();
            }
        }