Ejemplo n.º 1
0
        private void Scanner_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            _currentDevice = (DeviceInstance)e.Result;

            prgScanning.Visible = false;
            DisplayCurrentDevice();
        }
Ejemplo n.º 2
0
 private void Scanner_DoWork(object sender, DoWorkEventArgs e)
 {
     DeviceInstance currentDevice = null;
     var devices = _hardware.EnumerateUsbDevices();
     foreach (var usbDevice in devices) {
         SupportedDevice supportedDevice = _supportedDevices.GetDevice(usbDevice.VendorId, usbDevice.ProductId,
                                                                                                                                     usbDevice.Revision, usbDevice.InterfaceId);
         if (supportedDevice != null) {
             currentDevice = new DeviceInstance(supportedDevice, usbDevice);
             currentDevice.LoadDeviceInformation();
             break;
         }
     }
     e.Result = currentDevice;
 }
Ejemplo n.º 3
0
        private void DisplayTasksForDevice(DeviceInstance device)
        {
            lsvScripts.Items.Clear();

            var tasks = Tasks.LoadCompatibleTasksFor(device);
            foreach (var task in tasks) {
                var icon = task.Icon;
                var iconKey = (icon == null) ? DEFAULT_TASK_ICON : task.Folder.FullName;
                var item = new ListViewItem(task.Name, iconKey) { Tag = task };
                if ((icon != null) && !imlLargeIcons.Images.ContainsKey(iconKey)) {
                    imlLargeIcons.Images.Add(iconKey, icon);
                }
                lsvScripts.Items.Add(item);
            }
        }
Ejemplo n.º 4
0
        private void RunTask(Task task, DeviceInstance device)
        {
            tslStatus.Text = string.Format("Running task \"{0}\" for the \"{1}\"...", task.Name, device.Metadata.ProductName);
            lsvScripts.Enabled = false;

            string oldDirectory = Environment.CurrentDirectory;
            Action<PipelineStateInfo> completed = null;
            completed = state => {
                if (InvokeRequired) {
                    Invoke(new Action(() => completed(state)));
                    return;
                }

                Environment.CurrentDirectory = oldDirectory;
              lsvScripts.Enabled = true;

              // Update the device information and available task list
              DisplayCurrentDevice();
            };

            // Run the script
            Environment.CurrentDirectory = task.Folder.FullName;
            _psHost.RunAsync(task.Name, task.ScriptFile, completed,
                new KeyValuePair<string, object>("Device", device),
                new KeyValuePair<string, object>("UI", new ExposedUI(_psHost.UI, _psHost.WindowHandle))
            );
        }
Ejemplo n.º 5
0
        private void DisplayDeviceInformation(DeviceInstance device)
        {
            var props = device.BuildProperties;
            SetLink(lnkDeviceName, device.Metadata.DeviceName ?? props.ProductModel, device.Metadata.ProductPage);
            lblSerialNumber.Text = device.GetSerialNumber() ?? "(Unknown)";
            lblSystemVersion.Text = props.SystemVersion ?? "(Unknown)";
            SetLink(lnkVendor, device.Metadata.VendorName, device.Metadata.SupportPage);
            SetLink(lnkManufacturer, device.Metadata.ManufacturerName ?? props.ProductManufacturer, device.Metadata.ManufacturerPage);
            picDevice.Image = device.Metadata.DeviceImage;

            byte? batteryCharge = device.BatteryChargePercentage;
            if (batteryCharge == null) {
                lbdBatteryCharge.Visible = false;
                prgBatteryCharge.Visible = false;
            } else {
                lbdBatteryCharge.Visible = true;
                prgBatteryCharge.Visible = true;
                prgBatteryCharge.Value = batteryCharge.Value;
                toolTip.SetToolTip(prgBatteryCharge, batteryCharge.Value + "% charged");
            }

            Volume volume = device.Volumes.FirstOrDefault();
            if (volume == null) {
                lbdDiskUsage.Visible = false;
                prgDiskUsage.Visible = false;
            } else {
                lbdDiskUsage.Visible = true;
                prgDiskUsage.Visible = true;
                prgDiskUsage.Value = (int)volume.PercentUsed;
                toolTip.SetToolTip(prgDiskUsage, string.Format(
                    "{0} of {1}",
                    Conversions.ToSize(volume.SizeUsedBytes),
                    Conversions.ToSize(volume.SizeTotalBytes)
                ));
            }
        }