Пример #1
0
        /// <summary>
        /// 读取文件进度变更
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnReadDeviceFileProgress(object sender, ProgressChangedEventArgs e)
        {
            var newItem = (DeviceSyncReadProgressItem)e.UserState;

            if (newItem.ProgressType == ReadSyncFileTaskProgressType.TEXT_ONLY)
            {
                //发送状态栏提示信息
                OnTaskBarEvent?.Invoke(newItem.Notify);
                return;
            }
            //找到已添加的父列表
            var listItem = mSyncDataList.Where((el) => el.PcFolderNameView.Equals(newItem.PcFolderNameView)).FirstOrDefault();

            if (null == listItem)
            {
                //没有则新建一个项
                var listItemPcFileList     = new ObservableCollection <DeviceSyncItem>();
                var listItemMoblieFileList = new ObservableCollection <DeviceSyncItem>();
                AddFolderListFileItem(listItemPcFileList, listItemMoblieFileList, newItem);
                mSyncDataList.Add(new DeviceSyncListViewModel
                {
                    PcFolderNameView     = newItem.PcFolderNameView,
                    MobileFolderNameView = newItem.MobileFolderNameView,
                    PcItemList           = listItemPcFileList,
                    MobileItemList       = listItemMoblieFileList
                });
            }
            else
            {
                //有则直接添加
                AddFolderListFileItem(listItem.PcItemList, listItem.MobileItemList, newItem);
            }
        }
Пример #2
0
        /// <summary>
        /// 文件同步进度事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSyncFileProgress(object sender, ProgressChangedEventArgs e)
        {
            var arg = e.UserState as DeviceSyncTaskArgs;

            if (SyncTaskProgressType.SUB_ITEM_FINISH == arg.ProgressType)
            {
                if (SyncDeviceType.PC == arg.Source)
                {
                    arg.Item.PcItemList.Remove(arg.DeviceSyncItem);
                }
                else
                {
                    arg.Item.MobileItemList.Remove(arg.DeviceSyncItem);
                }
            }
            else
            {
                if (arg.IsOk)
                {
                    mSyncDataList.Remove(arg.Item);
                }
                arg.ThatButton.IsEnabled = true;
            }
            OnTaskBarEvent?.Invoke(arg.Progress);
        }
Пример #3
0
 /// <summary>
 /// 当主窗口点击停止任务后, 改变任务状态
 /// </summary>
 private void ChangeTaskStatus()
 {
     //发送提示文本
     OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
     {
         alertLevel  = AlertLevel.RUN,
         nowProgress = 99,
         message     = "正在停止.."
     });
     if (mSyncFileBgWorker.IsBusy)
     {
         mSyncFileBgWorker.CancelAsync();
     }
     while (mSyncTaskQueue.Count > 0)
     {
         var item = new DeviceSyncTaskArgs();
         _ = mSyncTaskQueue.TryDequeue(out item);
     }
     if (mReadDeviceFileWorker.IsBusy)
     {
         mReadDeviceFileWorker.CancelAsync();
     }
 }
Пример #4
0
        /// <summary>
        /// 项目双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImgItemLeftClick(object sender, MouseButtonEventArgs e)
        {
            var subListView = XamlUtil.GetParentListView(e);
            //根据触发按钮获取点击的行
            var selected    = (DeviceSyncItem)((ListViewItem)subListView.ContainerFromElement(sender as StackPanel)).Content;
            var curTimeMill = TimeUtil.CurrentMillis();
            var lastClick   = selected.LastLeftMouseClickTime;

            selected.LastLeftMouseClickTime = curTimeMill;
            //双击才执行操作
            if (curTimeMill - lastClick < 200)
            {
                if (selected.SourceView == SyncDeviceType.PC)
                {
                    //如果文件存在于PC, 则打开文件
                    System.Diagnostics.Process.Start(Path.Combine(selected.FolderView, selected.NameView));
                }
                else
                {
                    //不允许重复调用
                    if (selected.IsCopying)
                    {
                        return;
                    }

                    //读取系统的临时文件夹
                    var winTempFolder = Path.GetTempPath();
                    if (null == winTempFolder)
                    {
                        OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                        {
                            message    = "无法获取临时文件夹",
                            alertLevel = AlertLevel.ERROR,
                        });
                        return;
                    }
                    var targetFullPath = Path.Combine(winTempFolder, selected.NameView);
                    //如果已经存在于临时文件夹, 则直接打开
                    if (System.IO.File.Exists(targetFullPath))
                    {
                        System.Diagnostics.Process.Start(targetFullPath);
                        return;
                    }

                    //发送进度消息
                    selected.IsCopying = true;
                    OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                    {
                        message     = "正在复制文件",
                        alertLevel  = AlertLevel.RUN,
                        nowProgress = 99
                    });
                    //先复制目标文件到临时文件夹, 再打开
                    using (var device = (MediaDevice)DeviceListCombobox.SelectedItem)
                    {
                        device.Connect();
                        var           filePath = Path.Combine(((DeviceDriverViewModel)DriverListCombobox.SelectedItem).ValueView, selected.FolderView, selected.NameView);
                        MediaFileInfo fileInfo = device.GetFileInfo(filePath);
                        fileInfo.CopyTo(targetFullPath);
                        device.Disconnect();
                    }
                    selected.IsCopying = false;
                    OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                    {
                        message = string.Format("已复制到临时文件夹 {0}", targetFullPath)
                    });
                    System.Diagnostics.Process.Start(targetFullPath);
                }
            }
            else
            {
                //显示文件名
                OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                {
                    message = string.Format("{0}", Path.Combine(selected.FolderView, selected.NameView))
                });
            }
        }
Пример #5
0
        /// <summary>
        /// 读取设备文件任务完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnReadDeviceFileTaskComplate(object sender, RunWorkerCompletedEventArgs e)
        {
            var notify = (MainWindowStatusNotify)e.Result;

            OnTaskBarEvent?.Invoke(notify);
        }
Пример #6
0
        /// <summary>
        /// 同步文件后台任务执行完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SyncFileTaskComplate(object sender, RunWorkerCompletedEventArgs e)
        {
            var rb = (bool)e.Result;

            OnTaskBarEvent?.Invoke(WindowUtil.CalcProgress(new MainWindowStatusNotify(), rb ? "同步完成" : "任务中止", 100));
        }