Beispiel #1
0
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            DownQueue dq = e.UserState as DownQueue;

            procDownloadProgressChanged(dq.CurrentFile, e);
            OnDownloadMsgEvent(sender, dq, null, false);
        }
Beispiel #2
0
 private void OnDownloadMsgEvent(object sender, DownQueue dq, Exception error, bool completed)
 {
     if (dq != null && DownloadMsgEvent != null)
     {
         DownloadMsgEventArgs e = new DownloadMsgEventArgs(dq, error, completed);
         DownloadMsgEvent(sender, e);
     }
 }
Beispiel #3
0
 public ImageList()
 {
     InitializeComponent();
     CachePath             = ConfigManage.Base.CachePath;
     DownPath              = ConfigManage.Base.DownPath;
     this.SizeChanged     += new System.Windows.SizeChangedEventHandler(Resize);
     downQueue             = new DownQueue(this, true);
     downQueue.OnComplate += DownQueue_OnComplate;
     downQueue.OnError    += DownQueue_OnError;
     InitBtn();
 }
Beispiel #4
0
        private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            DownQueue dq = e.UserState as DownQueue;

            dq.CurrentFile.Completed = true;
            if (e.Error != null)
            {
                dq.CurrentFile.ErrorMsg = e.Error.Message;
                Helper.HandelException(e.Error);
            }
            OnDownloadMsgEvent(sender, dq, e.Error, true);
            if (dq.QueueFile.Any())
            {
                DownloadFileInfo nextFile = dq.QueueFile.Dequeue();
                dq.CurrentFile = nextFile;
                client.DownloadFileAsync(new Uri(nextFile.Url), nextFile.DescFilePath, dq);
            }
            else
            {
                IsRun = false;
                client.Dispose();
            }
        }
Beispiel #5
0
        public void DownloadFile()
        {
            if (!IsRunBlock(true))
            {
                try
                {
                    #region 远程文件信息
                    string        foldUrl       = getFoldersString();
                    string        fileUrl       = getFilesString();
                    string        foldersString = getRequestString(foldUrl);
                    List <string> lFolder       = getFolderInfo(foldersString);
                    lFolder.RemoveAll(delegate(string str) { return(str == "aspnet_client"); });
                    Dictionary <string, List <DownloadFileInfo> > dict = new Dictionary <string, List <DownloadFileInfo> >();
                    if (lFolder.Count > 0)
                    {
                        foreach (string folder in lFolder)
                        {
                            string filesString = getRequestString(fileUrl + "&CurrentFolder=" + WebUtility.HtmlEncode(folder));
                            List <DownloadFileInfo> lFileInfo = getFileInfo(folder, filesString);
                            if (lFileInfo.Count > 0)
                            {
                                dict.Add(folder, lFileInfo);
                            }
                        }
                    }
                    else
                    {
                        string filesString = getRequestString(fileUrl);
                        List <DownloadFileInfo> lFileInfo = getFileInfo(ResourceType, filesString);
                        if (lFileInfo.Count > 0)
                        {
                            dict.Add(ResourceType, lFileInfo);
                        }
                    }
                    #endregion

                    #region 处理本地目录及文件
                    if (Directory.Exists(DestDir) && dict.Count > 0)
                    {
                        DirectoryInfo oDir   = new System.IO.DirectoryInfo(DestDir);
                        FileInfo[]    aFiles = oDir.GetFiles();
                        procFile(dict, aFiles, ResourceType);

                        DirectoryInfo[] aDirectories = oDir.GetDirectories();
                        foreach (DirectoryInfo directoryInfo in aDirectories)
                        {
                            if (dict.ContainsKey(directoryInfo.Name))
                            {
                                FileInfo[] aFiles1 = directoryInfo.GetFiles();
                                procFile(dict, aFiles1, directoryInfo.Name);
                            }
                            else
                            {
                                directoryInfo.Delete(true);
                            }
                        }
                    }
                    #endregion


                    Queue <DownloadFileInfo> ll = new Queue <DownloadFileInfo>();
                    foreach (string folder in dict.Keys)
                    {
                        string downloadFileString = ConnectorUrlString
                                                    + "?command=DownloadFile"
                                                    + "&type=" + ResourceType;
                        if (!folder.Equals(ResourceType))
                        {
                            downloadFileString += "&CurrentFolder=" + WebUtility.HtmlEncode(folder);
                        }
                        foreach (DownloadFileInfo fileInfo in dict[folder])
                        {
                            string currentDownloadFileUrl = downloadFileString + "&FileName=" + WebUtility.HtmlEncode(fileInfo.FileName);
                            string descFilePath           = folder == ResourceType?Path.Combine(DestDir, fileInfo.FileName) : Path.Combine(DestDir, folder, fileInfo.FileName);

                            if (folder == ResourceType)
                            {
                                if (!Directory.Exists(DestDir))
                                {
                                    Directory.CreateDirectory(DestDir);
                                }
                            }
                            else
                            {
                                if (!Directory.Exists(Path.Combine(DestDir, folder)))
                                {
                                    Directory.CreateDirectory(Path.Combine(DestDir, folder));
                                }
                            }
                            fileInfo.DestDir      = folder;
                            fileInfo.DescFilePath = descFilePath;
                            fileInfo.Url          = currentDownloadFileUrl;
                            ll.Enqueue(fileInfo);
                        }
                    }
                    if (ll.Any())
                    {
                        DownloadFileInfo currentFile = ll.Dequeue();
                        DownQueue        dq          = new DownQueue();
                        dq.CurrentFile = currentFile;
                        dq.QueueFile   = ll;
                        client.DownloadFileAsync(new Uri(currentFile.Url), currentFile.DescFilePath, dq);
                    }
                    else
                    {
                        IsRun = false;
                        client.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    IsRun = false;
                    client.Dispose();
                    throw ex;
                }
            }
        }