Exemple #1
0
        internal static WebFile FromDbValue(WebFile file, string content, TypeBase type)
        {
            /*if (url == null) return null;
            var u = url.AsUri();
            var file =
                type == TypeBase.WebImage ? WebImage.FromUrl(u) :
                type == TypeBase.WebAudio ? WebAudio.FromUrl(u) :
                type == TypeBase.WebVideo ? WebVideo.FromUrl(u) :
                WebFile.FromUrl(u);
                */
            if (content != null)
            {
                var serializer = new JsonSerializer();

                serializer.AddAwdeeConverters();
                using (var sr = new StringReader(content))
                using (var jr = Utils.CreateJsonReader(sr))
                {
                    serializer.Deserialize(jr, type.NativeType);
                }

            }

            return file;
        }
Exemple #2
0
        public static WebFile FromUrlUntracked(Uri url, HttpResponseMessage partialResponse, bool continueDownload)
        {
            var existing = new WebFile(url);

            existing.SaveResponseInfo(partialResponse, continueDownload);
            return(existing);
        }
Exemple #3
0
 internal MediaStream(MediaStreamManager manager, WebFile file, int id, bool linger)
 {
     this.id = id;
     this.file = file;
     this.manager = manager;
     this.currentReadOperationWaitHandle = new AutoResetEvent(false);
     manager.NewDataAvailable += manager_NewDataAvailable;
     this.linger = linger;
 }
Exemple #4
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                if (reader.TokenType == JsonToken.Null)
                {
                    return(null);
                }
                var urlString = (string)reader.Value;
                var url       = urlString.AsUri();

                return
                    (#if !STANDALONE
                     objectType == typeof(WebAudio) ? WebAudio.FromUrl(url) :
                     objectType == typeof(WebVideo) ? WebVideo.FromUrl(url) :
                     objectType == typeof(WebImage) ? WebImage.FromUrl(url) :
#endif
                     WebFile.FromUrl(url));
            }
Exemple #5
0
        public static WebFile FromUrl(Uri url, HttpResponseMessage partialResponse, bool continueDownload)
        {
#if STANDALONE
            var existing = new WebFile(url);
#else
            ObjectManager.AssertMainThread();

            var existing = files[url.AbsoluteUri];
            if (existing == null)
            {
                existing = new WebFile(url);
                files[url.AbsoluteUri] = existing;
            }
#endif

            existing.SaveResponseInfo(partialResponse, continueDownload);
            return(existing);
        }
Exemple #6
0
        protected static void Initialize(WebFile existing, WebFile typed, HttpResponseMessage partialResponse, bool continueDownload)
        {
            typed.SaveResponseInfo(partialResponse, continueDownload);

            if (existing != null && !object.ReferenceEquals(typed, existing))
            {
                typed.Size = existing.Size;
                typed.contentDispositionFileName = existing.contentDispositionFileName;
                typed.contentTypeExtension       = existing.contentTypeExtension;
                lock (existing)
                {
                    lock (typed)
                    {
                        if (existing.manager != null && (typed.manager == null || !typed.manager.IsAlive))
                        {
                            existing.manager = typed.manager;
                        }
                    }
                }
            }
        }
Exemple #7
0
        internal static WebFile FromDbValue(WebFile file, string content, TypeBase type)
        {
            /*if (url == null) return null;
             * var u = url.AsUri();
             * var file =
             *  type == TypeBase.WebImage ? WebImage.FromUrl(u) :
             *  type == TypeBase.WebAudio ? WebAudio.FromUrl(u) :
             *  type == TypeBase.WebVideo ? WebVideo.FromUrl(u) :
             *  WebFile.FromUrl(u);
             */
            if (content != null)
            {
                var serializer = new JsonSerializer();

                serializer.AddAwdeeConverters();
                using (var sr = new StringReader(content))
                    using (var jr = Utils.CreateJsonReader(sr))
                    {
                        serializer.Deserialize(jr, type.NativeType);
                    }
            }

            return(file);
        }
Exemple #8
0
 internal MediaStream(Exception ex, WebFile file)
 {
     this.file = file;
     this.prebuiltException = ex;
     this.linger = true;
 }
Exemple #9
0
        protected static void Initialize(WebFile existing, WebFile typed, HttpResponseMessage partialResponse, bool continueDownload)
        {
            typed.SaveResponseInfo(partialResponse, continueDownload);

            if (existing != null && !object.ReferenceEquals(typed, existing))
            {
                typed.Size = existing.Size;
                typed.contentDispositionFileName = existing.contentDispositionFileName;
                typed.contentTypeExtension = existing.contentTypeExtension;
                lock (existing)
                {
                    lock (typed)
                    {
                        if (existing.manager != null && (typed.manager == null || !typed.manager.IsAlive))
                        {
                            existing.manager = typed.manager;
                        }
                    }
                }
            }

        }
Exemple #10
0
        public static WebFile FromUrlUntracked(Uri url, HttpResponseMessage partialResponse, bool continueDownload)
        {
            var existing = new WebFile(url);
            existing.SaveResponseInfo(partialResponse, continueDownload);
            return existing;

        }
Exemple #11
0
        public static WebFile FromUrl(Uri url, HttpResponseMessage partialResponse, bool continueDownload)
        {
#if STANDALONE
            var existing = new WebFile(url);
#else
            ObjectManager.AssertMainThread();

            var existing = files[url.AbsoluteUri];
            if (existing == null)
            {
                existing = new WebFile(url);
                files[url.AbsoluteUri] = existing;
            }
#endif

            existing.SaveResponseInfo(partialResponse, continueDownload);
            return existing;
            
        }
        public MediaStream TryCreateStream(WebFile file, ulong position, bool linger)
        {
            lock (syncObj)
            {
                if ((ulong)firstAvailableByte > position) return null;
                if (disposalCancellation != null)
                {
                    disposalCancellation.Cancel();
                    disposalCancellation.Dispose();
                    disposalCancellation = null;
                }

                consumers++;
                var stream = new MediaStream(this, file, mediaStreams.Count, linger);
                mediaStreams.Add(stream);
                stream.Seek(position);

                return stream;
            }
        }