private async Task PreviewDatasheet(ISearchResult item) { try { IsOperationInProgress = true; var pdffile = await DownloadDatasheet(item); // Shell open the file // TODO: This may be potentially dangerous as the file comes from the internet. string ext = System.IO.Path.GetExtension(pdffile).ToLowerInvariant(); if (Settings.AllowedPreviewTypes.Contains(ext)) { ShellOperation.ShellExecute(pdffile); } else { App.ErrorHandler($"Unsupported file type {ext}", fatal: false); } } finally { IsOperationInProgress = false; } }
private async Task DownloadDatasheetToLibrary(ISearchResult item) { try { string destfile = System.IO.Path.Combine(Settings.DocumentsDir, item.Filename); string tmpfile; if (!temporaryFileMap.TryGetValue(item, out tmpfile)) { // Download file to TEMP if not already downloaded tmpfile = await DownloadDatasheet(item); } if (!System.IO.File.Exists(tmpfile)) { throw new InvalidOperationException($"Temp file has disappeared?? {tmpfile}"); } // Copy the temporary file into the library await ShellOperation.SHFileOperationAsync( ShellOperation.FileOperation.Move, new string[] { tmpfile }, new string[] { destfile }); // FSWatcher should automatically pick up the new item when it's copied into the library directory IsOperationInProgress = false; // Close the search view FinishSearch(); } finally { IsOperationInProgress = false; } }
private IOperation BuildShellOperation() { var aboutInfo = new AboutNotificationInfo(text); var aboutController = new AboutNotificationController(context.AppConfig, uiFactory); var audio = new Audio(context.Settings.Audio, ModuleLogger(nameof(Audio))); var keyboard = new Keyboard(ModuleLogger(nameof(Keyboard))); var logInfo = new LogNotificationInfo(text); var logController = new LogNotificationController(logger, uiFactory); var powerSupply = new PowerSupply(ModuleLogger(nameof(PowerSupply))); var wirelessAdapter = new WirelessAdapter(ModuleLogger(nameof(WirelessAdapter))); var operation = new ShellOperation( actionCenter, audio, aboutInfo, aboutController, context, keyboard, logger, logInfo, logController, powerSupply, systemInfo, taskbar, taskview, text, uiFactory, wirelessAdapter); context.Activators.Add(new ActionCenterKeyboardActivator(ModuleLogger(nameof(ActionCenterKeyboardActivator)), nativeMethods)); context.Activators.Add(new ActionCenterTouchActivator(ModuleLogger(nameof(ActionCenterTouchActivator)), nativeMethods)); context.Activators.Add(new TaskviewKeyboardActivator(ModuleLogger(nameof(TaskviewKeyboardActivator)), nativeMethods)); context.Activators.Add(new TerminationActivator(ModuleLogger(nameof(TerminationActivator)), nativeMethods)); return(operation); }
private async Task <string> DownloadDatasheet(ISearchResult item) { // Create a new 0 byte temporary file placeholder //var tempfile = System.IO.Path.GetTempFileName(); string temppath = System.IO.Path.GetTempPath(); var tempfile = System.IO.Path.Combine(temppath, item.Filename); // Sanity check - ensure file doesn't end up outside the TEMP folder ShellOperation.ValidatePathRoot(tempfile, temppath); // Remove existing items // TODO: What if we can't remove? if (System.IO.File.Exists(tempfile)) { System.IO.File.Delete(tempfile); } // Download to temporary file // TODO: Show progress await item.DownloadDatasheetAsync(tempfile); // Keep track of it so we can delete it later temporaryFiles.Add(tempfile); temporaryFileMap[item] = tempfile; return(tempfile); }
private IOperation BuildShellOperation() { var aboutInfo = new AboutNotificationInfo(text); var aboutController = new AboutNotificationController(configuration.AppConfig, uiFactory); var logInfo = new LogNotificationInfo(text); var logController = new LogNotificationController(logger, uiFactory); var activators = new IActionCenterActivator[] { new KeyboardActivator(new ModuleLogger(logger, nameof(KeyboardActivator))), new TouchActivator(new ModuleLogger(logger, nameof(TouchActivator))) }; var operation = new ShellOperation( actionCenter, activators, configuration.Settings.ActionCenter, logger, aboutInfo, aboutController, logInfo, logController, keyboardLayout, powerSupply, wirelessNetwork, systemInfo, taskbar, configuration.Settings.Taskbar, terminationActivator, text, uiFactory); return(operation); }
public void OpenItem() { try { ShellOperation.ShellExecute(this.FilePath); } catch (Exception e) { //((App)App.Current) } }
private void miOpenWebpage_Click(object sender, RoutedEventArgs e) { try { // Open the original webpage var item = GetSelectedItem(); if (item != null) { ShellOperation.ShellOpenUri(item.WebpageUrl); } } catch (Exception ex) { App.ErrorHandler(ex.ToString(), "Error opening webpage for datasheet", fatal: false); } }
public void Initialize() { actionCenter = new Mock <IActionCenter>(); activators = new List <IActionCenterActivator>(); actionCenterSettings = new ActionCenterSettings(); audio = new Mock <IAudio>(); logger = new Mock <ILogger>(); aboutInfo = new Mock <INotificationInfo>(); aboutController = new Mock <INotificationController>(); keyboard = new Mock <IKeyboard>(); logInfo = new Mock <INotificationInfo>(); logController = new Mock <INotificationController>(); powerSupply = new Mock <IPowerSupply>(); systemInfo = new Mock <ISystemInfo>(); taskbar = new Mock <ITaskbar>(); taskbarSettings = new TaskbarSettings(); terminationActivator = new Mock <ITerminationActivator>(); text = new Mock <IText>(); uiFactory = new Mock <IUserInterfaceFactory>(); wirelessAdapter = new Mock <IWirelessAdapter>(); uiFactory .Setup(u => u.CreateNotificationControl(It.IsAny <INotificationController>(), It.IsAny <INotificationInfo>(), It.IsAny <Location>())) .Returns(new Mock <INotificationControl>().Object); sut = new ShellOperation( actionCenter.Object, activators, actionCenterSettings, audio.Object, aboutInfo.Object, aboutController.Object, keyboard.Object, logger.Object, logInfo.Object, logController.Object, powerSupply.Object, systemInfo.Object, taskbar.Object, taskbarSettings, terminationActivator.Object, text.Object, uiFactory.Object, wirelessAdapter.Object); }
public void Initialize() { actionCenter = new Mock <IActionCenter>(); audio = new Mock <IAudio>(); context = new ClientContext(); logger = new Mock <ILogger>(); aboutNotification = new Mock <INotification>(); keyboard = new Mock <IKeyboard>(); logNotification = new Mock <INotification>(); powerSupply = new Mock <IPowerSupply>(); systemInfo = new Mock <ISystemInfo>(); taskbar = new Mock <ITaskbar>(); taskview = new Mock <ITaskview>(); text = new Mock <IText>(); uiFactory = new Mock <IUserInterfaceFactory>(); wirelessAdapter = new Mock <IWirelessAdapter>(); context.Settings = new AppSettings(); uiFactory .Setup(u => u.CreateNotificationControl(It.IsAny <INotification>(), It.IsAny <Location>())) .Returns(new Mock <INotificationControl>().Object); sut = new ShellOperation( actionCenter.Object, audio.Object, aboutNotification.Object, context, keyboard.Object, logger.Object, logNotification.Object, powerSupply.Object, systemInfo.Object, taskbar.Object, taskview.Object, text.Object, uiFactory.Object, wirelessAdapter.Object); }
private IOperation BuildShellOperation() { var aboutInfo = new AboutNotificationInfo(text); var aboutController = new AboutNotificationController(configuration.AppConfig, uiFactory); var audio = new Audio(configuration.Settings.Audio, new ModuleLogger(logger, nameof(Audio))); var keyboard = new Keyboard(new ModuleLogger(logger, nameof(Keyboard))); var logInfo = new LogNotificationInfo(text); var logController = new LogNotificationController(logger, uiFactory); var powerSupply = new PowerSupply(new ModuleLogger(logger, nameof(PowerSupply))); var wirelessAdapter = new WirelessAdapter(new ModuleLogger(logger, nameof(WirelessAdapter))); var activators = new IActionCenterActivator[] { new KeyboardActivator(new ModuleLogger(logger, nameof(KeyboardActivator))), new TouchActivator(new ModuleLogger(logger, nameof(TouchActivator))) }; var operation = new ShellOperation( actionCenter, activators, configuration.Settings.ActionCenter, audio, aboutInfo, aboutController, keyboard, logger, logInfo, logController, powerSupply, systemInfo, taskbar, configuration.Settings.Taskbar, terminationActivator, text, uiFactory, wirelessAdapter); return(operation); }
private async void tree_Drop(object sender, DragEventArgs e) { // Determine the requested operation var result = tree_DragOperation(sender, e); var operation = result.Item1; var srcfiles = result.Item2; var srcuri = result.Item3; // Nothing dropped if ((srcfiles == null || srcfiles.Length == 0) && (srcuri == null)) { return; } // Default to the library root var destdir = Settings.DocumentsDir; // If dropped onto a folder, that's where the file should go var currentItem = (IItem)tree.SelectedItem; if (currentItem != null) { if (currentItem is Folder) { destdir = currentItem.FilePath; // Sanity check - don't want the file to end up somewhere outside the library! if (!System.IO.Path.GetFullPath(destdir).StartsWith(Settings.DocumentsDir)) { throw new InvalidOperationException($"Unexpected destination: {destdir}"); } } } // Otherwise this doesn't get called if you drop tree_DragLeaveForReal(sender, e); if (srcfiles != null && srcfiles.Length > 0) { switch (operation) { case DragDropEffects.Copy: await ShellOperation.SHFileOperationAsync(ShellOperation.FileOperation.Copy, srcfiles.ToArray(), destdir); //await Database.RefreshAsync(); break; case DragDropEffects.Move: await ShellOperation.SHFileOperationAsync(ShellOperation.FileOperation.Move, srcfiles.ToArray(), destdir); //await Database.RefreshAsync(); break; default: // Not supported throw new NotImplementedException($"{operation} operation not supported"); } } else if (srcuri != null) { if (operation == DragDropEffects.Link) { if (e.Data.GetData("FileGroupDescriptor") != null) { ShellOperation.ExtractUrlFileFromDrop(e, destdir); } else { //ShellOperation.CreateShellLink(srcuri, "title", destdir); throw new InvalidOperationException("Unsupported URL drop"); } } else { throw new NotImplementedException($"{operation} operation not supported"); } } else { throw new InvalidOperationException("Invalid drop operation"); } e.Handled = true; }
private void miOpenFolder_Activate(object sender, RoutedEventArgs e) { // Open the documents library in explorer ShellOperation.ShellOpenFolder(Settings.DocumentsDir); }