/// <summary> /// 建立log /// </summary> /// <param name="pushDataId"></param> /// <param name="deviceid"></param> /// <param name="publishDate"></param> /// <returns></returns> public PushLog CreatePushLog(int pushDataId, string deviceid, DateTime?publishDate = null) { var db = _uow.DbContext; try { var pushLog = new PushLog() { PushDataId = pushDataId, CreateDate = DateTime.UtcNow, DeviceId = deviceid }; if (publishDate.HasValue) { pushLog.PublishDate = publishDate.Value.ToUniversalTime(); } db.PushLog.Add(pushLog); return(pushLog); } catch (Exception ex) { return(null); throw ex; } }
/// <summary> /// 建立log /// </summary> /// <param name="pushDataId"></param> /// <param name="deviceid"></param> /// <param name="publishDate"></param> /// <returns></returns> public bool CreateMutiplePushLog(int pushDataId, List <string> deviceids, DateTime?publishDate = null) { var db = _uow.DbContext; try { foreach (var deviceid in deviceids) { var pushLog = new PushLog() { PushDataId = pushDataId, CreateDate = DateTime.UtcNow, DeviceId = deviceid, Enable = false }; if (publishDate.HasValue) { pushLog.PublishDate = publishDate.Value.ToUniversalTime(); } db.PushLog.Add(pushLog); } return(true); } catch (Exception ex) { return(false); throw ex; } }
/// <summary> /// Task that will convert <c>LogMessage</c> to <c>DiscordLogMessageAdapter</c> and print /// to the <c>LogService</c> the handler is attached to. /// </summary> /// <param name='message'> <c>LogMessage</c> object that will be adapted and /// sent to the <c>LogService</c></param> public Task Log(LogMessage message) { DiscordLogMessageAdapter discordMessage = new DiscordLogMessageAdapter(message); PushLog?.Invoke(discordMessage); return(Task.CompletedTask); }
public PushLog LogPushResult(string deviceConnectionStatus, string httpStatusCode, string messageId, string notificationStatus, string subscriptionStatus, string channelUri) { PushLog log = new PushLog(); _pushLogsRepository.SaveOrUpdate(log); return(log); }
public static void InsertPushLog(PushLog log) { var db = Conf.DbConfig.GetMongoClient().GetDatabase(BasicConfig.MsgLog); var coll = db.GetCollection <BsonDocument>(BasicConfig.PushLogCollection); var bson = new BsonDocument(); bson.Add("MsgNo", log.MsgNo); bson.Add("PushStatus", log.PushStatus); bson.Add("PushTime", log.PushTime); bson.Add("PushType", log.PushType); bson.Add("SubAppNo", log.SubAppNo); coll.InsertOne(bson); }
public async Task <PushLog> LogPushResult(string deviceConnectionStatus, string httpStatusCode, string messageId, string notificationStatus, string subscriptionStatus, string channelUri, Exception exception, CancellationToken cancellationToken = default(CancellationToken)) { PushLog log = new PushLog(); log.MessageId = messageId; log.Subscription = subscriptionStatus; log.Connection = deviceConnectionStatus; log.Status = httpStatusCode; log.Notification = notificationStatus; log.Exception = exception.ToString(); log.ChannelUri = channelUri; log.Timestamp = DateTime.Now.ToUniversalTime(); return(await _pushLogsRepository.SaveOrUpdateAsync(log, cancellationToken)); }
public PushLog LogPushResult(string deviceConnectionStatus, string httpStatusCode, string messageId, string notificationStatus, string subscriptionStatus, string channelUri, Exception exception) { PushLog log = new PushLog(); log.MessageId = messageId; log.Subscription = subscriptionStatus; log.Connection = deviceConnectionStatus; log.Status = httpStatusCode; log.Notification = notificationStatus; log.Exception = exception.ToString(); log.ChannelUri = channelUri; log.Timestamp = DateTime.Now.ToUniversalTime(); _pushLogsRepository.SaveOrUpdate(log); return(log); }
private void Process(PushLog p) { switch (p.Level) { case "trace": { s_logger.Trace(p.LogContent); break; } case "info": { s_logger.Info(p.LogContent); break; } default: { s_logger.Error(p.LogContent); break; } } }
/// <summary> /// 推送 /// </summary> /// <param name="usernumber">推送目标用户编号</param> /// <param name="id">对象ID(文章ID)</param> /// <param name="number">对象Number</param> /// <param name="name">用户名称/文章标题</param> /// <param name="pushtype">推送类型</param> /// <param name="ispush">是否推送</param> public void Push(string usernumber, int id, string number, string name, int pushtype, bool ispush = true) { try { if (string.IsNullOrWhiteSpace(usernumber)) { return; } var user = db.Single <User>(x => x.Number == usernumber); if (user == null) { return; } var result = ""; if (ispush) { if (user.ShowPush == 0) { return; } if (string.IsNullOrWhiteSpace(user.ClientID)) { return; } PushHelper message = new PushHelper(new List <string>() { user.ClientID }); var beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var endTime = DateTime.Now.AddHours(12).ToString("yyyy-MM-dd HH:mm:ss"); var url = System.Web.Configuration.WebConfigurationManager.AppSettings["base_url"]; switch (pushtype) { case Enum_PushType.Article: result = message.PushTemplate(Enum_Push.Single, "小微篇文章推荐啦", name, "", url + "Images/push.png", Enum_PushType.Article + "|" + id, beginTime, endTime); break; case Enum_PushType.Comment: result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友评论啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Comment + "|" + id + "|" + number, beginTime, endTime); break; case Enum_PushType.Money: result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友打赏啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Money.ToString(), beginTime, endTime); break; case Enum_PushType.Red: result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "小微篇送您一个红包,快去看看吧", "", url + "Images/push.png", Enum_PushType.Red.ToString(), beginTime, endTime); break; case Enum_PushType.Fan: result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有新的粉丝啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Fan.ToString(), beginTime, endTime); break; case Enum_PushType.FanArticle: result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友发文啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.FanArticle + "|" + id, beginTime, endTime); break; case Enum_PushType.Update: result = message.PushTemplate(Enum_Push.Single, "小微篇更新啦", "更新内容", "", url + "Images/push.png", "10", beginTime, endTime); break; default: break; } } //推送记录 PushLog log = new PushLog(); log.Number = usernumber; log.ObjectID = id; log.ObjectName = name; log.ObjectNumber = number; log.PushResult = result; log.PushType = pushtype; log.CreateTime = DateTime.Now; logdb.Add <PushLog>(log); } catch (Exception ex) { LogHelper.ErrorLoger.Error("推送失败:" + ex.Message); } }
/// <summary> /// Page through recent Push log entries. /// </summary> /// <param name="user">The user making the request.</param> /// <param name="page">Which page to fetch.</param> /// <param name="per_page">How many entries per page.</param> /// <param name="order_by">Which field to sort by.</param> /// <param name="order_dir">In asc[ending] or desc[ending] order.</param> /// <param name="id">Optional subscription ID.</param> /// <returns>A PushLog object.</returns> public static PushLog getLogs(User user, int page, int per_page, string order_by = ORDERBY_REQUEST_TIME, string order_dir = ORDERDIR_DESC, string id = "") { Dictionary<string, string> parameters = new Dictionary<string, string>(); if (page < 1) { throw new InvalidDataException("The specified page number is invalid"); } if (per_page < 1) { throw new InvalidDataException("The specified per_page value is invalid"); } if (order_by != ORDERBY_REQUEST_TIME) { throw new InvalidDataException("The specified order_by is not supported"); } if (order_dir != ORDERDIR_ASC && order_dir != ORDERDIR_DESC) { throw new InvalidDataException("The specified order_dir is not supported"); } if (id.Length > 0) { parameters.Add("id", id); } parameters.Add("page", page.ToString()); parameters.Add("per_page", per_page.ToString()); parameters.Add("order_by", order_by); parameters.Add("order_dir", order_dir); JSONdn res = user.callApi("push/log", parameters); if (!res.has("count")) { throw new ApiException("No count in the response"); } PushLog retval = new PushLog(res.getIntVal("count")); if (!res.has("log_entries") && retval.TotalCount > 0) { throw new ApiException("No log entries in the response"); } JToken[] children = res.getChildren("log_entries"); for (int i = 0; i < children.Length; i++) { retval.Add(new PushLogEntry(new JSONdn(children[i]))); } return retval; }