Ejemplo n.º 1
0
        public static void Inform(string message, NotificationTypes notifType=NotificationTypes.Notice, bool isModal=false)
        {
            printMsg(notifType.ToString(), message);

            if(isModal)
                MessageBox.Show(message, notifType.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);

            if(notifType == NotificationTypes.FATAL) {
                MessageBox.Show(message + "\nL'application va maintenant s'arrêter de fonctionner.", "Erreur critique", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Process.GetCurrentProcess().Kill();
            }
        }
        /// <summary>
        /// The GetNotificationTemplate method
        /// </summary>
        /// <param name="eventTypeId">The eventTypeId parameter</param>
        /// <param name="notifyType">The notifyType parameter</param>
        /// <returns>The AuthNet.PoC.EventModel.Entities.NotificationTemplate type object</returns>        
        public NotificationTemplate GetNotificationTemplate(int eventTypeId, NotificationTypes notifyType)
        {
            NotificationTemplate notification = new NotificationTemplate();
            string notificationstring = notifyType.ToString();
            string name = string.Empty;
            string sqlquery = "SELECT * from EventType where EventTypeId = " + eventTypeId;
            using (IDataReader reader = ExecuteInlineQueryReader(sqlquery))
            {
                while (reader.Read())
                {
                    name = reader[1].ToString();
                    break;
                }
            }

            sqlquery = "SELECT * from NotificationTemplate where EventType = '" + name + "' AND NotificationType = '" + notificationstring + "'";

            using (IDataReader reader = ExecuteInlineQueryReader(sqlquery))
            {
                while (reader.Read())
                {
                    notification.ID = int.Parse(reader[0].ToString());
                    notification.EventTypeID = eventTypeId;
                    notification.NotificationType = notifyType;
                    notification.GroupName = reader[3].ToString();
                    notification.TemplateName = reader[4].ToString();
                    break;
                }
            }

            return notification;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a client registration for a certain event type.
 /// </summary>
 /// <param name="clientUri"></param>
 /// <param name="eventType"></param>
 /// <param name="userName"></param>
 /// <param name="prox"></param>
 public void RegisterClient(Uri clientUri, NotificationTypes eventType, string userName, IClientNotification prox)
 {           
     var reg = new Registration() { RegistrationUri = clientUri, EventType = eventType.ToString(), UserName = userName, clientProxy=prox  };
     var key = reg.CreateKey();
     if (!Registrations.ContainsKey(key))
         Registrations.Add(key, new List<Registration> { reg });
     else if (Registrations[key].Find(rg => (rg.RegistrationUri.AbsolutePath == reg.RegistrationUri.AbsolutePath)) == null)
            Registrations[key].Add(reg);            
 }
Ejemplo n.º 4
0
 private NotificationsHelperBase GetHelper(NotificationTypes notificationType)
 {
     switch (notificationType)
     {
     case NotificationTypes.ProspectReminder:
         return(new ProspectsReminderNotificationsHelper(AppContext));
     }
     throw new Exception("Notification helper for notification type '" + notificationType.ToString() + "' has not been implemented");
 }
Ejemplo n.º 5
0
        public void ShowNotification(NotificationTypes notificationType, string message)
        {
            panNotification.CssClass   = string.Format("notification {0} canhide", notificationType).ToLower();
            litNotificationHeader.Text = notificationType.ToString().ToUpper() + ":";
            litMessage.Text            = message;
            panNotification.Style.Add("display", "block");

            this.Visible = true;
        }
Ejemplo n.º 6
0
        public static void ClearNotificationsByRoleAndLotID(UserRoles role, string lotID, NotificationTypes notificationType)
        {
            int recordCount = 0;

            //foreach (User user in UserService.GetUsersByRole(role, 0, 0x270f, out recordCount))
            //{
            //    foreach (Notification notification in notificationGateway.GetNotificationsBy(user.UserID, lotID, true, notificationType, "", false, 0, 0x270f, out recordCount))
            //    {
            //        notification.ReadTime = DateTime.Now;
            //        notification.Opened = true;
            //        notificationGateway.UpdateByPK(notification);
            //    }
            //}
            notificationGateway.SetNotificationStatus(role.ToString(), lotID, "1", notificationType.ToString());
        }
 public NotificationDataContainer(NotificationTypes notificationType, ObjectType objectType, string id)
 {
     _dictionary.Add("ObjectType", notificationType.ToString());
     _dictionary.Add("NotificationTypes", objectType.ToString());
     _dictionary.Add("Id", id);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Get all the client registrations
        /// </summary>
        /// <param name="eventType"></param>
        /// <returns></returns>
        public Registration[] GetAllRegistrations(NotificationTypes eventType)
        {
            var q = from reglst in Registrations.Values
                     from reg in reglst
                     where reg.EventType == eventType.ToString()
                     select reg;

            return q.ToArray();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Create a client registration for a certain event type.
 /// </summary>
 /// <param name="clientUri"></param>
 /// <param name="eventType"></param>
 public void UnRegisterClient(Uri clientUri, NotificationTypes eventType)
 {
     var reg = new Registration() { RegistrationUri = clientUri, EventType = eventType.ToString() };
      var key = reg.CreateKey();
      if (Registrations.ContainsKey(key))
          Registrations.Remove(key);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Clear all registrations for an event type
 /// </summary>
 /// <param name="eventType"></param>
 public void ClearRegistrations(NotificationTypes? eventType)
 {
     if (eventType == null)
         Registrations = new Dictionary<string, List<Registration>>();
     else if (Registrations.ContainsKey(eventType.ToString()))
     {
         Registrations[eventType.ToString()] = new List<Registration>();
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Get a particular registration
        /// </summary>
        /// <param name="eventType"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public Registration[] GetRegistrations(NotificationTypes eventType, string userName)
        {
            if (string.IsNullOrEmpty(userName))
                userName = "******";

            var q = from reglst in Registrations.Values
                    from reg in reglst
                    where ((reg.EventType == eventType.ToString()) && (reg.UserName == userName))
                    select reg;

            return q.ToArray();

        }
Ejemplo n.º 12
0
        public override void OnReceive(Context context, Intent intent)
        {
            Task.Run
            (
                async() =>
            {
                try
                {
                    // Wakelocker.Acquire(AppContext, WakelockTag);
                    // await new LocalOtaService().CacheAsync();
                    Logger.Debug("Notification OnReceive called");
                    int savedNotificationType = intent.GetIntExtra(NotificationType, 0);
                    if (savedNotificationType == 0)
                    {
                        Logger.Error("Unknown notification type");
                        return;
                    }
                    Logger.Debug("Notification type is " + savedNotificationType);
                    NotificationTypes notificationType = (NotificationTypes)savedNotificationType;
                    Logger.Debug("Showing notification of type " + notificationType.ToString());


                    if (notificationType == default(NotificationTypes))
                    {
                        return;
                    }



                    Logger.Debug("Booting up the core notification service");
                    NotificationsCoreService notificationsCoreService = new NotificationsCoreService();
                    Logger.Debug("Requesting core notification service for overdue notifications");
                    List <string> overdueNotifications =
                        await notificationsCoreService.GetOverdueNotificationsEntityIdsAsync(notificationType);

                    Logger.Debug("Establishing the notification helper to use");
                    NotificationsHelperBase notificationHelper = GetHelper(notificationType);

                    Logger.Debug("Asking notification helper to filter out notifications that aren't needed");
                    await notificationHelper.SetOverdueNotificationsAsync(overdueNotifications);

                    if (overdueNotifications == null)
                    {
                        overdueNotifications = new List <string>();
                    }
                    if (overdueNotifications.Count == 0)
                    {
                        Logger.Debug("Turns out there are no notifications to show");

                        return;
                    }


                    string message = notificationHelper.GetMessage();
                    PendingIntent contentIntent = PendingIntent.GetActivity(context, default(int), intent,
                                                                            PendingIntentFlags.CancelCurrent);



                    var notificationManager = NotificationManagerCompat.From(context);
                    var style = new NotificationCompat.BigTextStyle();
                    style.BigText(message);


                    var builder = new NotificationCompat.Builder(AppContext)
                                  .SetContentTitle(notificationHelper.GetTitle())
                                  .SetContentText(notificationHelper.GetMessage())
                                  .SetAutoCancel(notificationHelper.AutoCancel)
                                  .SetContentIntent(contentIntent)
                                  .SetSmallIcon(Resource.Drawable.Icon22x22)
                                  .SetStyle(style)
                                  .SetDefaults((int)notificationHelper.SoundAndOrVibrationAndOrLights)
                                  .SetWhen(JavaSystem.CurrentTimeMillis());

                    TaskStackBuilder taskStackBuilder = TaskStackBuilder.Create(AppContext);
                    Intent destIntent = await GetContentIntentAsync(notificationHelper, taskStackBuilder);

                    if (destIntent != null)
                    {
                        PendingIntent pendingIntent = taskStackBuilder.GetPendingIntent(0,
                                                                                        PendingIntentFlags.OneShot);
                        //PendingIntent.GetActivity(AppContext, 0, destIntent, PendingIntentFlags.OneShot);
                        builder.SetContentIntent(pendingIntent);
                    }
                    var notification = builder.Build();
                    notificationManager.Notify((int)notificationType, notification);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    throw;
                }
                finally
                {
                    Wakelocker.Release();
                }
            }
            );
        }
Ejemplo n.º 13
0
        public static void PreparationDataForSending(Recipient recipient, NotificationTypes notificationType, String text, NotificationApplications application, String eventCode)
        {
            log.Log.Info($"{recipient.EMail}, {notificationType.ToString()} {application.ToString()}, {eventCode}");

            if (string.IsNullOrEmpty(recipient.EMail))
            {
                log.Log.Warn("EMail is empty");
                return;
            }

            Random rnd = new Random();

            EmailData emailData = new EmailData()
            {
                R1      = rnd.Next(1000000, 9999999),
                Sender  = recipient.EMail,
                Subject = GetSubject((Int32)application, eventCode),
                Text    = text,
                R2      = rnd.Next(1000000, 9999999)
            };

            JsonSerializerOptions options = new JsonSerializerOptions()
            {
                WriteIndented = true
            };

            String finalText = string.Empty;

            try
            {
                /*
                 * We convert the emailData object into JSON, JSON into an array of bytes,
                 * and already this array of bytes is passed to the EncryptStringToBytes_Aes function.
                 */


                byte[] encryptedByte = AesEncryption.EncryptStringToBytes_Aes(JsonSerializer.SerializeToUtf8Bytes(emailData, options));
                finalText = Convert.ToBase64String(encryptedByte);
            }
            catch (Exception ex)
            {
                log.Log.Error(ex, $"Failed to use AES encryption. Message - {ex}");
                return;
            }

            Task <String> tasks = RequestSendingEmail(finalText);

            Int32?code = ProcessingResult(tasks.Result);

            if (code != null)
            {
                try
                {
                    // Add the response to the current request for sending to the log table
                    // If the code is 1 (successful), then add the current notification to the table with the "sent" flag.
                    // This is necessary so as not to break the current connectivity of notification events, since many
                    // notifications are checked for the sending frequency from this table.
                    Service.WriteResponseToLogNtfTable(recipient.Id, (Int32)notificationType, text, (Int32)code, application.ToString());
                }
                catch (Exception ex)
                {
                    log.Log.Error(ex, "Failed to write result to table.");
                }
            }
        }
        /// <summary>
        /// The SubscriptionExists method checks if a subscription exists
        /// </summary>
        /// <param name="subscriberId">The subscriberId parameter</param>
        /// <param name="eventTypeId">The eventTypeId parameter</param>
        /// <param name="ntype">The type parameter</param>
        /// <returns>The boolean type object</returns>        
        public bool SubscriptionExists(int subscriberId, int eventTypeId, NotificationTypes ntype)
        {
            string notification = ntype.ToString();
            List<DbParameter> parameters = new List<DbParameter>();
            parameters.Add(new IntParameter("subscriberId", subscriberId));
            parameters.Add(new IntParameter(Constants.Parameters.EventTypeId, eventTypeId));
            parameters.Add(new StringParameter("notification", notification));
            int count = ExecuteStoredProcNonQuery("VerifySubscription", parameters);
            if (count == 0)
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 15
0
 public ICollection <NotificationUserEntityModel> NotificationUsers(Guid shopGuid, NotificationTypes type)
 => this.Database.SqlQuery <NotificationUserEntityModel>("EXEC [Notification].[usp_GetNotificationUsers] @ShopGuid, @NotificationType;",
                                                         new SqlParameter("@ShopGuid", shopGuid.ToString()), new SqlParameter("@NotificationType", type.ToString())).ToList();