コード例 #1
0
        public static void getFileFromDevice(String deviceFolder, String localPath, String file)
        {
            PortableDevice currentDevice = FileManagerModel.getCurrentDevice();

            try
            {
                if (FileManagerModel.searchDeviceFile(currentDevice, deviceFolder, file))
                {
                    FileManagerModel.getFileFromDevice(currentDevice, deviceFolder, localPath, file);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("El archivo " + file + " fue movido a la PC");
                    Console.ResetColor();
                    currentDevice.Disconnect();
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine("No se encontro el archivo en el dispositivo");
                    Console.ResetColor();
                    currentDevice.Disconnect();
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Error.WriteLine(ex.Message);
                Console.ResetColor();
                currentDevice.Disconnect();
            }
        }
コード例 #2
0
        public static void sendFileToDevice(String deviceFolder, String localPath, String localFile, String newNameFile)
        {
            PortableDevice currentDevice = FileManagerModel.getCurrentDevice();

            try
            {
                if (FileManagerModel.searchDeviceFile(currentDevice, deviceFolder, localFile))
                {
                    FileManagerModel.deleteDeviceFile(currentDevice, deviceFolder, localFile);
                }
                FileManagerModel.sendFileToDevice(currentDevice, deviceFolder, localPath, localFile, newNameFile);
                Console.ForegroundColor = ConsoleColor.White;
                if (FileManagerModel.searchDeviceFile(currentDevice, deviceFolder, localFile))
                {
                    Console.WriteLine("El archivo " + localFile + " fue movido al dispositivo");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine("No se pudo enviar el archivo " + localFile + " al dispositivo");
                }
                Console.ResetColor();
                currentDevice.Disconnect();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Error.WriteLine(ex.Message);
                Console.ResetColor();
                currentDevice.Disconnect();
            }
        }
コード例 #3
0
        public static int DeviceInfoCommand(CommandLineItemCollection commandLine)
        {
            int?exitCode;

            PrintCommandName();

            var deviceId      = commandLine.GetArgument(0)?.Value;
            var directoryPath = commandLine.GetArgument(1)?.Value;

            PortableDevice device = default;

            try
            {
                PortableDeviceFolder directory;
                (exitCode, device, directory) = ConnectAndGetDeviceAndDirectory(deviceId, directoryPath);

                if (exitCode.HasValue)
                {
                    return(exitCode.Value);
                }

                PrintDirectory(directory);
            }
            finally
            {
                device?.Disconnect();
            }

            Console.WriteLine($"[{nameof(EXIT_CODE_OK)}]");
            return(EXIT_CODE_OK);
        }
コード例 #4
0
        public static void deleteDeviceFile(String deviceFolder, String file)
        {
            PortableDevice currentDevice = FileManagerModel.getCurrentDevice();

            try
            {
                if (FileManagerModel.searchDeviceFile(currentDevice, deviceFolder, file))
                {
                    FileManagerModel.deleteDeviceFile(currentDevice, deviceFolder, file);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Error.WriteLine("El archivo " + file + " fue eliminado");
                    Console.ResetColor();
                    currentDevice.Disconnect();
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine("Error al eliminar, no se encontro el archivo");
                    Console.ResetColor();
                    currentDevice.Disconnect();
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Error.WriteLine(ex.Message);
                Console.ResetColor();
                currentDevice.Disconnect();
            }
        }
コード例 #5
0
        public static bool searchDeviceFile(String deviceFolder, String file)
        {
            bool           status        = false;
            PortableDevice currentDevice = FileManagerModel.getCurrentDevice();

            try
            {
                if (FileManagerModel.searchDeviceFile(currentDevice, deviceFolder, file))
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("El archivo " + file + " fue encontrado");
                    Console.ResetColor();
                    status = true;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine(file + " no encontrado!");
                    Console.ResetColor();
                    status = false;
                }
                currentDevice.Disconnect();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Error.WriteLine(ex.Message);
                Console.ResetColor();
                status = false;
                currentDevice.Disconnect();
            }
            return(status);
        }
コード例 #6
0
        public static bool sendFileToDevice(PortableDevice device, String deviceFolder, String localPath, String localFile, String newNameFile)
        {
            bool status = false;

            try
            {
                String phoneDir             = deviceFolder;
                PortableDeviceFolder root   = device.Root();
                PortableDeviceFolder result = root.FindDir(phoneDir);
                if (null == result)
                {
                    status = false;
                }
                else
                {
                    device.TransferContentToDevice(result, localPath + localFile);
                    status = true;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                status = false;
            }
            return(status);
        }
コード例 #7
0
        public static bool getFileFromDevice(PortableDevice device, String deviceFolder, String localPath, String file)
        {
            bool status = false;

            try
            {
                String phoneDir             = deviceFolder;
                PortableDeviceFolder root   = device.Root();
                PortableDeviceFolder result = root.FindDir(phoneDir);
                if (null == result)
                {
                    //Console.Error.WriteLine(phoneDir + " no encontrado!");
                    status = false;
                }
                else
                {
                    PortableDeviceFile deviceFile = ((PortableDeviceFolder)result).FindFile(file);
                    device.TransferContentFromDevice(deviceFile, localPath, file);
                    status = true;
                }
            }
            catch (Exception)
            {
                //Console.Error.WriteLine(ex.Message);
                status = false;
            }
            return(status);
        }
コード例 #8
0
        public static bool deleteDeviceFile(PortableDevice device, String deviceFolder, String file)
        {
            bool status = false;

            try
            {
                String phoneDir                 = deviceFolder;
                PortableDeviceFolder root       = device.Root();
                PortableDeviceFolder result     = root.FindDir(phoneDir);
                PortableDeviceFile   deviceFile = result.FindFile(file);
                if (null == result)
                {
                    //Console.Error.WriteLine(phoneDir + " no encontrado!");
                    status = false;
                }
                else
                {
                    device.DeleteFile(deviceFile);
                    status = true;
                }
            }
            catch (Exception)
            {
                //Console.Error.WriteLine(ex.Message);
                status = false;
            }
            return(status);
        }
コード例 #9
0
        // public static string STORAGE_ES = "Almacenamiento interno compartido";

        public static PortableDevice getCurrentDevice()
        {
            PortableDevice currentDevice = null;

            try
            {
                var devices = new PortableDeviceCollection();
                //if (null == devices)
                //{

                //}
                //else
                //{
                devices.Refresh();
                currentDevice = devices.First();

                /*if (null == currentDevice)
                 * {
                 *  Console.Error.WriteLine("Dispositivo no encontrado!");
                 * }
                 * else
                 * {
                 *  Console.WriteLine("Dispositivo encontrado: " + currentDevice.FriendlyName);
                 * }*/
                //}
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
            return(currentDevice);
        }
コード例 #10
0
 public static void NavigateObject(PortableDevice device, PortableDeviceObject portableDeviceObject)
 {
     if (portableDeviceObject is PortableDeviceFolder)
     {
         NavigateFolderContents(device, (PortableDeviceFolder)portableDeviceObject);
     }
 }
コード例 #11
0
        public MTPDevice(string deviceId)
        {
            device = new PortableDevice();

            this.DeviceId = deviceId;
            this.Connect();
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: Nazin/AndroidServicePlatform
 private void cleanupInDir(PortableDevice device, PortableDeviceFolder folder)
 {
     foreach (var item in folder.Files)
     {
         device.DeleteFile((PortableDeviceFile)item);
     }
 }
コード例 #13
0
ファイル: MtpCommand.cs プロジェクト: nomada2/WpdMtp
        public virtual void Open(string deviceId)
        {
            if (device != null)
            {
                return;
            }

            // 排他制御用のセマフォを生成する
            var semName = Regex.Replace("WpdMtpSem" + deviceId, "[^0-9a-zA-Z]", "", RegexOptions.Singleline);

            if (sem == null)
            {
                sem = new Semaphore(1, 1, semName);
            }
            else if (!existSemaphoreName.Equals(semName))
            {
                var tempsem = sem;
                sem = new Semaphore(1, 1, semName);
                tempsem.Close();
            }

            device = new PortableDevice();
            IPortableDeviceValues clientInfo = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValues();

            device.Open(deviceId, clientInfo);
            Marshal.ReleaseComObject(clientInfo);

            // eventを受信できるようにする
            WpdEvent wpdEvent = new WpdEvent(this);
            IPortableDeviceValues eventParameter = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValues();

            device.Advise(0, wpdEvent, eventParameter, out eventCookie);
        }
コード例 #14
0
        public static void NavigateFolderContentsForDelete(PortableDevice device, PortableDeviceFolder folder)
        {
            var item = folder.Files.FirstOrDefault(x => x.Name.ToLower().Equals("vincapture"));

            var itemSub = (PortableDeviceFolder)item;

            DeleteFolderVincapture(device, itemSub);
        }
コード例 #15
0
        private void SetupDevice()
        {
            var devices = new PortableDeviceCollection();

            devices.Refresh();

            this.Device = devices.First();
        }
コード例 #16
0
        /// <summary>
        /// データ転送が無いオペレーションを実行する
        /// </summary>
        /// <param name="device"></param>
        /// <param name="code"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        private static MtpResponse executeNoDataCommand(PortableDevice device, ushort code, uint[] param)
        {
            IPortableDeviceValues spResults;
            int  ret;
            uint responseCode;

            uint[] responseParam;

            // MTPコマンドとパラメータを構築する
            IPortableDeviceValues mtpCommand = createMtpCommand(code, WpdProperty.WPD_COMMAND_MTP_EXT_EXECUTE_COMMAND_WITHOUT_DATA_PHASE);
            IPortableDevicePropVariantCollection mtpCommandParam = null;

            if (param != null)
            {
                mtpCommandParam = createMtpCommandParameter(param);
                mtpCommand.SetIPortableDevicePropVariantCollectionValue(ref WpdProperty.WPD_PROPERTY_MTP_EXT_OPERATION_PARAMS, mtpCommandParam);
            }
            // リクエストを送信
            device.SendCommand(0, mtpCommand, out spResults);
            // コマンドとパラメータは以後不要なので解放
            if (mtpCommandParam != null)
            {
                Marshal.ReleaseComObject(mtpCommandParam);
            }
            Marshal.ReleaseComObject(mtpCommand);
            // リクエストの結果を取得する
            spResults.GetErrorValue(ref WpdProperty.WPD_PROPERTY_COMMON_HRESULT, out ret);
            if (ret != 0)
            {   // エラーなら終了
                Marshal.ReleaseComObject(spResults);
                return(new MtpResponse(0, null, null));
            }
            // レスポンスコードを取得する
            spResults.GetUnsignedIntegerValue(ref WpdProperty.WPD_PROPERTY_MTP_EXT_RESPONSE_CODE, out responseCode);
            // レスポンスパラメータを取得する
            responseParam = null;
            if (responseCode == 0x2001)
            {
                IPortableDevicePropVariantCollection resultValues
                    = (IPortableDevicePropVariantCollection) new PortableDeviceTypesLib.PortableDevicePropVariantCollection();
                spResults.GetIPortableDevicePropVariantCollectionValue(ref WpdProperty.WPD_PROPERTY_MTP_EXT_RESPONSE_PARAMS, out resultValues);

                uint count = 1;
                resultValues.GetCount(ref count);
                responseParam = new uint[count];
                for (uint i = 0; i < count; i++)
                {
                    tag_inner_PROPVARIANT value = new tag_inner_PROPVARIANT();
                    resultValues.GetAt(i, ref value);
                    responseParam[i] = getUintValue(value);
                }
                Marshal.ReleaseComObject(resultValues);
            }
            Marshal.ReleaseComObject(spResults);

            return(new MtpResponse((ushort)responseCode, responseParam, null));
        }
コード例 #17
0
        static void Main()
        {
            //Connect to MTP devices and pick up the first one
            var devices = new PortableDeviceCollection();

            devices.Refresh();

            Tablet = devices.First();
            Tablet.Connect();

            //Getting root directory
            var root = Tablet.GetContents();

            //Displayinh directory content in console
            foreach (var resource in root.Files)
            {
                DisplayResourceContents(resource);
            }

            //Finding neccessary folder inside the root
            var folder = (root.Files.FirstOrDefault() as PortableDeviceFolder).
                         Files.FirstOrDefault(x => x.Name == "Folder") as PortableDeviceFolder;

            //Finding file inside the folder
            var file = (folder as PortableDeviceFolder)?.Files?.FirstOrDefault(x => x.Name == "File");

            //Transfering file into byte array
            var fileIntoByteArr = Tablet.DownloadFileToStream(file as PortableDeviceFile);

            //Transfering file into file system
            Tablet.DownloadFile(file as PortableDeviceFile, "\\LOCALPATH");

            //Transfering file rom file system into device folder
            Tablet.TransferContentToDevice("\\LOCALPATH", folder.Id);

            //Transfering file from stream into device folder
            var imgPath = "\\LOCALPATH";
            var image   = Image.FromFile(imgPath);

            byte[] imageB;
            using (var ms = new MemoryStream())
            {
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                imageB = ms.ToArray();
            }
            Tablet.TransferContentToDeviceFromStream("FILE NAME", new MemoryStream(imageB), folder.Id);

            //Close the connection
            Tablet.Disconnect();

            Console.WriteLine();
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
コード例 #18
0
ファイル: Form1.cs プロジェクト: Nazin/AndroidServicePlatform
 private void downloadFiles(PortableDevice device, PortableDeviceFolder folder, String outputFolder)
 {
     foreach (var item in folder.Files)
     {
         if (item is PortableDeviceFile)
         {
             Console.WriteLine("\tDownloading: " + item.Name);
             device.DownloadFile((PortableDeviceFile)item, outputFolder);
         }
     }
 }
コード例 #19
0
 /*
  * Connect to device
  * @param deviceName
  * */
 public void connectToDevice(string deviceName)
 {
     bool found = false;
     collection.Refresh();
     foreach (var dev in collection)
     {
         dev.Connect();
         if (dev.FriendlyName.Equals(deviceName)) { device = dev; found = true; }
         dev.Disconnect();
     }
     if (found) device.Connect();
     else MessageBox.Show("Urządzenie odłączone!");
 }
コード例 #20
0
        private long EnumerateContents(PortableDevice portableDevice, PortableDeviceFolder deviceFolder)
        {
            if (System.Threading.Thread.CurrentThread.IsBackground)
            {
                Utility.LogMessage("[EnumerateContents] [IsBackground]");
            }
            else
            {
                Utility.LogMessage("[EnumerateContents] [Foreground]");
            }

            try
            {
                foreach (var fileObject in deviceFolder.Files)
                {
                    if (_activeDevice != null && _activeDevice.ImportOption == DeviceImportOption.Never)
                    {
                        break;
                    }

                    if (fileObject is PortableDeviceFile)
                    {
                        //if (Common.Utilities.Utility.FileExtensions.IsValidFileExtension(Path.GetExtension(fileObject.Name.ToLower())))
                        if (Utility.ListValidImageExtensions.Contains(Path.GetExtension(fileObject.Name).ToLower()))
                        {
                            _totalFileCounter++;

                            string str = (string.IsNullOrEmpty(fileObject.Name) ? Path.GetFileName(fileObject.Id)
                                : Path.GetFileName(fileObject.Name));

                            if (!File.Exists(Path.Combine(_defaultMediaBackupPath, str)))
                            {
                                //Utility.LogMessage("{0} {1}", fileObject.Id, fileObject.Name);
                                _validFileCounter++;
                            }
                        }
                    }
                    else
                    {
                        //recursive call to enumerate contents
                        EnumerateContents(portableDevice, (PortableDeviceFolder)fileObject);
                    }
                }
                return(_totalFileCounter);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #21
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            DeviceInfo = new XmlDeviceData();
            SelectDevice wnd = new SelectDevice();

            wnd.ShowDialog();
            if (wnd.DialogResult == true && wnd.SelectedDevice != null)
            {
                try
                {
                    SelectedDevice = wnd.SelectedDevice;
                    DeviceDescriptor descriptor = new DeviceDescriptor {
                        WpdId = SelectedDevice.DeviceId
                    };
                    MtpProtocol device = new MtpProtocol(descriptor.WpdId);
                    device.ConnectToDevice("MTPTester", 1, 0);
                    descriptor.StillImageDevice = device;
                    MTPCamera = new BaseMTPCamera();
                    MTPCamera.Init(descriptor);
                    LoadDeviceData(MTPCamera.ExecuteReadDataEx(0x1001));
                    //LoadDeviceData(MTPCamera.ExecuteReadDataEx(0x9108));

                    PopulateProperties();
                }
                catch (DeviceException exception)
                {
                    MessageBox.Show("Error getting device information" + exception.Message);
                }
                catch (Exception exception)
                {
                    MessageBox.Show("General error" + exception.Message);
                }
                if (DefaultDeviceInfo != null)
                {
                    foreach (XmlCommandDescriptor command in DeviceInfo.AvaiableCommands)
                    {
                        command.Name = DefaultDeviceInfo.GetCommandName(command.Code);
                    }
                    foreach (XmlEventDescriptor avaiableEvent in DeviceInfo.AvaiableEvents)
                    {
                        avaiableEvent.Name = DefaultDeviceInfo.GetEventName(avaiableEvent.Code);
                    }
                    foreach (XmlPropertyDescriptor property in DeviceInfo.AvaiableProperties)
                    {
                        property.Name = DefaultDeviceInfo.GetPropName(property.Code);
                    }
                }
                InitUi();
            }
        }
コード例 #22
0
 void Init()
 {
     Devices = new PortableDeviceCollection();
     if (null == Devices)
     {
         throw new Exception("デバイスを取得できませんでした。");
     }
     else
     {
         Devices.Refresh();
         Device = Devices.First();
     }
     //devices.Clear();
 }
コード例 #23
0
ファイル: Form1.cs プロジェクト: Nazin/AndroidServicePlatform
        private void connectWithDevice(object state)
        {
            if (detected)
            {
                return;
            }

            detected = true;

            Console.WriteLine("Device detected");

            var devices = new PortableDeviceCollection();

            devices.Refresh();

            device = devices.First();
            device.Connect();

            Console.WriteLine("Connected to: " + device.FriendlyName);

            var root = device.GetContents();

            servicePlatformFolder = (PortableDeviceFolder)device.getServicePlatformFolder();

            if (servicePlatformFolder == null)
            {
                Console.WriteLine("Could not find ServicePlatform folder, have you installed ServicePlatform mobile app? Disconnecting...");
                device.Disconnect();
                return;
            }

            getServicesList(device, servicePlatformFolder);

            if (!servicesFileDetected)
            {
                Console.WriteLine("Could not detect services! Disconnecting...");
                device.Disconnect();
                return;
            }

            BeginInvoke(new MethodInvoker(delegate {
                Show();
                //MessageBox.Show("Connected to: " + device.FriendlyName);
            }));

            cleanup(device, servicePlatformFolder);

            //device.Disconnect();
        }
コード例 #24
0
        /// <summary>
        /// EndDataTransferを送信する
        /// </summary>
        /// <param name="device"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private static void sendEndDataTransfer(PortableDevice device, string context, out uint responseCode, out uint[] responseParam)
        {
            IPortableDeviceValues mtpEndDataTransfer = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValues();

            mtpEndDataTransfer.SetGuidValue(ref WpdProperty.WPD_PROPERTY_COMMON_COMMAND_CATEGORY, ref WpdProperty.WPD_COMMAND_MTP_EXT_END_DATA_TRANSFER.fmtid);
            mtpEndDataTransfer.SetUnsignedIntegerValue(ref WpdProperty.WPD_PROPERTY_COMMON_COMMAND_ID, WpdProperty.WPD_COMMAND_MTP_EXT_END_DATA_TRANSFER.pid);
            mtpEndDataTransfer.SetStringValue(ref WpdProperty.WPD_PROPERTY_MTP_EXT_TRANSFER_CONTEXT, context);

            IPortableDeviceValues spResults;

            device.SendCommand(0, mtpEndDataTransfer, out spResults);
            Marshal.ReleaseComObject(mtpEndDataTransfer);

            int ret = 1;

            spResults.GetErrorValue(ref WpdProperty.WPD_PROPERTY_COMMON_HRESULT, out ret);
            if (ret != 0)
            {
                Marshal.ReleaseComObject(spResults);
                responseCode  = 0;
                responseParam = null;
                return;
            }

            // レスポンスコード
            spResults.GetUnsignedIntegerValue(ref WpdProperty.WPD_PROPERTY_MTP_EXT_RESPONSE_CODE, out responseCode);

            // パラメータ
            responseParam = null;
            if (responseCode == 0x2001)
            {
                IPortableDevicePropVariantCollection resultValues
                    = (IPortableDevicePropVariantCollection) new PortableDeviceTypesLib.PortableDevicePropVariantCollection();
                spResults.GetIPortableDevicePropVariantCollectionValue(ref WpdProperty.WPD_PROPERTY_MTP_EXT_RESPONSE_PARAMS, out resultValues);

                uint count = 1;
                resultValues.GetCount(ref count);
                responseParam = new uint[count];
                for (uint i = 0; i < count; i++)
                {
                    tag_inner_PROPVARIANT value = new tag_inner_PROPVARIANT();
                    resultValues.GetAt(i, ref value);
                    responseParam[i] = getUintValue(value);
                }
                Marshal.ReleaseComObject(resultValues);
            }

            Marshal.ReleaseComObject(spResults);
        }
コード例 #25
0
ファイル: MtpCommand.cs プロジェクト: namazu510/WpdMtp
        /// <summary>
        /// デバイスを切断する
        /// </summary>
        public void Close()
        {
            if (device == null)
            {
                return;
            }
            device.Unadvise(eventCookie);
            device.Close();
            Marshal.ReleaseComObject(device);
            device = null;

            // 排他制御用セマフォを解放する
            sem.Close();
            sem = null;
        }
コード例 #26
0
ファイル: Form1.cs プロジェクト: Nazin/AndroidServicePlatform
 private void cleanup(PortableDevice device, PortableDeviceFolder folder)
 {
     Console.WriteLine("Cleaning up ServicePlatform folder...");
     foreach (var item in folder.Files)
     {
         if (item is PortableDeviceFile && (item.Name.Equals("input-params") || item.Name.Equals("desktop-finished") || item.Name.Equals("mobile-finished")))
         {
             device.DeleteFile((PortableDeviceFile)item);
         }
         else if (item is PortableDeviceFolder && (item.Name.Equals("Input") || item.Name.Equals("Output")))
         {
             cleanupInDir(device, (PortableDeviceFolder)item);
         }
     }
 }
コード例 #27
0
 /// <summary>
 /// オペレーションを実行する
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 internal static MtpResponse ExecuteCommand(PortableDevice device, ushort code, DataPhase dataPhase, uint[] param, byte[] sendData, bool noReadResponseParam)
 {
     if (dataPhase == DataPhase.NoDataPhase)
     {
         return(executeNoDataCommand(device, code, param, noReadResponseParam));
     }
     else if (dataPhase == DataPhase.DataReadPhase)
     {
         return(executeDataReadCommand(device, code, param, noReadResponseParam));
     }
     else
     {
         return(executeDataWriteCommand(device, code, param, sendData, noReadResponseParam));
     }
 }
コード例 #28
0
        /// <summary>
        /// デバイスを列挙します。
        /// </summary>
        public void EnumDevice()
        {
            this.Devices.Clear();
            foreach (var device in PortableDevice.EnumDevice(this._client))
            {
                this.Devices.Add(new PortableDeviceViewModel(device));
            }

            this.RaisePropertyChanged("Devices");

            if (this.Devices.Count == 0)
            {
                MessageBox.Show(ResUtility.GetString("Strings.Message.DeviceNotFound"), ResUtility.GetString("Strings.Common.Info"), MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
コード例 #29
0
        private void ShowFileCountNotification(Device connectedDevice)
        {
            PortableDevice portableDevice = null;

            try
            {
                if (_connectedDeviceCollection != null &&
                    _connectedDeviceCollection.Count > 0)
                {
                    //get the connect device of same Id
                    portableDevice = _connectedDeviceCollection.
                                     SingleOrDefault(p => p.DeviceId.Equals(connectedDevice.Id));

                    if (portableDevice != null)
                    {
                        portableDevice.Connect();

                        //set active device to curren-device
                        _activeDevice = connectedDevice;

                        PortableDeviceFolder deviceFolder = portableDevice.GetContents();

                        var fileCount = EnumerateContents(portableDevice, deviceFolder);
                        Console.WriteLine("Total number of files found {0}", fileCount);

                        if (_fileCounter > 0)
                        {
                            SystemTrayManager.ShowBalloonTip(balloonTipText: string.Format("{0} files found in - {1} "
                                                                                           , _fileCounter, connectedDevice.DisplayName));
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (portableDevice != null)
                {
                    portableDevice.Disconnect();
                }

                _activeDevice = null;
                _fileCounter  = 0;
            }
        }
コード例 #30
0
ファイル: MtpCommand.cs プロジェクト: nomada2/WpdMtp
 public virtual void Close()
 {
     if (device == null)
     {
         return;
     }
     sem.WaitOne();
     if (device != null)
     {
         device.Unadvise(eventCookie);
         device.Close();
         Marshal.ReleaseComObject(device);
         device = null;
     }
     sem.Release();
 }
コード例 #31
0
        public static void NavigateFolderContents(PortableDevice device, PortableDeviceFolder folder)
        {
            var folderPath = _copyPath + "\\" + "VinCapture";

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }


            var item = folder.Files.FirstOrDefault(x => x.Name.ToLower().Equals("vincapture"));

            var itemSub = (PortableDeviceFolder)item;

            CopyFolderInsideVincapture(device, itemSub, folderPath);
        }
コード例 #32
0
 /// <summary>
 /// インスタンスを初期化します。
 /// </summary>
 /// <param name="model">モデル。</param>
 public PortableDeviceViewModel( PortableDevice model )
 {
     this._model = model;
     this._model.Open( OnDeviceEvent );
 }
コード例 #33
0
 /// <summary>
 /// リソースを破棄します。
 /// </summary>
 /// <param name="disposing">マネージリソースを破棄する場合は true。それ以外は false。</param>
 protected override void Dispose( bool disposing )
 {
     try
     {
         if( this._model != null )
         {
             this._model.Dispose();
             this._model = null;
         }
     }
     catch( Exception exp )
     {
         Debug.WriteLine( exp );
     }
     finally
     {
         base.Dispose( disposing );
     }
 }
コード例 #34
0
 public WindowsPortableDevice(string deviceId)
 {
     this.deviceId = deviceId;
     portableDevice = new PortableDeviceClass();
 }