public static void Cleanup() { using (var ctx = new FeeblDataContext()) { ctx.ExecuteCommand("EXECUTE dbo.[Cleanup]"); } }
public ActionResult Index(string currentPassword, string newPassword, string newPassword2) { using (var ctx = new FeeblDataContext()) { var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; var u = ctx.Users.First(x => x.UserID == user.UserID); if (newPassword != newPassword2) { TempData["Error"] = "Passwords did not match."; return(View(new User())); } if (Methods.EncryptPassword(currentPassword) != u.Password) { TempData["Error"] = "Your current password is invalid, try again..."; return(View(new User())); } if (newPassword.Length < 6) { TempData["Error"] = "New password is too short, please use a minimum of 6 characters (8 recommended)."; return(View(new User())); } u.Password = Methods.EncryptPassword(newPassword); ctx.SubmitChanges(); TempData["Success"] = "Successfully changed password."; return(RedirectToAction("Index")); } }
public static void UpdateSchedule() { using (var ctx = new FeeblDataContext()) { ctx.ExecuteCommand("EXECUTE dbo.[UpdateSchedule]"); } }
public ActionResult Index(int id) { using (var ctx = new FeeblDataContext()) { var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if (!user.IsAdmin) { id = user.UserID; } var pt = (from s in ctx.UserSubscriptions where s.UserID == id select new SubscriptionTile { UserID = s.UserID, Name = s.Process.Name, Email = s.Email, SMS = s.SMS, Application = s.Process.Application.Name, ApplicationID = s.Process.ApplicationID, Customer = s.Process.Customer.Name, CustomerID = s.Process.CustomerID, ProcessID = s.ProcessID }).ToList(); return(View(pt)); } }
public ActionResult Subscribe(int id, int userID, string type) { using (var ctx = new FeeblDataContext()) { var sub = (from x in ctx.UserSubscriptions where x.ProcessID == id && x.UserID == userID select x).First(); if (type == "email") { sub.Email = !sub.Email; } if (type == "sms") { sub.SMS = !sub.SMS; } if (!sub.Email && !sub.SMS) { ctx.UserSubscriptions.DeleteOnSubmit(sub); } ctx.SubmitChanges(); TempData["Success"] = "User subscription was successfully changed."; return(RedirectToAction("Index", new { id = userID })); } }
public ActionResult Index() { using (var ctx = new FeeblDataContext()) { var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; var pt = (from u in ctx.Users where (!user.ApplicationID.HasValue || u.ApplicationID == user.ApplicationID) && (!user.CustomerID.HasValue || u.CustomerID == user.CustomerID) select new UserTile { UserID = u.UserID, Name = u.Email.Substring(0, u.Email.IndexOf('@') < 0 ? u.Email.Length : u.Email.IndexOf('@')), Email = u.Email, Application = u.Application.Name, ApplicationID = u.ApplicationID, Customer = u.Customer.Name, CustomerID = u.CustomerID, IsAdmin = u.IsAdmin, Mobile = u.Mobile }).ToList(); return(View(pt)); } }
public ActionResult Index(string email, string password, string remember) { using (var ctx = new FeeblDataContext()) { var user = (from u in ctx.Users where u.Email == email && u.Password == Methods.EncryptPassword(password) select u).FirstOrDefault(); if (user == null) { TempData["Error"] = "Invalid email and/or password."; return(View()); } var ticket = new FormsAuthenticationTicket(1, user.Email, DateTime.UtcNow, DateTime.UtcNow.AddYears(1), remember == "on", password); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); if (remember == "on") { cookie.Expires = DateTime.UtcNow.AddYears(1); } System.Web.HttpContext.Current.Response.Cookies.Add(cookie); TempData["Success"] = "Welcome back!"; return(RedirectToAction("Index", "Applications")); } }
public ActionResult Delete(int id, FormCollection collection) { using (var ctx = new FeeblDataContext()) { var demand = (from d in ctx.Demands where d.DemandID == id select d).First(); var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if ((user.ApplicationID.HasValue && demand.Process.ApplicationID != user.ApplicationID.Value) || (user.CustomerID.HasValue && demand.Process.CustomerID != user.CustomerID.Value)) { Response.StatusCode = 401; Response.End(); } var processID = demand.ProcessID; ctx.Histories.DeleteAllOnSubmit(demand.Histories); ctx.Demands.DeleteOnSubmit(demand); ctx.SubmitChanges(); TempData["Success"] = "Successfully deleted Demand."; return(RedirectToAction("Index", new { processID })); } }
public ActionResult Edit(int id, Demand dummy) { using (var ctx = new FeeblDataContext()) { var demand = (from d in ctx.Demands where d.DemandID == id select d).First(); var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if ((user.ApplicationID.HasValue && demand.Process.ApplicationID != user.ApplicationID.Value) || (user.CustomerID.HasValue && demand.Process.CustomerID != user.CustomerID.Value)) { Response.StatusCode = 401; Response.End(); } if (!TryUpdateModel(demand)) { TempData["Error"] = "Failure updating Demand."; return(View(demand)); } demand.CalculateNextRunTime(); ctx.SubmitChanges(); TempData["Success"] = "Successfully updated Demand."; return(RedirectToAction("Index", new { processID = demand.ProcessID })); } }
public ActionResult Delete(int id) { using (var ctx = new FeeblDataContext()) { var user = (from u in ctx.Users where u.UserID == id select u).First(); return(View(user)); } }
public static void ProcessWebsites() { Dictionary <int, string> pings; using (var ctx = new FeeblDataContext()) { pings = ctx.Processes .Where(x => x.URL != string.Empty && x.URL != null) .ToList() .ToDictionary(x => x.ProcessID, y => y.URL); } foreach (var d in pings) { var processID = d.Key; var url = d.Value; Task.Factory.StartNew(() => { try { using (var ctx = new FeeblDataContext()) { int ms; if (!Methods.Ping(url, out ms)) { return; } var process = ctx.Processes.First(x => x.ProcessID == processID); process.LastRunTime = DateTime.UtcNow; ctx.Events.InsertOnSubmit(new Event { Process = process, CreationTime = DateTime.UtcNow, Counter = ms }); ctx.SubmitChanges(); } } catch { // swallow } }); } }
public ActionResult Index(int processID, bool showAll = false) { using (var ctx = new FeeblDataContext()) { var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; var eventCount = showAll ? 9999999 : 13; var pt = (from p in ctx.Processes where p.ProcessID == processID select new ProcessTile { Application = p.Application.Name, ApplicationID = p.ApplicationID, Customer = p.Customer.Name, CustomerID = p.CustomerID, ProcessID = p.ProcessID, Name = p.Name, Demands = p.Demands.ToList(), Events = p.Events.OrderByDescending(e => e.CreationTime).Take(eventCount).ToList(), EventsToday = p.Events.Count(e => e.CreationTime > DateTime.Now.AddDays(-1)), CountsToday = p.Events.Where(e => e.CreationTime > DateTime.Now.AddDays(-1)).Select(e => e.Counter).Sum() ?? 0, FailsToday = p.Demands.Sum(d => (int?)d.Histories.Count(h => (h.Status == "Failed") && (h.CreationTime > DateTime.Now.AddDays(-1)))) ?? 0, History = p.Demands.SelectMany(d => d.Histories).OrderByDescending(h => h.CreationTime).Take(6).ToList(), ErrorMessage = p.Demands.OrderBy(d => d.IsMet).FirstOrDefault().ErrorMessage, Badge = p.Demands.All(d => d.IsMet) // ReSharper disable ReplaceWithStringIsNullOrEmpty ? p.URL == "" || p.URL == null ? "" : "available" : p.URL == "" || p.URL == null ? "error" : "busy", // ReSharper restore ReplaceWithStringIsNullOrEmpty Status = p.Demands.All(d => d.IsMet) ? "fg-color-white bg-color-green" : p.Demands.All(d => !d.IsMet) ? "fg-color-white bg-color-red" : "fg-color-white bg-color-orange", SubscribedEmail = p.UserSubscriptions.Any(s => s.UserID == user.UserID && s.Email), SubscribedSMS = p.UserSubscriptions.Any(s => s.UserID == user.UserID && s.SMS) }).First(); if ((user.ApplicationID.HasValue && pt.ApplicationID != user.ApplicationID) || (user.CustomerID.HasValue && pt.CustomerID != user.CustomerID)) { Response.StatusCode = 401; Response.End(); } return(View(pt)); } }
public ActionResult Index(int customerID, int applicationID, string groupID) { using (var ctx = new FeeblDataContext()) { var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if ((user.ApplicationID.HasValue && applicationID != user.ApplicationID.Value) || (user.CustomerID.HasValue && customerID != user.CustomerID.Value)) { Response.StatusCode = 401; Response.End(); } var list = (from p in ctx.Processes where p.CustomerID == customerID && p.ApplicationID == applicationID && (!user.ApplicationID.HasValue || p.ApplicationID == user.ApplicationID) && (!user.CustomerID.HasValue || p.CustomerID == user.CustomerID) && ((groupID == null || groupID == string.Empty) || (p.GroupID == groupID)) select new ProcessTile { Application = p.Application.Name, ApplicationID = p.ApplicationID, Customer = p.Customer.Name, CustomerID = p.CustomerID, ProcessID = p.ProcessID, Name = p.Name, LastRunTime = p.LastRunTime, ErrorMessage = p.Demands.OrderBy(d => d.IsMet).FirstOrDefault().ErrorMessage, Badge = p.Demands.All(d => d.IsMet) // ReSharper disable ReplaceWithStringIsNullOrEmpty ? p.URL == "" || p.URL == null ? "" : "available" : p.URL == "" || p.URL == null ? "error" : "busy", // ReSharper restore ReplaceWithStringIsNullOrEmpty FailsToday = p.Demands.Sum(d => (int?)d.Histories.Count(h => (h.Status == "Failed") && (h.CreationTime > DateTime.Now.AddDays(-1)))) ?? 0, Status = p.Demands.All(d => d.IsMet) ? "fg-color-white bg-color-green" : p.Demands.Any(d => !d.IsMet && d.Priority >= (int)Lists.Priority.Normal) ? "fg-color-white bg-color-red" : "fg-color-white bg-color-orange", SubscribedEmail = p.UserSubscriptions.Any(s => s.UserID == user.UserID && s.Email), SubscribedSMS = p.UserSubscriptions.Any(s => s.UserID == user.UserID && s.SMS), GroupID = p.GroupID }).ToList(); return(View(list)); } }
public ActionResult Broadcast(string message, string SMS, string applicationName, string customerName) { using (var ctx = new FeeblDataContext()) { var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; var applicationID = user.ApplicationID ?? (from a in ctx.Applications where a.Name.ToLower() == applicationName.ToLower() select(int?) a.ApplicationID).FirstOrDefault(); var customerID = user.CustomerID ?? (from c in ctx.Customers where c.Name.ToLower() == customerName.ToLower() select(int?) c.CustomerID).FirstOrDefault(); var sendSMS = (SMS.ToLower() == "yes"); var users = (from u in ctx.Users where (!u.ApplicationID.HasValue || !applicationID.HasValue || applicationID == u.ApplicationID) && (!u.CustomerID.HasValue || !customerID.HasValue || customerID == u.CustomerID) && (!sendSMS || (u.Mobile != null && u.Mobile != string.Empty)) && (sendSMS || (u.Email.Contains("@") && !u.Email.ToLower().Contains("bi_support"))) select u).ToList(); IMessage msg; if (sendSMS) { msg = new SmsMessage { Body = message }; } else { msg = new Email { Subject = "Feebl broadcast message", Body = message }; } foreach (var u in users) { msg.AddReceipient(sendSMS ? u.Mobile : u.Email); } msg.Send(); TempData["Success"] = "Successfully broadcasted message!"; return(RedirectToAction("Index")); } }
public ActionResult Subscribe(int id, string type) { using (var ctx = new FeeblDataContext()) { var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if (user.UserID == 0) { throw new Exception("User lookup mismatch, please try again."); } var sub = (from x in ctx.UserSubscriptions where x.UserID == user.UserID && x.ProcessID == id select x).FirstOrDefault(); if (sub == null) { sub = new UserSubscription { UserID = user.UserID, ProcessID = id }; ctx.UserSubscriptions.InsertOnSubmit(sub); } if (type == "email") { sub.Email = !sub.Email; } if (type == "sms") { sub.SMS = !sub.SMS; } if (!sub.Email && !sub.SMS) { ctx.UserSubscriptions.DeleteOnSubmit(sub); } ctx.SubmitChanges(); TempData["Success"] = "Your subscription was successfully changed."; return(RedirectToAction("Index", new { processID = id })); } }
public ActionResult Delete(int id) { using (var ctx = new FeeblDataContext()) { var demand = (from d in ctx.Demands where d.DemandID == id select d).First(); var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if ((user.ApplicationID.HasValue && demand.Process.ApplicationID != user.ApplicationID.Value) || (user.CustomerID.HasValue && demand.Process.CustomerID != user.CustomerID.Value)) { Response.StatusCode = 401; Response.End(); } return(View(demand)); } }
private static void Write(Type type, string name, string detail) { try { using (var ctx = new FeeblDataContext()) { ctx.Logs.InsertOnSubmit(new Feebl.Log { Message = name, StackTrace = detail, CreationTime = DateTime.Now, LogType = type.ToString() }); ctx.SubmitChanges(); } } catch { } // only email errors to me, ignore the rest if (type != Type.Error) { return; } try { var mail = new Email { Subject = name, Body = detail }; mail.AddReceipient("*****@*****.**"); mail.Send(); } catch { } }
internal FeeblIdentity(FeeblDataContext ctx, string email, string password) { var user = (from u in ctx.Users where u.Email == email && u.Password == Methods.EncryptPassword(password) select u).FirstOrDefault(); if (user != null) { _name = user.Email.Split('@')[0]; _isAuthenticated = true; UserID = user.UserID; Email = user.Email; Mobile = user.Mobile; ApplicationID = user.ApplicationID; CustomerID = user.CustomerID; IsAdmin = user.IsAdmin; } }
public ActionResult Delete(int id, FormCollection collection) { using (var ctx = new FeeblDataContext()) { var u = ctx.Users.First(x => x.UserID == id); var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if ((user.ApplicationID.HasValue && u.ApplicationID != user.ApplicationID.Value) || (user.CustomerID.HasValue && u.CustomerID != user.CustomerID.Value)) { TempData["Error"] = "You have no right to delete this user."; return(View(u)); } ctx.UserSubscriptions.DeleteAllOnSubmit(u.UserSubscriptions); ctx.Users.DeleteOnSubmit(u); ctx.SubmitChanges(); TempData["Success"] = "Successfully deleted User."; return(RedirectToAction("Index")); } }
public ViewResult Edit(int id) { using (var ctx = new FeeblDataContext()) { var user = (from u in ctx.Users where u.UserID == id select new UserTile { UserID = u.UserID, Name = u.Email.Substring(0, u.Email.IndexOf('@') < 0 ? u.Email.Length : u.Email.IndexOf('@')), Email = u.Email, Application = u.Application.Name, ApplicationID = u.ApplicationID, Customer = u.Customer.Name, CustomerID = u.CustomerID, IsAdmin = u.IsAdmin, Mobile = u.Mobile }).First(); return(View(user)); } }
public ActionResult Create(int id, Demand d) { using (var ctx = new FeeblDataContext()) { d.ProcessID = id; if (!TryUpdateModel(d)) { TempData["Error"] = "Failure creating Demand."; return(View(d)); } d.IsMet = true; d.CalculateNextRunTime(); ctx.Demands.InsertOnSubmit(d); ctx.SubmitChanges(); TempData["Success"] = "Successfully created Demand."; return(RedirectToAction("Index", new { processID = id })); } }
public static void CheckDemands() { List <int> demandIDs; using (var ctx = new FeeblDataContext()) { demandIDs = (from d in ctx.Demands select d.DemandID).ToList(); } foreach (var demandID in demandIDs) { var d = demandID; Task.Factory.StartNew(() => { try { using (var ctx = new FeeblDataContext()) { var demand = ctx.Demands.FirstOrDefault(x => x.DemandID == d); if (demand == null) { return; } demand.Check(ctx); ctx.SubmitChanges(); } } catch (Exception ex) { Utilities.Log.Error(ex); } }); } }
public ActionResult Index(int?applicationID) { using (var ctx = new FeeblDataContext()) { var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if (user.ApplicationID.HasValue) { applicationID = user.ApplicationID; } var data = (from p in ctx.Processes where (!user.CustomerID.HasValue || p.CustomerID == user.CustomerID) && (!applicationID.HasValue || p.ApplicationID == applicationID) select new { Application = p.Application.Name, p.ApplicationID, Customer = p.Customer.Name, p.CustomerID, p.ProcessID, p.Name, IsMet = p.Demands.All(d => d.IsMet), IsLowPrio = p.Demands.All(d => d.IsMet || d.Priority < (int)Lists.Priority.Normal), p.Demands.OrderBy(d => d.IsMet).FirstOrDefault().ErrorMessage, p.LastRunTime, SubscribedEmail = p.UserSubscriptions.Any(s => s.UserID == user.UserID && s.Email), SubscribedSMS = p.UserSubscriptions.Any(s => s.UserID == user.UserID && s.SMS), p.URL }).ToList(); var result = (from d in data group d by new { d.Customer, d.CustomerID } into grouped orderby grouped.Key.Customer ascending select new CustomerTile { Application = applicationID.HasValue ? grouped.First().Application : null, ApplicationID = applicationID.HasValue ? grouped.First().ApplicationID : 0, Customer = grouped.Key.Customer, CustomerID = grouped.Key.CustomerID, PassCount = grouped.Count(d => d.IsMet), Status = grouped.All(d => d.IsMet) ? "fg-color-white bg-color-green" : grouped.All(d => !d.IsMet) ? "fg-color-white bg-color-red" : "fg-color-white bg-color-orange", LastRunTime = (from d in grouped orderby d.LastRunTime descending select d.LastRunTime).FirstOrDefault(), Errors = (from pt in grouped group pt by new { pt.Application, pt.ApplicationID, pt.ProcessID, pt.Name, pt.URL } into process where process.Any(d => !d.IsMet && !d.IsLowPrio) orderby process.Key.Name ascending select new ProcessTile { ProcessID = process.Key.ProcessID, Application = process.Key.Application, ApplicationID = process.Key.ApplicationID, Customer = grouped.Key.Customer, CustomerID = grouped.Key.CustomerID, Name = process.Key.Name, ErrorMessage = process.OrderBy(d => d.IsMet).ThenByDescending(d => d.ErrorMessage).Select(d => d.ErrorMessage).FirstOrDefault(), Badge = process.All(d => d.IsMet) // ReSharper disable ReplaceWithStringIsNullOrEmpty ? process.Key.URL == "" || process.Key.URL == null ? "" : "available" : process.Key.URL == "" || process.Key.URL == null ? "error" : "busy", // ReSharper restore ReplaceWithStringIsNullOrEmpty Status = process.All(d => d.IsMet) ? "fg-color-white bg-color-green" : process.All(d => !d.IsMet) ? "fg-color-white bg-color-red" : "fg-color-white bg-color-orange", SubscribedEmail = process.First().SubscribedEmail, SubscribedSMS = process.First().SubscribedSMS, }).ToList() }).ToList(); return(View(result)); } }
public ActionResult Index(int processID, string ignoreUntil, string remark) { using (var ctx = new FeeblDataContext()) { var process = (from p in ctx.Processes where p.ProcessID == processID select p).First(); var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if ((user.ApplicationID.HasValue && process.ApplicationID != user.ApplicationID.Value) || (user.CustomerID.HasValue && process.CustomerID != user.CustomerID.Value)) { Response.StatusCode = 401; Response.End(); } if (String.IsNullOrEmpty(remark)) { remark = "Ignored"; } DateTime?ignoreUntilDate = null; if (!String.IsNullOrEmpty(ignoreUntil)) { DateTime dt; var ci = CultureInfo.InvariantCulture; if (!DateTime.TryParseExact(ignoreUntil, "yyyy/MM/dd HH:mm", ci, DateTimeStyles.None, out dt)) { TempData["Error"] = "Please fill in a valid Ignore Until date (yyyy/MM/dd HH:mm)."; return(RedirectToAction("Index", new { processID })); } var utcOffset = process.Demands.Select(d => d.UtcOffset).FirstOrDefault() ?? DateTimeExtensions.DefaultUtcOffset; ignoreUntilDate = dt.AddHours(-utcOffset).AddMinutes(-1); } foreach (var d in process.Demands) { if (d.IsMet) { if (ignoreUntilDate.HasValue) { d.CalculateNextRunTime(ignoreUntilDate.Value); } } else { d.Update(ctx, true, remark, null); d.CalculateNextRunTime(ignoreUntilDate); } } ctx.SubmitChanges(); TempData["Success"] = "Failed process demands are now ignored, and will be checked at the next expected run time."; return(RedirectToAction("Index", new { processID })); } }
public ActionResult Create(User u, string applicationName, string customerName, string admin) { using (var ctx = new FeeblDataContext()) { if (!TryUpdateModel(u, new[] { "Email", "Mobile" })) { TempData["Error"] = "Failure creating User."; return(View(u)); } #region Update Application, Customer and IsAdmin if (!string.IsNullOrEmpty(applicationName)) { u.ApplicationID = (from a in ctx.Applications where a.Name == applicationName select(int?) a.ApplicationID).FirstOrDefault(); if (!u.ApplicationID.HasValue) { TempData["Error"] = "Failure creating User, application '" + applicationName + "' does not exist."; return(View(u)); } } if (!string.IsNullOrEmpty(customerName)) { u.CustomerID = (from a in ctx.Customers where a.Name == customerName select(int?) a.CustomerID).FirstOrDefault(); if (!u.CustomerID.HasValue) { TempData["Error"] = "Failure creating User, customer '" + customerName + "' does not exist."; return(View(u)); } } u.IsAdmin = (admin.ToLower() == "true"); var user = (FeeblIdentity)FeeblPrincipal.Current.Identity; if (user.ApplicationID.HasValue) { u.ApplicationID = user.ApplicationID.Value; } if (user.CustomerID.HasValue) { u.CustomerID = user.CustomerID.Value; } #endregion #region Password var password = Methods.GeneratePassword(); var mail = new Email { Subject = "User registration", Body = "Hi,<br /><br /><br />" + $"An account has been created for you! You can log in using the link below, using your email address and the following temporary password: {password}." }; mail.AddReceipient(u.Email); mail.Send(); u.Password = Methods.EncryptPassword(password); #endregion ctx.Users.InsertOnSubmit(u); ctx.SubmitChanges(); TempData["Success"] = "Successfully created User."; return(RedirectToAction("Index")); } }