Example #1
0
        static void Main(string[] args)
        {
            string word = GetText();

            if (String.IsNullOrWhiteSpace(word))
            {
                return;
            }
            STRExp::Regex reg = new STRExp.Regex("[0-9]");

            if (reg.IsMatch(word))
            {
                return;
            }
            string[] address = new string[2];
            if (word.Length > 30)
            {//所查者太長,則翻譯之
                address[0] = @"https://translate.google.com/?source=gtx#auto/zh-TW/";
                address[1] = @"https://www.deepl.com/translator#en/zh/";
            }
            else
            {
                address    = new string[4];
                address[2] = @"https://translate.google.com/?source=gtx#auto/zh-TW/";
                address[0] = @"https://www.deepl.com/translator#en/zh/";
                address[1] = @"https://zh.forvo.com/search/";
                address[3] = @"https://dictionary.cambridge.org/zht/%E8%A9%9E%E5%85%B8/%E8%8B%B1%E8%AA%9E-%E6%BC%A2%E8%AA%9E-%E7%B9%81%E9%AB%94/";
            }
            //判斷是否有換行 http://bit.ly/2uu2Y6V  http://bit.ly/2twgwue
            if (word.IndexOf(NewLine) > -1)
            {
                word = word.Replace(NewLine, " ").Replace("  ", " ").Replace(@"/", "");
            }
            while (word.IndexOf("  ") > -1)
            {
                word = word.Replace("  ", " ");
            }
            foreach (var item in address)
            {
                //SD::Process.Start(item + word.Trim());
                BrowserChrome.OpenLinkChrome(item + word.Trim());
            }
            //SD::Process.Start(address+ word.Trim());
        }
Example #2
0
        private void ThreadLaunch(Timeline timeline, TimelineHandler handler)
        {
            try
            {
                _log.Trace($"Attempting new thread for: {handler.HandlerType}");

                Thread    t         = null;
                ThreadJob threadJob = new ThreadJob
                {
                    Id      = Guid.NewGuid().ToString(),
                    Handler = handler
                };

                switch (handler.HandlerType)
                {
                case HandlerType.NpcSystem:
                    NpcSystem npc = new NpcSystem(handler);
                    break;

                case HandlerType.Command:
                    t = new Thread(() =>
                    {
                        Cmd o = new Cmd(handler);
                    })
                    {
                        IsBackground = true,
                        Name         = threadJob.Id
                    };
                    t.Start();

                    threadJob.ProcessName = ProcessManager.ProcessNames.Command;

                    break;

                case HandlerType.Word:
                    _log.Trace("Launching thread for word");
                    if (_isWordInstalled)
                    {
                        var pids = ProcessManager.GetPids(ProcessManager.ProcessNames.Word).ToList();
                        if (pids.Count > timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.Word))
                        {
                            return;
                        }

                        t = new Thread(() =>
                        {
                            WordHandler o = new WordHandler(timeline, handler);
                        })
                        {
                            IsBackground = true,
                            Name         = threadJob.Id
                        };
                        t.Start();

                        threadJob.ProcessName = ProcessManager.ProcessNames.Word;
                    }
                    break;

                case HandlerType.Excel:
                    _log.Trace("Launching thread for excel");
                    if (_isExcelInstalled)
                    {
                        var pids = ProcessManager.GetPids(ProcessManager.ProcessNames.Excel).ToList();
                        if (pids.Count > timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.Excel))
                        {
                            return;
                        }

                        t = new Thread(() =>
                        {
                            ExcelHandler o = new ExcelHandler(timeline, handler);
                        })
                        {
                            IsBackground = true,
                            Name         = threadJob.Id
                        };
                        t.Start();

                        threadJob.ProcessName = ProcessManager.ProcessNames.Excel;
                    }
                    break;

                case HandlerType.Clicks:
                    _log.Trace("Launching thread to handle clicks");
                    t = new Thread(() =>
                    {
                        Clicks o = new Clicks(handler);
                    })
                    {
                        IsBackground = true,
                        Name         = threadJob.Id
                    };
                    t.Start();
                    break;

                case HandlerType.Reboot:
                    _log.Trace("Launching thread to handle reboot");
                    t = new Thread(() =>
                    {
                        Reboot o = new Reboot(handler);
                    })
                    {
                        IsBackground = true,
                        Name         = threadJob.Id
                    };
                    t.Start();
                    break;

                case HandlerType.PowerPoint:
                    _log.Trace("Launching thread for powerpoint");
                    if (_isPowerPointInstalled)
                    {
                        var pids = ProcessManager.GetPids(ProcessManager.ProcessNames.PowerPoint).ToList();
                        if (pids.Count > timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.PowerPoint))
                        {
                            return;
                        }

                        t = new Thread(() =>
                        {
                            PowerPointHandler o = new PowerPointHandler(timeline, handler);
                        })
                        {
                            IsBackground = true,
                            Name         = threadJob.Id
                        };
                        t.Start();

                        threadJob.ProcessName = ProcessManager.ProcessNames.PowerPoint;
                    }
                    break;

                case HandlerType.Outlook:
                    _log.Trace("Launching thread for outlook - note we're not checking if outlook installed, just going for it");
                    //if (this.IsOutlookInstalled)
                    //{
                    t = new Thread(() =>
                    {
                        Outlook o = new Outlook(handler);
                    })
                    {
                        IsBackground = true,
                        Name         = threadJob.Id
                    };
                    t.Start();

                    threadJob.ProcessName = ProcessManager.ProcessNames.Outlook;
                    //}

                    break;

                case HandlerType.BrowserIE:
                    //IE demands COM apartmentstate be STA so diff thread creation required
                    t = new Thread(() =>
                    {
                        BrowserIE o = new BrowserIE(handler);
                    });
                    t.SetApartmentState(ApartmentState.STA);
                    t.IsBackground = true;
                    t.Name         = threadJob.Id;
                    t.Start();

                    break;

                case HandlerType.Notepad:
                    //TODO
                    t = new Thread(() =>
                    {
                        Notepad o = new Notepad(handler);
                    })
                    {
                        IsBackground = true,
                        Name         = threadJob.Id
                    };
                    t.Start();

                    break;

                case HandlerType.BrowserChrome:
                    t = new Thread(() =>
                    {
                        BrowserChrome o = new BrowserChrome(handler);
                    })
                    {
                        IsBackground = true,
                        Name         = threadJob.Id
                    };
                    t.Start();

                    threadJob.ProcessName = ProcessManager.ProcessNames.Chrome;

                    break;

                case HandlerType.BrowserFirefox:
                    t = new Thread(() =>
                    {
                        BrowserFirefox o = new BrowserFirefox(handler);
                    })
                    {
                        IsBackground = true,
                        Name         = threadJob.Id
                    };
                    t.Start();

                    threadJob.ProcessName = ProcessManager.ProcessNames.Firefox;

                    break;

                case HandlerType.Watcher:
                    t = new Thread(() =>
                    {
                        Watcher o = new Watcher(handler);
                    })
                    {
                        IsBackground = true,
                        Name         = threadJob.Id
                    };
                    t.Start();

                    //threadJob.ProcessName = ProcessManager.ProcessNames.Watcher;

                    break;
                }

                if (threadJob.ProcessName != null)
                {
                    _threadJobs.Add(threadJob);
                }

                if (t != null)
                {
                    _threads.Add(t);
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }