コード例 #1
0
        private static void ListProcesses(String postfix,
                                          IEnsoService service)
        {
            Process[]          processes   = Process.GetProcesses();
            SortedSet <String> uniqueNames = new SortedSet <String>();

            foreach (Process p in processes)
            {
                uniqueNames.Add(p.ProcessName);
            }

            char   initial = '\0';
            String message = "";

            foreach (String s in uniqueNames)
            {
                String name = s.ToLower();

                if (name.Length > 0 && !name[0].Equals(initial))
                {
                    initial = name[0];
                    name    = char.ToUpper(name[0]) + name.Substring(1);
                }

                message += name + " ";
            }

            message = "<p>" + message.Trim() + "</p>";

            service.DisplayMessage(new FreeFormatMessage(message));
        }
コード例 #2
0
        public void ExecuteCommand(IEnsoService service, Command command)
        {
            Logging.AddActionLog(string.Format("WebSearcher: Executing command '{0}' ...", command.Name));

            if (command.Name == "learn as web search command with name")
            {
                ShortcutTemplates.CreateShortcutTemplate(command.parametersOnExecute[0].GetValueAsText(), command.parametersOnExecute[1].GetValueAsText());
                SuggestionsCache.DropCache(typeof(WorkItemsProviders.ShortcutTemplates.ShortcutTemplates));
                EnsoPlus.current.Reinitialize();
                string message = string.Format("{0} is now a command.", command.parametersOnExecute[0].GetValueAsText());
                Logging.AddActionLog(string.Format("WebSearcher: {0}", message));
                MessagesHandler.Display(message);
            }
            else
            {
                string  shortcutFilePath = ShortcutTemplates.BuildFilePath(command.Name);
                string  template         = ShortcutTemplates.GetTemplate(shortcutFilePath);
                string  queryString      = string.Format(template, command.parametersOnExecute[0].GetValueAsText());
                Process process          = new Process();
                process.StartInfo.UseShellExecute = true;
                process.StartInfo.FileName        = queryString;
                Logging.AddActionLog(string.Format("WebSearcher: Starting '{0}' ...", process.StartInfo.FileName));
                process.Start();
            }
        }
コード例 #3
0
        public void Load(IEnsoService service)
        {
            Debug.Assert(service != null);
            this.service = service;

            String uri = this.GetType().Name + ".rem";
            service.RegisterCommand(this, uri, command);
        }
コード例 #4
0
        public void Load(IEnsoService service)
        {
            Debug.Assert(service != null);
            this.service = service;

            String uri = this.GetType().Name + ".rem";

            service.RegisterCommand(this, uri, command);
        }
コード例 #5
0
 public void Deinit()
 {
     this._blockedByMouseHover     = false;
     this._blockedByCheckbox       = false;
     this._blockedByPasteOperation = false;
     this._blockedByModifierKey    = false;
     this._blockedByMouseWheel     = false;
     this._service = null;
     this._formSelectionListener = null;
 }
コード例 #6
0
 public void Init(IEnsoService service, FormSelectionListener formSelectionListener)
 {
     this._service = service;
     this._formSelectionListener   = formSelectionListener;
     this._lastAddedSelection      = null;
     this._blockedByMouseHover     = false;
     this._blockedByCheckbox       = false;
     this._blockedByPasteOperation = false;
     this._blockedByModifierKey    = false;
     this._blockedByMouseWheel     = false;
 }
コード例 #7
0
        public void AssignPasteKeyCombination(IEnsoService service)
        {
            List <Keys> selectedKeyCombination = KeyCombinationRetriever.Execute(null);

            if (selectedKeyCombination != null)
            {
                Settings.Current.pasteKeyCombination = CraftSynth.BuildingBlocks.UI.WindowsForms.KeysHelper.ToCommaSeparatedCodesString(selectedKeyCombination);
                Settings.Save();

                MessagesHandler.Display(CraftSynth.BuildingBlocks.UI.WindowsForms.KeysHelper.ToUserFriendlyString(selectedKeyCombination) + " is now key combination for paste operation. Please restart Selection Listener.");
            }
        }
コード例 #8
0
        public void Load(IEnsoService service)
        {
            Debug.Assert(service != null);
            this.service = service;

            String uri = this.GetType().Name + ".rem";

            service.RegisterCommand(this, uri, command);
            service.SetCommandValidPostfixes(command,
                new String[] { "", POSTFIX_LOWER, POSTFIX_UPPER,
                                POSTFIX_NUMERIC });
        }
コード例 #9
0
 private static void QuitLingvo(String postfix, IEnsoService service)
 {
     try
     {
         ILingvoApplication lingvo = new CLingvoApplication();
         lingvo.Quit();
     }
     catch (Exception)
     {
         service.DisplayMessage(new EnsoMessage(ERROR_MESSAGE));
     }
 }
コード例 #10
0
        public void Load(IEnsoService service)
        {
            Debug.Assert(service != null);
            this.service = service;

            String uri = this.GetType().Name + ".rem";

            service.RegisterCommand(this, uri, command);
            service.SetCommandValidPostfixes(command,
                                             new String[] { "", POSTFIX_LOWER, POSTFIX_UPPER,
                                                            POSTFIX_NUMERIC });
        }
コード例 #11
0
 private static void DialInternet(String postfix, IEnsoService service)
 {
     try
     {
         if (!"".Equals(postfix))
         {
             RAS.Dial(postfix);
         }
     }
     catch (Exception)
     {
         service.DisplayMessage(new EnsoMessage(CONNECT_ERROR));
     }
 }
コード例 #12
0
        public void ExecuteCommand(IEnsoService service, Command command)
        {
            Logging.AddActionLog(string.Format("Memorizer: Executing command '{0}' ...", command.Name));

            if (command.Name == "memorize" && command.Postfix == "[what to memorize] as [item name]")
            {
                if (!Directory.Exists(Settings.Current.MemorizerDataFolder))
                {
                    Directory.CreateDirectory(Settings.Current.MemorizerDataFolder);
                    Logging.AddActionLog(string.Format("Memorizer: Folder '{0}' created.", Settings.Current.MemorizerDataFolder));
                }
                string filePath = Path.Combine(Settings.Current.MemorizerDataFolder, command.parametersOnExecute[1].GetValueAsText() + ".txt");
                File.WriteAllText(filePath, command.parametersOnExecute[0].GetValueAsText());
                SuggestionsCache.DropCache(typeof(WorkItemsProviders.MemorizedData.MemorizedData));
                string message = string.Format("{0} memorized", command.parametersOnExecute[1].GetValueAsText());
                Logging.AddActionLog(string.Format("Memorizer: {0}", message));
                MessagesHandler.Display(message);
            }
            else
            if (command.Name == "memorize-as" && command.Postfix == "[item name] [what to memorize]")
            {
                if (!Directory.Exists(Settings.Current.MemorizerDataFolder))
                {
                    Directory.CreateDirectory(Settings.Current.MemorizerDataFolder);
                    Logging.AddActionLog(string.Format("Memorizer: Folder '{0}' created.", Settings.Current.MemorizerDataFolder));
                }
                string filePath = Path.Combine(Settings.Current.MemorizerDataFolder, command.parametersOnExecute[0].GetValueAsText() + ".txt");
                File.WriteAllText(filePath, command.parametersOnExecute[1].GetValueAsText());
                SuggestionsCache.DropCache(typeof(WorkItemsProviders.MemorizedData.MemorizedData));
                string message = string.Format("{0} memorized", command.parametersOnExecute[0].GetValueAsText());
                Logging.AddActionLog(string.Format("Memorizer: {0}", message));
                MessagesHandler.Display(message);
            }
            else
            if (command.Name == "display" && command.Postfix == "[item name]")
            {
                MessagesHandler.Display(command.parametersOnExecute[0].GetValueAsText());
                Logging.AddActionLog(string.Format("Memorizer: {0} displayed.", command.parametersOnExecute[0].GetValueAsText()));
            }
            else
            if (command.Name == "drop" && command.Postfix == "[item name]")
            {
                HandlerForSelection.Put(command.parametersOnExecute[0].GetValueAsText());
                Logging.AddActionLog(string.Format("Memorizer: {0} dropped.", command.parametersOnExecute[0].GetValueAsText()));
            }
            else
            {
                throw new ApplicationException(string.Format("Memorizer: Command not found. Command: {0} {1}", command.Name, command.Postfix));
            }
        }
コード例 #13
0
        private static void QueryMemoryUsage(String postfix,
                                             IEnsoService service)
        {
            List <Process> processes    = new List <Process>(GetProcesses(postfix));
            int            processCount = processes.Count();

            if (processCount > 0)
            {
                String message = "";

                if (processCount == 1)
                {
                    message = "<p>"
                              + GetProcessMemoryUsage(processes[0], true)
                              + "</p>";
                }
                else if (processCount <= 5)
                {
                    processes.Sort((Process l, Process r) =>
                                   - l.WorkingSet64.CompareTo(r.WorkingSet64));

                    foreach (Process process in processes)
                    {
                        message += "<p>"
                                   + GetProcessMemoryUsage(process, true)
                                   + "</p>";
                    }
                }
                else
                {
                    processes.Sort((Process l, Process r) =>
                                   - l.WorkingSet64.CompareTo(r.WorkingSet64));

                    foreach (Process process in processes)
                    {
                        message += "<caption>"
                                   + GetProcessMemoryUsage(process, true)
                                   + "</caption>";
                    }
                }

                service.DisplayMessage(new FreeFormatMessage(message));
            }
            else
            {
                service.DisplayMessage(new EnsoMessage("Process " + postfix
                                                       + " not found"));
            }
        }
コード例 #14
0
        public void Load(IEnsoService service)
        {
            Debug.Assert(service != null);
            this.service = service;

            String uri = this.GetType().Name + ".rem";

            foreach (EnsoCommand command in commands)
            {
                service.RegisterCommand(this, uri, command);

                CommandDesc desc = commandActions[command.Name];
                if (desc.getPostfixes != null)
                    service.SetCommandValidPostfixes(command,
                        desc.getPostfixes());
            }
        }
コード例 #15
0
        public void Load(IEnsoService service)
        {
            Debug.Assert(service != null);
            this.service = service;

            String uri = this.GetType().Name + ".rem";

            foreach (EnsoCommand command in commands)
            {
                service.RegisterCommand(this, uri, command);

                CommandDesc desc = commandActions[command.Name];
                if (desc.getPostfixes != null)
                {
                    service.SetCommandValidPostfixes(command,
                                                     desc.getPostfixes());
                }
            }
        }
コード例 #16
0
 private static void HangupInternet(String postfix,
                                    IEnsoService service)
 {
     try
     {
         if (!"".Equals(postfix))
         {
             IntPtr hConn = RAS.GetConnection(postfix);
             if (hConn != IntPtr.Zero)
             {
                 RAS.HangUp(hConn);
             }
         }
     }
     catch (Exception)
     {
         service.DisplayMessage(new EnsoMessage(HANGUP_ERROR));
     }
 }
コード例 #17
0
        private static void KillProcess(String postfix, IEnsoService service)
        {
            Process [] processes = GetProcesses(postfix);

            if (processes.Count() > 0)
            {
                foreach (Process process in processes)
                {
                    try
                    {
                        process.Kill();
                    }
                    catch (Exception) { }
                }
            }
            else
            {
                service.DisplayMessage(new EnsoMessage("Process " + postfix
                                                       + " not found"));
            }
        }
コード例 #18
0
        private static void TranslateWord(String postfix, IEnsoService service)
        {
            Match m = wordParser.Match(postfix);

            String word = m.Groups[1].Value;

            if ("".Equals(word.Trim()))
            {
                word = service.GetUnicodeSelection();
            }

            bool isLatin = latinMatcher.IsMatch(word);

            m = directionParser.Match(postfix);

            String from = m.Groups[1].Value;

            if (!lang2code.Keys.Contains(from))
            {
                from = isLatin ? LINGVO_SECONDARY_LANG : LINGVO_CORE_LANG;
            }

            String to = m.Groups[2].Value;

            if (!lang2code.Keys.Contains(to))
            {
                to = isLatin ? LINGVO_CORE_LANG : LINGVO_SECONDARY_LANG;
            }

            try
            {
                ILingvoApplication lingvo = new CLingvoApplication();
                lingvo.TranslateTextInDirection(word, lang2code[from],
                                                lang2code[to]);
            }
            catch (Exception)
            {
                service.DisplayMessage(new EnsoMessage(ERROR_MESSAGE));
            }
        }
コード例 #19
0
        private static void TranslateWord(String postfix, IEnsoService service)
        {
            Match m = wordParser.Match(postfix);

            String word = m.Groups[1].Value;
            if ("".Equals(word.Trim()))
                word = service.GetUnicodeSelection();

            bool isLatin = latinMatcher.IsMatch(word);

            m = directionParser.Match(postfix);

            String from = m.Groups[1].Value;
            if (!lang2code.Keys.Contains(from))
                from = isLatin ? LINGVO_SECONDARY_LANG : LINGVO_CORE_LANG;

            String to = m.Groups[2].Value;
            if (!lang2code.Keys.Contains(to))
                to = isLatin ? LINGVO_CORE_LANG : LINGVO_SECONDARY_LANG;

            try
            {
                ILingvoApplication lingvo = new CLingvoApplication();
                lingvo.TranslateTextInDirection(word, lang2code[from],
                    lang2code[to]);
            }
            catch (Exception)
            {
                service.DisplayMessage(new EnsoMessage(ERROR_MESSAGE));
            }
        }
コード例 #20
0
        public static void FinishCommand(string commandName, Process selectedProcess, IEnsoService service)
        {
            if (commandName == "kill")
            {
                selectedProcess.Kill();
                string message = string.Format("{0} killed", selectedProcess.ProcessName);
                Logging.AddActionLog(string.Format("ProcessesManager: {0}", message));
                MessagesHandler.Display(message);
            }
            else if (commandName == "restart process")
            {
                string processExePath = selectedProcess.MainModule.FileName;
                selectedProcess.Kill();
                ContinueWhenProcessIsNotActive(selectedProcess);
                string message = string.Format("{0} killed", selectedProcess.ProcessName);
                Logging.AddActionLog(string.Format("ProcessesManager: {0}", message));
                MessagesHandler.Display(message);

                CraftSynth.BuildingBlocks.WindowsNT.Misc.OpenFile(processExePath);
                message = string.Format("{0} restarted", selectedProcess.ProcessName);
                Logging.AddActionLog(string.Format("ProcessesManager: {0}", message));
                MessagesHandler.Display(message);
            }
        }
コード例 #21
0
        private void FinishCommand(string commandName, List <Process> selectedProcesses, IEnsoService service)
        {
            string message = string.Empty;

            if (commandName == "kill")
            {
                foreach (Process p in selectedProcesses)
                {
                    p.Kill();
                    message += string.Format(",\r\n{0} ({1})", p.ProcessName, p.Id);
                    MessagesHandler.Display(message + "Killed");
                }
                message = message + " - Killed all";
                Logging.AddActionLog(string.Format("ProcessesManager: {0}", message));
                MessagesHandler.Display(message);
            }
            else if (commandName == "restart process")
            {
                List <string> processesFilePaths = new List <string>();
                //call kill
                foreach (Process p in selectedProcesses)
                {
                    processesFilePaths.Add(p.MainModule.FileName);
                    p.Kill();
                }

                //wait
                foreach (Process p in selectedProcesses)
                {
                    ContinueWhenProcessIsNotActive(p);
                    if (message != string.Empty)
                    {
                        message += ",";
                    }
                    message += string.Format("\r\n{0} ({1})", p.ProcessName, p.Id);
                    MessagesHandler.Display(message + "Killed");
                }
                message = message + " - Killed all";
                Logging.AddActionLog(string.Format("ProcessesManager: {0}", message));
                MessagesHandler.Display(message);

                //start
                message = string.Empty;
                foreach (string processFilePath in processesFilePaths)
                {
                    CraftSynth.BuildingBlocks.WindowsNT.Misc.OpenFile(processFilePath);
                    if (message != string.Empty)
                    {
                        message += ",";
                    }
                    message += string.Format("\r\n{0} ", Path.GetFileName(processFilePath));
                    MessagesHandler.Display(message + "Restarted");
                }
                message = message + " - Restarted all";
                Logging.AddActionLog(string.Format("ProcessesManager: {0}", message));
                MessagesHandler.Display(message);
            }
        }
コード例 #22
0
 private static void QuitLingvo(String postfix, IEnsoService service)
 {
     try
     {
         ILingvoApplication lingvo = new CLingvoApplication();
         lingvo.Quit();
     }
     catch (Exception)
     {
         service.DisplayMessage(new EnsoMessage(ERROR_MESSAGE));
     }
 }
コード例 #23
0
        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));
            }
        }
コード例 #24
0
 internal void Execute(IEnsoService service)
 {
     this.provider.ExecuteCommand(service, this);
 }
コード例 #25
0
 private static void HangupInternet(String postfix, 
     IEnsoService service)
 {
     try
     {
         if (!"".Equals(postfix))
         {
             IntPtr hConn = RAS.GetConnection(postfix);
             if (hConn != IntPtr.Zero)
                 RAS.HangUp(hConn);
         }
     }
     catch (Exception)
     {
         service.DisplayMessage(new EnsoMessage(HANGUP_ERROR));
     }
 }
コード例 #26
0
        private void ProcessCommand(Object o)
        {
            KeyValuePair <IEnsoService, Command> parameters = (KeyValuePair <IEnsoService, Command>)o;
            IEnsoService service = parameters.Key;
            Command      command = parameters.Value;

            if (command.parametersOnExecute[0] is ImageWorkItem)
            {
                string targetFilePath = null;
                try
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.DefaultExt = ".png";
                    saveFileDialog.Filter     = ".bmp|.bmp|.emf|.emf|.exif|.exif|.gif|.gif|.ico|.ico|.jpg|.jpg|.png|.png|.tif|.tif|.wmf|.wmf";
                    SetSaveFileDialogCommonOptions(saveFileDialog);

                    Thread bringToFrontAssistant = new Thread(BringToFront);
                    bringToFrontAssistant.Start(saveFileDialog.Title);

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        Settings.Current.FileManagerSaveToDefaultFolder = Path.GetDirectoryName(saveFileDialog.FileName);
                        targetFilePath = saveFileDialog.FileName;
                        string      targetExtension   = Path.GetExtension(targetFilePath);
                        ImageFormat targetImageFormat = ImageFormat.Png;
                        if (string.Compare(targetExtension, ".bmp", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Bmp;
                        }
                        else
                        if (string.Compare(targetExtension, ".emf", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Emf;
                        }
                        else
                        if (string.Compare(targetExtension, ".exif", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Exif;
                        }
                        else
                        if (string.Compare(targetExtension, ".gif", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Gif;
                        }
                        else
                        if (string.Compare(targetExtension, ".ico", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Icon;
                        }
                        else
                        if (string.Compare(targetExtension, ".jpg", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Jpeg;
                        }
                        else
                        if (string.Compare(targetExtension, ".png", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Png;
                        }
                        else
                        if (string.Compare(targetExtension, ".tif", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Tiff;
                        }
                        else
                        if (string.Compare(targetExtension, ".wmf", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Wmf;
                        }

                        ImageWorkItem imageWorkItem = (ImageWorkItem)command.parametersOnExecute[0];
                        imageWorkItem.image.Save(targetFilePath, targetImageFormat);

                        Logging.AddActionLog(string.Format("FileManager: Image saved to '{0}'.", targetFilePath));
                        MessagesHandler.Display(string.Format("Saved.", command.Name));

                        if (command.Postfix == "[what] and copy its file path")
                        {
                            CraftSynth.BuildingBlocks.IO.Clipboard.SetTextToClipboard(targetFilePath);
                            Logging.AddActionLog(string.Format("ClipboardManager: file path '{0}' copied to clipboard.", targetFilePath));
                            MessagesHandler.Display("Image saved and its file path copied.");
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw new ApplicationException(string.Format("FileManager: Failed to save image to '{0}'.", targetFilePath ?? "not set"), exception);
                }
            }
            else
            if ((command.parametersOnExecute[0] is Entities.StringWorkItem) ||
                (command.parametersOnExecute[0] is Entities.Shortcut) ||
                (command.parametersOnExecute[0] is Entities.Contact) ||
                (command.parametersOnExecute[0] is Entities.CallerHistoryItem) ||
                (command.parametersOnExecute[0] is Entities.MemorizedString))
            {
                string targetFilePath = null;
                try
                {
                    MessagesHandler.Display(command.parametersOnExecute[0].GetValueAsText());

                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.DefaultExt = ".txt";
                    saveFileDialog.Filter     = ".txt|.txt";
                    SetSaveFileDialogCommonOptions(saveFileDialog);

                    Thread bringToFrontAssistant = new Thread(BringToFront);
                    bringToFrontAssistant.Start(saveFileDialog.Title);

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        Settings.Current.FileManagerSaveToDefaultFolder = Path.GetDirectoryName(saveFileDialog.FileName);
                        targetFilePath = saveFileDialog.FileName;

                        File.WriteAllText(targetFilePath, command.parametersOnExecute[0].GetValueAsText());

                        Logging.AddActionLog(string.Format("FileManager: Text saved from work item to '{0}'.", targetFilePath));
                        MessagesHandler.Display(string.Format("Saved.", command.Name));

                        if (command.Postfix == "[what] and copy its file path")
                        {
                            CraftSynth.BuildingBlocks.IO.Clipboard.SetTextToClipboard(targetFilePath);
                            Logging.AddActionLog(string.Format("ClipboardManager: file path '{0}' copied to clipboard.", targetFilePath));
                            MessagesHandler.Display("Text saved and its file path copied.");
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw new ApplicationException(string.Format("FileManager: Failed to save text from work item to '{0}'.", targetFilePath ?? "not set"), exception);
                }
            }
            else
            {
                Logging.AddErrorLog(string.Format("FileManager: Tried to save unsupported work item type."));
                MessagesHandler.Display("Can not save work item of this type.");
            }
        }
コード例 #27
0
 private static void DialInternet(String postfix, IEnsoService service)
 {
     try
     {
         if (!"".Equals(postfix))
             RAS.Dial(postfix);
     }
     catch (Exception)
     {
         service.DisplayMessage(new EnsoMessage(CONNECT_ERROR));
     }
 }