Beispiel #1
0
            public static void StartUpload()
            {
                webClient.UploadProgressChanged += WebClient_UploadProgressChanged;
                webClient.UploadFileCompleted   += WebClient_UploadFileCompleted;
                long preProcent = -1;

                while (true)
                {
                    if (!webClient.IsBusy)
                    {
                        if (procent != -1)
                        {
                            ConsoleColor _c = Console.ForegroundColor;
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n | Completed!\n");
                            Console.ForegroundColor = _c;
                        }
                        if (uploadList.Count > 0)
                        {
                            int index = uploadList.Count - 1;
                            Console.WriteLine("Uploading \"" + uploadList[index] + "\" to " + ulUrl);
                            Upload(uploadList[index]);
                            uploadList.RemoveAt(index);
                        }
                        else
                        {
                            Console.WriteLine("Uploads are complete.");
                            break;
                        }
                    }
                    if (procent != -1 && preProcent != procent)
                    {
                        BytePreference bp = bytePreference;

                        if (bp == BytePreference.Auto)
                        {
                            if (totalBytes < 1000)
                            {
                                bp = BytePreference.Bytes;
                            }
                            else if (totalBytes < 1000000)
                            {
                                bp = BytePreference.KiloBytes;
                            }
                            else if (totalBytes < 1000000000)
                            {
                                bp = BytePreference.MegaBytes;
                            }
                            else if (totalBytes >= 1000000000)
                            {
                                bp = BytePreference.GigaBytes;
                            }
                        }

                        if (bp == BytePreference.Bytes)
                        {
                            Console.Write(procent + "% | " + curbytes + " B/" + totalBytes + " B ");
                        }
                        else if (bp == BytePreference.KiloBytes)
                        {
                            Console.Write(procent + "% | " + Math.Round(curbytes / 1000.0, 2) + " KB/" + Math.Round(totalBytes / 1000.0, 2) + " KB ");
                        }
                        else if (bp == BytePreference.MegaBytes)
                        {
                            Console.Write(procent + "% | " + Math.Round(curbytes / 1000000.0, 2) + " MB/" + Math.Round(totalBytes / 1000000.0, 2) + " MB ");
                        }
                        else if (bp == BytePreference.GigaBytes)
                        {
                            Console.Write(procent + "% | " + Math.Round(curbytes / 1000000000.0, 2) + " GB/" + Math.Round(totalBytes / 1000000000.0, 2) + " GB ");
                        }
                        Console.CursorLeft = 0;
                        preProcent         = procent;
                    }
                }
            }
Beispiel #2
0
            /// <summary>
            /// Start Download from downloadList
            /// </summary>
            public static Dictionary <string, int> StartDownload()
            {
                Dictionary <string, int> newFiles = new Dictionary <string, int>
                {
                    { "new", 0 },
                    { "updated", 0 },
                    { "exists", 0 },
                    { "failed", 0 }
                };

                webClient.DownloadDataCompleted   += WebClient_DownloadDataCompleted;
                webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
                int preProcent = -1;

                while (true)
                {
                    if (!webClient.IsBusy)
                    {
                        if (procent != -1)
                        {
                            ConsoleColor _c = Console.ForegroundColor;
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n | Completed!\n");
                            Console.ForegroundColor = _c;
                        }
                        if (downloadList.Count > 0)
                        {
                            string   fileName     = downloadList[0][1];
                            string   fullFileName = dlDirectory + "/" + fileName;
                            FileInfo fileInfo     = new FileInfo(fullFileName);
                            try
                            {
                                webClient.OpenRead(downloadList[0][0]);
                                if (!forceDownload && File.Exists(fullFileName) && fileInfo.Length == Convert.ToInt64(webClient.ResponseHeaders["Content-Length"]))
                                {
                                    if (!silentDownload)
                                    {
                                        ConsoleColor _c = Console.ForegroundColor;
                                        Console.ForegroundColor = ConsoleColor.Yellow;
                                        Console.WriteLine("File already in folder: " + fullFileName);
                                        Console.ForegroundColor = _c;
                                        newFiles["exists"]++;
                                        procent = -1;
                                    }
                                }
                                else
                                {
                                    if (!forceDownload && File.Exists(fullFileName))
                                    {
                                        newFiles["updated"]++;
                                        if (!silentDownload)
                                        {
                                            Console.WriteLine("Updating \"" + fileName + "\" from " + downloadList[0][0]);
                                        }
                                    }
                                    else
                                    {
                                        newFiles["new"]++;
                                        if (!silentDownload)
                                        {
                                            Console.WriteLine("Downloading \"" + fileName + "\" from " + downloadList[0][0]);
                                        }
                                    }
                                    string dlToDir =
                                        dlDirectory + "/" + fileName.Substring(0, fileName.Length - GetFileName(fileName).Length);
                                    string dlAsName = fileName.Substring(fileName.Length - GetFileName(fileName).Length);
                                    DownloadFile(downloadList[0][0], dlToDir, dlAsName);
                                }
                            }
                            catch (Exception e)
                            {
                                ConsoleColor _c = Console.ForegroundColor;
                                Base.Error(e.Message);
                                Base.Error(fullFileName + "\nFrom " + downloadList[0][0]);
                                newFiles["failed"]++;
                                preProcent = -1;
                                //Thread.Sleep(1000);
                            }
                            downloadList.RemoveAt(0);
                        }
                        else
                        {
                            Console.WriteLine("Downloads are complete.");
                            return(newFiles);
                        }
                    }
                    if (!silentDownload && procent != -1 && preProcent != procent)
                    {
                        BytePreference bp = bytePreference;

                        if (bp == BytePreference.Auto)
                        {
                            if (totalBytes < 1000)
                            {
                                bp = BytePreference.Bytes;
                            }
                            else if (totalBytes < 1000000)
                            {
                                bp = BytePreference.KiloBytes;
                            }
                            else if (totalBytes < 1000000000)
                            {
                                bp = BytePreference.MegaBytes;
                            }
                            else if (totalBytes >= 1000000000)
                            {
                                bp = BytePreference.GigaBytes;
                            }
                        }

                        if (bp == BytePreference.Bytes)
                        {
                            Console.Write(procent + "% | " + curbytes + " B/" + totalBytes + " B ");
                        }
                        else if (bp == BytePreference.KiloBytes)
                        {
                            Console.Write(procent + "% | " + Math.Round(curbytes / 1000.0, 2) + " KB/" + Math.Round(totalBytes / 1000.0, 2) + " KB ");
                        }
                        else if (bp == BytePreference.MegaBytes)
                        {
                            Console.Write(procent + "% | " + Math.Round(curbytes / 1000000.0, 2) + " MB/" + Math.Round(totalBytes / 1000000.0, 2) + " MB ");
                        }
                        else if (bp == BytePreference.GigaBytes)
                        {
                            Console.Write(procent + "% | " + Math.Round(curbytes / 1000000000.0, 2) + " GB/" + Math.Round(totalBytes / 1000000000.0, 2) + " GB ");
                        }
                        Console.CursorLeft = 0;
                        preProcent         = procent;
                    }
                }
            }
Beispiel #3
0
 /// <summary>
 /// Start Download from downloadList
 /// </summary>
 /// <param name="bytePreference">Set how you want to show bytes, like Bytes, KiloBytes, MegaBytes and GigaBytes</param>
 public static Dictionary <string, int> StartDownload(BytePreference bytePreference)
 {
     DL.bytePreference = bytePreference;
     return(StartDownload());
 }
Beispiel #4
0
 /// <summary>
 /// Set the Byte preference
 /// </summary>
 public static void BytePref(BytePreference bp)
 {
     bytePreference = bp;
 }