Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        public void Create(ExportLine line)
        {
            if (_project == null)
            {
                FindOrCreateProject();
            }

            var task = FindOrCreateTask(string.IsNullOrEmpty(line.TaskNumber) ? line.TaskName : line.TaskNumber, line.TaskType, line.Description);

            CreateTracking(task, line.Date, line.StartTime, line.EndTime, line.Duration);

            _db.SaveChanges();
        }
 public void Add(User user)
 {
     _context.Add(user);
     _context.SaveChanges();
 }
 public void Add(Report report)
 {
     _context.Add(report);
     _context.SaveChanges();
 }
Exemplo n.º 5
0
 public void Add(Deviation deviation)
 {
     _context.Add(deviation);
     _context.SaveChanges();
 }
        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();
                }
            }
        }