public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("ClipboardManager: Executing command '{0}' ...", command.Name)); if (command.Name == "copy full path" || command.Name == "put on clipboard") { CraftSynth.BuildingBlocks.IO.Clipboard.SetTextToClipboard(command.parametersOnExecute[0].GetValueAsText()); Logging.AddActionLog(string.Format("ClipboardManager: full path copied to clipboard: {0}", command.parametersOnExecute[0].GetValueAsText())); MessagesHandler.Display(string.Format("Copied to clipboard: {0}", command.parametersOnExecute[0].GetValueAsText())); EnsoPlus.NotifyOtherApplicationsAboutClipboardChange(); } else if ((command.Name == "save-clipboard-as" && command.Postfix == "[work item name]") || (command.Name == "save-clipboard-as" && command.Postfix == "[work item name] and copy its file path")) { string clipboardContentsFormat = CraftSynth.BuildingBlocks.IO.Clipboard.GetClipboardFormatName(); if (clipboardContentsFormat == DataFormats.Bitmap) { Image clipboardImage = CraftSynth.BuildingBlocks.IO.Clipboard.GetImageFromClipboard(); string imageFilePath = command.parametersOnExecute[0].GetValueAsText(); try { if (!Directory.Exists(Settings.Current.ImagesFolder)) { Directory.CreateDirectory(Settings.Current.ImagesFolder); } imageFilePath = Path.Combine(Settings.Current.ImagesFolder, command.parametersOnExecute[0].GetValueAsText() + ".png"); clipboardImage.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Png); Logging.AddActionLog(string.Format("ClipboardManager: clipboard image saved to: {0}", imageFilePath)); MessagesHandler.Display("Saved."); if (command.Postfix.CompareTo("[work item name] and copy its file path") == 0) { CraftSynth.BuildingBlocks.IO.Clipboard.SetTextToClipboard(imageFilePath); Logging.AddActionLog(string.Format("ClipboardManager: file path '{0}' copied to clipboard.", imageFilePath)); MessagesHandler.Display("Image saved and its file path copied."); EnsoPlus.NotifyOtherApplicationsAboutClipboardChange(); } } catch (Exception exception) { throw new ApplicationException(string.Format("Clipboard manager: Failed to save clipboard image to '{0}'.", imageFilePath), exception); } } else { MessagesHandler.Display("Clipboard contents unrecognized. Only bitmap supported so far."); } } //else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") // { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); // } else { throw new ApplicationException(string.Format("ClipboardManager: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
private void SetSourceFolderOnBackupProfile(Extension.IEnsoService service, Command command, string name, string sourceFolder) { string filePath = WorkItemsProviders.BackupProfiles.BackupProfiles.GetFilePath(name); BackupProfile backupProfile = null; if (File.Exists(filePath)) { backupProfile = WorkItemsProviders.BackupProfiles.BackupProfiles.Load(name); } else { backupProfile = new BackupProfile(); backupProfile.Name = name; } backupProfile.SourceFolder = sourceFolder; WorkItemsProviders.BackupProfiles.BackupProfiles.Save(backupProfile); if (string.IsNullOrEmpty(backupProfile.DestinationFolder)) { SuggestionsCache.DropCache(this.GetType()); MessagesHandler.Display(string.Format("Profile created. Use 'set as backup destination...' command now.", command.Name)); } else { MessagesHandler.Display(string.Format(string.Format("Profile updated. You can now use 'backup {0}' command to create backups quickly.", name))); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("ProviderSample: Executing command '{0}' ...", command.Name)); if (command.Name == "watch selections") { SelectionListener.SelectionListener.Current.Start(service, command); } else if (command.Name == "stop watching of selections") { //MessagesHandler.Display( string.Format("Closing selection listener ...", command.Name)); SelectionListener.SelectionListener.Current.Stop(); } else if (command.Name == "assign key combination for paste operation") { //MessagesHandler.Display( string.Format("Closing selection listener ...", command.Name)); SelectionListener.SelectionListener.Current.AssignPasteKeyCombination(service); } //else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") // { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); // } else { throw new ApplicationException(string.Format("ProviderSample: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("CommandsManager: Executing command '{0}' ...", command.Name)); if (command.Name == "repeat") { Logging.AddActionLog(string.Format("CommandsManager: Repeating last command: {0}", CommandsHistory.GetLast().caption)); CommandsHistory.GetLast().Execute(service); } else if (command.Name == "remove" || command.Name == "forget") { command.parametersOnExecute[0].GetProvider().Remove(command.parametersOnExecute[0]); Logging.AddActionLog(string.Format("CommandsManager: Command '{0}' removed.", command.parametersOnExecute[0].GetCaption())); MessagesHandler.Display(string.Format("{0} removed.", command.parametersOnExecute[0].GetCaption())); } else if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") { MessagesHandler.Display(string.Format("Executing {0} ...", command.Name)); } else { throw new ApplicationException(string.Format("HistoryManager: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("MessagesDisplayer: Executing command '{0}' ...", command.Name)); if (command.Name == "display-last-message") { MessagesHandler.Display(MessagesHandler.GetLastFromHistory(), false); Logging.AddActionLog(string.Format("MessagesDisplayer: Last message '{0}' displayed.", MessagesHandler.GetLastFromHistory())); } else //if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") //{ // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); //} //else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") // { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); // } // else { throw new ApplicationException(string.Format("MessagesDisplayer: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("Opener: Executing command '{0}' ...", command.Name)); if (command.Name == "open") { //if (command.parametersOnExecute[0] is Entities.WorkItems.Shortcuts) //{ // Entities.WorkItems.Shortcuts shortcuts = command.parametersOnExecute[0] as Entities.WorkItems.Shortcuts; // Logging.AddActionLog(string.Format("Opener: Opening '{0}' in Chrome ...", shortcuts.shortcutsFilePath)); // MessagesHandler.Display( string.Format("Opening {0} ...", shortcuts.caption)); // foreach (Shortcut shortcut in shortcuts.shortcuts) // { // Logging.AddActionLog(string.Format("COpener: Opening '{0}' in Chrome ...", shortcut.targetPath)); // OpenInChrome(shortcut.targetPath, command.Name.Contains("tab"), command.Name.Contains("incognito")); // } //} //else //{ Logging.AddActionLog(string.Format("Opener: Opening '{0}' ...", command.parametersOnExecute[0].GetValueAsText())); string message = command.parametersOnExecute[0].GetValueAsText(); if (File.Exists(message)) { message = Path.GetFileNameWithoutExtension(message); } else if (Directory.Exists(message)) { message = Path.GetFileNameWithoutExtension(message); } MessagesHandler.Display(string.Format("Opening {0} ...", message)); Open(command.parametersOnExecute[0].GetValueAsText()); //} } else if (command.Name == "learn as open") { Logging.AddActionLog(string.Format("Opener: learn as open '{0}' ...", command.parametersOnExecute[0].GetValueAsText())); string content = "[InternetShortcut]\r\nURL=" + command.parametersOnExecute[1].GetValueAsText(); string shortcutsFolder = Settings.Current.EnsoLearnAsOpenCommandsFolder; CraftSynth.BuildingBlocks.IO.FileSystem.CreateFolderIfItDoesNotExist(shortcutsFolder); string filePath = Path.Combine(shortcutsFolder, command.parametersOnExecute[0].GetValueAsText() + ".url"); File.WriteAllText(filePath, content); SuggestionsCache.DropCache(typeof(WorkItemsProviders.Shortcuts.FilesWorkItems)); MessagesHandler.Display("Learned 'open " + command.parametersOnExecute[0].GetValueAsText() + "'"); } }
public static void SaveAllTabs(bool saveInOneFile, Extension.IEnsoService service, string caption, string shortcutsFolder, string commandProviderNameForLog) { string clipboardText = CraftSynth.BuildingBlocks.IO.Clipboard.GetTextFromClipboard(); clipboardText = clipboardText.Trim(); if (string.IsNullOrEmpty(clipboardText)) { MessagesHandler.Display("Error: Clipboard empty.", saveAllTabsUserManual); } else { Entities.WorkItems.Shortcuts shortcuts = null; try { shortcuts = new Entities.WorkItems.Shortcuts(caption, clipboardText); if (shortcuts.shortcuts.Count == 0) { throw new ApplicationException("No urls in clipboard."); } } catch (Exception) { MessagesHandler.Display("Error: Invalid text format in clipboard.", saveAllTabsUserManual); Logging.AddErrorLog(commandProviderNameForLog + ": Error: Invalid text format in clipboard"); } if (shortcuts != null && shortcuts.shortcuts.Count > 0) { if (string.IsNullOrEmpty(shortcutsFolder)) { shortcutsFolder = Settings.Current.EnsoLearnAsOpenCommandsFolder; } CraftSynth.BuildingBlocks.IO.FileSystem.CreateFolderIfItDoesNotExist(shortcutsFolder); if (saveInOneFile) { shortcuts.Save(shortcutsFolder); SuggestionsCache.DropCache(typeof(WorkItemsProviders.Shortcuts.ShortcutsLists)); Logging.AddActionLog(string.Format(commandProviderNameForLog + ": {0} tabs saved in '{1}'.", shortcuts.shortcuts.Count, Path.Combine(shortcutsFolder, caption))); MessagesHandler.Display(string.Format("{0} tabs saved in one shortcut {1}.", shortcuts.shortcuts.Count, caption)); } else { shortcuts.SaveAsSeparateShortcuts(shortcutsFolder); Logging.AddActionLog(string.Format(commandProviderNameForLog + ": {0} tabs saved as separate files in '{1}'.", shortcuts.shortcuts.Count, shortcutsFolder)); MessagesHandler.Display(string.Format("{0} shortcuts saved in category {1}.", shortcuts.shortcuts.Count, caption)); } } } }
public void Start(Extension.IEnsoService service, Command command) { if (Started) { MessagesHandler.Display("Allready started."); } else { Started = true; this._service = service; this._command = command; formSelectionListenerUIThread = new Thread(this.Start_NewThread); formSelectionListenerUIThread.Name = "FormSelectionListenerUIThread"; formSelectionListenerUIThread.SetApartmentState(System.Threading.ApartmentState.STA); formSelectionListenerUIThread.Start(); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("SsmsOpener: Executing command '{0}' ...", command.Name)); if (command.Name == "ssms" || command.Name == "ssms as default user") { //if (command.Name=="rdc" && IsPathSuitable(command.parametersOnExecute[0].GetValueAsText())) //{//open .rdc file // Logging.AddActionLog(string.Format("RdcOpener: Opening file '{0}' in RDC ...", command.parametersOnExecute[0].GetValueAsText())); // MessagesHandler.Display( string.Format("Opening file {0} ...", command.parametersOnExecute[0].GetValueAsText())); // CraftSynth.BuildingBlocks.WindowsNT.Misc.OpenFile(command.parametersOnExecute[0].GetValueAsText()); //} //else //{ Thread thread = new Thread(() => SsmsInNewThread(command)); thread.Start(); //} } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { //Exception ee = new Exception("inner one"); //Exception ee2 = new Exception("inner two",ee); //Exception ee3 = new Exception("test ex",ee2); //throw ee3; Logging.AddActionLog(string.Format("Caller: Executing command '{0}' ...", command.Name)); if (command.Name == "call" || command.Name == "dial") { Dialer.service = service; if (command.parametersOnExecute[0] is StringWorkItem) { Dialer.contactToDial = new ContactUnknown(command.parametersOnExecute[0].GetValueAsText()); } else if (command.parametersOnExecute[0] is Contact) { Dialer.contactToDial = (command.parametersOnExecute[0] as Contact); } WorkItemsProviders.CallerHistory.CallerHistory.Add(Dialer.contactToDial); Dialer.Dial(); } else if (command.Name == "recall" || command.Name == "redial") { Dialer.service = service; Dialer.Redial(); } else if (command.Name == "later") { Dialer.service = service; Dialer.Cancel(); } else { throw new ApplicationException(string.Format("Caller: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("ProviderSample: Executing command '{0}' ...", command.Name)); if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") { MessagesHandler.Display(string.Format("Executing {0} ...", command.Name)); } else if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") { MessagesHandler.Display(string.Format("Executing {0} ...", command.Name)); } else if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") { MessagesHandler.Display(string.Format("Executing {0} ...", command.Name)); } else { throw new ApplicationException(string.Format("ProviderSample: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("ProviderSample: Executing command '{0}' ...", command.Name)); if (command.Name == "activate house alarm") { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); CraftSynth.BuildingBlocks.WindowsNT.WindowsMessage.Send("F4CIOsPortControl", 273, 704, 0); } else if (command.Name == "deactivate house alarm") { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); CraftSynth.BuildingBlocks.WindowsNT.WindowsMessage.Send("F4CIOsPortControl", 273, 705, 0); } else if (command.Name == "house alarm restart") { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); CraftSynth.BuildingBlocks.WindowsNT.WindowsMessage.Send("F4CIOsPortControl", 273, 703, 0); } else //if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") //{ // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); //} //else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") // { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); // } // else { throw new ApplicationException(string.Format("ProviderSample: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("MacroManager: Executing command '{0}' ...", command.Name)); string errorMessage = null; Macro macro = null; if (errorMessage == null) { try { string filePath = Path.Combine(Settings.Current.MacrosDataFolder, command.Name + ".mcr"); macro = Macros.Get(filePath, true); } catch (Exception exception) { errorMessage = "Can not load macro. " + exception.Message; } } if (errorMessage == null) { string macroString = string.Empty; foreach (string line in macro.body) { macroString += line + "\r"; } for (int i = 0; i < command.parametersOnExecute.Count; i++) { macroString = macroString.Replace(Settings.Current.startOfMacroParameter + i + Settings.Current.endOfMacroParameter, command.parametersOnExecute[i].GetValueAsText()); } try { File.WriteAllText(Path.Combine(Settings.Current.MacrosDataFolder, "Macro.tmp.mcr"), macroString); } catch (Exception exception) { errorMessage = "Error occured while writeing temp file." + exception.Message; } } if (errorMessage == null) { try { Process process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.FileName = Path.Combine(Settings.Current.MacrosDataFolder, "Macro.tmp.mcr"); Logging.AddActionLog(string.Format("MacroManager: Starting macro '{0}' ({1}) ...", macro.filePath, macro.GetCaption())); process.Start(); } catch (Exception exception) { errorMessage = "Error occured while starting temp file. " + exception.Message; } } if (errorMessage != null) { throw new ApplicationException("ExtensionMacro: OnCommand failed :" + errorMessage); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("TOpener: Executing command '{0}' ...", command.Name)); if (command.Name == "topen" || command.Name == "rtopen") { Logging.AddActionLog(string.Format("TOpener: Opening '{0}' in Total Commander ...", command.parametersOnExecute[0].GetValueAsText())); MessagesHandler.Display(string.Format("Opening {0} ...", command.parametersOnExecute[0].GetValueAsText())); if (IsPathSuitable(command.parametersOnExecute[0].GetValueAsText())) { TotalCommanderPane pane = TotalCommanderPane.Left; if (command.Name == "topen") { pane = TotalCommanderPane.Left; } else if (command.Name == "rtopen") { pane = TotalCommanderPane.Right; } OpenInTotalComander(command.parametersOnExecute[0].GetValueAsText(), pane); } else {//extract filepaths and try to open their parent folder List <string> fileSelectionList = Syntax.FileSelectionFromString(command.parametersOnExecute[0].GetValueAsText()); if (fileSelectionList.Count == 0) { Logging.AddErrorLog(string.Format("TOpener: File/Folder '{0}' not found.", command.parametersOnExecute[0].GetValueAsText())); MessagesHandler.Display("File/Folder not found.", command.parametersOnExecute[0].GetValueAsText()); } else { string parentFolder = Directory.GetParent(fileSelectionList[0]).FullName; if (IsPathSuitable(parentFolder)) { TotalCommanderPane pane = TotalCommanderPane.Left; if (command.Name == "topen") { pane = TotalCommanderPane.Left; } else if (command.Name == "rtopen") { pane = TotalCommanderPane.Right; } OpenInTotalComander(parentFolder, pane); } else { Logging.AddErrorLog(string.Format("TOpener: File/Folder '{0}' not found.", parentFolder)); MessagesHandler.Display("File/Folder not found.", parentFolder); } //foreach (string filePath in fileSelectionList) //{ // if (File.Exists(filePath) || Directory.Exists(filePath)) // { // OpenInTotalComander(filePath); // } // else // { // MessagesHandler.Display( "File/Folder not found.", filePath); // } //} } } } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("BookmarkManager: Executing command '{0}' ...", command.Name)); if (command.Name == "bookmark as") { //MessagesHandler.Display( "Loading bookmark folders ..."); this.service = service; OSD.OSD.SettingsFilePath = "OSD.Bookmarks.ini"; OSD.Menu.Menu bookmarkMenu = new OSD.Menu.Menu(null, "Bookmarks", Settings.Current.EnsoLearnAsOpenCommandsFolder, false, false, false, false, "[New Category]", false, new OSD.Menu.MenuItemChosenDelegate(MenuItemChoosen)); Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("OSD"); OSD.Menu.MenuItem selectedMenuItem = OSD.Menu.Menu.ShowMenu(bookmarkMenu); if (selectedMenuItem != null) { string bookmarkFilePath = Path.Combine((string)selectedMenuItem.tag, command.parametersOnExecute[0].GetValueAsText() + ".url"); BookmarkManager.SaveLinkFile(bookmarkFilePath, command.parametersOnExecute[1].GetValueAsText()); string message = command.parametersOnExecute[1].GetValueAsText(); MessagesHandler.Display(string.Format("{0} saved as bookmark.", message)); } } else if (command.Name == "bookmark all tabs as") { this.service = service; OSD.OSD.SettingsFilePath = "OSD.Bookmarks.ini"; OSD.Menu.Menu bookmarkMenu = new OSD.Menu.Menu(null, "Bookmarks", Settings.Current.EnsoLearnAsOpenCommandsFolder, false, false, false, false, "[New Category]", false, new OSD.Menu.MenuItemChosenDelegate(MenuItemChoosen)); Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("OSD"); OSD.Menu.MenuItem selectedMenuItem = OSD.Menu.Menu.ShowMenu(bookmarkMenu); if (selectedMenuItem != null) { //string bookmarkFilePath = Path.Combine((string)selectedMenuItem.tag, command.parametersOnExecute[0].GetCaption() + "."+Entities.WorkItems.Shortcuts.extension); CommandsProviders.FOpener.FOpener.SaveAllTabs(true, service, command.parametersOnExecute[0].GetCaption(), (string)selectedMenuItem.tag, "BookmarkManager"); } } else if (command.Name == "bookmark all tabs in one category") { this.service = service; OSD.OSD.SettingsFilePath = "OSD.Bookmarks.ini"; OSD.Menu.Menu bookmarkMenu = new OSD.Menu.Menu(null, "Bookmarks", Settings.Current.EnsoLearnAsOpenCommandsFolder, false, false, false, false, "[New Category]", false, new OSD.Menu.MenuItemChosenDelegate(MenuItemChoosen)); Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("OSD"); OSD.Menu.MenuItem selectedMenuItem = OSD.Menu.Menu.ShowMenu(bookmarkMenu); if (selectedMenuItem != null) { //string bookmarkFilePath = Path.Combine((string)selectedMenuItem.tag, command.parametersOnExecute[0].GetCaption() + "."+Entities.WorkItems.Shortcuts.extension); CommandsProviders.FOpener.FOpener.SaveAllTabs(false, service, Path.GetFileNameWithoutExtension(selectedMenuItem.tag.ToString()), (string)selectedMenuItem.tag, "BookmarkManager"); } } else if (command.Name == "open bookmark") { //MessagesHandler.Display( "Loading bookmark folders ..."); OSD.OSD.SettingsFilePath = "OSD.Bookmarks.ini"; OSD.Menu.Menu bookmarkMenu = new OSD.Menu.Menu(null, "Bookmarks", Settings.Current.EnsoLearnAsOpenCommandsFolder, true, false, true, false, "[All From This Category]", false, null); Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("OSD"); OSD.Menu.MenuItem selectedMenuItem = OSD.Menu.Menu.ShowMenu(bookmarkMenu); if (selectedMenuItem != null) { List <string> filePathsToOpen = new List <string>(); if (selectedMenuItem.text == "[All From This Category]") { List <string> filePathsInFolder = CraftSynth.BuildingBlocks.IO.FileSystem.GetFilePaths(selectedMenuItem.tag.ToString()); foreach (string filePathInFolder in filePathsInFolder) { if (filePathInFolder.EndsWith(Entities.WorkItems.Shortcuts.extension, StringComparison.InvariantCultureIgnoreCase) || filePathInFolder.EndsWith("lnk", StringComparison.InvariantCultureIgnoreCase) || filePathInFolder.EndsWith("url", StringComparison.InvariantCultureIgnoreCase) ) { filePathsToOpen.Add(filePathInFolder); } } } else { filePathsToOpen.Add(selectedMenuItem.tag.ToString()); } foreach (string filePathToOpen in filePathsToOpen) { if (filePathToOpen.EndsWith(Entities.WorkItems.Shortcuts.extension, StringComparison.OrdinalIgnoreCase)) { Entities.WorkItems.Shortcuts shortcuts = new Entities.WorkItems.Shortcuts(filePathToOpen); Logging.AddActionLog(string.Format("BookmarkManager: Opening '{0}' in Firefox ...", shortcuts.shortcutsFilePath)); MessagesHandler.Display(string.Format("Opening {0} ...", shortcuts.caption)); foreach (Shortcut shortcut in shortcuts.shortcuts) { Logging.AddActionLog(string.Format("BookmarkManager: Opening '{0}' in Firefox ...", shortcut.targetPath)); CommandsProviders.FOpener.FOpener.OpenInFirefox(shortcut.targetPath, true); } } else { MessagesHandler.Display(string.Format("Opening {0} ...", filePathToOpen)); CraftSynth.BuildingBlocks.WindowsNT.Misc.OpenFile(filePathToOpen); } } } } else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") //{ // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); //} else { throw new ApplicationException(string.Format("BookmarkManager: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("Misc: Executing command '{0}' ...", command.Name)); if (command.Name == "edit general settings") { Logging.AddActionLog(string.Format("Misc: Opening settings file '{0}' ...", Settings.FilePath)); MessagesHandler.Display(string.Format("Opening {0} ...", Settings.FilePath)); Process process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.Arguments = string.Format("\"{0}\"", Settings.FilePath); process.StartInfo.FileName = "Notepad"; process.Start(); CraftSynth.BuildingBlocks.WindowsNT.Misc.SetForegroundWindow("EnsoPlusSettings.xml - Notepad"); Logging.AddActionLog("Misc: Settings file opened."); } else if (command.Name == "edit selection listener settings") { Logging.AddActionLog(string.Format("Misc: Opening settings file '{0}' ...", SelectionListener.Settings.FilePath)); MessagesHandler.Display(string.Format("Opening {0} ...", SelectionListener.Settings.FilePath)); Process process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.Arguments = string.Format("\"{0}\"", SelectionListener.Settings.FilePath); process.StartInfo.FileName = "Notepad"; process.Start(); CraftSynth.BuildingBlocks.WindowsNT.Misc.SetForegroundWindow("SelectionListener.ini - Notepad"); Logging.AddActionLog("Misc: Settings file opened."); } else if (command.Name == "exit Enso+" || command.Name == "close Enso+") { Exit(); } else if (command.Name == "caps lock on") { Logging.AddActionLog("Misc: Turning caps lock on ..."); //MessagesHandler.Display( string.Format("Exiting Enso+ ...")); Program.cornerLauncher.TurnOnCapsLock(); } else if (command.Name == "caps lock off") { Logging.AddActionLog("Misc: Turning caps lock off ..."); //MessagesHandler.Display( string.Format("Exiting Enso+ ...")); Program.cornerLauncher.TurnOffCapsLock(); } else if (command.Name == "clear cached suggestions") { SuggestionsCache.DropAllCache(); Logging.AddActionLog("Misc: Cache cleared."); MessagesHandler.Display("Cache cleared."); } else if (command.Name == "restart Enso+") { Restart(); } else if (command.Name == "open in notepad" || command.Name == "preview in notepad") { //MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); CraftSynth.BuildingBlocks.WindowsNT.Misc.OpenTextInNotepad(Common.Helper.GetEnsoTempraryFilePath("txt"), command.parametersOnExecute[0].GetValueAsText()); } else //if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") //{ // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); //} //else { throw new ApplicationException(string.Format("Misc: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("BackupManager: Executing command '{0}' ...", command.Name)); if (command.Name == "set as backup source folder" && command.Postfix == "for profile [profile name] [folder]") { string name = command.parametersOnExecute[0].GetValueAsText(); string sourceFolder = command.parametersOnExecute[1].GetValueAsText(); this.SetSourceFolderOnBackupProfile(service, command, name, sourceFolder); } else if (command.Name == "set as backup destination folder" && command.Postfix == "for profile [profile name] [folder]") { string name = command.parametersOnExecute[0].GetValueAsText(); string destinationFolder = command.parametersOnExecute[1].GetValueAsText(); this.SetDestinationFolderOnBackupProfile(service, command, name, destinationFolder); } else if (command.Name == "set as backup source folder" && command.Postfix == "[folder]") { string sourceFolder = command.parametersOnExecute[0].GetValueAsText(); string name = PromptProfileSelectionDialog(); if (!string.IsNullOrEmpty(name)) { this.SetSourceFolderOnBackupProfile(service, command, name, sourceFolder); } } else if (command.Name == "set as backup destination folder" && command.Postfix == "[folder]") { string destinationFolder = command.parametersOnExecute[0].GetValueAsText(); string name = PromptProfileSelectionDialog(); if (!string.IsNullOrEmpty(name)) { this.SetDestinationFolderOnBackupProfile(service, command, name, destinationFolder); } } else if (command.Name == "backup") { BackupProfile backupProfile = command.parametersOnExecute[0].GetValue() as BackupProfile; throw new NotImplementedException(); //TODO: finish display async //string label = ParameterInput.Display("Label", new List<string>(), false, false, backupProfile.Name, false, false, null); //if (!string.IsNullOrEmpty(label)) //{ // if(!Directory.Exists(backupProfile.SourceFolder)) // { // MessagesHandler.Display( "Source folder does not exist.", backupProfile.SourceFolder); // }else // if(!Directory.Exists(backupProfile.DestinationFolder)) // { // MessagesHandler.Display( "Destination folder does not exist.", backupProfile.DestinationFolder); // }else // { // MessagesHandler.Display( string.Format("Backing up '{0}' to '{1}' ...", backupProfile.SourceFolder, backupProfile.DestinationFolder)); // //{EnsoPlusDataFolder}\7z.exe // //a -r "{DestinationFolderPath}\{CurrentDateTime} {Label}\{SourceFolderName}" "{SourceFolderPath}"; // string parameters = Settings.Current.BackupManagerParameters; // parameters = parameters.Replace("{DestinationFolderPath}", backupProfile.DestinationFolder); // parameters = parameters.Replace("{CurrentDateTime}", CraftSynth.BuildingBlocks.Common.DateAndTime.GetCurrentDateAndTimeInSortableFormatForFileSystem()); // parameters = parameters.Replace("{Label}", label); // parameters = parameters.Replace("{SourceFolderName}", Path.GetFileName(backupProfile.SourceFolder)); // parameters = parameters.Replace("{SourceFolderPath}", backupProfile.SourceFolder); // CraftSynth.BuildingBlocks.WindowsNT.Misc.OpenFile(Settings.Current.BackupManagerExePath, parameters); // } //} } else { throw new ApplicationException(string.Format("BackupManager: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("Comparer: Executing command '{0}' ...", command.Name)); if (command.Name == "comparer item 1") { if (command.parametersOnExecute[0] is StringWorkItem) { this.comparerItem1 = command.parametersOnExecute[0].GetValueAsText(); MessagesHandler.Display("Item 1 marked."); } else { MessagesHandler.Display("Only text is supported currently."); } } else if (command.Name == "compare case sensitive" || command.Name == "compare case insensitive") { if (this.comparerItem1 == null) { MessagesHandler.Display("Use 'comparer item 1' command first."); } else { if (command.parametersOnExecute[0] is StringWorkItem) { this.comparerItem2 = command.parametersOnExecute[0].GetValueAsText(); bool areEqual = false; bool compareAsStrings = true; if (command.Name != "compare case insensitive") { if (CraftSynth.BuildingBlocks.IO.FileSystem.IsFilePathValid(this.comparerItem1.ToString()) && CraftSynth.BuildingBlocks.IO.FileSystem.IsFilePathValid(this.comparerItem2.ToString()) && File.Exists(this.comparerItem1.ToString()) && File.Exists(this.comparerItem2.ToString()) ) { Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("Comparer"); if (MessageBox.Show(string.Format("Marked items:\n\r{0}\n\r{1}\n\r are paths to existing files on disk. Should file content be compared?", this.comparerItem1.ToString(), this.comparerItem2.ToString()), "Comparer", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { compareAsStrings = false; } } } if (compareAsStrings) { CompareOptions compareOprions = CompareOptions.Ordinal; if (command.Name == "compare case sensitive") { compareOprions = CompareOptions.Ordinal; } else if (command.Name == "compare case insensitive") { compareOprions = CompareOptions.OrdinalIgnoreCase; } areEqual = string.Compare(this.comparerItem1.ToString(), this.comparerItem2.ToString(), CultureInfo.InvariantCulture, compareOprions) == 0; } else { areEqual = CraftSynth.BuildingBlocks.IO.FileSystem.CompareFileContent(this.comparerItem1.ToString(), this.comparerItem2.ToString()); } if (areEqual) { MessagesHandler.Display("Equal."); } else { MessagesHandler.Display("Different."); } } else { MessagesHandler.Display("Only text is supported currently."); } } } else if (command.Name == "compare in notepad") { if (this.comparerItem1 == null) { MessagesHandler.Display("Use 'comparer item 1' command first."); } else { if (command.parametersOnExecute[0] is StringWorkItem) { this.comparerItem2 = command.parametersOnExecute[0].GetValueAsText(); string notepadContent = string.Format("{0}\r\n{1}", this.comparerItem1, this.comparerItem2); CraftSynth.BuildingBlocks.WindowsNT.Misc.OpenTextInNotepad(Common.Helper.GetEnsoTempraryFilePath("txt"), notepadContent); } else { MessagesHandler.Display("Only text is supported currently."); } } } //else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") // { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); // } else { throw new ApplicationException(string.Format("ProviderSample: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("COpener: Executing command '{0}' ...", command.Name)); if (command.Name == "copen in new window" || command.Name == "copen in new tab" || command.Name == "copen in new incognito window" || command.Name == "copen in new incognito tab") { if (command.parametersOnExecute[0] is Entities.WorkItems.Shortcuts) { Entities.WorkItems.Shortcuts shortcuts = command.parametersOnExecute[0] as Entities.WorkItems.Shortcuts; Logging.AddActionLog(string.Format("COpener: Opening '{0}' in Chrome ...", shortcuts.shortcutsFilePath)); MessagesHandler.Display(string.Format("Opening {0} ...", shortcuts.caption)); foreach (Shortcut shortcut in shortcuts.shortcuts) { Logging.AddActionLog(string.Format("COpener: Opening '{0}' in Chrome ...", shortcut.targetPath)); OpenInChrome(shortcut.targetPath, command.Name.Contains("tab"), command.Name.Contains("incognito")); } } else { Logging.AddActionLog(string.Format("COpener: Opening '{0}' in Chrome ...", command.parametersOnExecute[0].GetValueAsText())); MessagesHandler.Display(string.Format("Opening {0} ...", command.parametersOnExecute[0].GetValueAsText())); OpenInChrome(command.parametersOnExecute[0].GetValueAsText(), command.Name.Contains("tab"), command.Name.Contains("incognito")); } } else if (command.Name == "preview in chrome" || command.Name == "preview in new tab of chrome") { string filePath = Common.Helper.GetEnsoTempraryFilePath("htm"); File.WriteAllText(filePath, command.parametersOnExecute[0].GetValueAsText()); OpenInChrome(filePath, command.Name.Contains("tab"), command.Name.Contains("incognito")); } else if (command.Name == "test js in chrome in new window" || command.Name == "test js in chrome in new tab") { string filePath = Common.Helper.GetEnsoTempraryFilePath("htm"); string js = command.parametersOnExecute[0].GetValueAsText(); string templatePath = Path.Combine(Common.Helper.GetEnsoPlusWorkingFolder(), @"Resources\TemplateJavascriptTest.htm"); string template = File.ReadAllText(templatePath); string html = template.Replace("{0}", js); File.WriteAllText(filePath, html); OpenInChrome(filePath, command.Name.Contains("tab"), command.Name.Contains("incognito")); } if (command.Name == "test js function in chrome in new window" || command.Name == "test js function in chrome in new tab") { string filePath = Common.Helper.GetEnsoTempraryFilePath("htm"); string functionName = command.parametersOnExecute[0].GetValueAsText(); string js = command.parametersOnExecute[1].GetValueAsText(); string templatePath = Path.Combine(Common.Helper.GetEnsoPlusWorkingFolder(), @"Resources\TemplateJavascriptFunctionTest.htm"); string template = File.ReadAllText(templatePath); if (js.IndexOf(functionName, StringComparison.OrdinalIgnoreCase) > 0) { functionName = js.Substring(js.IndexOf(functionName, StringComparison.OrdinalIgnoreCase), functionName.Length); } string html = template.Replace("{0}", functionName); html = html.Replace("{1}", js); File.WriteAllText(filePath, html); OpenInChrome(filePath, command.Name.Contains("tab"), command.Name.Contains("incognito")); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("FileManager: Executing command '{0}' ...", command.Name)); if (command.Name == "copy to" || command.Name == "move to") { string selectedPath = service.GetUnicodeSelection(); if (string.IsNullOrEmpty(selectedPath)) { selectedPath = service.GetFileSelection()[0]; } if (string.IsNullOrEmpty(selectedPath)) { MessagesHandler.Display("Nothing is selected therefore no destination path."); Logging.AddErrorLog("FileManager: Nothing is selected therefore no destination path."); } else { try { string destinationPath = Path.Combine(command.parametersOnExecute[0].GetValueAsText(), Path.GetFileName(selectedPath)); if (command.Name == "copy to") { Logging.AddActionLog(string.Format("FileManager: Copying '{0}' to {1} ...", selectedPath, command.parametersOnExecute[0].GetValueAsText())); CraftSynth.BuildingBlocks.IO.FileSystem.CopyFileOrFolder(selectedPath, command.parametersOnExecute[0].GetValueAsText()); if (CraftSynth.BuildingBlocks.IO.FileSystem.FileOrFolderExist(destinationPath)) { Logging.AddActionLog("FileManager: Copied."); MessagesHandler.Display("Copied."); } else { string errorMessage = string.Format("Destination file/folder '{0}' does not exist after copy operation.", destinationPath); Logging.AddErrorLog(string.Format("FileManager: {0}", errorMessage)); MessagesHandler.Display(errorMessage); } } else if (command.Name == "move to") { Logging.AddActionLog(string.Format("FileManager: Moving '{0}' to {1} ...", selectedPath, command.parametersOnExecute[0].GetValueAsText())); CraftSynth.BuildingBlocks.IO.FileSystem.MoveFileOrFolder(selectedPath, command.parametersOnExecute[0].GetValueAsText()); if (CraftSynth.BuildingBlocks.IO.FileSystem.FileOrFolderDoesNotExist(destinationPath)) { string errorMessage = string.Format("Destination file/folder '{0}' does not exist after move operation.", destinationPath); Logging.AddErrorLog(string.Format("FileManager: {0}", errorMessage)); MessagesHandler.Display(errorMessage); } else if (CraftSynth.BuildingBlocks.IO.FileSystem.FileOrFolderExist(selectedPath)) { string errorMessage = string.Format("Destination file/folder '{0}' still exist after move operation.", destinationPath); Logging.AddErrorLog(string.Format("FileManager: {0}", errorMessage)); MessagesHandler.Display(errorMessage); } else { Logging.AddActionLog("FileManager: Moved."); MessagesHandler.Display("Moved."); } } } catch (System.IO.FileNotFoundException) { Logging.AddErrorLog(string.Format("FileManager: File not found: {0}", command.parametersOnExecute[1].GetValueAsText())); MessagesHandler.Display("File not found.", command.parametersOnExecute[1].GetValueAsText()); } catch (System.IO.DirectoryNotFoundException) { Logging.AddErrorLog(string.Format("FileManager: Folder not found: {0}", command.parametersOnExecute[1].GetValueAsText())); MessagesHandler.Display("Folder not found.", command.parametersOnExecute[1].GetValueAsText()); } catch (Exception exception) { Logging.AddErrorLog(string.Format("FileManager: {0}", exception.Message)); MessagesHandler.Display(exception.Message); } } } else if (command.Name == "empty") { string path = command.parametersOnExecute[0].GetValueAsText(); Logging.AddActionLog(string.Format("FileManager: Emptying '{0}' ...", path)); bool isFolder = true; if (File.Exists(path) && !Directory.Exists(path)) { isFolder = false; } else if (!File.Exists(path) && Directory.Exists(path)) { isFolder = true; } try { Logging.AddActionLog(string.Format("FileManager: Deleting '{0}' ...", path)); CraftSynth.BuildingBlocks.IO.FileSystem.DeleteFileOrFolder(path, false); if (!isFolder) { Logging.AddActionLog(string.Format("FileManager: Creating '{0}' ...", path)); File.Create(path); } else { Logging.AddActionLog(string.Format("FileManager: Creating '{0}' ...", path)); Directory.CreateDirectory(path); } Logging.AddActionLog("FileManager: Contents deleted."); MessagesHandler.Display("Contents deleted."); } catch (System.IO.FileNotFoundException) { Logging.AddErrorLog(string.Format("FileManager: File not found: {0}", command.parametersOnExecute[1].GetValueAsText())); MessagesHandler.Display("File not found.", command.parametersOnExecute[1].GetValueAsText()); } catch (System.IO.DirectoryNotFoundException) { Logging.AddErrorLog(string.Format("FileManager: Folder not found: {0}", command.parametersOnExecute[1].GetValueAsText())); MessagesHandler.Display("Folder not found.", command.parametersOnExecute[1].GetValueAsText()); } catch (Exception exception) { //if operation failed but item is empty report success if (!isFolder && File.Exists(path)) { FileInfo fileInfo = new FileInfo(path); if (fileInfo.Length == 0) { exception = null; } } else if (Directory.Exists(path)) { if (CraftSynth.BuildingBlocks.IO.FileSystem.GetFilePaths(path).Count == 0 && CraftSynth.BuildingBlocks.IO.FileSystem.GetFolderPaths(path).Count == 0) { exception = null; } } if (exception == null) { Logging.AddActionLog("FileManager: Contents deleted."); MessagesHandler.Display("Contents deleted."); } else { Logging.AddErrorLog(string.Format("FileManager: {0}", exception.Message)); MessagesHandler.Display(exception.Message); } } } else if ((command.Name == "save" && command.Postfix == "[what] to") || (command.Name == "save" && command.Postfix == "[what] and copy its file path")) { ParameterizedThreadStart ts = new ParameterizedThreadStart(ProcessCommand); clipboardHost = new Thread(ts); clipboardHost.SetApartmentState(ApartmentState.STA); KeyValuePair <IEnsoService, Command> parameters = new KeyValuePair <IEnsoService, Command>(service, command); clipboardHost.Start(parameters); clipboardHost.Join(); } else if (command.Name == "copy file content as text") { string filePath = command.parametersOnExecute[0].GetValueAsText(); string content = File.ReadAllText(filePath); if (string.Empty == (content.Trim())) { MessagesHandler.Display(string.Format("File is empty.", filePath)); } else { CraftSynth.BuildingBlocks.IO.Clipboard.SetTextToClipboard(content); //content = BuildingBlocks.DataAccess.Clipboard.Helper.GetTextFromClipboard(); string message = content.Substring(0, (content.Length <= 200) ? content.Length : 200); if (content.Length > 200) { message = message + "..."; } try { MessagesHandler.Display(message, string.Format("{0} characters on clipboard", content.Length)); } catch { MessagesHandler.Display(string.Format("Copied {0} characters.", content.Length)); } } } // else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") // { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); // } else { throw new ApplicationException(string.Format("FileManager: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("ProcessesManager: Executing command '{0}' ...", command.Name)); if (command.Name == "kill" || command.Name == "restart process") { if (command.parametersOnExecute[0] is ProcessWorkItem) { ProcessWorkItem processWorkItem = command.parametersOnExecute[0] as ProcessWorkItem; FinishCommand(command.Name, processWorkItem.procces, service); } else if (command.parametersOnExecute[0] is StringWorkItem) { Process processById = null; try { int id = Convert.ToInt32(command.parametersOnExecute[0].GetValueAsText()); processById = Process.GetProcessById(id); } catch { } if (processById != null) { FinishCommand(command.Name, processById, service); } else { Process[] processesByName = Process.GetProcessesByName(command.parametersOnExecute[0].GetValueAsText()); if (processesByName.Length == 1) { FinishCommand(command.Name, processesByName[0], service); } //else if (processesByName.Length > 1) //{ // if (MessageBox.Show(string.Format("{0} proccesses have name '{1}'. Kill'em all?", processesByName.Length, command.parametersOnExecute[0].GetValueAsText()), "", MessageBoxButtons.OKCancel) == DialogResult.OK) // { // //string message = string.Empty; // foreach (Process p in processesByName) // { // p.Kill(); // } // MessagesHandler.Display( "Killed"); // } //} else if (processesByName.Length == 0 || processesByName.Length > 1) { //if (MessageBox.Show(string.Format("None is found. Search partialy?"), "", MessageBoxButtons.OKCancel) == DialogResult.OK) //{ //MessagesHandler.Display( "0 found. Searching partialy..."); Process[] allProcesses = Process.GetProcesses(); List <Process> processesThatContainPhraseInName = new List <Process>(); foreach (Process processToCheck in allProcesses) { if (-1 != processToCheck.ProcessName.IndexOf(command.parametersOnExecute[0].GetValueAsText(), StringComparison.InvariantCultureIgnoreCase)) { processesThatContainPhraseInName.Add(processToCheck); } } if (processesThatContainPhraseInName.Count == 0) { MessagesHandler.Display("0 found"); } else { string resultNames = string.Empty; foreach (Process p in processesThatContainPhraseInName) { resultNames += string.Format(",\r\n{0} ({1})", p.ProcessName, p.Id); } if (!string.IsNullOrEmpty(resultNames)) { resultNames = resultNames.Remove(0, 3); } if (MessageBox.Show(string.Format("{0}\r\n\r\nfound. Affect all?", resultNames), "", MessageBoxButtons.OKCancel) == DialogResult.OK) { //string message = string.Empty; FinishCommand(command.Name, processesThatContainPhraseInName, service); } } //} } } } else { var warperException = new ApplicationException(string.Format("Process manager: Unsupported type '{0}'found as parameter.", command.parametersOnExecute[0].GetType().FullName)); Common.Logging.AddExceptionLog(warperException); MessagesHandler.Display("Unsupported type found as parameter."); } } else //if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") //{ // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); //} //else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") // { // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); // } // else { throw new ApplicationException(string.Format("ProcessManager: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }