public void TestCreateShortcut() { var id = CreateShortcut.DriveCreateShortcut(); Assert.IsNotNull(id); DeleteFileOnCleanup(id); }
public StartupFolderRegistration(string appName, ShortcutOptions options, CreateShortcut createShortcut, ReadShortcut readShortcut) { _appName = appName; _createShortcut = createShortcut; _options = options; _readShortcut = readShortcut; }
public override void CreateShortcut(CreateShortcut action) { string shortcutFileName = Runner.InvokeExpression <string>( action.ShortcutFileName ); AddToInstallLog(new InstallLogCreateFile { Path = shortcutFileName }); _form.RaiseProgressChanged(String.Format(UILabels.CreatingShortcut, shortcutFileName)); var shellLink = new ShellLink { Target = Runner.InvokeExpression <string>(action.TargetFileName), }; if (action.IconFileName != null) { shellLink.IconPath = Runner.InvokeExpression <string>(action.IconFileName); } if (action.IconIndex != null) { shellLink.IconIndex = Runner.InvokeExpression <int>(action.IconIndex); } if (action.StartOptions != null) { shellLink.Arguments = Runner.InvokeExpression <string>(action.StartOptions); } if (action.Description != null) { shellLink.Description = Runner.ParseTemplate(action.Description); } Directory.CreateDirectory(Path.GetDirectoryName(shortcutFileName)); shellLink.Save(shortcutFileName); }
/// <summary> /// Configuration Settings for Twain Scan /// </summary> /// <param name="twainDriver"></param> /// <param name="deviceDetails"></param> public static bool ConfigureSettings(IDevice deviceDetails, TwainDriverActivityData twainDriver) { // Get the common desktop directory var shortcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory), "HP Scan Twain.lnk"); if (File.Exists(shortcut)) { ProcessStartInfo processInfo = new ProcessStartInfo(shortcut) { UseShellExecute = true, Verb = "runas" }; Process.Start(processInfo); } else { throw new Exception("Desktop shortcut not found"); } _modelName = deviceDetails.GetDeviceInfo().ModelName; _hpscanConfiguration = new HPScanTwain(UIAFramework.ManagedUIA); _saveOperations = new SaveOperations(_modelName); CommunicationError communicationError = new CommunicationError(_modelName); try { Retry.WhileThrowing(() => _hpscanConfiguration.SaveasPDFListItem.IsAvailable(), 15, TimeSpan.FromSeconds(3), new List <Type>() { typeof(Exception) }); //Selecting the Configuration switch (twainDriver.TwainConfigurations) { case TwainConfiguration.SavesAsPdf: _hpscanConfiguration.SaveasPDFListItem.Select(WindowsTimeout); _hpscanConfiguration.SaveasPDFListItem.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); break; case TwainConfiguration.SaveAsJpeg: _hpscanConfiguration.SaveasJPEGListItem.Select(WindowsTimeout); _hpscanConfiguration.SaveasJPEGListItem.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); break; case TwainConfiguration.EmailAsPdf: _hpscanConfiguration.EmailasPDFListItem.Select(WindowsTimeout); _hpscanConfiguration.EmailasPDFListItem.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); break; case TwainConfiguration.EmailAsJpeg: _hpscanConfiguration.EmailasJPEGListItem.Select(WindowsTimeout); _hpscanConfiguration.EmailasJPEGListItem.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); break; case TwainConfiguration.EveryDayScan: _hpscanConfiguration.EverydayScanListItem.Select(WindowsTimeout); _hpscanConfiguration.EverydayScanListItem.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); break; case TwainConfiguration.NewScanShortCut: _hpscanConfiguration.CreateNewScanShButton.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); break; } //Creating Shortcut if (twainDriver.TwainConfigurations.ToString() == TwainConfiguration.NewScanShortCut.ToString()) { //Creating Scan Shortcut Button CreateShortcut createShortcut = new CreateShortcut(_modelName); Thread.Sleep(ShortWaitWindowsTimeout); createShortcut.EnterthenameoftEdit.PerformHumanAction(x => x.ClickWithMouse(WindowsTimeout)); switch (twainDriver.ShortcutSettings) { case ShortcutSettings.SavesAsPdf: createShortcut.EnterthenameoftEdit.PerformHumanAction(x => x.EnterText("SaveAsPDF_shortcut", WindowsTimeout)); createShortcut.NewScanShortcutComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); createShortcut.SaveasPDFDup0ListItem.Select(WindowsTimeout); break; case ShortcutSettings.SaveAsJpeg: createShortcut.EnterthenameoftEdit.PerformHumanAction(x => x.EnterText("SaveAsJPEG_shortcut", WindowsTimeout)); createShortcut.NewScanShortcutComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); createShortcut.SaveasJPEGDup0ListItem.Select(WindowsTimeout); break; case ShortcutSettings.EmailAsPdf: createShortcut.EnterthenameoftEdit.PerformHumanAction(x => x.EnterText("EmailAsPDF_shortcut", WindowsTimeout)); createShortcut.NewScanShortcutComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); createShortcut.EmailasPDFDup0ListItem.Select(WindowsTimeout); break; case ShortcutSettings.EmailAsJpeg: createShortcut.EnterthenameoftEdit.PerformHumanAction(x => x.EnterText("EmailAsJPEG_shortcut", WindowsTimeout)); createShortcut.NewScanShortcutComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); createShortcut.EmailasJPEGDup0ListItem.Select(WindowsTimeout); break; } createShortcut.CreateButton1Button.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); if (createShortcut.OKButton1Button.IsAvailable()) { createShortcut.OKButton1Button.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); throw new Exception("Shortcut already exists"); } _hpscanConfiguration.ExitButton1007Button.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); } else { //Enabling or disabling Reservation JobReservationSettings(twainDriver); //Selecting the Item Type _hpscanConfiguration.ItemTypeComboBoComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); switch (twainDriver.ItemType) { case ItemType.Document: _hpscanConfiguration.DocumentListItem.Select(WindowsTimeout); break; case ItemType.Photo: _hpscanConfiguration.PhotoListItem.Select(WindowsTimeout); break; } //Selecting the Page Size _hpscanConfiguration.PageSizeComboBoComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); switch (twainDriver.PageSize) { case PageSize.DetectContentOnPage: if (twainDriver.ItemType.ToString() == ItemType.Document.ToString()) { _hpscanConfiguration.DetectContentonListItem.Select(WindowsTimeout); break; } else { _hpscanConfiguration.DetectPhotosListItem.Select(WindowsTimeout); break; } case PageSize.EntireScanArea: _hpscanConfiguration.EntireScanAreaListItem.Select(WindowsTimeout); break; case PageSize.Letter11Inches: _hpscanConfiguration.Letter85x11inchListItem.Select(WindowsTimeout); break; case PageSize.Legal14Inches: _hpscanConfiguration.Legal85x14incheListItem.Select(WindowsTimeout); break; case PageSize.A4: _hpscanConfiguration.A4210x297mmListItem.Select(WindowsTimeout); break; case PageSize.TwentyCrossTwentyFive: _hpscanConfiguration.A8x10in20x25cmListItem.Select(WindowsTimeout); break; } //Selecting the Source _hpscanConfiguration.SourceComboBox1ComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); switch (twainDriver.Source) { case Source.DocumentFeederifloaded: if (twainDriver.IsReservation) { _hpscanConfiguration.AutomaticDocumeListItem.Select(WindowsTimeout); break; } else { _hpscanConfiguration.DocumentFeederiListItem.Select(WindowsTimeout); break; } case Source.Flatbed: _hpscanConfiguration.FlatbedListItem.Select(WindowsTimeout); break; } //Selecting the Page Sides _hpscanConfiguration.PageSidesComboBComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); switch (twainDriver.PageSides) { case PageSides.OneSided: _hpscanConfiguration.A1sidedListItem.Select(WindowsTimeout); break; case PageSides.TwoSidedBook: _hpscanConfiguration.A2sidedbookListItem.Select(WindowsTimeout); break; case PageSides.TwoSidedTablet: _hpscanConfiguration.A2sidedtabletListItem.Select(WindowsTimeout); break; } //Selecting the ColorMode _hpscanConfiguration.ColorModeComboBComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); switch (twainDriver.ColorMode) { case ColorMode.BlackWhite: _hpscanConfiguration.BlackWhiteListItem.Select(WindowsTimeout); break; case ColorMode.Gray: _hpscanConfiguration.GrayListItem.Select(WindowsTimeout); break; case ColorMode.Halftone: _hpscanConfiguration.HalftoneListItem.Select(WindowsTimeout); break; case ColorMode.Color: _hpscanConfiguration.ColorListItem.Select(WindowsTimeout); break; case ColorMode.AutoDetectColor: _hpscanConfiguration.AutoDetectColorListItem.Select(WindowsTimeout); break; } //Selecting the Filetype and SendTo if the selected configuration is EveryDayScan if (twainDriver.TwainConfigurations.ToString() == TwainConfiguration.EveryDayScan.ToString()) { _hpscanConfiguration.FileTypeComboBoComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); switch (twainDriver.FileType) { case FileType.Bmp: _hpscanConfiguration.BMPListItem.Select(WindowsTimeout); break; case FileType.Jpeg: _hpscanConfiguration.JPEGListItem.Select(WindowsTimeout); break; case FileType.Pdf: _hpscanConfiguration.PDFListItem.Select(WindowsTimeout); break; case FileType.Png: _hpscanConfiguration.PNGListItem.Select(WindowsTimeout); break; case FileType.Tif: _hpscanConfiguration.TIFListItem.Select(WindowsTimeout); break; } //Ensure the FileType is selected Thread.Sleep(ShortWaitWindowsTimeout); _hpscanConfiguration.SendToComboBox1ComboBox.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); switch (twainDriver.SendTo) { case SendTo.Email: _hpscanConfiguration.EmailListItem.Select(WindowsTimeout); break; case SendTo.LocalorNetworkfolder: _hpscanConfiguration.LocalorNetworkfListItem.Select(WindowsTimeout); break; } } _hpscanConfiguration.ScanButton1012Button.PerformHumanAction(x => x.ClickWithMouse(MouseButton.Left, WindowsTimeout)); if (communicationError.OKButton1Button.IsAvailable(WindowsTimeout)) { throw new Exception( "Scanner Communication cannot be established/Communication with the device ended prematurely"); } } return(_hpscanConfiguration.PreparingtoscanText.IsAvailable()); } catch (Exception ex) { throw new DeviceWorkflowException(ex.Message); } }