コード例 #1
0
ファイル: Ripper.cs プロジェクト: be-zark/TumblRipper3
        public FileToDownloadStatusCodes DownloadFile(IFileToDownload myfile)
        {
            string      str         = Path.Combine(this.string_0, myfile.Filename);
            MyWebClient myWebClient = new MyWebClient();
            FileToDownloadStatusCodes downloadStatusCodes = FileToDownloadStatusCodes.OK;

            try
            {
                myWebClient.AllowAutoRedirect = true;
                myWebClient.DownloadFile(myfile.Url, str);
            }
            catch (WebException ex)
            {
                HttpWebResponse httpWebResponse = (HttpWebResponse)ex.Response;
                downloadStatusCodes = httpWebResponse != null ? (FileToDownloadStatusCodes)httpWebResponse.StatusCode : FileToDownloadStatusCodes.UnknownError;
            }
            catch (Exception ex)
            {
                downloadStatusCodes = FileToDownloadStatusCodes.UnknownError;
            }
            if (downloadStatusCodes == FileToDownloadStatusCodes.OK)
            {
                if (!System.IO.File.Exists(str))
                {
                    return(FileToDownloadStatusCodes.FileNotDownloaded);
                }
                try
                {
                    if (new FileInfo(str).Length < 1L)
                    {
                        downloadStatusCodes = FileToDownloadStatusCodes.FileDownloadedButEmpty;
                    }
                }
                catch (Exception ex)
                {
                    downloadStatusCodes = FileToDownloadStatusCodes.FileUnknownError;
                }
                WebHeaderCollection responseHeaders = myWebClient.ResponseHeaders;
                DateTime            creationTime    = DateTime.Now;
                for (int index = 0; index < responseHeaders.Count; ++index)
                {
                    if (responseHeaders.GetKey(index).Equals("Last-Modified"))
                    {
                        creationTime = DateTime.Parse(responseHeaders.Get(index));
                    }
                }
                try
                {
                    System.IO.File.SetCreationTime(str, creationTime);
                }
                catch (Exception ex)
                {
                }
            }
            if (myWebClient != null)
            {
                myWebClient.Dispose();
            }
            return(downloadStatusCodes);
        }
コード例 #2
0
 public FileToDownloadFailed(IFileToDownload ifileToDownload_0, FileToDownloadStatusCodes fileToDownloadStatusCodes_0)
     : base(ifileToDownload_0.Url, ifileToDownload_0.Filename, ifileToDownload_0.Key)
 {
     this.ErrorCode = fileToDownloadStatusCodes_0;
 }
コード例 #3
0
ファイル: Ripper.cs プロジェクト: be-zark/TumblRipper3
        public void DownloadPostsFound(CancellationToken _cancellationToken)
        {
            List <IFileToDownload> list = new List <IFileToDownload>((IEnumerable <IFileToDownload>) this.PostsFound);
            int num = 0;

            foreach (string str in Enumerable.ToList <string>(Enumerable.Select <string, string>(Directory.EnumerateFiles(this.Website.LocalDir), new Func <string, string>(Path.GetFileName))))
            {
                // ISSUE: object of a compiler-generated type is created
                // ISSUE: variable of a compiler-generated type
                Ripper.Class3 class3 = new Ripper.Class3();
                // ISSUE: reference to a compiler-generated field
                class3.string_0 = str;
                // ISSUE: reference to a compiler-generated method
                IFileToDownload fileToDownload = Enumerable.FirstOrDefault <IFileToDownload>((IEnumerable <IFileToDownload>)list, new Func <IFileToDownload, bool>(class3.method_0));
                // ISSUE: reference to a compiler-generated field
                if (fileToDownload != null && new FileInfo(Path.Combine(this.Website.LocalDir, class3.string_0)).Length > 0L)
                {
                    list.Remove(fileToDownload);
                }
            }
            this.PostsFound = new System.Collections.Generic.Queue <IFileToDownload>((IEnumerable <IFileToDownload>)list);
            list.Clear();
            this.UpdateStatusPendingPosts(this.PostsFound.Count);
            while (!_cancellationToken.IsCancellationRequested)
            {
                // ISSUE: object of a compiler-generated type is created
                // ISSUE: variable of a compiler-generated type
                Ripper.Class4 class4 = new Ripper.Class4();
                // ISSUE: reference to a compiler-generated field
                class4.ripper_0 = this;
                while (this.ActiveThreads.Count > this.MaxThreads)
                {
                    try
                    {
                        Thread.Sleep(50);
                    }
                    catch (Exception ex)
                    {
                    }
                }
                // ISSUE: reference to a compiler-generated field
                class4.ifileToDownload_0 = (IFileToDownload)null;
                System.Collections.Generic.Queue <IFileToDownload> postsFound = this.PostsFound;
                bool lockTaken = false;
                try
                {
                    Monitor.Enter((object)postsFound, ref lockTaken);
                    if (num++ == 50)
                    {
                        num = 0;
                        this.SaveHistory();
                        this.MaxThreads = Math.Min(this.MaxThreads + 1, 10);
                    }
                    if (this.PostsFound.Count == 0)
                    {
                        this.SaveHistory();
                        Console.WriteLine("Queue is empty, but still have ongoing threads");
                        while (this.ActiveThreads.Count > 0)
                        {
                            Thread.Sleep(50);
                        }
                        break;
                    }
                    // ISSUE: reference to a compiler-generated field
                    class4.ifileToDownload_0 = this.PostsFound.Dequeue();
                    this.UpdateStatusPendingPosts(this.PostsFound.Count);
                    // ISSUE: reference to a compiler-generated field
                    string url = class4.ifileToDownload_0.Url;
                }
                finally
                {
                    if (lockTaken)
                    {
                        Monitor.Exit((object)postsFound);
                    }
                }
                // ISSUE: reference to a compiler-generated method
                Thread thread = new Thread(new ThreadStart(class4.method_0));
                // ISSUE: reference to a compiler-generated field
                thread.Name = class4.ifileToDownload_0.Filename;
                this.ActiveThreads.Add(thread);
                thread.Start();
            }
            while (true)
            {
                IList <Thread> activeThreads = this.ActiveThreads;
                bool           lockTaken     = false;
                try
                {
                    Monitor.Enter((object)activeThreads, ref lockTaken);
                    if (this.ActiveThreads.Count == 0)
                    {
                        break;
                    }
                }
                finally
                {
                    if (lockTaken)
                    {
                        Monitor.Exit((object)activeThreads);
                    }
                }
                Thread.Sleep(1000);
            }
        }