示例#1
0
        private static void Download(string[] args)
        {
            var param = UrlDownloaderParam.ParseArgs(args);

            if (!File.Exists(param.UrlTextPath))
            {
                log.Error("File not exists " + param.UrlTextPath);
            }
            else
            {
                try
                {
                    bool isOverwrite = param.IsOverWrite;
                    var  SaveDir     = param.DownloadDirectory;
                    Gdp.Utils.FileUtil.CheckOrCreateDirectory(SaveDir);
                    var           FileUrls = File.ReadAllLines(param.UrlTextPath);
                    List <string> failed   = new List <string>();
                    int           okCount  = 0;
                    foreach (string url in FileUrls)
                    {
                        string info = "Downloading successfully!";
                        if (!Gdp.Utils.NetUtil.FtpDownload(url, Path.Combine(SaveDir, Path.GetFileName(url)), isOverwrite))
                        {
                            failed.Add(url);
                            info = "Downloading Filed!";
                        }
                        else
                        {
                            okCount++;
                        }
                        ShowInfo(info + url);
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Download Error:" + ex.Message);
                }
            }
        }
        private static UrlDownloaderParam ParseDic(Dictionary <string, List <string> > dic)
        {
            UrlDownloaderParam UrlDownloaderParam = new UrlDownloaderParam();

            foreach (var item in dic)
            {
                var type    = Gdp.Utils.EnumUtil.TryParse <UrlDownloaderParamType>(item.Key);
                var listVal = item.Value;
                switch (type)
                {
                case UrlDownloaderParamType._:
                    break;

                case UrlDownloaderParamType.D:
                    break;

                case UrlDownloaderParamType.DownloadDirectory:
                    UrlDownloaderParam.DownloadDirectory = (listVal[0]);
                    break;

                case UrlDownloaderParamType.UrlTextPath:
                    UrlDownloaderParam.UrlTextPath = (listVal[0]);
                    break;

                case UrlDownloaderParamType.IsOverWrite:
                    UrlDownloaderParam.IsOverWrite = Boolean.Parse(listVal[0]);
                    break;

                default:
                    log.Warn(type + " Not implemented ");
                    break;
                }
            }

            return(UrlDownloaderParam);
        }