private void UpdatePersonSummary(List <TemplateMessage> summaryTemplates, NotificationToCommunity NotificationTo, int PersonID)
        {
            try
            {
                session.BeginTransaction();

                System.Guid UniqueSummaryID = System.Guid.NewGuid();

                DateTime Day = new DateTime(NotificationTo.SentDate.Year, NotificationTo.SentDate.Month, NotificationTo.SentDate.Day);


                List <NotificationSummary> UserSummaries = (from NotificationSummary s in dc.PersonSummaries
                                                            where s.PersonID == PersonID && s.ModuleID == NotificationTo.ModuleID &&
                                                            s.ActionID == NotificationTo.ActionID && s.Day == Day &&
                                                            s.CommunityID == NotificationTo.CommunityID
                                                            select s).ToList <NotificationSummary>();

                System.Guid DBUniqueID = System.Guid.NewGuid();
                if (UserSummaries.Count > 0)
                {
                    DBUniqueID = UserSummaries[0].UniqueNotifyID;
                }
                foreach (TemplateMessage template in summaryTemplates)
                {
                    try
                    {
                        NotificationSummary summary = (from NotificationSummary n in UserSummaries
                                                       where n.LanguageID == template.LanguageID
                                                       select n).FirstOrDefault <NotificationSummary>();
                        if (summary == null || summary.UniqueNotifyID == System.Guid.Empty)
                        {
                            summary = GetMessageSummary(NotificationTo, UniqueSummaryID, PersonID);
                            summary.UniqueNotifyID = DBUniqueID;
                            summary.Template       = template;
                            summary.LanguageID     = template.LanguageID;
                        }
                        if (summary.isDeleted)
                        {
                            summary.isDeleted     = false;
                            summary.TotalMessages = 0;
                        }
                        summary.TotalMessages++;
                        string messageToTranslate = string.Format(template.Message, summary.TotalMessages);

                        summary.Message = messageToTranslate;
                        session.SaveOrUpdate(summary);
                    }
                    catch (Exception ex)
                    {
                    }
                }

                session.CommitTransaction();
            }
            catch (Exception ex)
            {
                session.RollbackTransaction();
            }
        }
Beispiel #2
0
 public UserNotification(NotificationSummary summary, string title, string message, string totals, string conclusion)
 {
     Summary    = summary;
     Title      = title;
     Message    = message;
     Totals     = totals;
     Conclusion = conclusion;
 }
        private NotificationSummary GetMessageSummary(NotificationToCommunity NotificationTo, System.Guid UniqueSummaryID, int PersonID)
        {
            NotificationSummary Summary = new NotificationSummary();

            Summary.ActionID       = NotificationTo.ActionID;
            Summary.CommunityID    = NotificationTo.CommunityID;
            Summary.ModuleCode     = NotificationTo.ModuleCode;
            Summary.ModuleID       = NotificationTo.ModuleID;
            Summary.SentDate       = NotificationTo.SentDate;
            Summary.isDeleted      = false;
            Summary.Message        = "";
            Summary.SavedDate      = DateTime.Now;
            Summary.Day            = new DateTime(NotificationTo.SentDate.Year, NotificationTo.SentDate.Month, NotificationTo.SentDate.Day);
            Summary.isDeleted      = false;
            Summary.UniqueNotifyID = UniqueSummaryID;
            Summary.Day            = new DateTime(NotificationTo.SentDate.Year, NotificationTo.SentDate.Month, NotificationTo.SentDate.Day);
            Summary.PersonID       = PersonID;
            return(Summary);
        }
Beispiel #4
0
        private Exception StoreNotification(NotificationADO notify)
        {
            string saveDir = null;

            try
            {
                lock (_lockTryCreateDir)
                {
                    if (!TryCreateDir(notify, out saveDir))
                    {
                        throw new ApplicationException($"TryCreateDir({notify.JMessage} failed");
                    }
                }
                notify.FileName = Path.Combine(saveDir, notify.RandomString + ".notification.json");

                File.WriteAllText(notify.FileName, notify.JMessage);
                Log.LogInformation($"Notify Stored:{notify.FileName} stored :");
                Log.LogInformation($"{notify.JMessage}");

                var notificationSummary = new NotificationSummary(notify);
                var fileName            = notify.FileName.Replace(".json", ".summary.json");
                File.WriteAllText(fileName, notificationSummary.ToString());
            }
            catch (Exception ex)
            {
                Log.LogError($"Error{ex.StackTrace}");
                //Rewind Directory
                if (!string.IsNullOrWhiteSpace(saveDir) && Directory.Exists(saveDir))
                {
                    try
                    {
                        Directory.Delete(saveDir, true);
                    }
                    catch (Exception)
                    {
                        //throw;
                    }
                }
                return(ex);
            }
            return(null);
        }
Beispiel #5
0
        public async Task <ActionResult <NotificationSummary> > Recap(CancellationToken cancellation)
        {
            var serverTime = DateTimeOffset.UtcNow;
            var tenantId   = _accessor.TenantId ?? throw new InvalidOperationException("TenantId was not provided");
            var status     = await _service.Recap(cancellation);

            var result = new NotificationSummary
            {
                Inbox = new InboxStatusToSend
                {
                    Count           = status?.Count ?? 0,
                    UnknownCount    = status?.UnknownCount ?? 0,
                    UpdateInboxList = true,
                    ServerTime      = serverTime,
                    TenantId        = tenantId,
                },
            };

            return(Ok(result));
        }
        public Boolean RemoveNewsSummary(Guid NotificationID)
        {
            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    session.BeginTransaction();
                    NotificationSummary nm = session.Get <NotificationSummary>(NotificationID);

                    if (nm != null && nm.ID != System.Guid.Empty)
                    {
                        session.Delete(nm);
                        session.CommitTransaction();
                        return(true);
                    }
                    return(false);
                }
                catch (Exception ex)
                {
                    session.RollbackTransaction();
                    return(false);
                }
            }
        }