Ejemplo n.º 1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            using (TimeTrackingContext ctx = new TimeTrackingContext()) {
                MessageBox.Show("USER COUNT: " + ctx.Users.Count());
            }


            // Create viewmodel
            MainViewModel vm = new MainViewModel();
            // Create window
            MainWindow window = new MainWindow(vm);

            window.Show();
        }
Ejemplo n.º 2
0
        private static void SaveForegroundWindowToDb()
        {
            var windowName = TimeTrackingTools.GetTitleOfWindowInForeground();

            var context = new TimeTrackingContext();

            try
            {
                var lowerDayLimit = DateTime.UtcNow.Date;
                var upperDayLimit = DateTime.UtcNow.AddDays(1).Date;

                var lastEntry = context.UsageTime
                                .Where(x => x.ApplicationIdentification == windowName && x.StartTime >= lowerDayLimit &&
                                       x.StartTime < upperDayLimit).OrderByDescending(x => x.StartTime).FirstOrDefault();

                if (lastEntry == null ||
                    (DateTime.UtcNow - lastEntry.StartTime.ToUniversalTime().AddSeconds(lastEntry.Duration))
                    .TotalSeconds > 15)
                {
                    context.UsageTime.Add(new UsageTime()
                    {
                        StartTime = DateTime.UtcNow,
                        ApplicationIdentification = windowName,
                        Duration = 10,
                    });

                    context.SaveChanges();
                }
                else
                {
                    lastEntry.Duration += 10;

                    context.SaveChanges();
                }
            }
            finally
            {
                context.Dispose();
            }
        }
Ejemplo n.º 3
0
 public PTORequestsController(TimeTrackingContext context)
 {
     _context = context;
 }
Ejemplo n.º 4
0
        //private readonly Microsoft.AspNetCore.Identity.UserManager<Employee> _userManager;

        public HomeController(TimeTrackingContext context)
        {
            _context = context;
            //_userManager = _userManager;
        }
 public UserRepository(TimeTrackingContext context)
 {
     _context = context;
 }
Ejemplo n.º 6
0
 public UserController(TimeTrackingContext context, IUserService userService)
 {
     _context = context;
     _service = userService;
 }
Ejemplo n.º 7
0
 public EmployeesController(TimeTrackingContext context)
 {
     _context = context;
 }
Ejemplo n.º 8
0
 public RolesController(TimeTrackingContext context)
 {
     _context = context;
 }
Ejemplo n.º 9
0
 public ContactsController(TimeTrackingContext context)
 {
     _context = context;
 }
Ejemplo n.º 10
0
 public AdminController(TimeTrackingContext context)
 {
     _context = context;
 }
 public ReportRepository(TimeTrackingContext context)
 {
     _context = context;
 }
Ejemplo n.º 12
0
 public DeviationRepository(TimeTrackingContext context)
 {
     _context = context;
 }
        public void HandleEvent <T>(Dictionary <string, object> eventArgs)
            where T : IEventType
        {
            if (typeof(T).IsAssignableFrom(typeof(IShutdownEvent)))
            {
                mutex.ReleaseMutex();
            }
            else if (typeof(T).IsAssignableFrom(typeof(IStartupEvent)))
            {
                // taken from: https://stackoverflow.com/questions/2186747/how-can-i-create-a-system-mutex-in-c-sharp
                try
                {
                    mutex = System.Threading.Mutex.OpenExisting("soluinet.devtools_TimeTracking");

                    // we got mutex and can try to obtain a lock by WaitOne
                    mutex.WaitOne();
                }
                catch
                {
                    // the specified mutex doesn't exist, we should create it
                    mutex = new System.Threading.Mutex(true, "soluinet.devtools_TimeTracking"); // these names need to match.
                }
            }
            else if (typeof(T).IsAssignableFrom(typeof(IApplicationStartedEvent)))
            {
                var context = new TimeTrackingContext();

                try
                {
                    var currentDateTime = DateTime.UtcNow;
                    var currentDate     = currentDateTime.Date;

                    var lastUsageTime = context.UsageTime.Where(x => x.StartTime > currentDate)
                                        .OrderByDescending(x => x.StartTime).FirstOrDefault();

                    if (lastUsageTime == null ||
                        !((DateTime.UtcNow - lastUsageTime.StartTime.ToUniversalTime()
                           .AddSeconds(lastUsageTime.Duration)).TotalSeconds > 15))
                    {
                        return;
                    }

                    var usageTimeName = Prompt.ShowDialog(
                        Resources.GetString("DescriptionForMeantime", CultureInfo.CurrentCulture),
                        Resources.GetString("MeantimeDescriptionTitle", CultureInfo.CurrentCulture));

                    context.UsageTime.Add(new UsageTime()
                    {
                        StartTime =
                            lastUsageTime.StartTime.ToUniversalTime().AddSeconds(lastUsageTime.Duration),
                        ApplicationIdentification = usageTimeName,
                        Duration = Convert.ToInt32(
                            (currentDateTime - lastUsageTime.StartTime.ToUniversalTime()
                             .AddSeconds(lastUsageTime.Duration)).TotalSeconds),
                    });

                    context.SaveChanges();
                }
                finally
                {
                    context.Dispose();
                }
            }
        }