Exemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                unityWebRequest.Dispose();
                unityWebRequest = null;

                ErrorReceived.RemoveAllListeners();
                ErrorReceived = null;

                DownloadInProgress.RemoveAllListeners();
                DownloadInProgress = null;

                DownloadCompleted.RemoveAllListeners();
                DownloadCompleted = null;

                ExceptionCaught.RemoveAllListeners();
                ExceptionCaught = null;
            }

            disposed = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnityHttpClient"/> class.
        /// </summary>
        public UnityHttpClient()
        {
            ErrorReceived      = new ErrorReceivedEvent();
            DownloadInProgress = new DownloadInProgressEvent();
            DownloadCompleted  = new DownloadCompletedEvent();
            ExceptionCaught    = new ExceptionCaughtEvent();

            unityWebRequest = new UnityWebRequest();
            AutoDispose     = true;
        }
Exemplo n.º 3
0
 void DownloadFile()
 {
     try
     {
         Thread.Sleep(500);
         Request         = WebRequest.Create(Url) as HttpWebRequest;
         Request.Timeout = 5000;
         Request.AddRange(From, To);
         HttpWebResponse Response = Request.GetResponse() as HttpWebResponse;
         using (Stream ResponseStream = Response.GetResponseStream())
         {
             using (Stream Stream = new FileStream(DownloadPath, FileMode.Create))
             {
                 byte[] Array = new byte[512];
                 int    i     = ResponseStream.Read(Array, 0, Array.Length);
                 while (i > 0)
                 {
                     DownloadedLength += i;
                     Stream.Write(Array, 0, i);
                     i = ResponseStream.Read(Array, 0, Array.Length);
                 }
             }
         }
         Completed = true;
         DownloadCompletedEvent?.Invoke(this);
     }
     catch (ThreadAbortException) { return; }
     catch (Exception ex)
     {
         if (ex.Message.Contains("终止") || ex.Message.Contains("内部"))
         {
             return;
         }
         if (ErrorNum >= 5)
         {
             Failed = true;
             DownloadFailedEvent?.Invoke(this);
             return;
         }
         MessageBox.Show(ex.ToString());
         ErrorNum++;
         DownloadedLength = 0L;
         WorkThread       = new Thread(DownloadFile);
         WorkThread.Start();
     }
 }
Exemplo n.º 4
0
        public void Handle(DownloadCompletedEvent message)
        {
            foreach (var book in message.TrackedDownload.RemoteBook.Books)
            {
                var history = new History
                {
                    EventType   = HistoryEventType.DownloadImported,
                    Date        = DateTime.UtcNow,
                    Quality     = message.TrackedDownload.RemoteBook.ParsedBookInfo?.Quality ?? new QualityModel(),
                    SourceTitle = message.TrackedDownload.DownloadItem.Title,
                    AuthorId    = book.AuthorId,
                    BookId      = book.Id,
                    DownloadId  = message.TrackedDownload.DownloadItem.DownloadId
                };

                _historyRepository.Insert(history);
            }
        }
Exemplo n.º 5
0
        public void Handle(DownloadCompletedEvent message)
        {
            foreach (var album in message.TrackedDownload.RemoteAlbum.Albums)
            {
                var history = new History
                {
                    EventType   = HistoryEventType.DownloadImported,
                    Date        = DateTime.UtcNow,
                    Quality     = message.TrackedDownload.RemoteAlbum.ParsedAlbumInfo?.Quality ?? new QualityModel(),
                    SourceTitle = message.TrackedDownload.DownloadItem.Title,
                    ArtistId    = album.ArtistId,
                    AlbumId     = album.Id,
                    DownloadId  = message.TrackedDownload.DownloadItem.DownloadId
                };

                _historyRepository.Insert(history);
            }
        }
Exemplo n.º 6
0
        public void Handle(DownloadCompletedEvent message)
        {
            var downloadItem = message.TrackedDownload.DownloadItem;

            var history = new DownloadHistory
            {
                EventType        = DownloadHistoryEventType.DownloadImported,
                MovieId          = message.MovieId,
                DownloadId       = downloadItem.DownloadId,
                SourceTitle      = downloadItem.Title,
                Date             = DateTime.UtcNow,
                Protocol         = message.TrackedDownload.Protocol,
                DownloadClientId = message.TrackedDownload.DownloadClient
            };

            history.Data.Add("DownloadClient", downloadItem.DownloadClientInfo.Type);
            history.Data.Add("DownloadClientName", downloadItem.DownloadClientInfo.Name);

            _repository.Insert(history);
        }
Exemplo n.º 7
0
 private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
 {
     DownloadCompletedEvent?.Invoke(sender, e);
 }