Example #1
0
        public IWpdProperty Find(_tagpropertykey key, bool throwNotFound = true)
        {
            foreach (var item in this)
            {
                if (PortableDevicePKeys.Equals(key, item.Key))
                {
                    return(item);
                }
            }

            if (throwNotFound)
            {
                throw new KeyNotFoundException();
            }

            return(null);
        }
Example #2
0
      public void DumpSupportedResources()
      {
         IPortableDeviceResources resources;
         IPortableDeviceKeyCollection keys;
         var count = 0U;

         this.Content.Transfer( out resources );
         resources.GetSupportedResources( this.ObjectID, out keys );
         keys.GetCount( ref count );

         for ( var i = 0U; i < count; i++ )
         {
            _tagpropertykey key = new _tagpropertykey();
            keys.GetAt( i, ref key );
            var output = String.Format( "[{0}] {1}", i, PortableDevicePKeys.FindKeyName( key ) );
            System.Diagnostics.Trace.WriteLine( output );
            Console.WriteLine( output );
         }
      }
Example #3
0
 public void DumpProperties()
 {
    for ( var i = 0; i < this.Properties.Count; i++ )
    {
       var output = String.Format( "{0} {1} ({2}): {3}", i.ToString( "D" + this.Properties.Count.CountDigits().ToString() ), PortableDevicePKeys.FindKeyName( this.Properties[i].Key ), this.Properties[i].Type, this.Properties[i].Value );
       System.Diagnostics.Trace.WriteLine( output );
       Console.WriteLine( output );
    }
 }
Example #4
0
        static void Main(string[] args)
        {
            CommandLine <CLArguments> commandLine = null;

            try
            {
                commandLine = new CommandLine <CLArguments>();
                var arguments = commandLine.Parse(args);

                using (var devices = WpdDeviceCollection.Create())
                {
                    if (devices.Count == 0)
                    {
                        Console.WriteLine("No devices found.");
                    }
                    else if (arguments.CommandDiscover)
                    {
                        foreach (var device in devices)
                        {
                            Console.WriteLine("\"{0}\"{1}", device.Name, arguments.ShowDeviceID ? " " + device.DeviceID : string.Empty);
                        }
                    }
                    else if (arguments.CommandInfo)
                    {
                        var device = devices.Find(arguments.InfoDeviceName, false);
                        if (device == null)
                        {
                            Console.WriteLine("No device found with the name \"{0}\".", arguments.InfoDeviceName);
                        }
                        else
                        {
                            if (arguments.InfoCopyID)
                            {
                                ClipboardApi.Copy(device.DeviceID, true);
                            }

                            Console.WriteLine("Found {0} properties.", device.Properties.Count);

                            for (var i = 0; i < device.Properties.Count; i++)
                            {
                                Console.WriteLine("{0} {1} ({2}): {3}", i.ToString("D" + device.Properties.Count.CountDigits().ToString()), PortableDevicePKeys.FindKeyName(device.Properties[i].Key), device.Properties[i].Type, device.Properties[i].Value);
                            }
                        }
                    }
                    else if (arguments.CommandUpload)
                    {
                        var device = devices.Find(arguments.UploadDeviceName, false);
                        if (device == null)
                        {
                            Console.WriteLine("No device found with the name \"{0}\".", arguments.UploadDeviceName);
                        }
                        else
                        {
                            Console.WriteLine("Uploading...");

                            var components   = WildcardSearch.SplitPattern(arguments.UploadSourcePath);
                            var targetObject = device.ObjectFromPath(arguments.UploadTargetPath, arguments.CreatePath);

                            var commander = new DeviceCommander(device);
                            commander.DataCopyStarted += (sender, e) =>
                            {
                                Console.WriteLine("\r{0}", e.SourcePath);
                            };
                            commander.DataCopied += (sender, e) =>
                            {
                                var percent = 100.0 * ((double)e.CopiedBytes / (double)e.MaxBytes);
                                Console.Write("\r  {0}/{1} bytes ({2}%)", e.CopiedBytes, e.MaxBytes, percent.ToString("G3"));
                            };
                            commander.DataCopyEnded += (sender, e) =>
                            {
                            };
                            commander.DataCopyError += (sender, e) =>
                            {
                                Console.WriteLine("\r" + e.Exception.Message);
                            };

                            Console.WriteLine();
                            if (String.IsNullOrEmpty(components.Item2))
                            {
                                commander.Upload(targetObject, components.Item1, arguments.Overwrite);
                            }
                            else
                            {
                                commander.Upload(targetObject, components.Item1, arguments.Overwrite, components.Item2, arguments.Recursive, arguments.Flatten);
                            }
                            Console.WriteLine("\rCompleted                                                                     ");
                        }
                    }
                    else if (arguments.CommandDownload)
                    {
                        var device = devices.Find(arguments.DownloadDeviceName, false);
                        if (device == null)
                        {
                            Console.WriteLine("No device found with the name \"{0}\".", arguments.DownloadDeviceName);
                        }
                        else
                        {
                            Console.WriteLine("Downloading...");

                            var components   = WildcardSearch.SplitPattern(arguments.DownloadSourcePath);
                            var sourceObject = device.ObjectFromPath(components.Item1, false);

                            if (!System.IO.Directory.Exists(arguments.DownloadTargetPath))
                            {
                                if (arguments.CreatePath)
                                {
                                    System.IO.Directory.CreateDirectory(arguments.DownloadTargetPath);
                                }
                                else
                                {
                                    throw new System.IO.DirectoryNotFoundException(String.Format("The directory \"{0}\" was not found.", arguments.DownloadTargetPath));
                                }
                            }

                            var commander = new DeviceCommander(device);
                            commander.DataCopyStarted += (sender, e) =>
                            {
                                Console.WriteLine("\r{0}", e.SourcePath);
                            };
                            commander.DataCopied += (sender, e) =>
                            {
                                var percent = 100.0 * ((double)e.CopiedBytes / (double)e.MaxBytes);
                                Console.Write("\r  {0}/{1} bytes ({2}%)", e.CopiedBytes, e.MaxBytes, percent.ToString("G3"));
                            };
                            commander.DataCopyEnded += (sender, e) =>
                            {
                            };
                            commander.DataCopyError += (sender, e) =>
                            {
                                Console.WriteLine("\r" + e.Exception.Message);
                            };

                            Console.WriteLine();
                            if (String.IsNullOrEmpty(components.Item2))
                            {
                                commander.Download(sourceObject, arguments.DownloadTargetPath, arguments.Overwrite);
                            }
                            else
                            {
                                commander.Download(sourceObject, arguments.DownloadTargetPath, arguments.Overwrite, components.Item2, arguments.Recursive, arguments.Flatten);
                            }
                            Console.WriteLine("\rCompleted                                                                     ");
                        }
                    }
                    else
                    {
                        Console.WriteLine(commandLine.Help());
                    }
                }
            }
            catch (CommandLineDeclarationException ex)
            {
                if (commandLine != null)
                {
                    Console.WriteLine(commandLine.Help());
                }
                System.Diagnostics.Trace.WriteLine(ex);
                Console.WriteLine(ex);
            }
            catch (CommandLineException ex)
            {
                if (commandLine != null)
                {
                    Console.WriteLine(commandLine.Help());
                }
                System.Diagnostics.Trace.WriteLine(ex);
                Console.WriteLine(ex);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex);
                Console.WriteLine(ex);
            }
        }