Esempio n. 1
0
        /// <summary>
        /// Updates Keju dialog
        /// </summary>
        public static void UpdateKejuDialog(KejuQA kejuQA)
        {
            KejuDialog dialog = KejuDialog.GetInstance(kejuQA);

            if (!KejuDialog.IsOpen)
            {
                dialog.ShowDialog();
                return;
            }

            dialog.Invoke(new MethodInvoker(() => {
                dialog.WindowState = FormWindowState.Normal;
                dialog.Activate();
                dialog.UpdateDialog(kejuQA);
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// Process the screenshot
        /// </summary>
        /// <param name="screenshot">Screenshot bitmap</param>
        /// <returns>Always returns an ActionResult instance</returns>
        public void Process(Bitmap screenshot)
        {
            System.Windows.Forms.Clipboard.SetImage(screenshot);
            var ocr    = new Ocr();
            var result = ocr.GeneralBasicParse(screenshot);

            var kejuQA = new KejuQA();

            string topic        = result[0];
            string topicPattern = @"^(.{0,2}(\d*)分)?(.*)$";

            foreach (Match match in Regex.Matches(result[0], topicPattern))
            {
                GroupCollection groups = match.Groups;
                kejuQA.Topic = groups[3].Value;
                kejuQA.Score = groups[2].Length > 0 ? Convert.ToInt32(groups[2].Value): 0;
            }

            var options = result.Count > 1 ? result.GetRange(1, result.Count - 1) : new List <string>();

            kejuQA.Options = options;
            App.UpdateKejuDialog(kejuQA);

            string question = JsonConvert.SerializeObject(kejuQA);
            string res      = "";

            try
            {
                // Console.WriteLine("question: "+ question);
                res = App.GetHttpResponse("/api/nshkj/qa/" + System.Web.HttpUtility.UrlEncode(question, System.Text.Encoding.UTF8)); // TODO 你自己的服务
                // Console.WriteLine("res: " + res);
            }
            catch (Exception e)
            {
                return;
            }
            JObject jObject = JObject.Parse(res);
            JArray  jlist   = JArray.Parse(jObject["optionalAnswers"].ToString());
            string  answer  = "";

            for (int i = 0; i < jlist.Count; ++i)
            {
                var    row     = JObject.Parse(jlist[i].ToString());
                string content = row["content"].ToString();
                int    score   = Convert.ToInt32(row["score"].ToString());
                string desc    = row["description"].ToString();

                answer += "【" + content + "】 ";
                if (score > 0)
                {
                    answer += "正确率:" + score + "% ";
                }
                if (!String.IsNullOrEmpty(desc))
                {
                    answer += "相关:" + desc;
                }
                answer += "\r\n";
            }

            kejuQA.Answer = answer;
            App.UpdateKejuDialog(kejuQA);
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            Mutex mutex = new Mutex(false, Application.ProductName + Application.ProductVersion.ToString());

            try {
                if (!mutex.WaitOne(0, false))
                {
                    // another instance of the application may be running
                    return;
                }

                if (args.Contains("/verbose"))
                {
                    ConsoleManager.Show();
                }

                Logger = new Logger();
                Logger.WriteLine(LogLevel.Informational, "{0} version {1}", Application.ProductName, Application.ProductVersion);

                Directory.CreateDirectory(AppDirectory);
                FileStream stream = new FileStream(Path.Combine(AppDirectory, Application.ProductName + ".log"), args.Contains("/appendLog") ? FileMode.Append : FileMode.OpenOrCreate);
                Logger.Streams.Add(stream);

#if !DEBUG
                AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e) {
                    Logger.WriteLine(LogLevel.Error, "unhandled exception: {0}", e.ExceptionObject);

                    if (e.IsTerminating)
                    {
                        Logger.WriteLine(LogLevel.Warning, "CLR terminating");
                        Environment.Exit(1);
                    }
                };
#endif

                // Disable Windows XP-like text rendering
                Application.SetCompatibleTextRenderingDefault(false);

                // Initialize context menu
                mContextMenu = new ContextMenu(new MenuItem[] {
                    new MenuItem("科举截图", OnScreenshotClicked)
                    {
                        DefaultItem = true
                    },
                    new MenuItem("-"),
                    new MenuItem("设置", OnPreferencesClicked),
                    new MenuItem("关于", OnAboutClicked),
                    new MenuItem("-"),
                    new MenuItem("退出", OnQuitClicked)
                });

                // Initialize notify icon
                mNotifyIcon = new NotifyIcon()
                {
                    Icon = IconExtensions.ExtractFromAssembly("AppIcon", new Size(16, 16)),
                    Text = APP_NAME,

                    ContextMenu = mContextMenu
                };
                mNotifyIcon.MouseClick += delegate(object sender, MouseEventArgs mouseEventArgs) {
                    if (mouseEventArgs.Button == MouseButtons.Left)
                    {
                        OnScreenshotClicked(sender, mouseEventArgs);
                    }
                    else if (mouseEventArgs.Button == MouseButtons.Middle)
                    {
                        OnQuitClicked(sender, mouseEventArgs);
                    }
                };

                SetIconFrame(0, 16, GetNotifyIconVariant());
                mNotifyIcon.Visible = true;

                Preferences = Preferences.Load();
                RegisterHotKeys();

                InitializeAssetCache();
                CheckSettings();

                // start application event loop
                // 先出提示弹窗
                KejuQA kejuQA = new KejuQA();
                kejuQA.Topic = "Alt+Q截图题目即可,“拼诗句”需要截题目+9宫格候选字";
                List <string> tips = new List <string>();
                tips.Add("不要截取太多无用的东西,以免影响检索成功率");
                tips.Add(indexTip);
                kejuQA.Options = tips;
                Application.Run(KejuDialog.GetInstance(kejuQA));
            } finally {
                if (mutex != null)
                {
                    mutex.Close();
                    mutex = null;
                }
            }

            // UpdateKejuDialog(kejuQA);
        }