static string FindNikonCamera() { if (PortableDeviceCollection.Instance == null) { const string AppName = "CameraControl"; const int AppMajorVersionNumber = 1; const int AppMinorVersionNumber = 0; PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; } //_deviceEnumerator.RemoveDisconnected(); foreach (PortableDevice portableDevice in PortableDeviceCollection.Instance.Devices) { Log.Debug("Connection device " + portableDevice.DeviceId); //TODO: avoid to load some mass storage in my computer need to find a general solution if (!portableDevice.DeviceId.StartsWith("\\\\?\\usb") && !portableDevice.DeviceId.StartsWith("\\\\?\\comp")) { continue; } // find Nikon cameras if (portableDevice.DeviceId.Contains("vid_04b0")) { return(portableDevice.DeviceId); } } return(""); }
public async void InitDevice() { _connectedDeviceCollection = new PortableDeviceCollection(); _deviceProcessingQueue = new Queue <Device>(); //retrieve settings from db and IsDeviceBackupEnabled = _settingService.DeviceBackupEnabled; IsDefaultMediaBackupPathEnabled = _settingService.DefaultMediaBackupPathEnabled; DefaultMediaBackupPath = _settingService.MediaBackupPath; //create Default-MediaBackupPath if (!Directory.Exists(DefaultMediaBackupPath)) { try { Directory.CreateDirectory(DefaultMediaBackupPath); } catch { /*parse*/ } } if (IsDeviceBackupEnabled) { CheckDeviceStatusChange(); } }
// 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); }
static void Main() { var devices = new PortableDeviceCollection(); devices.Refresh(); var kindle = devices.First(); kindle.Connect(); var root = kindle.GetContents(); foreach (var resource in root.Files) { DisplayResourceContents(resource); } PortableDeviceFolder documents = (from r in ((PortableDeviceFolder)root.Files[0]).Files where r.Name.Contains("documents") select r).First() as PortableDeviceFolder; var books = from b in documents.Files where b.Name.Contains("Kindle_Users_Guide") select b; foreach (PortableDeviceFile book in books) { Console.WriteLine(book.Id); kindle.DeleteFile(book); } kindle.Disconnect(); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
public static void TransferFilesFromWpdToHardDrive(string path) { _copyPath = path; var collection = new PortableDeviceCollection(); collection.Refresh(); foreach (var device in collection) { device.Connect(); var folder = device.GetContents(); var item = folder.Files.FirstOrDefault(x => x.Name.ToLower().Equals("camera") || x.Name.ToLower().Equals("tablet")); if (item == null) { continue; } NavigateObject(device, item); device.Disconnect(); } }
private void SetupDevice() { var devices = new PortableDeviceCollection(); devices.Refresh(); this.Device = devices.First(); }
public static void ConnectDevice() { var devices = new PortableDeviceCollection(); devices.Refresh(); gopro = devices.First(); gopro.Connect(); currentDeviceId = gopro.DeviceId; }
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(); }
public SynchronizeCommand(Options options, PortableDeviceCollection portableDeviceCollection, IUserInterface userInterface, ApplicationInformation applicationInformation) { Contract.Assert(options != null); Contract.Assert(applicationInformation != null); Contract.Assert(portableDeviceCollection != null); Contract.Assert(userInterface != null); _options = options; _applicationInformation = applicationInformation; _portableDeviceCollection = portableDeviceCollection; _userInterface = userInterface; }
private void RefreshDevicesList() { DevicesListBox.Items.Clear(); collection = new PortableDeviceCollection(); collection.Refresh(); foreach (var device in collection) { device.Connect(); DevicesListBox.Items.Add(device.FriendlyName); device.Disconnect(); } DevicesListBox.Items.Add("Load from disk"); }
/* * Return list of available devices * */ public LinkedList<string> devicesList() { LinkedList<string> devices = new LinkedList<string>(); collection = new PortableDeviceCollection(); collection.Refresh(); foreach (var dev in collection) { dev.Connect(); devices.AddLast(dev.FriendlyName); dev.Disconnect(); } return devices; }
void Init() { Devices = new PortableDeviceCollection(); if (null == Devices) { throw new Exception("デバイスを取得できませんでした。"); } else { Devices.Refresh(); Device = Devices.First(); } //devices.Clear(); }
private void ConnectDevices() { if (_connectionInProgress) { return; } _connectionInProgress = true; if (PortableDeviceCollection.Instance == null) { PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; } _deviceEnumerator.RemoveDisconnected(); if (UseExperimentalDrivers) { InitCanon(); } foreach (PortableDevice portableDevice in PortableDeviceCollection.Instance.Devices) { Log.Debug("Connection device " + portableDevice.DeviceId); //TODO: avoid to load some mass storage in my computer need to find a general solution if (!portableDevice.DeviceId.StartsWith("\\\\?\\usb") && !portableDevice.DeviceId.StartsWith("\\\\?\\comp")) { continue; } // ignore some Canon cameras if (!SupportedCanonCamera(portableDevice.DeviceId)) { continue; } portableDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); if (_deviceEnumerator.GetByWpdId(portableDevice.DeviceId) == null && GetNativeDriver(portableDevice.Model) != null) { ICameraDevice cameraDevice; DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = portableDevice.DeviceId }; cameraDevice = (ICameraDevice)Activator.CreateInstance(GetNativeDriver(portableDevice.Model)); cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); NewCameraConnected(cameraDevice); cameraDevice.Init(descriptor); descriptor.CameraDevice = cameraDevice; _deviceEnumerator.Add(descriptor); ConnectedDevices.Add(cameraDevice); } } _connectionInProgress = false; }
private void Window_Loaded(object sender, RoutedEventArgs e) { if (PortableDeviceCollection.Instance == null) { PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; } foreach (PortableDevice portableDevice in PortableDeviceCollection.Instance.Devices) { portableDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); Devices.Add(portableDevice); } cmb_devices.ItemsSource = Devices; }
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(); }
public bool FindNikonCamera() { if (PortableDeviceCollection.Instance == null) { const string AppName = "CameraControl"; const int AppMajorVersionNumber = 1; const int AppMinorVersionNumber = 0; try { PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; }catch (Exception) { StatusMessage = "Failed to load depentant .dll's"; return(false); } } foreach (PortableDevice portableDevice in PortableDeviceCollection.Instance.Devices) { Log.Debug("Connection device " + portableDevice.DeviceId); //TODO: avoid to load some mass storage in my computer need to find a general solution if (!portableDevice.DeviceId.StartsWith("\\\\?\\usb") && !portableDevice.DeviceId.StartsWith("\\\\?\\comp")) { continue; } // find Nikon cameras if (portableDevice.DeviceId.Contains("vid_04b0")) { deviceId = portableDevice.DeviceId; try { SerialNumber = deviceId.Split('#')[2]; } catch (Exception) { StatusMessage = "Failed to find Serial Number"; return(false); } return(true); } } StatusMessage = "Failed to Find Nikon Camera"; deviceId = ""; return(false); }
public static (int?, PortableDevice) GetDevice(string deviceId) { var devices = new PortableDeviceCollection(); devices.Refresh(); var deviceCollection = devices.ToList(); var device = deviceCollection.SingleOrDefault(d => string.Equals(deviceId, d.DeviceId, StringComparison.Ordinal)); if (device == null) { Console.WriteLine($"[{nameof(EXIT_CODE_DEVICE_NOT_FOUND)}]"); return(EXIT_CODE_DEVICE_NOT_FOUND, null); } return(null, device); }
static void Main() { var devices = new PortableDeviceCollection(); devices.Refresh(); var kindle = devices.First(); kindle.Connect(); kindle.TransferContentToDevice( @"d:\temp\Kindle_Users_Guide.azw", @"g:\documents"); kindle.Disconnect(); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
public static void DeleteFromWpdToHardDrive() { var collection = new PortableDeviceCollection(); collection.Refresh(); foreach (var device in collection) { device.Connect(); var folder = device.GetContents(); var item = folder.Files.FirstOrDefault(x => x.Name.ToLower().Equals("camera")); NavigateObjectForDelete(device, item); device.Disconnect(); } }
static void Main() { var collection = new PortableDeviceCollection(); collection.Refresh(); foreach(var device in collection) { //Console.WriteLine(device.DeviceId); device.Connect(); Console.WriteLine(device.FriendlyName); device.Disconnect(); } Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
private async void InitDevice() { _connectedDeviceCollection = new PortableDeviceCollection(); _deviceProcessingQueue = new Queue <Device>(); //retrieve settings from db and _isDeviceBackupEnabled = true; if (_isDeviceBackupEnabled) { //default folder,get from db, if null init with default path. _defaultMediaBackupPath = System.IO.Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyPictures), @"OnePhotoBackup"); if (!Directory.Exists(_defaultMediaBackupPath)) { try { Directory.CreateDirectory(_defaultMediaBackupPath); } catch { /*parse*/ } } RegisterDriveDetector(); //get all devices from db.if empty,initialize StoredDevices var devices = await _deviceService.GetAllDevices(); if (devices == null) { StoredDevices = new ObservableCollection <Device>(); } else { StoredDevices = new ObservableCollection <Device>(devices); } CheckDeviceStatusChange(); } }
public static int SystemInfoCommand(CommandLineItemCollection commandLine) { PrintCommandName(); var includeFriendlyName = commandLine.HasFlag("friendlyName"); var devices = new PortableDeviceCollection(); devices.Refresh(); Console.WriteLine("[Devices]"); foreach (var device in devices) { string deviceFriendlyName; if (includeFriendlyName) { try { device.Connect(); deviceFriendlyName = device.FriendlyName; } finally { device.Disconnect(); } } else { deviceFriendlyName = "-"; } Console.WriteLine($"{deviceFriendlyName}\t{device.DeviceId}"); } Console.WriteLine($"[{nameof(EXIT_CODE_OK)}]"); return(EXIT_CODE_OK); }
static void Main() { var collection = new PortableDeviceCollection(); collection.Refresh(); foreach(var device in collection) { device.Connect(); Console.WriteLine(device.FriendlyName); var folder = device.GetContents(); foreach(var item in folder.Files) { DisplayObject(item); } device.Disconnect(); } Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
///循环监测是否有Pad插入 private void LoopDetection() { //LogHelper.LogWrite("MTP服务开启!"); //创建同步历史记录XML while (true) { ///获取接入的Pad信息 portableDevices = new ObservableCollection <PortableDevice>(); if (PortableDeviceCollection.Instance == null) { try { PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; } catch (Exception ex) { LogHelper.LogWrite(ex.Message); } } ///添加Pad设备,一次只能接入一个Pad设备 foreach (var device in PortableDeviceCollection.Instance.Devices) { if (device.DeviceId == padOne || device.DeviceId == padTwo) { portableDevices.Add(device); } } if (portableDevices.Count >= 1)//需增加判断,是否远程WCF服务已开启?? { if ((portableDevices[0].DeviceId == padOne || portableDevices[0].DeviceId == padTwo) && isUpdateComplete == false) { foreach (var portableDevice in portableDevices) { string[] paths = padSourcePath.Split('\\'); try { portableDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); } catch//(Exception ex) { //LogHelper.LogWrite(ex.Message); continue; } portableDevice.ScanContent(paths); PortableDeviceContainerObject lastObj = portableDevice.GetLast(portableDevice.Content); if (lastObj.Name == "uploadRefresh") { portableDevice.ScanFolderEnumerate(lastObj.ID, lastObj); //从Pad向PC复制文件 try { portableDevice.CopyFolderToPC(lastObj, pcTargetFolder); } catch (Exception ex) { LogHelper.LogWrite(ex); } ///查找Pad端指定位置 string[] paths1 = padTargetFolder.Split('\\'); portableDevice.ScanContent(paths1); lastObjDown = portableDevice.GetLast(portableDevice.Content); //find the all files in the last folder portableDevice.ScanFolderEnumerate(lastObjDown.ID, lastObjDown); //copy folder from pc to pad //portableDevice.CopyFolderToPad(lastObjDown, pcSourceFolder); if (Directory.Exists(pcTargetFolder + "\\uploadRefresh")) { ///执行数据更新工作 StartUpdateDate(); } bool complete = true; ///判断是否更新成功 do { if (n == 6) { ///上传同步记录 if (portableDevices[0].DeviceId == padOne) { portableDevices[0].CopyFolderToPad(lastObjDown, historyRecordXmlOne); } if (portableDevices[0].DeviceId == padTwo) { portableDevices[0].CopyFolderToPad(lastObjDown, historyRecordXmlTwo); } ///上传结束标志文件 using (FileStream wcfFile = new FileStream(wcfdownloadpath + "time.xml", FileMode.Create)) { byte[] bytes = new byte[0]; wcfFile.Write(bytes, 0, bytes.Length); wcfFile.Flush(); } try { portableDevices[0].CopyFolderToPad(lastObjDown, wcfdownloadpath + "time.xml"); } catch (Exception ex) { LogHelper.LogWrite(ex.Message); } complete = false; n = 0; if (wcfclient != null) { try { wcfclient.Close(); } catch (Exception ex) { wcfclient.Abort(); LogHelper.LogWrite(ex); } } } Thread.Sleep(100); }while (complete); isUpdateComplete = true; } } } } if (portableDevices.Count == 0) { isUpdateComplete = false; } if (portableDevices != null) { portableDevices = null; } GC.Collect(); Thread.Sleep(100); } }
private void ConnectDevices() { if (_connectionInProgress) { return; } _connectionInProgress = true; if (PortableDeviceCollection.Instance == null) { PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; } _deviceEnumerator.RemoveDisconnected(); Log.Debug("Connection device start"); try { var devices = PortableDeviceCollection.Instance.Devices; foreach (PortableDevice portableDevice in devices) { Log.Debug("Connection device " + portableDevice.DeviceId); //TODO: avoid to load some mass storage in my computer need to find a general solution if (!portableDevice.DeviceId.StartsWith("\\\\?\\usb") && !portableDevice.DeviceId.StartsWith("\\\\?\\comp")) { continue; } // ignore some Canon cameras if (!SupportedCanonCamera(portableDevice.DeviceId)) { continue; } portableDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); if (_deviceEnumerator.GetByWpdId(portableDevice.DeviceId) == null && GetNativeDriver(portableDevice.Model) != null) { ICameraDevice cameraDevice; DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = portableDevice.DeviceId }; cameraDevice = (ICameraDevice)Activator.CreateInstance(GetNativeDriver(portableDevice.Model)); MtpProtocol device = new MtpProtocol(descriptor.WpdId); device.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); descriptor.StillImageDevice = device; cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); cameraDevice.Init(descriptor); if (string.IsNullOrWhiteSpace(cameraDevice.SerialNumber)) { cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); } ConnectedDevices.Add(cameraDevice); NewCameraConnected(cameraDevice); descriptor.CameraDevice = cameraDevice; _deviceEnumerator.Add(descriptor); } } } catch (Exception exception) { Log.Error("Unable to connect to cameras ", exception); } _connectionInProgress = false; }
//---------------------------------------------------------------------------------------------- private static void OnTimedEvent(object source, ElapsedEventArgs e) { //Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime); readCfg(); if(outputDir == "") { Console.WriteLine("invalid output path, check the cfg file"); return; } var collection = new PortableDeviceCollection(); collection.Refresh(); PortableDevice myCamera = null; // foreach(var device in collection) for (int i = 0; i < collection.Count; i++) { collection[i].Connect(); if (collection[i].FriendlyName == "D5000") { myCamera = collection[i]; break; } collection[i].Disconnect(); } if (myCamera == null) { Console.WriteLine("nothing is connected?"); collection = null; return; } //Console.WriteLine(myCamera.FriendlyName); var folder = myCamera.GetContents(); foreach (var item in folder.Files) { DisplayObject(myCamera, item); } Console.WriteLine("--------------------------"); myCamera.Disconnect(); collection = null; myCamera = null; }
static void Main(string[] args) { var collection = new PortableDeviceCollection(); bool another; int? depth = null; bool folderOnly = false; collection.Refresh(); var device = collection.First(); device.Connect(); do { //Console.Write("Enter depth: "); //if (int.TryParse(Console.ReadLine(), out int depthInt)) // depth = depthInt; //Console.WriteLine(); //Console.Write("Folder Only? (y/n): "); //if (Console.ReadLine().ToLower().Equals("y")) // folderOnly = true; //collection.Refresh(); //foreach (var device in collection) //{ // device.Connect(); // Console.WriteLine("-------------------------\n" + device.FriendlyName + "\n-------------------------"); // DisplayFolderContents(device.GetContents(depth, folderOnly)); // device.DisConnect(); //} //device.TransferToDevice(@"F:\LDPlayer\Garulea Continent.record", "o2"); //var content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\Garulea Continent.record"); var content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\A.txt"); device.DeleteFile(content.Id, true); content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\Q.txt"); device.DeleteFile(content.Id, true); Console.Write("Another? (y/n) "); if (!Console.ReadLine().ToLower().Equals("n")) { another = true; } else { another = false; } } while (another); device.DisConnect(); //var device2 = collection.GetDeviceByName("HM NOTE 1LTEW"); //device2.Connect(); ////Console.WriteLine("Enter folder name and folder parent id"); ////var folder = device2.NewFolder(Console.ReadLine(), Console.ReadLine()); //var folder = device2.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android"); //Console.WriteLine(folder.Id + " ||| " + folder.Name); //device2.DisConnect(); //manager.CreateDirectory(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2"); //Console.WriteLine(manager.Exist(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2").Id); //manager.Delete(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test", true); //Console.WriteLine(manager.Exist(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2")?.Id ?? "NotFound"); Console.ReadKey(true); }
private static PortableDeviceCollection CreatePortableDeviceCollectionFromApplicationInformation(ApplicationInformation applicationInformation) { PortableDeviceCollection.CreateInstance(applicationInformation.Name, applicationInformation.MajorVersionNumber, applicationInformation.MinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; return(PortableDeviceCollection.Instance); }