示例#1
0
文件: fApp1.cs 项目: git-thinh/appie
        private void f_event_OnReceiveMessage(IFORM form, Message m)
        {
            switch (m.JobName)
            {
            case JOB_NAME.SYS_LINK:
                switch (m.getAction())
                {
                case MESSAGE_ACTION.ITEM_SEARCH:
                    if (m.Output.Ok)
                    {
                        if (m.Output.GetData() is oLink[])
                        {
                            f_history_drawNodes((oLink[])m.Output.GetData());
                        }
                    }
                    break;

                case MESSAGE_ACTION.URL_REQUEST_CACHE:
                    if (m.Output.Ok)
                    {
                        if (m.Output.GetData() is string)
                        {
                            m_brow_web.crossThreadPerformSafely(() =>
                            {
                                m_brow_web.DocumentText = m.Output.GetData().ToString();
                            });
                        }
                    }
                    break;
                }
                break;
            }
        }
示例#2
0
        public void f_form_Remove(IFORM form)
        {
            int key = form.f_getFormID();

            if (storeForms.ContainsKey(key))
            {
                storeForms.Remove(key);
            }
        }
示例#3
0
        public void f_form_Add(IFORM form)
        {
            int key = form.f_getFormID();

            if (!storeForms.ContainsKey(key))
            {
                storeForms.Add(key, form);
            }
        }
示例#4
0
        public IFORM f_form_Get(int id)
        {
            IFORM fom = null;

            if (storeForms.TryGetValue(id, out fom) && fom != null)
            {
                return(fom);
            }
            return(null);
        }
示例#5
0
 public void response_toMainRuntime(msg m)
 {
     if (fom == null)
     {
         fom = app.get_Main();
     }
     if (fom != null)
     {
         fom.api_responseMsg(null, new threadMsgEventArgs(m));
     }
 }
示例#6
0
        public api_base()
        {
            if (timer_api == null)
            {
                timer_api = new System.Threading.Timer(new System.Threading.TimerCallback((obj) =>
                {
                    if (fom == null)
                    {
                        fom = app.get_Main();
                    }
                    lock (_lock_api)
                    {
                        if (cache_api.Count > 0)
                        {
                            msg m = null;
                            if (fom != null &&
                                cache_api.TryDequeue(out m) && m != null)
                            {
                                fom.api_responseMsg(null, new threadMsgEventArgs(m));
                            }
                        }
                    }
                }), fom, 100, 100);
            }

            if (timer_msg == null)
            {
                timer_msg = new System.Threading.Timer(new System.Threading.TimerCallback((obj) =>
                {
                    if (fom == null)
                    {
                        fom = app.get_Main();
                    }
                    lock (_lock_msg)
                    {
                        if (cache_msg.Count > 0)
                        {
                            msg m = null;
                            if (fom != null &&
                                cache_msg.TryDequeue(out m) && m != null)
                            {
                                fom.api_responseMsg(null, new threadMsgEventArgs(m));
                            }
                        }
                    }
                }), fom, 500, 500);
            }
        }
示例#7
0
        private void f_event_OnReceiveMessage(IFORM form, Message m)
        {
            switch (m.JobName)
            {
            case JOB_NAME.SYS_LINK:
                switch (m.getAction())
                {
                case MESSAGE_ACTION.ITEM_SEARCH:
                    break;

                case MESSAGE_ACTION.URL_REQUEST_CACHE:
                    break;
                }
                break;
            }
        }
示例#8
0
        public fBase(IJobAction jobAction)
        {
            StoreMessages = new QueueThreadSafe <Message>();
            JobAction     = jobAction;
            //store.f_form_Add(this);
            //this.FormClosing += (se, ev) => { store.f_form_Remove(this); };

            timer_api = new System.Threading.Timer(new System.Threading.TimerCallback((obj) =>
            {
                IFORM form = (IFORM)obj;
                if (StoreMessages.Count > 0)
                {
                    Message m = StoreMessages.Dequeue(null);
                    if (m != null)
                    {
                        OnReceiveMessage?.Invoke(form, m);
                    }
                }
            }), this, 100, 100);
        }
示例#9
0
        public void f_runLoop(object state, bool timedOut)
        {
            if (!_inited)
            {
                _inited = true;
                f_Init();
                _state = JOB_STATE.INIT;
                if (jobInfo != null)
                {
                    lock (jobInfo)
                        jobInfo = (JobInfo)state;
                }
                else
                {
                    jobInfo = (JobInfo)state;
                }
                return;
            }

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

            if (_state != JOB_STATE.RUNNING)
            {
                _state = JOB_STATE.RUNNING;
            }

            //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)
                {
                    //[1] SEND REQUEST TO JOB FOR EXECUTE
                    if (m.Type == MESSAGE_TYPE.REQUEST)
                    {
                        IJob[] jobs = this.StoreJob.f_job_getByID(m.GetReceiverId());
                        if (jobs.Length > 0)
                        {
                            for (int i = 0; i < jobs.Length; i++)
                            {
                                jobs[i].f_receiveMessage(m);
                            }
                        }
                    }
                    else
                    {
                        //[2] RESPONSE TO SENDER
                        switch (m.getSenderType())
                        {
                        case SENDER_TYPE.IS_FORM:
                            IFORM fom = this.StoreJob.f_form_Get(m.GetSenderId());
                            if (fom != null)
                            {
                                fom.f_receiveMessage(m.GetMessageId());
                            }
                            // write to LOG ...
                            break;

                        case SENDER_TYPE.HIDE_SENDER:
                            // do not send response to sender
                            // write to LOG ...
                            break;
                        }
                    }
                }
            }
        }