Пример #1
0
        /// <summary>
        /// 创建同步项
        /// </summary>
        /// <param name="fileName">文件名称</param>
        /// <param name="folderPath">文件路径</param>
        /// <param name="source">源 1 PC, 2 移动设备</param>
        /// <param name="device">设备</param>
        /// <param name="driverName">设备驱动</param>
        /// <returns></returns>
        private DeviceSyncItem CreateSyncItem(string fileName, string folderPath, SyncDeviceType source, MediaDevice device, string driverName)
        {
            //判断文件是否存在于设备
            var item = new DeviceSyncItem()
            {
                NameView   = fileName,
                SourceView = source,
                FolderView = folderPath,
            };
            var mediaType = FileUtil.GetMediaTypeByName(fileName);

            item.ContentType = mediaType;
            if (mediaType == SyncContentType.IMAGE || mediaType == SyncContentType.VIDEO)
            {
                if (source == SyncDeviceType.PHONE)
                {
                    var fileInfo = device.GetFileInfo(Path.Combine(driverName, folderPath, fileName));
                    var imgByte  = GetMediaFileThumbnail(fileInfo);
                    if (null != imgByte)
                    {
                        item.ImgByte = imgByte;
                    }
                }
                else
                {
                    var imgByte = ImageUtil.CreateThumbnail(Path.Combine(folderPath, fileName), 100, 100);
                    item.ImgByte = ImageUtil.ImageToByteArray(imgByte);
                }
            }
            if (mediaType == SyncContentType.AUDIO)
            {
                //PC文件直接读取
                if (source == SyncDeviceType.PC)
                {
                    item.ImgByte = FileUtil.GetAudioFileAlbum(Path.Combine(folderPath, fileName));
                }
                else
                {
                    //手机文件, 先复制到临时文件夹, 再读取
                    var winTempFolder = Path.GetTempPath();
                    if (!string.IsNullOrEmpty(winTempFolder))
                    {
                        var tempFullPath = Path.Combine(winTempFolder, fileName);
                        if (System.IO.File.Exists(tempFullPath))
                        {
                            //已存在则直接读取
                            item.ImgByte = FileUtil.GetAudioFileAlbum(tempFullPath);
                        }
                        else
                        {
                            //不存在则复制
                            var fileInfo = device.GetFileInfo(Path.Combine(driverName, folderPath, fileName));
                            fileInfo.CopyTo(tempFullPath);
                            item.ImgByte = FileUtil.GetAudioFileAlbum(tempFullPath);
                        }
                    }
                }
            }
            return(item);
        }
 private void LoadDeviceIcon(SyncDeviceType deviceType)
 {
     string iconName = string.Empty;
     switch (deviceType)
     {
         case SyncDeviceType.Linux:
             iconName = "pc_linux_large";
             break;
         case SyncDeviceType.OSX:
             iconName = "pc_mac_large";
             break;
         case SyncDeviceType.Windows:
             iconName = "pc_windows_large";
             break;
         case SyncDeviceType.iPhone:
             iconName = "phone_iphone_large";
             break;
         case SyncDeviceType.iPad:
             iconName = "tablet_ipad_large";
             break;
         case SyncDeviceType.AndroidPhone:
             iconName = "phone_android_large";
             break;
         case SyncDeviceType.AndroidTablet:
             iconName = "tablet_android_large";
             break;
         case SyncDeviceType.WindowsPhone:
             iconName = "phone_windows_large";
             break;
         case SyncDeviceType.WindowsStore:
             iconName = "tablet_windows_large";
             break;
     }
     imageViewDevice.Image = ImageResources.Images.FirstOrDefault(x => x.Name == iconName);
 }
        public SyncDeviceType GetDeviceType()
        {
            if (_deviceType != SyncDeviceType.Unknown)
                return _deviceType;

            var telephonyManager = (TelephonyManager)_context.GetSystemService(Context.TelephonyService);
            _deviceType = telephonyManager.PhoneType == PhoneType.None ? SyncDeviceType.AndroidTablet : SyncDeviceType.AndroidPhone;
            return _deviceType;
        }
Пример #4
0
        /// <summary>
        /// 收集并提醒
        /// </summary>
        /// <param name="files"></param>
        /// <param name="workArgs"></param>
        /// <param name="progressEvent"></param>
        /// <param name="e"></param>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        private bool CollectAndNotify(List <string> files, DoWorkEventArgs workArgs, MediaSyncConfig e, SyncDeviceType deviceType)
        {
            var args = (DeviceSyncReadArgs)workArgs.Argument;

            foreach (var fileName in files)
            {
                if (mReadDeviceFileWorker.CancellationPending)
                {
                    return(false);
                }
                var targetFolderPath = deviceType == SyncDeviceType.PC ? e.PcPath : e.MobilePath;
                //汇报文本进度
                mReadDeviceFileWorker.ReportProgress(0, new DeviceSyncReadProgressItem
                {
                    ProgressType = ReadSyncFileTaskProgressType.TEXT_ONLY,
                    Notify       = new MainWindowStatusNotify
                    {
                        alertLevel  = AlertLevel.RUN,
                        message     = string.Format("正在收集差异文件  [{0}]", Path.Combine(targetFolderPath, fileName)),
                        nowProgress = 99
                    }
                });
                var item = CreateSyncItem(fileName, targetFolderPath, deviceType, args.Device, args.MediaDrive.NameView);
                //汇报文件进度
                mReadDeviceFileWorker.ReportProgress(0, new DeviceSyncReadProgressItem
                {
                    ProgressType         = ReadSyncFileTaskProgressType.FILE_READED,
                    PcFolderNameView     = e.PcPath,
                    MobileFolderNameView = e.MobilePath,
                    FileItem             = item,
                    FileSource           = deviceType
                });
            }
            return(true);
        }