private async void ProcessNewMessage(int gId, int id, Message message) { var chat = _protoService.GetChat(message.ChatId); if (chat == null) { return; } var caption = GetCaption(chat); var content = GetContent(chat, message); var sound = ""; var launch = GetLaunch(chat, message); var tag = $"{id}"; var group = $"{gId}"; var picture = GetPhoto(chat); var date = BindConvert.Current.DateTime(message.Date).ToUniversalTime().ToString("s") + "Z"; var loc_key = chat.Type is ChatTypeSupergroup super && super.IsChannel ? "CHANNEL" : string.Empty; var user = _protoService.GetUser(_protoService.Options.MyId); Update(chat, async() => { await NotificationTask.UpdateToast(caption, content, user?.GetFullName() ?? string.Empty, $"{_sessionService.Id}", sound, launch, tag, group, picture, string.Empty, date, loc_key); }); if (App.Connection is AppServiceConnection connection && _settings.Notifications.InAppFlash) { await connection.SendMessageAsync(new ValueSet { { "FlashWindow", string.Empty } }); } }
public async Task <ActionResult> PostTelemetry([FromRoute, BindRequired] string thingId) { Task.Delay(20000).Wait(); await _context.Event.AsQueryable().Where(@event => @event.Variable.EndsWith(":" + thingId) | @event.Variable.StartsWith(thingId + ":")) .ForEachAsync(async @event => { if (@event.EventType.Equals(EventType.Threshold)) { await NotificationTask.Process(@event); } @event.OnHold = false; _context.Entry(@event).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } }); return(NoContent()); }
public async void Handle(UpdateUnreadChatCount update) { if (update.ChatList is ChatListArchive) { return; } if (_settings.Notifications.CountUnreadMessages || !_sessionService.IsActive) { return; } if (_settings.Notifications.IncludeMutedChats) { NotificationTask.UpdatePrimaryBadge(update.UnreadCount); } else { NotificationTask.UpdatePrimaryBadge(update.UnreadUnmutedCount); } if (App.Connection is AppServiceConnection connection) { await connection.SendMessageAsync(new ValueSet { { "UnreadCount", _settings.Notifications.IncludeMutedChats ? update.UnreadCount : 0 }, { "UnreadUnmutedCount", update.UnreadUnmutedCount } }); } }
public ProgressNotification( string message, NotificationTask taskType, NotificationState notificationType) : base(message, taskType, notificationType) { }
protected Task CreateTask(NotificationTask task, Notification notification) { Task taskEntity = new Task(); taskEntity.Notification = notification; taskEntity.ConcatenatedId = CreateTaskConcatenatedId(notification.NotificationSapId, task.TaskKey); taskEntity.Description = task.Description; taskEntity.Type = task.Type; taskEntity.ActualEffort = 5; //taskEntity.ActualEffort = Int32.Parse(task.ActualEffort); taskEntity.AssignationDate = task.AssignationDate; taskEntity.EstEffort = 5; taskEntity.EstEnd = task.EstEnd; if (task.IsComplete == "No") { taskEntity.IsComplete = false; } else { taskEntity.IsComplete = true; } taskEntity.Status = SetTaskSatus(task); taskEntity.TaskSAPId = task.SAPid; return(taskEntity); }
public MessageNotification( string message, NotificationTask taskType, NotificationState notificationType) : this(message, null, taskType, notificationType, 0) { }
protected String SetTaskSatus(NotificationTask task) { String status; if (task.Status == "Complete") { status = "Completed"; } else { if (task.EstEnd < System.DateTime.Today && task.EstEnd != nullDate) { status = "Late"; } if (task.EstEnd == nullDate) { status = "Not Started"; } else { status = "In Progress"; } } return(status); }
public MessageNotification( NotificationTask taskType, NotificationState notificationType, int displayTime) : this(null, null, taskType, notificationType, displayTime) { }
public void GetTaskNameTest() { var task = new NotificationTask(db); string expected = TaskName.NotificationTask, actual = task.GetTaskName(); Assert.IsTrue(actual == expected, $"Error: GetTaskName() returned {actual} when {expected} was expected. Check that the derived task class overrides the GetTaskName() method"); }
public ProgressNotification( string message, NotificationTask taskType, NotificationState notificationType, int percentage) : base(message, taskType, notificationType) { this._percentage = percentage; }
public Notification( NotificationTask taskType, NotificationState notificationType, int displayTime) : base(null) { this._task = taskType; this._type = notificationType; this._appearances = 0U; this._displayTime = displayTime <= 0 ? 5000 : displayTime; }
public void Handle(UpdateUnreadMessageCount update) { if (_settings.Notifications.IncludeMutedChats) { NotificationTask.UpdatePrimaryBadge(update.UnreadCount); } else { NotificationTask.UpdatePrimaryBadge(update.UnreadUnmutedCount); } }
private void UpdateBadge(int count) { //var tick = Environment.TickCount; //if (tick < _tickCount + 500) //{ // return; //} //_tickCount = tick; NotificationTask.UpdatePrimaryBadge(count); }
public MessageNotification( string message, string subMessage, NotificationTask taskType, NotificationState notificationType, int displayTime) : base(taskType, notificationType, displayTime) { this._message = message; this._subMessage = subMessage; }
private async Task RunSUT(NotificationTask sut, ConnectorConfigModel model, Func <Task, Task> code) { var source = new CancellationTokenSource(); var task = Task.Run(() => sut.RunAsync(model, string.Empty, source.Token)); // Give it a second to get started await Task.Delay(TimeSpan.FromSeconds(1)); await code(task); source.Cancel(); await task.AwaitCompleteOrCancel(); }
public NotificationService(INavigationService navigationService, IVidMeClient vidMeClient, ITileService tileService) { _vidMeClient = vidMeClient; _tileService = tileService; _navigationService = navigationService; _notificationTask = new NotificationTask(); _timer = new DispatcherTimer { Interval = TimeSpan.FromMinutes(Interval) }; _timer.Tick += TimerOnTick; }
public void Handle(UpdateNewMessage update) { if (update.DisableNotification || !_settings.Notifications.InAppPreview) { return; } var difference = DateTime.Now.ToTimestamp() - update.Message.Date; if (difference > 180) { return; } // Adding some delay to be 110% the message hasn't been read already ThreadPoolTimer.CreateTimer(timer => { var chat = _protoService.GetChat(update.Message.ChatId); if (chat == null || chat.LastReadInboxMessageId >= update.Message.Id) { return; } var caption = GetCaption(chat); var content = GetContent(chat, update.Message); var sound = ""; var launch = GetLaunch(chat); var tag = GetTag(update.Message); var group = GetGroup(chat); var picture = GetPhoto(chat); var date = BindConvert.Current.DateTime(update.Message.Date).ToString("o"); var loc_key = chat.Type is ChatTypeSupergroup super && super.IsChannel ? "CHANNEL" : string.Empty; Execute.BeginOnUIThread(() => { var service = WindowWrapper.Current().NavigationServices.GetByFrameId("Main"); if (service == null) { return; } if (WindowContext.GetForCurrentView().ActivationState != Windows.UI.Core.CoreWindowActivationState.Deactivated && service.CurrentPageType == typeof(ChatPage) && (long)service.CurrentPageParam == chat.Id) { return; } NotificationTask.UpdateToast(caption, content, sound, launch, tag, group, picture, date, loc_key); NotificationTask.UpdatePrimaryTile(caption, content, picture); }); }, TimeSpan.FromSeconds(3)); }
public void Notify(TLMessageCommonBase commonMessage) { var caption = commonMessage.Parent.DisplayName; var content = GetFromLabel(commonMessage) + GetBriefLabel(commonMessage, true); var sound = ""; var launch = GetLaunch(commonMessage); var tag = GetTag(commonMessage); var group = GetGroup(commonMessage); var picture = GetPicture(commonMessage, group); var date = BindConvert.Current.DateTime(commonMessage.Date).ToString("o"); var loc_key = commonMessage.Parent is TLChannel channel && channel.IsBroadcast ? "CHANNEL" : string.Empty; NotificationTask.UpdateToast(caption, content, sound, launch, tag, group, picture, date, loc_key); }
public void CheckCompanyForPassedUnpackDatesTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser); EMailService.EMailService service = new EMailService.EMailService(db); service.EmptyEMailQueue(); var task = new NotificationTask(db); // Check email queue - should be 0 added var expected = 0; task.CheckCompanyForPassedUnpackDates(testCompany); var actual = service.GetQueueCount(); Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected"); // Call email queue = 0 = actual // Create POs with Data > now var poStatuses = Enum.GetValues(typeof(PurchaseOrderStatus)); var names = Enum.GetNames(typeof(PurchaseOrderStatus)); foreach (var value in Enum.GetValues(typeof(PurchaseOrderStatus))) { var po = GetTestPurchaseOrderHeader(testCompany, testUser); po.RealisticRequiredDate = DateTime.Now.AddDays((int)value); po.POStatus = (int)value; PurchasingService.InsertOrUpdatePurchaseOrderHeader(po, testUser, PurchasingService.LockPurchaseOrderHeader(po)); } task.CheckCompanyForPassedUnpackDates(testCompany); actual = service.GetQueueCount(); Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected"); // Create POs with Data < now foreach (var value in Enum.GetValues(typeof(PurchaseOrderStatus))) { var po = GetTestPurchaseOrderHeader(testCompany, testUser); po.RealisticRequiredDate = DateTime.Now.AddDays((int)value - 100); po.POStatus = (int)value; PurchasingService.InsertOrUpdatePurchaseOrderHeader(po, testUser, PurchasingService.LockPurchaseOrderHeader(po)); } expected = 9; task.CheckCompanyForPassedUnpackDates(testCompany); actual = service.GetQueueCount(); Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected"); }
public void Handle(UpdateNewMessage update) { if (update.DisableNotification) { return; } // Adding some delay to be 110% the message hasn't been read already ThreadPoolTimer.CreateTimer(timer => { var chat = _protoService.GetChat(update.Message.ChatId); if (chat == null || chat.LastReadInboxMessageId >= update.Message.Id) { return; } var caption = _protoService.GetTitle(chat); var content = UpdateFromLabel(chat, update.Message) + GetBriefLabel(update.Message); var sound = ""; var launch = "GetLaunch(commonMessage)"; var tag = update.Message.Id.ToString(); var group = GetGroup(update.Message, chat); var picture = string.Empty; var date = BindConvert.Current.DateTime(update.Message.Date).ToString("o"); var loc_key = "CHANNEL"; //var loc_key = commonMessage.Parent is TLChannel channel && channel.IsBroadcast ? "CHANNEL" : string.Empty; Execute.BeginOnUIThread(() => { var service = WindowWrapper.Current().NavigationServices.GetByFrameId("Main"); if (service == null) { return; } if (WindowContext.GetForCurrentView().ActivationState != Windows.UI.Core.CoreWindowActivationState.Deactivated && service.CurrentPageType == typeof(DialogPage) && (long)service.CurrentPageParam == chat.Id) { return; } NotificationTask.UpdateToast(caption, content, sound, launch, tag, group, picture, date, loc_key); NotificationTask.UpdatePrimaryTile(caption, content, picture); }); }, TimeSpan.FromSeconds(2)); }
public void Handle(UpdateNewMessage update) { if (update.DisableNotification || !_settings.Notifications.InAppPreview) { return; } var difference = DateTime.Now.ToTimestamp() - update.Message.Date; if (difference > 180) { return; } // Adding some delay to be 110% the message hasn't been read already ThreadPoolTimer.CreateTimer(timer => { var chat = _protoService.GetChat(update.Message.ChatId); if (chat == null || chat.LastReadInboxMessageId >= update.Message.Id) { return; } var caption = GetCaption(chat); var content = GetContent(chat, update.Message); var sound = ""; var launch = GetLaunch(chat); var tag = GetTag(update.Message); var group = GetGroup(chat); var picture = GetPhoto(chat); var date = BindConvert.Current.DateTime(update.Message.Date).ToString("o"); var loc_key = chat.Type is ChatTypeSupergroup super && super.IsChannel ? "CHANNEL" : string.Empty; var user = _protoService.GetUser(_protoService.GetMyId()); Update(chat, () => { NotificationTask.UpdateToast(caption, content, user?.GetFullName() ?? string.Empty, user?.Id.ToString() ?? string.Empty, sound, launch, tag, group, picture, date, loc_key); NotificationTask.UpdatePrimaryTile($"{_protoService.SessionId}", caption, content, picture); }); }, TimeSpan.FromSeconds(3)); }
public async Task <IActionResult> PutEvent([FromRoute, Required] long id, [FromBody, BindRequired] EventDTO eventDto) { if (!EventExists(id)) { return(NotFound()); } Event eventEntry = await _context.Event.AsNoTracking().Where(e => e.Id.Equals(id)).FirstAsync(); if (!eventEntry.Username.ToString().Equals(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(StatusCode(403)); } Event @event = new Event { Id = id, Username = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value), Variable = eventDto.Variable, EventType = eventDto.EventType, EventValueType = eventDto.EventValueType, EventValue = eventDto.EventValue, EventFrequency = eventDto.EventFrequency, NotificationType = eventDto.NotificationType, OnHold = false }; NotificationTask.UpdateTaskFromSchedule(@event); _context.Entry(@event).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }
public async Task <ActionResult <Event> > DeleteEvent([FromRoute, Required] long id) { var @event = await _context.Event.FindAsync(id); if (@event == null) { return(NotFound()); } else if ([email protected]().Equals(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(StatusCode(403)); } NotificationTask.RemoveTaskFromSchedule(@event); _context.Event.Remove(@event); await _context.SaveChangesAsync(); return(@event); }
public async Task <ActionResult <Event> > PostEvent([FromBody, BindRequired] EventDTO eventDto) { Event @event = new Event { Username = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value), Variable = eventDto.Variable, EventType = eventDto.EventType, EventValueType = eventDto.EventValueType, EventValue = eventDto.EventValue, EventFrequency = eventDto.EventFrequency, NotificationType = eventDto.NotificationType }; _context.Event.Add(@event); await _context.SaveChangesAsync(); NotificationTask.AddTaskToSchedule(@event); return(CreatedAtAction("GetEvent", new { id = @event.Id }, @event)); }
public void FindUndeliveredPurchaseOrders2Test() { // Tests the TaskProcessor/emails // Get a test user and test company var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser, true); // Get the current email queue count db.EmptyEMailQueue(); int beforeCount = db.FindEMailQueues().Count(); var task = new NotificationTask(db); task.StartTask(); int afterCount = db.FindEMailQueues().Count(); Assert.IsTrue(afterCount == beforeCount, $"Error: The EMail queue contains {afterCount} item(s) when {beforeCount} were expected (1)"); // Create some orders var order1 = GetTestPurchaseOrderHeader(testCompany, testUser, 10); var order2 = GetTestPurchaseOrderHeader(testCompany, testUser, 10); task.CheckCompanyForPassedUnpackDates(testCompany); // The orders are not overdue, so we should not have added any messages to the email queue afterCount = db.FindEMailQueues().Count(); Assert.IsTrue(afterCount == beforeCount, $"Error: The EMail queue contains {afterCount} item(s) when {beforeCount} were expected (2)"); // Now move the RealisticRequiredDate back so that the orders are overdue order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1); string lockGuid = PurchasingService.LockPurchaseOrderHeader(order1); PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid); beforeCount = db.FindEMailQueues().Count(); var error = task.CheckCompanyForPassedUnpackDates(testCompany); Assert.IsTrue(!error.IsError, error.Message); // We should have added a message to the email queue afterCount = db.FindEMailQueues().Count(); int expected = 1 + beforeCount; Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (3)"); // Now move the other order back order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1); lockGuid = PurchasingService.LockPurchaseOrderHeader(order2); PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid); beforeCount = db.FindEMailQueues().Count() - beforeCount; task.CheckCompanyForPassedUnpackDates(testCompany); // We should have added two messages afterCount = db.FindEMailQueues().Count(); expected = 2 + beforeCount; Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (4)"); // Now add another sales person to the user groups of the orders. // Note that each order could be a different brand category/group var testUser2 = GetTestUser(); var brandCategory = ProductService.FindBrandCategoryModel(order1.BrandCategoryId.Value, testCompany, false); MembershipManagementService.AddUserToGroup(brandCategory.CategoryName + " Purchasing", testUser2); brandCategory = ProductService.FindBrandCategoryModel(order2.BrandCategoryId.Value, testCompany, false); MembershipManagementService.AddUserToGroup(brandCategory.CategoryName + " Purchasing", testUser2); beforeCount = db.FindEMailQueues().Count(); task.CheckCompanyForPassedUnpackDates(testCompany); // We should have added another 4 messages afterCount = db.FindEMailQueues().Count(); expected = 2 + beforeCount; Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (5)"); // Put the orders forward order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10)); lockGuid = PurchasingService.LockPurchaseOrderHeader(order1); PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid); order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10)); lockGuid = PurchasingService.LockPurchaseOrderHeader(order2); PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid); beforeCount = db.FindEMailQueues().Count(); task.CheckCompanyForPassedUnpackDates(testCompany); // We should not have added any more messages afterCount = db.FindEMailQueues().Count(); expected = 0 + beforeCount; Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (6)"); task.EndTask(0); }
public Notification(NotificationTask taskType, NotificationState notificationType) : this(taskType, notificationType, 0) { }
private async Task HandleTextAsync(string replyToken, string userMessage, string userId) { var message = userMessage.Split(" "); DateTime pushTime = DateTime.Now; bool doPush = false; ISendMessage replyMessage = null; CommandEum command; _ = message[0].TryParseStringValueToEnum <CommandEum>(out command); switch (command) { case CommandEum.JAfleetGa: replyMessage = new TextMessage(GALogics.GetReportStringMyNormal1(_context)); break; case CommandEum.PlanNotice: string additional = string.Empty; if (message[1].StartsWith("a")) { message[1] = DateTime.Now.AddMinutes(Int32.Parse(message[1].Replace("a", string.Empty))).ToString("yyyyMMddHHmm"); } else if (message[1].Length == 4) { additional = DateTime.Now.ToString("yyyyMMdd"); } else if (message[1].Length == 8) { additional = DateTime.Now.ToString("yyyy"); } else if (message[1].Length == 10) { additional = "20"; } doPush = DateTime.TryParseExact(additional + message[1], "yyyyMMddHHmm", null, System.Globalization.DateTimeStyles.None, out pushTime); if (pushTime <= DateTime.Now) { doPush = false; } string mes; if (doPush) { mes = "予約しました"; } else { mes = "予約に失敗しました"; } replyMessage = new TextMessage(mes); break; case CommandEum.PlanList: var tasks = _tContext.NotificationTasks.AsNoTracking().Where(t => t.NotificationTime >= DateTime.Now && t.NotificationTo == userId).OrderBy(t => t.NotificationTime).ToList(); var planList = new StringBuilder(); bool firstLine = true; foreach (var t in tasks) { if (!firstLine) { planList.AppendLine(); } else { firstLine = false; } planList.Append($"{t.NotificationTime?.ToString("yyyy/MM/dd HH:mm")}:{t.NotificationDetail} {t.Status.GetStringValue()}"); } replyMessage = new TextMessage(planList.ToString()); break; case CommandEum.ExceptionDelete: _context.Log.RemoveRange(_context.Log.Where(l => l.LogType == LogType.EXCEPTION)); int result = _context.SaveChanges(); replyMessage = new TextMessage($"{result}件削除しました"); break; default: if (Regex.IsMatch(message[0], "[0-9]{4}") || Regex.IsMatch(message[0], "[0-9]{3}[a-zA-Z]{1}") || Regex.IsMatch(message[0], "[0-9]{2}[a-zA-Z]{2}")) { replyMessage = new TextMessage($"googlechromes://ja-fleet.noobow.me/e/JA{message[0].ToUpper()}"); } break; } await messagingClient.ReplyMessageAsync(replyToken, new List <ISendMessage> { replyMessage }); if (doPush) { //task登録 var nTask = new NotificationTask { NotificationDetail = message[2], NotificationTime = pushTime, Status = NotificationTaskStatusEnum.INITIAL, NotificationTo = userId }; _tContext.NotificationTasks.Add(nTask); _tContext.SaveChanges(); if ((pushTime - DateTime.Now).TotalMilliseconds < AppConfig.TimerInterval) { //1時間以内なら即座にタスクを実行 //1時間以上ならタイマーに任せる _ = Task.Run(() => { using (var serviceScope = _services.CreateScope()) { var executer = new TaskExecuter(nTask.TaskId); _ = executer.ExecuteAsync(); } }); } } }
public MessageNotification(NotificationTask taskType, NotificationState notificationType) : this(null, null, taskType, notificationType, 0) { }
public AdminController(NotificationTask notificationTask, RightsTask rightsTask) { _notificationTask = notificationTask; _rightsTask = rightsTask; }