コード例 #1
0
ファイル: StepLocker.cs プロジェクト: niuniuzhu/AnimalRunning
 public void Brocast(Packet packet, IUserToken except = null)
 {
     lock (this._lockObj)
     {
         SendHelper.Brocast(this._users, packet, except);
     }
 }
コード例 #2
0
        /// <summary>
        /// Get DApp info
        /// </summary>
        /// <param name="req">request content</param>
        /// <param name="url">interface address</param>
        /// <param name="certPath">https cert path</param>
        /// <returns></returns>
        public static Tuple <bool, string, AppInfoResBody> GetAppInfo(AppSetting config)
        {
            try
            {
                //Get the unsigned signature of DApp
                NodeApiReq req = new NodeApiReq()
                {
                    header = new ReqHeader()
                    {
                        userCode = config.userCode,
                        appCode  = config.appInfo.AppCode
                    }
                };
                NodeApiResBody <AppInfoResBody> res = SendHelper.SendPost <NodeApiResBody <AppInfoResBody> >(config.reqUrl + appInfoUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, AppInfoResBody>(false, res.header.msg, null));
                    }

                    return(new Tuple <bool, string, AppInfoResBody>(true, null, res.body));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, AppInfoResBody>(false, "failed to get DApp info", null));
        }
コード例 #3
0
ファイル: AddressesController.cs プロジェクト: God0916/111
        //显示信息
        public List <Addresses> show()
        {
            string           str  = SendHelper.Send("get", "/api/Addressess/show/");
            List <Addresses> list = JsonConvert.DeserializeObject <List <Addresses> >(str);

            return(list);
        }
コード例 #4
0
ファイル: NotificationSender.cs プロジェクト: Hugoberry/WEB
        public void SendNotificationByNotificationTaskQueueId(int notificationTaskQueueId, NotificationsCredentials credentials)
        {
            var notificationTaskQueue = _executor.GetQuery <GetNotificationTaskQueueByIdQuery>().Process(q => q.Execute(notificationTaskQueueId));

            if (notificationTaskQueue != null)
            {
                if (notificationTaskQueue.ConditionStageId == null || notificationTaskQueue.Document.CurrentWorkflows.Any(d => d.CurrentStage.Code.Equals(notificationTaskQueue.ConditionStage.Code)))
                //if (notificationTaskQueue.ConditionStageId == null || notificationTaskQueue.ConditionStage.Code.Equals(notificationTaskQueue.Document.CurrentWorkflow.CurrentStage.Code))
                {
                    var sendModel = new SendModel
                    {
                        IsSms          = notificationTaskQueue.IsSms,
                        EmailAddresses = notificationTaskQueue.DicCustomer.ContactInfos
                                         .Where(ci => ci.Type.Code == DicContactInfoType.Codes.Email)
                                         .Select(ci => ci.Info)
                                         .ToList(),
                        MobilePhones = notificationTaskQueue.DicCustomer.ContactInfos
                                       .Where(ci => ci.Type.Code == DicContactInfoType.Codes.MobilePhone)
                                       .Select(ci => ci.Info)
                                       .ToList(),
                        Message     = notificationTaskQueue.Message,
                        Subject     = notificationTaskQueue.Subject,
                        Attachment  = notificationTaskQueue.Attachment,
                        Credentials = credentials
                    };

                    var statusCode = new SendHelper().Send(sendModel);

                    // TODO: Если успешно отправлено, ставить Executed, если нет, то обновить дату отправки сообщения.
                    _executor.GetHandler <UpdateNotificationStatusHandler>().Process <int>(h => h.Handle(notificationTaskQueue, statusCode));
                }
            }
        }
コード例 #5
0
        public void Brocast(Packet packet, IUserToken except = null)
        {
            List <string> users = new List <string>();

            CacheFactory.HALL_CACHE.ForeachUser(user =>
            {
                users.Add(user);
            });
            SendHelper.Brocast(users, packet, except);
        }
コード例 #6
0
        public void Dispose(Boolean disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    client = null;
                    SendHelper.Dispose();

                    disposed = true;
                }
            }
        }
コード例 #7
0
ファイル: AddressesController.cs プロジェクト: God0916/111
        //删除
        public string Delete(int id)
        {
            string str = SendHelper.Send("delete", "/api/Addressess/Del/?id=" + id);

            if (str == "1")
            {
                return("成功");
            }
            else
            {
                return("失败");
            }
        }
コード例 #8
0
ファイル: AddressesController.cs プロジェクト: God0916/111
        public string Edit(Addresses a)
        {
            string ss  = JsonConvert.SerializeObject(a);
            string str = SendHelper.Send("put", "/api/Addressess/Upd/", ss);

            if (str == "1")
            {
                return("成功");
            }
            else
            {
                return("失败");
            }
        }
コード例 #9
0
ファイル: NetWorkService.cs プロジェクト: xinyutian86/Fork
        public static void SendProConnRecord(NetProcess pro)
        {
            ProConnRecordBag rs = new ProConnRecordBag();

            rs.Name   = pro.ProcessName;
            rs.Count  = pro.Ports.Count();
            rs.Record = new List <ProConnRecord>();
            foreach (var p in pro.Ports)
            {
                var r = rs.Record.FirstOrDefault(x => x.LI == p.LocalAddress && x.RI == p.RemoteAddress);
                if (r != null)
                {
                    r.Conn.Add(new ProConnPort()
                    {
                        LP = p.Port,
                        RP = p.RemotePort,
                        TP = p.Type.ToString().Replace("Type", ""),
                    });
                }
                else
                {
                    var rcd = new ProConnRecord()
                    {
                        LI   = p.LocalAddress,
                        RI   = p.RemoteAddress,
                        Conn = new List <ProConnPort>(),
                    };
                    rcd.Conn.Add(new ProConnPort()
                    {
                        LP = p.Port,
                        RP = p.RemotePort,
                        TP = p.Type.ToString().Replace("Type", ""),
                    });
                    rs.Record.Add(rcd);
                }
            }
            try
            {
                string rsJson = JsonTool.ToStr(rs);
                string path   = R.Paths.BasePath + @"ProConnRec";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //Write(string.Format(path + @"\{0}-{1}.txt", DateTime.Now.ToString("yyyyMMddHHmmss"), pro.ProcessName), rsJson);
                SendHelper.Send("43", rsJson);
            }
            catch { }
        }
コード例 #10
0
ファイル: AddressesController.cs プロジェクト: God0916/111
        public string Add(Addresses addresses, string Sheng, string Shi, string Qu)
        {
            addresses.Region = Sheng + Shi + Qu;
            string ss  = JsonConvert.SerializeObject(addresses);
            string str = SendHelper.Send("post", "/api/Addressess/add/", ss);

            if (str == "1")
            {
                return("成功");
            }
            else
            {
                return("失败");
            }
        }
コード例 #11
0
ファイル: NetWorkService.cs プロジェクト: xinyutian86/Fork
 public static void SendProConnRecord(ProConnRecordBag rec)
 {
     try
     {
         rec.Name = ProcessAPI.GetProcessNameByPID(int.Parse(rec.Name));
         if (!string.IsNullOrWhiteSpace(rec.Name) && rec.Name.ToLower() != "idle")
         {
             string rsJson = JsonTool.ToStr(rec);
             string path   = R.Paths.BasePath + @"ProConnRec";
             if (!Directory.Exists(path))
             {
                 Directory.CreateDirectory(path);
             }
             //Write(string.Format(path + @"\{0}-{1}.txt", DateTime.Now.ToString("yyyyMMddHHmmss"), rec.Name), rsJson);
             SendHelper.Send("43", rsJson);
         }
     }
     catch { }
 }
コード例 #12
0
        /// <summary>
        /// Run and limit tasks concurrency
        /// </summary>
        /// <param name="listSms"></param>
        /// <param name="maxConcurrency"></param>
        /// <param name="worker"></param>
        private async Task ProcessSMS_CSKH(IList <SmsModel> listSms, int maxConcurrency = 1, int worker = 0)
        {
            using (SemaphoreSlim semaphore = new SemaphoreSlim(maxConcurrency))
            {
                List <Task> tasks = new List <Task>();

                foreach (var sms in listSms)
                {
                    await semaphore.WaitAsync();

                    Task task = Task.Run(() =>
                    {
                        try
                        {
                            if (sms.SENDBY.Equals(AppConst.API))
                            {
                                SendHelper.SendSMS_API_CSKH(this.listRabbitWorker[worker], sms);
                            }
                            else if (sms.SENDBY.Equals(AppConst.SMPP))
                            {
                                SendHelper.SendSMS_SMPP(this.listRabbitWorker[worker], sms);
                            }
                            else
                            {
                                sms.ERR_CODE       = AppConst.SYS_ERR_EXCEPTION;
                                sms.RECEIVE_RESULT = "SMS Anonymous!";
                                this.listRabbitWorker[worker].PublishMessage(AppConfig.QUEUE_ERROR, JsonConvert.SerializeObject(sms));
                                logger.Error(AppConst.A("ProcessSMS", sms.ID, sms.RECEIVE_RESULT));
                            }
                        }
                        finally
                        {
                            semaphore.Release();
                        }
                    });

                    tasks.Add(task);
                }

                await Task.WhenAll(tasks);
            }
        }
コード例 #13
0
ファイル: NetWorkService.cs プロジェクト: xinyutian86/Fork
        public static void WriteRecord(DateTime beginTime, DateTime endTime, List <NetProcess> netProcesses, string ip)
        {
            NetRecordBag rs = new NetRecordBag();

            rs.IP    = ip;
            rs.Begin = beginTime.ToString("yyyy-MM-dd HH:mm:ss");
            rs.End   = endTime.ToString("yyyy-MM-dd HH:mm:ss");
            if (netProcesses.Count() > 0)
            {
                rs.Record = new List <NetRecord>();
                NetRecord rcd;
                foreach (var pro in netProcesses)
                {
                    if (pro.UpLoadCount > 0 || pro.DownLoadCount > 0)
                    {
                        rcd = new NetRecord()
                        {
                            Name = pro.ProcessName,
                            Up   = pro.UpLoadCount,
                            Down = pro.DownLoadCount,
                        };
                        rs.Record.Add(rcd);
                    }
                }
            }
            //判断只有有流量纪录数据时 向服务器发送数据
            if (rs != null && rs.Record != null && rs.Record.Count() > 0)
            {
                try
                {
                    string rsJson = JsonTool.ToStr(rs);
                    string path   = R.Paths.BasePath + @"FlowRec";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    //Write(string.Format(path + @"\{0}.txt", DateTime.Now.ToString("yyyyMMddHHmmss")), rsJson);
                    SendHelper.Send("38", rsJson);
                }
                catch { }
            }
        }
コード例 #14
0
ファイル: RoomBiz.cs プロジェクト: niuniuzhu/Lockstep
        private void BrocastTeam(Room room, int teamIndex, Packet packet,
                                 IUserToken except = null)
        {
            List <Room.Player> team = teamIndex == 0 ? room.teamOne : room.teamTwo;

            if (team.Count == 0)
            {
                return;
            }

            List <string> users = new List <string>();

            lock (CacheFactory.ROOM_CACHE.lockObj2)
            {
                int count = team.Count;
                for (int i = 0; i < count; i++)
                {
                    users.Add(team[i].id);
                }
            }
            SendHelper.Brocast(users, packet, except);
        }
コード例 #15
0
        public void SendMail(SendModel model)
        {
            var msg  = SendHelper.PacketMessage(model);
            var host = SendHelper.GetHost(model.From.Address);

            client.Credentials = new System.Net.NetworkCredential(model.From.Address, model.Password);
            client.Port        = host.Port;
            client.Host        = host.Host;
            client.EnableSsl   = host.Ssl;

            try
            {
                client.Send(msg);
            }
            catch (System.Net.Mail.SmtpException sex)
            {
                throw (sex);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
コード例 #16
0
        /// <summary>
        /// Event listener receive message from queue
        /// </summary>
        /// <param name="message">message receive</param>
        /// <param name="worker">worker receive</param>
        private void ReceivedHandlerCallback(string message, int worker)
        {
            try
            {
                logger.Info(AppConst.A("ReceivedHandlerCallback Deliver", worker, message));

                if (!String.IsNullOrEmpty(message))
                {
                    IList <SmsModel> listSms = JsonConvert.DeserializeObject <IList <SmsModel> >(message);
                    if (listSms[0].SMS_TYPE.Equals(AppConst.CSKH))
                    {
                        ProcessSMS_CSKH(listSms, AppConfig.WORKER_TASK_COUNT, worker).Wait();
                    }
                    else
                    {
                        SendHelper.SendSMS_API_QC(this.listRabbitWorker[worker], listSms);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("ReceivedHandlerCallback", ex));
            }
        }
コード例 #17
0
 public SmtpClient()
 {
     SendHelper.SetHosts();
     client = new System.Net.Mail.SmtpClient();
 }
コード例 #18
0
ファイル: NetWorkService.cs プロジェクト: xinyutian86/Fork
        public static void StartConnectCheck()
        {
            if (!ProConnRun)
            {
                ProConnRun = true;
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        List <string> connInfo = GetProConnInfo2();
                        //LogHelper.writeLog(string.Format("y-connInfo web 访问记录信息条数:{0}", connInfo == null ? "null" : connInfo.Count().ToString()));
                        DateTime maxConnRunTime = DateTime.Now.AddMinutes(ThresholdTime);
                        DateTime recConnRunTime = DateTime.Now.AddSeconds(RecProConnect);
                        List <string> rcd       = new List <string>();
                        while (ProConnLoop)
                        {
                            #region 发送连接数超限数据
                            if (DateTime.Now > maxConnRunTime)
                            {
                                try
                                {
                                    List <ProConnRecordBag> rec = GetNetConn();
                                    foreach (var r in rec)
                                    {
                                        if (r.Count > MaxProConnect)
                                        {
                                            SendProConnRecord(r);
                                            //LogHelper.writeLog("y-监控软件连接数超过上限");
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    R.Log.v(string.Format("y-监控软件连接数运行异常:{0}", ex.Message));
                                }
                                maxConnRunTime = DateTime.Now.AddMinutes(ThresholdTime);
                            }
                            #endregion
                            #region 发送访问记录
                            try
                            {
                                List <ProConnRecordBag> rec = GetNetConn();
                                if (connInfo != null && connInfo.Count() > 0)
                                {
                                    #region 统计本次访问记录
                                    //循环服务器IP列表
                                    foreach (var _info in connInfo)
                                    {
                                        //循环软件列表
                                        foreach (var r in rec)
                                        {
                                            //如果软件连接>0
                                            if (r.Count > 0)
                                            {
                                                //循环记录
                                                foreach (var _r in r.Record)
                                                {
                                                    //过滤 0. 和 127. 开头 ip
                                                    string tempr = "filter" + _r.RI;
                                                    if (!tempr.Contains("filter0.") && !tempr.Contains("filter127."))
                                                    {
                                                        //循环端口
                                                        foreach (var _p in _r.Conn)
                                                        {
                                                            //仅通过Established:连接成功
                                                            if (_p.Status == "Established")
                                                            {
                                                                #region 新访问记录处理方法
                                                                //把IP和端口号转换为组
                                                                List <string> ipnum   = string.Format("{0}.{1}", _r.RI, _p.RP).Trim().Split('.').ToList();
                                                                List <string> infonum = _info.Trim().Replace(":", ".").Split('.').ToList();

                                                                if (ipnum != null && ipnum.Count() == 5 && infonum != null && infonum.Count() == 5)
                                                                {
                                                                    bool match = true;
                                                                    for (int i = 0; i < 5; i++)
                                                                    {
                                                                        if (infonum[i] == "*")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ipnum[i] == infonum[i])
                                                                        {
                                                                            continue;
                                                                        }
                                                                        string[] numarr = infonum[i].Split('-');
                                                                        if (numarr != null && numarr.Count() == 2)
                                                                        {
                                                                            try
                                                                            {
                                                                                if (int.Parse(ipnum[i]) >= int.Parse(numarr[0]) &&
                                                                                    int.Parse(ipnum[i]) <= int.Parse(numarr[1]))
                                                                                {
                                                                                    continue;
                                                                                }
                                                                            }
                                                                            catch { }
                                                                        }
                                                                        match = false;
                                                                    }
                                                                    if (match && !rcd.Contains(string.Format("{0}:{1}", _r.RI, _p.RP).Trim()))
                                                                    {
                                                                        rcd.Add(string.Format("{0}:{1}", _r.RI, _p.RP).Trim());
                                                                    }
                                                                }
                                                                #endregion
                                                            }
                                                            #region 2016年10月17日(原有访问记录处理方法备份)
                                                            //string con = string.Format("{0}:{1}", _r.RI, _p.RP);
                                                            //if (_info == con)
                                                            //{
                                                            //    if (!rcd.Contains(_info))
                                                            //        rcd.Add(_info);
                                                            //}
                                                            #endregion
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                    #region 周期发送记录
                                    if (DateTime.Now > recConnRunTime)
                                    {
                                        //组装结果字符串并发送回服务器
                                        if (rcd != null && rcd.Count() > 0)
                                        {
                                            string result = "";
                                            foreach (var _info in rcd)
                                            {
                                                result += _info + ",";
                                            }
                                            result        = result.Substring(0, result.Length - 1);
                                            bool send_res = SendHelper.Send("46", result + "&");
                                            //LogHelper.writeLog(result + "&");
                                        }
                                        rcd            = new List <string>();
                                        recConnRunTime = DateTime.Now.AddSeconds(RecProConnect);
                                    }
                                    #endregion
                                }
                                else
                                {
                                    if (DateTime.Now > recConnRunTime)
                                    {
                                        connInfo = GetProConnInfo2();
                                        //LogHelper.writeLog(string.Format("y-connInfo web 访问记录信息条数:{0}", connInfo == null ? "null" : connInfo.Count().ToString()));
                                        recConnRunTime = DateTime.Now.AddSeconds(RecProConnect);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                R.Log.e(string.Format("y-监控访问记录异常:{0}", ex.Message));
                            }
                            #endregion
                            Thread.Sleep(1000);
                        }
                        ProConnRun = false;
                    }
                    catch (Exception ex)
                    {
                        R.Log.e("StartConnectCheck发送连接数异常" + ex.Message);
                    }
                });
            }
        }