예제 #1
1
        public static void NewRequest(IHubContext context, kRequest request)
        {
            context.Clients.All.newRequest(request);

            string type = request.GetType().Name;

            //Send all subscribed users an email notification
            var subscribers = Mongo.GetAllUsers().FindAll(u => u.NotificationSettings.ReceiveEmail);
            foreach (var user in subscribers)
            {
                TimeSpan localTime = DateTime.UtcNow.AddHours(user.TimeZoneOffset).TimeOfDay;
                if (user.NotificationSettings.EmailStart <= localTime && user.NotificationSettings.EmailEnd >= localTime)
                {
                    Mail.Send(user.Email,
                        "kReport: " + type,
                        @"
                        <h2>Hi " + user.GetName() + @",</h2>
                        <p>A <b>" + type.ToLowerInvariant() + "</b> request has been made from <b>" + request.Server.Name + @".</b></p>
                        <p>Have a nice day!</p>
                        <p style='font-size:0.8em'>You can change your email settings any time from the Settings page on kReport.  If you did not sign up for these emails, please reply with your concern!</p>");
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Used to save incoming requests to the database
 /// Also increments a few counters for the tracker/analytics
 /// </summary>
 /// <param name="req">Request to save</param>
 private void Save(kRequest req)
 {
     Mongo.IncrementRequestsToday(req);
     Mongo.SaveRequest(req);
 }
예제 #3
0
 internal static void SaveRequest(kRequest request)
 {
     if (request != null)
     {
         request.Date = DateTime.Now;
         if (request.Reason != null)
         {
             request.Reason = new string(request.Reason.Trim().Where(char.IsLetterOrDigit).ToArray());
         }
         Db.GetCollection<Report>("requests").Save(request);
     }
 }
예제 #4
0
        /// <summary>
        /// Used to count how many requests happen per day
        /// </summary>
        internal static void IncrementRequestsToday(kRequest req)
        {
            //Update requests for today
            Db.GetCollection("trackers").FindAndModify(new FindAndModifyArgs
            {
                Upsert = true,
                Query = Query.EQ("day", DateTime.Now.ToString("yyyy-MM-dd")),
                Update = Update.Inc("requests", 1)
            });

            //Update server requests
            if (req.Server.IP != null)
            {
                Db.GetCollection("servers").FindAndModify(new FindAndModifyArgs
                {
                    Upsert = true,
                    Query = Query.And(Query.EQ("ip", req.Server.IP), Query.EQ("name", req.Server.Name)),
                    Update = Update.Inc("requests", 1)
                });
            }
        }