Beispiel #1
0
 public override void Delete()
 {
     lock (SyncRoot) {
         if (IsShared && IsPersisted && State == TimeEntryState.Running)
         {
             try {
                 Stop();
             } catch (InvalidOperationException ex) {
                 var log = ServiceContainer.Resolve <Logger> ();
                 log.Debug(LogTag, ex, "Failed to stop time entry before deleting it.");
             }
         }
         base.Delete();
         RunningCache.Invalidate();
     }
 }
Beispiel #2
0
 public static TimeEntryModel FindRunning()
 {
     return(RunningCache.Get());
 }
Beispiel #3
0
        protected override void OnPropertyChanged(string property)
        {
            base.OnPropertyChanged(property);

            // Make sure the string tags are converted into actual relations as soon as possible:
            if (property == PropertyIsShared ||
                property == PropertyIsPersisted ||
                property == PropertyWorkspaceId)
            {
                if (IsShared && IsPersisted && stringTagsList != null && Workspace != null)
                {
                    StringTags = stringTagsList;
                }
            }

            if (property == PropertyDeletedAt)
            {
                if (State == TimeEntryState.Running)
                {
                    RunningCache.Invalidate();
                }
            }

            if (property == PropertyProjectId)
            {
                if (IsShared && !IsMerging && Project != null)
                {
                    IsBillable = Project.IsBillable;
                }
            }

            if (property == PropertyIsShared ||
                property == PropertyState ||
                property == PropertyIsPersisted)
            {
                if (IsShared && State == TimeEntryState.Running && IsPersisted)
                {
                    // Make sure that this is the only time entry running:
                    var entries = Model.Manager.Cached <TimeEntryModel> ().Where((m) => m.UserId == UserId && m.State == TimeEntryState.Running);
                    foreach (var entry in entries)
                    {
                        if (entry == this)
                        {
                            continue;
                        }
                        try {
                            entry.Stop();
                        } catch (InvalidOperationException ex) {
                            var log = ServiceContainer.Resolve <Logger> ();
                            log.Debug(LogTag, ex, "Failed to stop time entry in memory.");
                        }
                    }

                    // Double check the database as well:
                    entries = Model.Query <TimeEntryModel> (
                        (m) => m.UserId == UserId && m.State == TimeEntryState.Running && m.Id != Id)
                              .NotDeleted();
                    foreach (var entry in entries)
                    {
                        try {
                            entry.Stop();
                        } catch (InvalidOperationException ex) {
                            var log = ServiceContainer.Resolve <Logger> ();
                            log.Debug(LogTag, ex, "Failed to stop time entry from store.");
                        }
                    }

                    RunningCache.Invalidate();
                }
            }
        }