Esempio n. 1
0
        private void dataGridView_logShow_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            DataGridViewColumn column = dataGridView_logShow.Columns[e.ColumnIndex];

            if (column.Name != "Column_NotifyState")
            {
                return;
            }
            string msg = "";

            NotifyContent info = (NotifyContent)notifyContentBS[e.RowIndex];

            if (info.NotifyState == NotifyState.Failed)
            {
                msg = _emailStatusFailed;
            }
            else if (info.NotifyState == NotifyState.Succeed)
            {
                msg = _emailStatusSucceed;
            }
            else
            {
                msg = _emailStatusSended;
            }

            e.Value = msg;
        }
 /// <summary>
 /// 执行通知
 /// </summary>
 /// <param name="context">上下文</param>
 /// <returns></returns>
 public async Task NotifyAsync(NotifyContent context)
 {
     foreach (var item in clients)
     {
         await item.NotifyAsync(context);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 监控对象异常触发时
        /// </summary>
        /// <param name="item">监控对象</param>
        /// <param name="ex">异常消息</param>
        protected virtual async void OnMonitorItemException(IMonitorItem item, Exception ex)
        {
            this.Context
            .LoggerFactory
            .CreateLogger(item.Alias)
            .LogError(0, ex, "监控对象遇到问题");

            var context = new NotifyContent
            {
                Title   = $"[{item.Alias}] 监控提醒",
                Message = ex.ToString()
            };

            try
            {
                await this.Context.NotifyClientFactory.NotifyAsync(context);
            }
            catch (Exception exception)
            {
                this.Context
                .LoggerFactory
                .CreateLogger("LoggerFactory")
                .LogError(0, exception, "通知工厂遇到问题");
            }
        }
Esempio n. 4
0
 public async Task SendData(NotifyContent notifyContent, string connectionId)
 {
     try
     {
         await Clients.Client(connectionId).SendAsync("SendSignal", notifyContent);
     }
     catch (Exception)
     {
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Http 异常通知
        /// </summary>
        /// <param name="context">通知上下文</param>
        /// <returns></returns>
        public async Task NotifyAsync(NotifyContent context)
        {
            var httpContent = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Title", context.Title),
                new KeyValuePair <string, string>("Message", context.Message)
            };

            await HttpApiFactory.Create <IHttpNotifyApi>()
            .SendNotifyAsync(this.opt.Uri, this.opt.Header, httpContent);
        }
Esempio n. 6
0
        private void openMenu_Click(object Sender, EventArgs e)
        {
            //this.Show();
            if (_notifications != null)
            {
                // Menghapus tumpkan
                NotifyContent.Clear();

                foreach (var notification in _notifications)
                {
                    NotifyContent.Add(notification);
                }
            }
            Notify();
        }
        public bool SendErrorNotify(NotifyContent notifyContent, string logFileName)
        {
            if (_bSending)
            {
                NotifySendInfo newSend = new NotifySendInfo();
                newSend.NtfContent = notifyContent;
                newSend.NotifyFile = logFileName;

                _notifyContextList.Add(newSend);
                return true;
            }
            else
            {
                return SendOneNotify(notifyContent, logFileName);
            }
        }
Esempio n. 8
0
        public async Task SaveNotifiAsync(int QuyTrinhId, string MaLenh, string TenNguoiGui, string NoiDung, int NguoiNhanId, int TrangThaixl, string router)
        {
            Sys_QT_ThongBao sys_QT_ThongBao = new Sys_QT_ThongBao()
            {
                QuyTrinhId    = QuyTrinhId,
                MaLenh        = MaLenh,
                TenNguoiGui   = TenNguoiGui,
                NoiDung       = NoiDung,
                NgayGui       = DateTime.Now,
                NgayDoc       = null,
                DaDoc         = false,
                RouterLink    = router,
                NguoiNhanId   = NguoiNhanId,
                TrangThaiXuLy = TrangThaixl,
                TrangThai     = getTrangThaiXuLy(TrangThaixl, QuyTrinhId),
                IsNotifi      = true
            };
            NotifyContent notifyContent = new NotifyContent()
            {
                TenNguoiGui = sys_QT_ThongBao.TenNguoiGui,
                TrangThai   = sys_QT_ThongBao.TrangThai,
                Ngay        = DateTime.Now,
                NoiDung     = sys_QT_ThongBao.NoiDung
            };
            var connect = await _context.Sys_Dm_Connection.FirstOrDefaultAsync(x => x.UserId == NguoiNhanId);

            if (connect != null)
            {
                int[] typeflow = { 2, 3, 5, 6, 16, 15 };
                if (QuyTrinhId == 2 && typeflow.Contains(TrangThaixl))
                {
                    int[] pushtypef = { TrangThaixl };
                    HubService.Instance.PushTypeFlow(pushtypef, connect.ConnectionId);
                }
                HubService.Instance.CallHub(notifyContent, connect.ConnectionId);
            }
            else
            {
                sys_QT_ThongBao.IsNotifi = false;
            }
            _context.Sys_QT_ThongBao.Add(sys_QT_ThongBao);
            await _context.SaveChangesAsync();
        }
        private NotifyContent GetEmailNotifyContent(string title,string msg, string displayName,DateTime time)
        {
            NotifyContent content = new NotifyContent();
            Guid guid = Guid.NewGuid();

            content.MsgContent = msg;
            content.MsgDate = time.ToString();
            content.MsgID = guid.ToString();

            content.MsgTitle = title;
            content.NotifyState = NotifyState.Sended;
            string receiver = "";
            for (int i = 0; i < _emailConfig.ReceiveInfoList.Count; i++)
            {
                receiver += _emailConfig.ReceiveInfoList[i].Name + ":"
                    + _emailConfig.ReceiveInfoList[i].EmailAddr + "\r\n";
            }
            content.Receiver = receiver;
            content.SendEMailTime = displayName;
            return content;
        }
        private bool SendOneNotify(NotifyContent notifyContent, string logFileName)
        {
            lock (_sendObj)
            {
                //发送邮件
                SmtpException smtpEx = new SmtpException();

                MailUserToken userToken = new MailUserToken(notifyContent.MsgID, logFileName, notifyContent);
                List<string> receiver = new List<string>();
                for (int i = 0; i < _emailConfig.ReceiveInfoList.Count; i++)
                {
                    receiver.Add(_emailConfig.ReceiveInfoList[i].EmailAddr);
                }
                if (receiver.Count <= 0)
                {
                    return false;
                }

                for (int i = 0; i < notifyContent.AttachmentFileNameList.Count; i++)
                {
                    _mailSender.Attachments(notifyContent.AttachmentFileNameList[i]);
                }
                bool isSendSucceed = true;
                if (!_mailSender.SetMailMessageContext(notifyContent.MsgContent, notifyContent.MsgTitle, false))
                {
                    isSendSucceed = false;
                }
                else
                {
                    if (!_mailSender.SendAsync(receiver, System.Net.Mail.MailPriority.Normal,
                                               ref smtpEx, userToken))
                    {
                        isSendSucceed = false;
                    }
                    else
                    {
                        _bSending = true;
                    }
                }
                if (_emailConfig.EnableJournal)
                {
                    #region 写入日志

                    #endregion
                }
                return isSendSucceed;
            }
        }
Esempio n. 11
0
        //寫入通知
        public async Task <string> CreateNotification(int groupType, int orderId, int senderId, string notifyContent)
        {
            int        contentID                 = 0;
            DateTime   nowTime                   = DateTime.Now;
            List <int> targetMemberId            = new List <int>();
            List <Tuple <int, bool> > returnList = new List <Tuple <int, bool> >();

            //排除空訊息
            if (notifyContent != "")
            {
                NotifyContent n = new NotifyContent();
                n.ContentText = notifyContent;
                _context.Add(n);
                await _context.SaveChangesAsync();

                contentID = n.ContentId;
            }
            if (contentID != 0)
            {
                switch (groupType)
                {
                case 1:
                    var orderhost = await _context.Orders.Where(n => n.OrderId == orderId).Select(n => n.HostMemberId).ToListAsync();

                    var orderjoin = await _context.OrderBuyRecords.Where(n => n.OrderId == orderId).Select(n => n.MemberId).ToListAsync();

                    targetMemberId = orderhost.Union(orderjoin).ToList();
                    break;

                case 2:
                    var garbhost = await _context.GarbageServiceOffers.Where(n => n.GarbageServiceId == orderId).Select(n => n.HostMemberId).ToListAsync();

                    var garbjoin = await _context.GarbageServiceUseRecords.Where(n => n.GarbageServiceOfferId == orderId).Select(n => n.MemberId).ToListAsync();

                    targetMemberId = garbhost.Union(garbjoin).ToList();
                    break;

                case 3:
                    break;
                }
                targetMemberId.Remove(senderId);

                var existNotify         = _context.Notifications.Where(n => n.SourceType == groupType && n.SourceId == orderId);
                var existNotifyMemberId = existNotify.Where(n => n.Checked == false).Select(n => n.MemberId).Distinct().ToList();
                var x = targetMemberId.Except(existNotifyMemberId).ToList();
                foreach (int id in x)
                {
                    Notification notification = new Notification
                    {
                        MemberId   = id,
                        ContentId  = contentID,
                        SourceType = (byte)groupType,
                        SourceId   = orderId,
                        SentTime   = nowTime,
                        Checked    = false
                    };
                    _context.Add(notification);
                    returnList.Add(new Tuple <int, bool>(id, true));
                }
                var y = targetMemberId.Intersect(existNotifyMemberId).ToList();
                foreach (int id in y)
                {
                    var item = existNotify.Where(n => n.MemberId == id && n.Checked == false).FirstOrDefault();
                    item.SentTime  = nowTime;
                    item.ContentId = contentID;
                    //_context.Update(item);
                    returnList.Add(new Tuple <int, bool>(id, false));
                }
                await _context.SaveChangesAsync();
            }

            return(JsonConvert.SerializeObject(returnList));
        }
Esempio n. 12
0
 /// <summary>
 /// 异常通知
 /// </summary>
 /// <param name="context">通知上下文</param>
 /// <returns></returns>
 public async Task NotifyAsync(NotifyContent context)
 {
     await this.SendEmailAsync(context.Title, context.Message);
 }