Beispiel #1
0
        private async void btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            diskitem = btn.DataContext as DiskItemModel;
            if (diskitem.FileTyp == "Archive")
            {
                string downfile = diskitem.FullName;
                btn.IsEnabled = false;
                //await new MessageDialog("选择下载或取消").ShowAsync();
                filemodel          = new FileDownLoadModel();
                filemodel.Img      = diskitem.Img;
                filemodel.FullName = diskitem.FullName;
                filemodel.Name     = diskitem.Name;
                //filemodel.Size =100;

                //filemodel.Count = 0;

                //看是否有要 下载的文件没
                if (App.downloadfile.Count == 0)
                {
                    filemodel.Status = "正在下载";
                    //向待下载队列添加文件
                    App.downloadfile.Add(filemodel);
                    //向历史队列添加文件
                    //也是listview的绑定对象,只增加,不减少
                    App.historyfile.Add(filemodel);
                    App.DownloadFile(downfile, App.socketFile);
                    await new MessageDialog("准备下载").ShowAsync();
                    btn.IsEnabled = true;
                    //App.ReceiveFile(diskitem, App.socketFile);
                    Task t = Task.Factory.StartNew(() =>
                    {
                        App.ReceiveFile(diskitem, App.socketFile);
                    });

                    //Task t = new Task(DoReciveFile);
                    //t.Start();

                    //await new MessageDialog("文件下载完毕").ShowAsync();
                }
                else
                {
                    filemodel.Status = "等待下载";
                    //向待下载队列添加文件
                    App.downloadfile.Add(filemodel);
                    //向历史队列添加文件
                    App.historyfile.Add(filemodel);
                    await new MessageDialog("已加入下载队列").ShowAsync();
                    btn.IsEnabled = true;
                }
            }
        }
Beispiel #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }


            diskfolderitem = e.Parameter as List <DiskFolder>;
            if (diskfolderitem.Count > 0)
            {
                pathname.DataContext = new DiskFolder()
                {
                    FullName = handle_PathName(diskfolderitem[0].FullName)
                };
                for (int i = 0; i < diskfolderitem.Count; i++)
                {
                    if (diskfolderitem[i].FileTyp == "Directory")
                    {
                        diskitemmodel.Add(new DiskItemModel {
                            Img = "ms-appx:///Image/folder.png", Name = diskfolderitem[i].Name, FullName = diskfolderitem[i].FullName, DownLoadPic = null, FileTyp = diskfolderitem[i].FileTyp
                        });
                    }
                    else if (diskfolderitem[i].FileTyp == "Archive")
                    {
                        diskitemmodel.Add(new DiskItemModel {
                            Img = "ms-appx:///Image/file.png", Name = diskfolderitem[i].Name, FullName = diskfolderitem[i].FullName, DownLoadPic = "ms-appx:///Image/download.png", FileTyp = diskfolderitem[i].FileTyp
                        });
                    }
                    else
                    {
                        diskitemmodel.Add(new DiskItemModel {
                            Img = "ms-appx:///Image/folder.png", Name = diskfolderitem[i].Name, FullName = diskfolderitem[i].FullName, DownLoadPic = null, FileTyp = diskfolderitem[i].FileTyp
                        });
                    }
                }
            }

            disklistview.ItemsSource = diskitemmodel;
            Task t = Task.Factory.StartNew(new Action(async() =>
            {
                while (true)
                {
                    while (App.alreadydownload <= App.totaldownload)
                    {
                        if (DiskListitem.filemodel != null)
                        {
                            if (App.alreadydownload == 0)
                            {
                                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
                                {
                                    loadanimation.Begin();
                                    btn.IsEnabled = false;
                                }));
                            }

                            if (App.alreadydownload != App.predownload)
                            {
                                FileDownLoadModel filemodel = new FileDownLoadModel();
                                filemodel.Name     = DiskListitem.filemodel.Name;
                                filemodel.FullName = DiskListitem.filemodel.FullName;
                                filemodel.Img      = "ms-appx:///Image/file1.png";
                                filemodel.Size     = App.totaldownload;
                                filemodel.Count    = App.alreadydownload;
                                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
                                {
                                    grid.DataContext = filemodel;
                                }));
                                await Task.Delay(30);
                            }
                        }
                        if (App.alreadydownload == App.totaldownload && App.totaldownload != 0)
                        {
                            await new MessageDialog("下载完毕").ShowAsync();
                            App.alreadydownload = 0;
                            //App.totaldownload = 0;
                            //App.predownload = 0;
                            DiskListitem.filemodel = null;
                            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
                            {
                                canelanimation.Begin();
                                btn.IsEnabled = true;
                            }));
                        }
                    }
                }
            }));
        }