Пример #1
0
        void f_history_items_selectIndexChange(object sender, EventArgs e)
        {
            TreeNode node = m_history_items_treeView.SelectedNode;

            if (node != null && node.Tag != null)
            {
                oLink  link = node.Tag as oLink;
                string url  = string.Empty;
                if (link.Title == "Youtube" || link.Title == "Google")
                {
                    string key = Prompt.ShowDialog("Input to search?", link.Title).Trim();
                    if (key.Length > 0)
                    {
                        url = string.Format(link.Link, key);
                    }
                }
                else
                {
                    url = link.Link;
                }
                if (url.Length > 0)
                {
                    m_url_textBox.Text      = url;
                    m_tab_Browser.Text      = link.TitleDomain();
                    m_brow_web.DocumentText = "<h1>LOADING: " + url + "</h1>";

                    this.f_sendRequestToJob(JOB_NAME.SYS_LINK, MESSAGE_ACTION.URL_REQUEST_CACHE, url);
                }
            }
        }
Пример #2
0
        public void f_runLoop(object state, bool timedOut)
        {
            if (!_inited)
            {
                _inited = true;
                f_Init();
                return;
            }

            JobInfo ti = (JobInfo)state;

            if (!timedOut)
            {
                // Tracer.WriteLine("J{0} executes on thread {1}: SIGNAL -> STOP ...", Id, Thread.CurrentThread.GetHashCode().ToString());
                ti.f_stopJob();
                return;
            }

            // Tracer.WriteLine("J{0} executes on thread {1}:DO SOMETHING ...", Id, Thread.CurrentThread.GetHashCode().ToString());
            // Do something ...

            if (msg.Count > 0)
            {
                Message m = msg.Dequeue(null);
                if (m != null)
                {
                    switch (m.getAction())
                    {
                    case MESSAGE_ACTION.ITEM_SEARCH:
                        #region
                        if (true)
                        {
                            oLink[] a = new oLink[] { };
                            if (m.Input != null)
                            {
                                string key = m.Input as string;
                                a = list.Where(x => x.Link.Contains(key) || x.Title.Contains(key) || x.Tags.Contains(key), false, int.MaxValue);
                                m.Output.Counter = a.Length;
                            }
                            else
                            {
                                a = list.Take(10).ToArray();
                                m.Output.Counter = list.Count;
                            }

                            m.Type    = MESSAGE_TYPE.RESPONSE;
                            m.JobName = this._groupName;

                            m.Output.Ok         = true;
                            m.Output.PageSize   = 10;
                            m.Output.PageNumber = 1;
                            m.Output.Total      = list.Count;
                            m.Output.SetData(a);

                            this.StoreJob.f_responseMessageFromJob(m);
                        }
                        #endregion
                        break;

                    case MESSAGE_ACTION.URL_REQUEST_CACHE:
                        #region
                        if (m.Input != null)
                        {
                            string url = m.Input as string;
                            if (urlData.ContainsKey(url))
                            {
                                string htm = urlData[url];

                                m.Type    = MESSAGE_TYPE.RESPONSE;
                                m.JobName = this._groupName;

                                m.Output.Ok = true;
                                m.Output.SetData(htm);

                                this.StoreJob.f_responseMessageFromJob(m);
                            }
                            else
                            {
                                UrlService.GetAsync(url, m, UrlService.Func_GetHTML_UTF8_FORMAT_BROWSER, (result) =>
                                {
                                    if (result.Ok)
                                    {
                                        string htm = result.Html;
                                        if (!urlData.ContainsKey(url))
                                        {
                                            urlData.Add(url, htm);
                                        }

                                        m.Type    = MESSAGE_TYPE.RESPONSE;
                                        m.JobName = this._groupName;

                                        m.Output.Ok = true;
                                        m.Output.SetData(htm);

                                        this.StoreJob.f_responseMessageFromJob(m);
                                    }
                                });
                            }
                        }
                        #endregion
                        break;
                    }
                }
            }
        }