コード例 #1
0
ファイル: Download.cs プロジェクト: iSudocat/SudoDrive
        public void TaskStatusDetection()
        {
            while (true)
            {
                switch (DownloadTaskList.GetStatus(File.Key))
                {
                case StatusType.RequestPause:
                {
                    downloadTask.Pause();
                    DownloadTaskList.SetStatus(File.Key, StatusType.Paused);
                    break;
                }

                case StatusType.RequestRusume:
                {
                    downloadTask.Resume();
                    DownloadTaskList.SetStatus(File.Key, StatusType.Running);
                    break;
                }

                case StatusType.RequestCancel:
                {
                    downloadTask.Cancel();
                    DownloadTaskList.Remove(File.Key);
                    break;
                }

                default:
                    break;
                }

                Thread.Sleep(500);
            }
        }
コード例 #2
0
        public void refresh()
        {
            waiting.Clear();
            SortedList <long, FileControlBlock> watingList = DownloadTaskList.GetWaitingList();

            foreach (var x in watingList)
            {
                waiting.Add(new FileControlBlockVO(x.Value));
            }
            running.Clear();
            SortedList <long, FileControlBlock> runningList = DownloadTaskList.GetRunningList();

            foreach (var x in runningList)
            {
                running.Add(new FileControlBlockVO(x.Value));
            }
            success.Clear();
            SortedList <long, FileControlBlock> successList = DownloadTaskList.GetSuccessList();

            foreach (var x in successList)
            {
                success.Add(new FileControlBlockVO(x.Value));
            }
            fail.Clear();
            SortedList <long, FileControlBlock> failList = DownloadTaskList.GetFailureList();

            foreach (var x in failList)
            {
                fail.Add(new FileControlBlockVO(x.Value));
            }
        }
コード例 #3
0
ファイル: DownloadManagerInfo.cs プロジェクト: bxstar/KanKan
        public async Task DownLoadFile(string title, string videoSrcUrl, string mode, string downPath)
        {
            if (!string.IsNullOrEmpty(title))
            {
                var downloader = new FlvDownloader(videoSrcUrl);



                var partUrls = new List <string>();

                partUrls = await downloader.GetDownloadFiles(mode);

                if (partUrls != null && partUrls.Count > 0)
                {
                    string newdir = Path.Combine(downPath, title);
                    if (!Directory.Exists(newdir))
                    {
                        Directory.CreateDirectory(newdir);
                    }

                    var taskInfo = new DownloadTaskInfo(title, newdir, partUrls);
                    DownloadTaskList.Add(taskInfo);

                    taskInfo.Start();
                }
            }
        }
コード例 #4
0
 private void OnDownloadCompletedOrCanceled(DownloadStateChangedEventArgs e)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         DownloadTaskList.Remove(DownloadTaskList.FirstOrDefault(item => item.FileId == e.FileId));
     });
     RaisePropertyChanged(nameof(TotalDownloadQuantity));
     OnDownloadProgressChanged(null, null);
 }
コード例 #5
0
        protected override void OnLoaded()
        {
            if (_netDiskUser == null)
            {
                DownloadTaskList.Clear();
                return;
            }

            InitialDownloadList();
        }
コード例 #6
0
        private void OnDownloadCompleted(DownloadStateChangedEventArgs e)
        {
            var temp = _netDiskUser.GetCompletedFiles().FirstOrDefault(element => element.FileId == e.FileId);

            if (temp == null)
            {
                return;
            }
            var localFile = Container.Resolve <DownloadedTaskItemViewModel>(new DependencyOverride <ILocalDiskFile>(temp));

            DownloadTaskList.Insert(0, localFile);
        }
コード例 #7
0
        public DownloadedPageViewModel(IUnityContainer container, ILocalDiskUserRepository localDiskUserRepository)
            : base(container)
        {
            _localDiskUserRepository = localDiskUserRepository;

            ClearAllRecordCommand = new Command(ClearAllRecordCommandExecute, () => DownloadTaskList?.Any() ?? false);
            EventAggregator.GetEvent <DownloadStateChangedEvent>().Subscribe(
                OnDownloadCompleted,
                Prism.Events.ThreadOption.UIThread,
                keepSubscriberReferenceAlive: false,
                filter: e => e.NewState == DownloadStateEnum.Completed);
        }
コード例 #8
0
        public DownloadingPageViewModel(IUnityContainer container, IMountUserRepository mountUserRepository)
            : base(container)
        {
            _mountUserRepository = mountUserRepository;
            Func <bool> isAnyElementInDownloadTaskList = () => DownloadTaskList?.Any() ?? false;

            PauseAllCommand  = new Command(PauseAllCommandExecute, isAnyElementInDownloadTaskList);
            StartAllCommand  = new Command(StartAllCommandExecute, isAnyElementInDownloadTaskList);
            CancelAllCommand = new Command(CancelAllCommandExecute, isAnyElementInDownloadTaskList);

            EventAggregator.GetEvent <DownloadProgressChangedEvent>().Subscribe(OnDownloadPregressChanged, ThreadOption.UIThread);
            EventAggregator.GetEvent <DownloadStateChangedEvent>().Subscribe(OnDownloadStateChanged, ThreadOption.UIThread);
        }
コード例 #9
0
        private void InitialDownloadEvents(HttpDownload downloadInfo)
        {
            var taskInfo = DownloadTaskList.FirstOrDefault(item => item.FilePath.FullPath == downloadInfo.DownloadPath);

            if (taskInfo != null)
            {
                downloadInfo.DownloadProgressChangedEvent += taskInfo.OnDownloadProgressChanged;
                downloadInfo.DownloadStateChangedEvent    += taskInfo.OnDownloadStateChanged;
            }

            downloadInfo.DownloadProgressChangedEvent += OnDownloadProgressChanged;
            downloadInfo.DownloadStateChangedEvent    += OnDownloadStateChanged;
        }
コード例 #10
0
        protected override void OnLoaded()
        {
            var netDiskUser = _localDiskUserRepository?.FirstOrDefault()?.CurrentNetDiskUser;

            if (netDiskUser == null)
            {
                return;
            }
            foreach (var item in netDiskUser.GetUncompletedFiles())
            {
                DownloadTaskList.Add(Container.Resolve <DownloadingTaskItemViewModel>(new DependencyOverride <IDiskFile>(item)));
            }
        }
コード例 #11
0
        private void OnDownloadCompleted(object sender, DownloadStateChangedEventArgs e)
        {
            var temp = TaskManager.GetTaskManagerByLocalDiskUser(MountUserRepository.MountedUser).
                       GetCompletedList().
                       FirstOrDefault(element => element.FileId == e.FileId);

            if (temp == null)
            {
                return;
            }
            var localFile = new DownloadedTaskItemViewModel(temp);

            DownloadTaskList.Insert(0, localFile);
        }
コード例 #12
0
 /// <summary>
 /// 下载文件
 /// </summary>
 /// <param name="localPath"></param>
 /// <param name="fileName"></param>
 /// <param name="guid"></param>
 /// <returns></returns>
 public string download(string localPath, string fileName, string id)
 {
     if (userService == null)
     {
         return(null);
     }
     DownloadTaskList.Add(new FileControlBlock
     {
         FileName  = fileName,
         Id        = id,
         LocalPath = localPath,
         Status    = StatusType.Waiting
     });
     return(null);
 }
コード例 #13
0
        private void InitialDownloadList()
        {
            foreach (var item in TaskManager.GetTaskManagerByLocalDiskUser(_netDiskUser).GetUnCompletedList())
            {
                if (DownloadTaskList.Any(element => element.FileId == item.FileId))
                {
                    continue;
                }

                var viewmodel = new DownloadingTaskItemViewModel(item);
                viewmodel.RemoveItemEvent += (task) =>
                {
                    DownloadTaskList.Remove(task);
                };
                DownloadTaskList.Add(viewmodel);
            }
        }
コード例 #14
0
 protected override void OnLoaded()
 {
     SetProperty(ref _netDiskUser, _mountUserRepository?.FirstOrDefault()?.GetCurrentNetDiskUser());
     if (_netDiskUser == null)
     {
         DownloadTaskList.Clear();
         return;
     }
     foreach (var item in _netDiskUser.GetUncompletedFiles())
     {
         if (DownloadTaskList.Any(element => element.FileId == item.FileId))
         {
             continue;
         }
         DownloadTaskList.Add(Container.Resolve <DownloadingTaskItemViewModel>(new DependencyOverride <IMountUser>(_mountUserRepository.FirstOrDefault()), new DependencyOverride <IDiskFile>(item)));
     }
 }
コード例 #15
0
        protected override void OnLoaded()
        {
            TaskManager.GetTaskManagerByLocalDiskUser(MountUserRepository.MountedUser).TaskCollectionChanged += (httpdownload) =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                });
            };


            foreach (var item in TaskManager.GetTaskManagerByLocalDiskUser(MountUserRepository.MountedUser).GetCompletedList())
            {
                if (DownloadTaskList.Any(element => element.FileId == item.FileId))
                {
                    continue;
                }
                DownloadTaskList.Add(new DownloadedTaskItemViewModel(item));
            }
        }
コード例 #16
0
        private void OnDownloadStateChanged(DownloadStateChangedEventArgs e)
        {
            OnPropertyChanged(nameof(IsStartAll));
            if (e.NewState == DownloadStateEnum.Completed || e.NewState == DownloadStateEnum.Canceled)
            {
                OnDownloadCompletedOrCanceled(e);
            }

            if (e.NewState == DownloadStateEnum.Downloading)
            {
                var temp      = DownloadTaskList.FirstOrDefault(item => item.FileId == e.FileId);
                var indexThis = DownloadTaskList.IndexOf(temp);
                if (indexThis != 0)
                {
                    DownloadTaskList.Insert(0, temp);
                    DownloadTaskList.Remove(temp);
                }
            }
            Debug.WriteLine($"{DateTime.Now}: FileId={e.FileId}, OldState={e.OldState}, NewState={e.NewState}, IsStartAll={IsStartAll}");
        }
コード例 #17
0
        public DownloadingPageViewModel()
        {
            InitialDownloadList();


            TaskManager.GetTaskManagerByLocalDiskUser(MountUserRepository.MountedUser).TaskAddedCompleted += () =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    InitialDownloadList();
                });
            };

            TaskManager.GetTaskManagerByLocalDiskUser(MountUserRepository.MountedUser).TaskCollectionChanged += (httpdownload) =>
            {
                Application.Current.Dispatcher.Invoke(() => InitialDownloadEvents(httpdownload));
            };



            var https = TaskManager.GetTaskManagerByLocalDiskUser(MountUserRepository.MountedUser).GetHttpDownloads();

            foreach (var item in https)
            {
                if (item.DownloadState == DownloadStateEnum.Downloading)
                {
                    var downloadingItem = DownloadTaskList.FirstOrDefault(p => p.FilePath.FullPath == item.DownloadPath);
                    if (downloadingItem != null)
                    {
                        downloadingItem.OnDownloadStateChanged(null,
                                                               new DownloadStateChangedEventArgs(DownloadStateEnum.Waiting, DownloadStateEnum.Downloading));

                        item.DownloadStateChangedEvent    += downloadingItem.OnDownloadStateChanged;
                        item.DownloadProgressChangedEvent += downloadingItem.OnDownloadProgressChanged;
                    }
                }

                item.DownloadStateChangedEvent    += OnDownloadStateChanged;
                item.DownloadProgressChangedEvent += OnDownloadProgressChanged;
            }
        }
コード例 #18
0
 protected override void OnDispose(bool fDisposing)
 {
     if (fDisposing)
     {
         if (this._deviceList != null)
         {
             this._deviceList.DeviceAddedEvent        -= new DeviceListEventHandler(this.OnDeviceAdded);
             this._deviceList.DeviceRemovedEvent      -= new DeviceListEventHandler(this.OnDeviceRemoved);
             this._deviceList.DeviceConnectedEvent    -= new DeviceListEventHandler(this.OnDeviceConnected);
             this._deviceList.DeviceDisconnectedEvent -= new DeviceListEventHandler(this.OnDeviceDisconnected);
             this._deviceList = null;
         }
         if (this._downloadTasks != null)
         {
             this._downloadTasks.ActiveDownloads.PropertyChanged -= new PropertyChangedEventHandler(this.OnDownloadPropertyChanged);
             this._downloadTasks = null;
         }
         SignIn.Instance.PropertyChanged          -= new PropertyChangedEventHandler(this.SignInPropertyChanged);
         AccountCreationWizard.CreationCompleted  -= new EventHandler(this.AccountCreationFinished);
         DeviceManagement.DeviceConnectionHandled -= new DeviceConnectionHandledEventHandler(this.OnDeviceConnectionHandled);
     }
     base.OnDispose(fDisposing);
 }
コード例 #19
0
        private void OnDownloadStateChanged(object sender, DownloadStateChangedEventArgs e)
        {
            RaisePropertyChanged(nameof(IsStartAll));
            if (e.NewState == DownloadStateEnum.Completed || e.NewState == DownloadStateEnum.Canceld)
            {
                OnDownloadCompletedOrCanceled(e);
            }

            if (e.NewState == DownloadStateEnum.Downloading)
            {
                var temp      = DownloadTaskList.FirstOrDefault(item => item.FileId == e.FileId);
                var indexThis = DownloadTaskList.IndexOf(temp);
                if (indexThis != 0)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        DownloadTaskList.Insert(0, temp);
                        DownloadTaskList.Remove(temp);
                    });
                }
            }
            Debug.WriteLine($"{DateTime.Now}: FileId={e.FileId}, OldState={e.OldState}, NewState={e.NewState}, IsStartAll={IsStartAll}");
        }
コード例 #20
0
ファイル: MainWindow.xaml.cs プロジェクト: iSudocat/SudoDrive
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            UserRequest userService = new UserRequest();

            userService.Login("sudodog", "ssss11111", out _);

            DownloadTaskList.Add(new FileControlBlock
            {
                FileName  = "1.txt",
                Id        = "335",
                LocalPath = @"C:\Users\i\Desktop",
                Status    = StatusType.Waiting
            });

            DownloadTaskList.Add(new FileControlBlock
            {
                FileName  = "2.txt",
                Id        = "336",
                LocalPath = @"C:\Users\i\Desktop",
                Status    = StatusType.Waiting
            });

            DownloadTaskList.Add(new FileControlBlock
            {
                FileName  = "3.txt",
                Id        = "337",
                LocalPath = @"C:\Users\i\Desktop",
                Status    = StatusType.Waiting
            });

            DownloadTaskList.Add(new FileControlBlock
            {
                FileName  = "4.txt",
                Id        = "338",
                LocalPath = @"C:\Users\i\Desktop",
                Status    = StatusType.Waiting
            });

            DownloadTaskList.Add(new FileControlBlock
            {
                FileName  = "5.txt",
                Id        = "339",
                LocalPath = @"C:\Users\i\Desktop",
                Status    = StatusType.Waiting
            });

            DownloadTaskList.Add(new FileControlBlock
            {
                FileName  = "6.txt",
                Id        = "340",
                LocalPath = @"C:\Users\i\Desktop",
                Status    = StatusType.Waiting
            });

            DownloadTaskList.Add(new FileControlBlock
            {
                FileName  = "7.txt",
                Id        = "341",
                LocalPath = @"C:\Users\i\Desktop",
                Status    = StatusType.Waiting
            });
        }
コード例 #21
0
 private void OnDownloadCompletedOrCanceled(DownloadStateChangedEventArgs e)
 {
     DownloadTaskList.Remove(DownloadTaskList.FirstOrDefault(item => item.FileId == e.FileId));
     OnPropertyChanged(nameof(TotalDownloadQuantity));
     OnDownloadPregressChanged(null);
 }
コード例 #22
0
ファイル: Download.cs プロジェクト: iSudocat/SudoDrive
        public void Run()
        {
            FileRequest fileRequest = new FileRequest();
            int         status      = fileRequest.Download(File.Id, out FileListResponse res);

            switch (status)
            {
            case -20000:
                TaskStatusDetectionThread.Abort();
                DownloadTaskList.SetFailure(File.Key, "请求服务器失败,请稍后再试。");
                break;

            case -20001:
                TaskStatusDetectionThread.Abort();
                DownloadTaskList.SetFailure(File.Key, "请求下载的文件不存在。");
                break;

            case -10000:
                TaskStatusDetectionThread.Abort();
                DownloadTaskList.SetFailure(File.Key, res.message);
                break;

            case 0:
            {
                string bucket        = res.data.tencentCos.bucket;    //存储桶,格式:BucketName-APPID
                string cosPath       = res.data.files[0].storageName; //对象在存储桶中的位置标识符,即称对象键
                string localDir      = File.LocalPath;                //本地文件夹
                string localFileName = File.FileName;                 //指定本地保存的文件名

                CosService      cosService      = new CosService(res.data.tencentCos.region);
                CosXml          cosXml          = cosService.getCosXml(res.data.token.credentials.tmpSecretId, res.data.token.credentials.tmpSecretKey, res.data.token.credentials.token, res.data.token.expiredTime);
                TransferConfig  transferConfig  = new TransferConfig();
                TransferManager transferManager = new TransferManager(cosXml, transferConfig);
                downloadTask = new COSXMLDownloadTask(bucket, cosPath, localDir, localFileName);

                downloadTask.progressCallback = delegate(long completed, long total)
                {
                    DownloadTaskList.SetProgress(File.Key, completed, total);
                    Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));
                };
                downloadTask.successCallback = delegate(CosResult cosResult)
                {
                    TaskStatusDetectionThread.Abort();
                    COSXMLDownloadTask.DownloadTaskResult result = cosResult as COSXMLDownloadTask.DownloadTaskResult;
                    Console.WriteLine("successCallback: " + result.GetResultInfo());
                    string eTag = result.eTag;
                    DownloadTaskList.SetSuccess(File.Key);
                };
                downloadTask.failCallback = delegate(CosClientException clientEx, CosServerException serverEx)
                {
                    if (clientEx != null)
                    {
                        Console.WriteLine("CosClientException: " + clientEx);
                    }
                    if (serverEx != null)
                    {
                        Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                    }
                    TaskStatusDetectionThread.Abort();
                    DownloadTaskList.SetFailure(File.Key, "COS下载出错。");
                };
                transferManager.Download(downloadTask);
            }
            break;

            default:
                TaskStatusDetectionThread.Abort();
                DownloadTaskList.SetFailure(File.Key, "未知原因下载失败。");
                break;
            }
        }