Exemple #1
0
 protected void RaiseNotifyEvent(EventHandler handler, NotifyArgs e)
 {
     if (handler != null)
     {
         handler(this, e);
     }
 }
Exemple #2
0
        //public void Connected(Connected cb)
        //{
        //    _connectCallback = cb;
        //}

        //public void Notify(Notify notify)
        //{
        //    _notify = notify;
        //}

        #endregion

        private void TimerHandler(object sender, ElapsedEventArgs e)
        {
            //The timer trigger its callback every interval. It don't concern the real callback cost.
            //So we need to stop the timer before running the task, and start it after finishing task.
            _timer.Stop();

            //Send the heartbeat message
            var result = UFXBLLManager.Instance.LoginBLL.HeartBeat();

            if (result != Model.ConnectionCode.Success)
            {
                //TODO: to reconnnect
                logger.Error("Fail to check heartbeat");

                if (_notify != null)
                {
                    NotifyArgs arg = new NotifyArgs
                    {
                        Code    = (int)result,
                        Message = "UFX心跳检测失败!",
                    };

                    _notify(arg);
                }
            }

            _timer.Start();
        }
Exemple #3
0
 protected void RaiseNotifyEvent <T>(
     EventHandler <NotifyArgs <T> > handler, NotifyArgs <T> e)
 {
     if (handler != null)
     {
         handler(this, e);
     }
 }
Exemple #4
0
        public void Dispose()
        {
            _notifier.OnNotify -= _notifier_OnNotify;
            _notifier           = null;

            _event.Close();
            _event = null;

            _args = null;
        }
Exemple #5
0
 /// <summary>
 /// Called whenever a property of vpaned1 is modified.
 /// We use this to trap when the user moves the handle
 /// which separates the two text editors. Unfortunately,
 /// this is called many times per second as long as the
 /// user is dragging the handle. I couldn't find a better
 /// event to trap - the MoveHandle event only fires when
 /// the handle is moved via keypresses.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnPropertyNotified(object sender, NotifyArgs args)
 {
     try
     {
         if (args.Property == "position")
         {
             SplitterChanged?.Invoke(this, EventArgs.Empty);
         }
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
 void wt_OnNotifySend(NotifyArgs args)
 {
     ((Action)(delegate()
     {
         if (!string.IsNullOrEmpty(args.MsgContext))
         {
             WXService s = new WXService();
             s.Sid = args.Sid;
             s.Uin = args.WxUin;
             foreach (var u in args.GroupUserName)
             {
                 //s.SendMsg(args.MsgContext, args.MyUserName, u, 1);
                 WriteLog("【发送】" + args.MsgContext);
             }
         }
     })).BeginInvoke(null, null);
 }
Exemple #7
0
        /// <summary>
        /// 进行消息派发;
        /// MVVM架构中,VM占主导地位,因此执行顺序为VM>V
        /// </summary>
        /// <param name="actionKey">消息码</param>
        /// <param name="sender">标准事件模型中的发送者</param>
        /// <param name="notifyArgs">消息模型</param>
        internal virtual void Dispatch(string actionKey, object sender, NotifyArgs notifyArgs)
        {
            Command         cmd      = null;
            Queue <Command> cmdQueue = null;
            IList <EventHandler <NotifyArgs> > handlerList = null;

            lock (locker)
            {
                if (cmdTypeDict.TryGetValue(actionKey, out var type))
                {
                    if (typeCmdQueueDict.TryGetValue(type, out cmdQueue))
                    {
                        if (cmdQueue.Count > 0)
                        {
                            cmd = cmdQueue.Dequeue();
                        }
                        else
                        {
                            cmd = Activator.CreateInstance(type) as Command;
                        }
                    }
                    else
                    {
                        cmdQueue = new Queue <Command>();
                        cmd      = Activator.CreateInstance(type) as Command;
                    }
                }
                eventDict.TryGetValue(actionKey, out handlerList);
            }
            cmd?.ExecuteCommand(sender, notifyArgs);
            if (handlerList != null)
            {
                var length = handlerList.Count;
                for (int i = 0; i < length; i++)
                {
                    handlerList[i].Invoke(sender, notifyArgs);
                }
            }
            cmdQueue.Enqueue(cmd);
        }
Exemple #8
0
        public PluginBase()
        {
            PlayerConnected += delegate(Entity player)
            {
                Script.PlayerConnected.Run(player, player);
            };

            PlayerDisconnected += delegate(Entity player)
            {
                Script.PlayerDisconnected.Run(player, player);
            };

            Tick += delegate()
            {
                Script.Tick.Run(this);
            };

            Notified += delegate(int id, string str, Parameter[] param)
            {
                if (str == "trigger")
                {
                    return;
                }

                var data = new NotifyArgs(id, str, param);

                //Log.Info($"Notify: id: {id}, str: {str}, param: {string.Join<Parameter>(", ", param)}");

                if (id >= 0 && id < 18)
                {
                    Script.PlayerNotified.Run(this, data);
                }

                Script.Notified.Run(this, data);
            };

            Script.Instance = this;

            Script.Init();
        }
Exemple #9
0
        private void OnPanedPositionChanged(object o, NotifyArgs a)
        {
            if (!snap_lock)
            {
                return;
            }

            size_alloc_lock = true;

            int  ec_reqh = expander.Child.SizeRequest().Height;
            bool e       = paned.Position + ec_reqh <
                           paned.MaxPosition + (expander.Expanded ? ec_reqh : 0);

            if (expander.Expanded != e)
            {
                expander.Expanded = e;
            }

            if (e)
            {
                stored_pos =
                    (double)paned.Position / (double)paned.Allocation.Height;
            }
        }
Exemple #10
0
 private void _notifier_OnNotify(object sender, NotifyArgs args)
 {
     _args = args;
     Set();
 }
Exemple #11
0
 protected virtual void OnAnchorChanged(object sender, NotifyArgs args)
 {
     SetShaderParamFloat("z", (float)GetProperty("anchor-x") / (float)(Width));
 }
Exemple #12
0
 protected virtual void OnAngleChanged(object sender, NotifyArgs args)
 {
     SetShaderParamFloat("angle", (float)((double)GetProperty("rotation-angle-y") * Math.PI / 180));
 }
 public abstract void ExecuteCommand(object sender, NotifyArgs notifyArgs);
Exemple #14
0
        private bool InitDataSource()
        {
            var setting = GetSetting();

            _dataSource             = new TDFImp(setting);
            _dataSource.SysMsgDeal  = OnRecvSysMsg;
            _dataSource.DataMsgDeal = OnRecvDataMsg;

            _dataSource.SetEnv(EnvironSetting.TDF_ENVIRON_OUT_LOG, 1);

            //TODO:订阅多支股票和股指期货
            //增加订阅列表中的股票
            //dataSource.SetSubscription("", SubscriptionType.SUBSCRIPTION_ADD);
            //删除订阅列表中的订阅
            //dataSource.SetSubscription("", SubscriptionType.SUBSCRIPTION_DEL);
            //设置为订阅列表中的股票
            //dataSource.SetSubscription("", SubscriptionType.SUBSCRIPTION_SET);

            TDFERRNO openRet = _dataSource.Open();

            if (openRet != TDFERRNO.TDF_ERR_SUCCESS)
            {
                var msg = string.Format("宏汇行情初始化失败:{0}", openRet.ToString());
                logger.Error(msg);

                if (_connectCallback != null)
                {
                    _connectCallback(ServiceType.TDFQuote, (int)openRet, msg);
                }

                if (_notify != null)
                {
                    NotifyArgs args = new NotifyArgs
                    {
                        ServiceType = ServiceInterface.ServiceType.TDFQuote,
                        Code        = (int)openRet,
                        Message     = msg,
                    };

                    _notify(args);
                }

                Close();

                return(false);
            }
            else
            {
                var msg = "宏汇行情初始化成功!";
                logger.Info(msg);

                if (_connectCallback != null)
                {
                    _connectCallback(ServiceType.TDFQuote, (int)openRet, msg);
                }
                //_waitHandle.WaitOne();

                //Close();

                return(true);
            }
        }
Exemple #15
0
 public static void Dispatch(string actionKey, NotifyArgs notifyArgs)
 {
     View.Instance.Dispatch(actionKey, null, notifyArgs);
 }
Exemple #16
0
 public abstract void HandleEvent(object sender, NotifyArgs notifyArgs);
Exemple #17
0
 private void FrequencyTextChanged(object o, NotifyArgs args)
 {
 }
Exemple #18
0
 public void Dispatch(string actionKey, object sender, NotifyArgs notifyArgs)
 {
     ViewModel.Instance.Dispatch(actionKey, sender, notifyArgs);
 }
Exemple #19
0
 protected virtual void OnOpacityChanged(object sender, NotifyArgs args)
 {
     SetShaderParamFloat("alpha", (float)this.Opacity / 255f);
 }
Exemple #20
0
 private void Notify(NotifyArgs args)
 {
     _worker.ReportProgress(0, args);
 }
Exemple #21
0
        /// <summary>
        /// 自动发送消息
        /// </summary>
        public void AutoSendMsg()
        {
            try
            {
                while (true)
                {
                    var    dt       = WeChatAdvertisementDal.QueryTask(this.robotID);
                    string msgText  = string.Empty;
                    var    _taskDic = new Dictionary <int, string>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        var adverId = 0;
                        adverId = int.Parse(dr["AdverId"].ToString());
                        var lastSendTime_str = dr["LastSendTime"].ToString();
                        var last             = DateTime.Now.AddDays(-2);
                        if (!string.IsNullOrEmpty(lastSendTime_str))
                        {
                            last = Convert.ToDateTime(lastSendTime_str);
                        }
                        if (int.Parse(dr["AdverCategory"].ToString()) == (int)EnumContainer.AdverCategoryEnum.公告语)
                        {
                            switch (int.Parse(dr["SendMode"].ToString()))
                            {
                            case (int)EnumContainer.SendModeEnum.每隔多少分钟:
                                if (DateTime.Now.Subtract(last).TotalMinutes > int.Parse(dr["SendModeParas"].ToString()))
                                {
                                    msgText = dr["AdverContent"].ToString();
                                    if (!_taskDic.ContainsKey(adverId))
                                    {
                                        _taskDic.Add(adverId, msgText);
                                    }
                                }
                                break;

                            case (int)EnumContainer.SendModeEnum.每天某一时刻:
                                var tempTime = Convert.ToDateTime(string.Format("{0} {1}", DateTime.Now.ToString("yyyy-MM-dd"), dr["SendModeParas"]));
                                var s_i      = tempTime.Subtract(DateTime.Now).TotalSeconds;
                                if (s_i <= 0 && s_i > -10)
                                {
                                    if (DateTime.Now.Subtract(last).TotalMinutes > 2)
                                    {
                                        msgText = dr["AdverContent"].ToString();
                                        if (!_taskDic.ContainsKey(adverId))
                                        {
                                            _taskDic.Add(adverId, msgText);
                                        }
                                    }
                                }
                                break;

                            case (int)EnumContainer.SendModeEnum.指定具体时间:
                                var temp  = Convert.ToDateTime(dr["SendModeParas"]);
                                var s_i_i = temp.Subtract(DateTime.Now).TotalSeconds;
                                if (s_i_i <= 0 && s_i_i > -10)
                                {
                                    if (DateTime.Now.Subtract(last).TotalMinutes > 2)
                                    {
                                        msgText = dr["AdverContent"].ToString();
                                        if (!_taskDic.ContainsKey(adverId))
                                        {
                                            _taskDic.Add(adverId, msgText);
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    System.Threading.Thread.Sleep(1000);
                    foreach (var k in _taskDic)
                    {
                        //通知发送
                        WeChatAdvertisementDal.UpdateLastSendTime(k.Key.ToString());
                        if (OnNotifySend != null)
                        {
                            if (!string.IsNullOrEmpty(k.Value))
                            {
                                WxContact contact    = new WxContact(this.Uin);
                                var       gUserNames = contact.GetGroupUserNames();
                                var       args       = new NotifyArgs()
                                {
                                    Sid           = this.Sid,
                                    WxUin         = this.Uin,
                                    MsgContext    = k.Value,
                                    MyUserName    = this.user.UserName,
                                    GroupUserName = gUserNames
                                };
                                OnNotifySend(args);
                                System.Threading.Thread.Sleep(1500);
                            }
                        }
                    }
                    _taskDic.Clear();
                }
            }
            catch (Exception ex)
            {
                //写日志
                Tools.WriteLog(ex.ToString());
            }
        }