public override void SetUp ()
        {
            base.SetUp ();

            RunAsync (async delegate {
                workspace = await DataStore.PutAsync (new WorkspaceData () {
                    Name = "Test",
                });

                user = await DataStore.PutAsync (new UserData () {
                    Name = "John Doe",
                    TrackingMode = TrackingMode.StartNew,
                    DefaultWorkspaceId = workspace.Id,
                });

                await SetUpFakeUser (user.Id);
                var activeManager = new ActiveTimeEntryManager ();
                await Util.AwaitPredicate (() => activeManager.ActiveTimeEntry != null);

                ServiceContainer.Register<ExperimentManager> (new ExperimentManager ());
                ServiceContainer.Register<ISyncManager> (Mock.Of<ISyncManager> (mgr => !mgr.IsRunning));
                ServiceContainer.Register<ActiveTimeEntryManager> (activeManager);
                ServiceContainer.Register<ITracker> (() => new FakeTracker ());
            });
        }
        private static void ImportJson (IDataStoreContext ctx, WorkspaceUserData data, WorkspaceUserJson json)
        {
            var workspaceId = GetLocalId<WorkspaceData> (ctx, json.WorkspaceId);
            var user = GetByRemoteId<UserData> (ctx, json.UserId, null);

            // Update linked user data:
            if (user == null) {
                user = new UserData () {
                    RemoteId = json.UserId,
                    Name = json.Name,
                    Email = json.Email,
                    DefaultWorkspaceId = workspaceId,
                    ModifiedAt = DateTime.MinValue,
                };
            } else {
                user.Name = json.Name;
                user.Email = json.Email;
            }
            user = ctx.Put (user);

            data.IsAdmin = json.IsAdmin;
            data.IsActive = json.IsActive;
            data.WorkspaceId = workspaceId;
            data.UserId = user.Id;

            ImportCommonJson (data, json);
        }
        public UserData Import (IDataStoreContext ctx, UserJson json, Guid? localIdHint = null, UserData mergeBase = null)
        {
            var data = GetByRemoteId<UserData> (ctx, json.Id.Value, localIdHint);

            var merger = mergeBase != null ? new UserMerger (mergeBase) : null;
            if (merger != null && data != null)
                merger.Add (new UserData (data));

            if (json.DeletedAt.HasValue) {
                if (data != null) {
                    ctx.Delete (data);
                    data = null;
                }
            } else if (merger != null || ShouldOverwrite (data, json)) {
                data = data ?? new UserData ();
                ImportJson (ctx, data, json);

                if (merger != null) {
                    merger.Add (data);
                    data = merger.Result;
                }

                data = ctx.Put (data);
            }

            return data;
        }
Beispiel #4
0
 public UserData (UserData other) : base (other)
 {
     Name = other.Name;
     Email = other.Email;
     StartOfWeek = other.StartOfWeek;
     DateFormat = other.DateFormat;
     TimeFormat = other.TimeFormat;
     ImageUrl = other.ImageUrl;
     Locale = other.Locale;
     Timezone = other.Timezone;
     SendProductEmails = other.SendProductEmails;
     SendTimerNotifications = other.SendTimerNotifications;
     SendWeeklyReport = other.SendWeeklyReport;
     TrackingMode = other.TrackingMode;
     DefaultWorkspaceId = other.DefaultWorkspaceId;
 }
        private void CreateTestData ()
        {
            RunAsync (async delegate {
                workspace = await DataStore.PutAsync (new WorkspaceData () {
                    RemoteId = 1,
                    Name = "Unit Testing",
                    IsDirty = true,
                });

                user = await DataStore.PutAsync (new UserData () {
                    RemoteId = 1,
                    Name = "Tester",
                    DefaultWorkspaceId = workspace.Id,
                    IsDirty = true,
                });

                var project = await DataStore.PutAsync (new ProjectData () {
                    RemoteId = 1,
                    Name = "Ad design",
                    WorkspaceId = workspace.Id,
                    IsDirty = true,
                });

                await DataStore.PutAsync (new TimeEntryData () {
                    RemoteId = 1,
                    Description = "Initial concept",
                    State = TimeEntryState.Finished,
                    StartTime = new DateTime (2013, 01, 01, 09, 12, 0, DateTimeKind.Utc),
                    StopTime = new DateTime (2013, 01, 01, 10, 1, 0, DateTimeKind.Utc),
                    ProjectId = project.Id,
                    WorkspaceId = workspace.Id,
                    UserId = user.Id,
                    IsDirty = true,
                });

                await DataStore.PutAsync (new TimeEntryData () {
                    RemoteId = 2,
                    Description = "Breakfast",
                    State = TimeEntryState.Finished,
                    StartTime = new DateTime (2013, 01, 01, 10, 12, 0, DateTimeKind.Utc),
                    StopTime = new DateTime (2013, 01, 01, 10, 52, 0, DateTimeKind.Utc),
                    WorkspaceId = workspace.Id,
                    UserId = user.Id,
                    IsDirty = true,
                });
            });
        }
        public override void SetUp ()
        {
            base.SetUp ();

            RunAsync (async delegate {
                workspace = await DataStore.PutAsync (new WorkspaceData () {
                    Name = "Test",
                    RemoteId = 9999
                });
                user = await DataStore.PutAsync (new UserData () {
                    Name = "John Doe",
                    TrackingMode = TrackingMode.StartNew,
                    DefaultWorkspaceId = workspace.Id,
                    StartOfWeek = DayOfWeek.Monday,
                });
                await SetUpFakeUser (user.Id);

                // configure IReportClient service
                var serviceMock = new Mock<IReportsClient>();

                startTime = ResolveStartDate ( DateTime.Now, ZoomLevel.Week, user);
                endTime = ResolveEndDate ( startTime, ZoomLevel.Week);

                serviceMock.Setup ( x => x.GetReports ( startTime, endTime, Convert.ToInt64 ( workspace.RemoteId)))
                .Returns ( Task.FromResult (CreateEmptyReportJson ( ZoomLevel.Week, startTime)));

                startTime = ResolveStartDate ( DateTime.Now, ZoomLevel.Month, user);
                endTime = ResolveEndDate ( startTime, ZoomLevel.Month);

                serviceMock.Setup ( x => x.GetReports ( startTime, endTime, Convert.ToInt64 ( workspace.RemoteId)))
                .Returns ( Task.FromResult (CreateEmptyReportJson ( ZoomLevel.Month, startTime)));

                startTime = ResolveStartDate ( DateTime.Now, ZoomLevel.Year, user);
                endTime = ResolveEndDate ( startTime, ZoomLevel.Year);

                serviceMock.Setup ( x => x.GetReports ( startTime, endTime, Convert.ToInt64 ( workspace.RemoteId)))
                .Returns ( Task.FromResult (CreateEmptyReportJson ( ZoomLevel.Year, startTime)));

                ServiceContainer.Register<IReportsClient> (serviceMock.Object);
                ServiceContainer.Register<ReportJsonConverter> ();
            });
        }
        private static void ImportJson (IDataStoreContext ctx, UserData data, UserJson json)
        {
            var defaultWorkspaceId = GetLocalId<WorkspaceData> (ctx, json.DefaultWorkspaceId);

            data.Name = json.Name;
            data.Email = json.Email;
            data.StartOfWeek = json.StartOfWeek;
            data.DateFormat = json.DateFormat;
            data.TimeFormat = json.TimeFormat;
            data.ImageUrl = json.ImageUrl;
            data.Locale = json.Locale;
            data.Timezone = json.Timezone;
            data.SendProductEmails = json.SendProductEmails;
            data.SendTimerNotifications = json.SendTimerNotifications;
            data.SendWeeklyReport = json.SendWeeklyReport;
            data.TrackingMode = json.StoreStartAndStopTime ? TrackingMode.StartNew : TrackingMode.Continue;
            data.DefaultWorkspaceId = defaultWorkspaceId;

            ImportCommonJson (data, json);
        }
        public async void Load()
        {
            if (IsLoading) {
                return;
            }
            IsLoading = true;

            try {
                userData = ServiceContainer.Resolve<AuthManager> ().User;
                var store = ServiceContainer.Resolve<IDataStore> ();
                queryStartDate = Time.UtcNow - TimeSpan.FromDays (9);
                var recentEntries = await store.Table<TimeEntryData> ()
                                    .OrderByDescending (r => r.StartTime)
                                    .Take (maxCount)
                                    .Where (r => r.DeletedAt == null
                                            && r.UserId == userData.Id
                                            && r.State != TimeEntryState.New
                                            && r.StartTime >= queryStartDate)
                                    .ToListAsync()
                                    .ConfigureAwait (false);

                dataObject = new List<ListEntryData> ();
                foreach (var entry in recentEntries) {
                    var entryData = await ConvertToListEntryData (entry);
                    dataObject.Add (entryData);
                }

                var runningEntry = await store.Table<TimeEntryData> ()
                                   .Where (r => r.DeletedAt == null
                                           && r.UserId == userData.Id
                                           && r.State == TimeEntryState.Running)
                                   .ToListAsync()
                                   .ConfigureAwait (false);

                hasRunning = runningEntry.Count > 0;
                activeTimeEntry = hasRunning ? await ConvertToListEntryData (runningEntry[0]) : null;

            } finally {
                IsLoading = false;
            }
        }
        public UserData Import (IDataStoreContext ctx, UserJson json, Guid? localIdHint = null, UserData mergeBase = null)
        {
            var log = ServiceContainer.Resolve<ILogger> ();

            var data = GetByRemoteId<UserData> (ctx, json.Id.Value, localIdHint);

            var merger = mergeBase != null ? new UserMerger (mergeBase) : null;
            if (merger != null && data != null) {
                merger.Add (new UserData (data));
            }

            if (json.DeletedAt.HasValue) {
                if (data != null) {
                    log.Info (Tag, "Deleting local data for {0}.", data.ToIdString ());
                    ctx.Delete (data);
                    data = null;
                }
            } else if (merger != null || ShouldOverwrite (data, json)) {
                data = data ?? new UserData ();
                ImportJson (ctx, data, json);

                if (merger != null) {
                    merger.Add (data);
                    data = merger.Result;
                }

                if (merger != null) {
                    log.Info (Tag, "Importing {0}, merging with local data.", data.ToIdString ());
                } else {
                    log.Info (Tag, "Importing {0}, replacing local data.", data.ToIdString ());
                }

                data = ctx.Put (data);
            } else {
                log.Info (Tag, "Skipping import of {0}.", json.ToIdString ());
            }

            return data;
        }
        public override void SetUp ()
        {
            base.SetUp ();

            RunAsync (async delegate {
                workspace = await DataStore.PutAsync (new WorkspaceData () {
                    Name = "Test",
                });

                user = await DataStore.PutAsync (new UserData () {
                    Name = "John Doe",
                    TrackingMode = TrackingMode.StartNew,
                    DefaultWorkspaceId = workspace.Id,
                });

                await SetUpFakeUser (user.Id);

                ServiceContainer.Register<ISyncManager> (Mock.Of<ISyncManager> (
                    (mgr) => mgr.IsRunning == syncManagerRunning));
                ServiceContainer.Register<ActiveTimeEntryManager> (new ActiveTimeEntryManager ());
            });
        }
        public UserJson Export (IDataStoreContext ctx, UserData data)
        {
            var defaultWorkspaceId = GetRemoteId<WorkspaceData> (ctx, data.DefaultWorkspaceId);

            return new UserJson () {
                Id = data.RemoteId,
                ModifiedAt = data.ModifiedAt.ToUtc (),
                Name = data.Name,
                Email = data.Email,
                StartOfWeek = data.StartOfWeek,
                DateFormat = data.DateFormat,
                TimeFormat = data.TimeFormat,
                ImageUrl = data.ImageUrl,
                Locale = data.Locale,
                Timezone = data.Timezone,
                SendProductEmails = data.SendProductEmails,
                SendTimerNotifications = data.SendTimerNotifications,
                SendWeeklyReport = data.SendWeeklyReport,
                StoreStartAndStopTime = data.TrackingMode == TrackingMode.StartNew,
                DefaultWorkspaceId = defaultWorkspaceId,
            };
        }
 private DateTime ResolveStartDate ( DateTime currentDate, ZoomLevel period, UserData usr)
 {
     DateTime result;
     if (period == ZoomLevel.Week) {
         result = currentDate.StartOfWeek (usr.StartOfWeek);
     } else if (period == ZoomLevel.Month) {
         result = new DateTime (currentDate.Year, currentDate.Month, 1);
     } else {
         result = new DateTime (currentDate.Year, 1, 1);
     }
     return result;
 }
Beispiel #13
0
        private async Task CreateTestData ()
        {
            workspace = await DataStore.PutAsync (new WorkspaceData () {
                RemoteId = 1,
                Name = "Unit Testing",
            });

            user = await DataStore.PutAsync (new UserData () {
                RemoteId = 1,
                Name = "Tester",
                DefaultWorkspaceId = workspace.Id,
            });

            var project = await DataStore.PutAsync (new ProjectData () {
                RemoteId = 1,
                Name = "Ad design",
                WorkspaceId = workspace.Id,
            });

            await DataStore.PutAsync (new TimeEntryData () {
                RemoteId = 1,
                Description = "Initial concept",
                State = TimeEntryState.Finished,
                StartTime = MakeTime (09, 12),
                StopTime = MakeTime (10, 1),
                ProjectId = project.Id,
                WorkspaceId = workspace.Id,
                UserId = user.Id,
            });

            await DataStore.PutAsync (new TimeEntryData () {
                RemoteId = 2,
                Description = "Breakfast",
                State = TimeEntryState.Finished,
                StartTime = MakeTime (10, 5),
                StopTime = MakeTime (10, 30),
                WorkspaceId = workspace.Id,
                UserId = user.Id,
            });

            await DataStore.PutAsync (new TimeEntryData () {
                RemoteId = 3,
                Description = "Initial concept",
                State = TimeEntryState.Finished,
                StartTime = MakeTime (10, 35),
                StopTime = MakeTime (12, 21),
                ProjectId = project.Id,
                WorkspaceId = workspace.Id,
                UserId = user.Id,
            });

            await DataStore.PutAsync (new TimeEntryData () {
                RemoteId = 4,
                State = TimeEntryState.Finished,
                StartTime = MakeTime (12, 25),
                StopTime = MakeTime (13, 57),
                ProjectId = project.Id,
                WorkspaceId = workspace.Id,
                UserId = user.Id,
            });

            await DataStore.PutAsync (new TimeEntryData () {
                RemoteId = 5,
                State = TimeEntryState.Finished,
                StartTime = MakeTime (14, 0),
                StopTime = MakeTime (14, 36),
                WorkspaceId = workspace.Id,
                UserId = user.Id,
            });
        }
Beispiel #14
0
 public static UserData Import (this UserJson json, IDataStoreContext ctx,
                                Guid? localIdHint = null, UserData mergeBase = null)
 {
     var converter = ServiceContainer.Resolve<UserJsonConverter> ();
     return converter.Import (ctx, json, localIdHint, mergeBase);
 }
        private void FormatActivityTimeData ( IList<ReportActivity> activities, UserData user)
        {
            for (int i = 0; i < activities.Count; i++) {
                var activity = activities [i];

                string formattedString = string.Empty;
                if (activity.TotalTime > 0) {
                    TimeSpan duration = TimeSpan.FromSeconds (activity.TotalTime);
                    decimal totalHours = Math.Floor ((decimal)duration.TotalHours);

                    formattedString = String.Format ("{0}:{1}", (int)totalHours, duration.ToString (@"mm"));
                    if (user.DurationFormat == DurationFormat.Decimal) {
                        formattedString = String.Format ("{0:0.00} h", duration.TotalHours);
                    }
                }

                activity.FormattedTotalTime = formattedString;
                activities [i] = activity;
            }
        }
 private void FormatTimeData ( IList<ReportProject> items, UserData user)
 {
     for (int i = 0; i < items.Count; i++) {
         var project = items[i];
         project.FormattedTotalTime = GetFormattedTime (user, project.TotalTime);
         project.FormattedBillableTime = GetFormattedTime (user, project.BillableTime);
         items[i] = project;
     }
 }
        private string GetFormattedTime ( UserData user, long milliseconds)
        {
            TimeSpan duration = TimeSpan.FromMilliseconds ( milliseconds);
            decimal totalHours = Math.Floor ((decimal)duration.TotalHours);
            string formattedString = String.Format ("{0}:{1}:{2}", (int)totalHours, duration.ToString (@"mm"), duration.ToString (@"ss"));

            if ( user!= null) {
                if ( user.DurationFormat == DurationFormat.Classic) {
                    if (duration.TotalMinutes < 1) {
                        formattedString = duration.ToString (@"s\ \s\e\c");
                    } else if (duration.TotalMinutes > 1 && duration.TotalMinutes < 60) {
                        formattedString = duration.ToString (@"mm\:ss\ \m\i\n");
                    }
                } else if (user.DurationFormat == DurationFormat.Decimal) {
                    formattedString = String.Format ("{0:0.00} h", duration.TotalHours);
                }
            }
            return formattedString;
        }