private static void GenerateLogTimeIntervals(int computerId, List <string> usersNames) { var now = DateTime.Now; var dateTime = new DateTime(now.Year, now.Month, now.Day, 2.Random(), 60.Random(), 0); usersNames.Add(null); for (var i = 0; i < Settings.MaxAmountOfLogTimeIntervals.Random(10); i++) { var timeSpan = new TimeSpan(2.Random(), 57.Random(), 0); var userName = usersNames.Random(); var log = new LogTimeInterval { LogTimeIntervalId = 0, ComputerId = computerId, StartTime = dateTime, Duration = timeSpan, //ComputerUserId = userId, ComputerUser = userName, State = userName == null ? "Idle" : (2.Random() == 0 ? "Idle" : "Active") }; Db.LogTimeIntervals.Add(log); Db.SaveChanges(); var name = Db.ComputerUsers.FirstOrDefault(cu => cu.Name == log.ComputerUser)?.Name ?? ""; LocalLogger.Log($" LogTimeInterval Starting at {log.StartTime:g} and lasting {log.Duration:g} added"); LocalLogger.Log($" User name: {name}, state: {log.State}"); dateTime += timeSpan + new TimeSpan(0, 20.Random(), 50.Random()); } }
internal LogFileDataStore() { _currentLogTimeInterval = LogTimeInterval.day; LOG_BASE_PATH = Properties.Settings.Default.Log_file_base_path; CreateNewLogFile(); _xmlDocument = new System.Xml.XmlDocument(); }
public ActionResult DeleteConfirmed(int id) { LogTimeInterval logTimeInterval = db.LogTimeIntervals.Find(id); db.LogTimeIntervals.Remove(logTimeInterval); db.SaveChanges(); return(RedirectToAction("Index")); }
public static LogTimeIntervalViewModel ToViewModel(this LogTimeInterval log) { return(new LogTimeIntervalViewModel() { User = log.ComputerUser ?? "", StartTime = log.StartTime.Subtract(new DateTime(1900, 1, 1)).TotalMilliseconds, Duration = (int)log.Duration.TotalSeconds, State = log.State }); }
public ActionResult Edit([Bind(Include = "LogTimeIntervalId,ComputerUser,ComputerId,StartTime,Duration,State")] LogTimeInterval logTimeInterval) { if (ModelState.IsValid) { db.Entry(logTimeInterval).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ComputerId = new SelectList(db.Computers, "ComputerId", "Name", logTimeInterval.ComputerId); return(View(logTimeInterval)); }
public static LogTimeIntervalResource ToResource(this LogTimeInterval log) { return(new LogTimeIntervalResource() { ComputerId = log.ComputerId, UserName = log.ComputerUser, StartTime = log.StartTime, Duration = log.Duration, State = log.State, LogTimeIntervalId = log.LogTimeIntervalId }); }
// GET: TempLogTimeIntervals/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LogTimeInterval logTimeInterval = db.LogTimeIntervals.Find(id); if (logTimeInterval == null) { return(HttpNotFound()); } return(View(logTimeInterval)); }
// GET: TempLogTimeIntervals/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LogTimeInterval logTimeInterval = db.LogTimeIntervals.Find(id); if (logTimeInterval == null) { return(HttpNotFound()); } ViewBag.ComputerId = new SelectList(db.Computers, "ComputerId", "Name", logTimeInterval.ComputerId); return(View(logTimeInterval)); }
/// <summary> /// Is Log file obsolete? check. /// 1-true (need to recreate file) /// 0-false /// </summary> /// <param name="currentLogTimeInterval"></param> /// <returns> /// 1-true (need to recreate file) /// 0-false /// </returns> private bool IsLogFileObsolete(LogTimeInterval currentLogTimeInterval) { switch (currentLogTimeInterval) { case LogTimeInterval.minute: return _logFileCreateDate.Minute != DateTime.Now.Minute; case LogTimeInterval.hour: return _logFileCreateDate.Hour != DateTime.Now.Hour; case LogTimeInterval.day: return _logFileCreateDate.Day != DateTime.Now.Day; default: return false; } }