public void SetPropertiesFrom(IDatabaseTimeEntry entity, Realms.Realm realm)
        {
            IsDeleted            = entity.IsDeleted;
            SyncStatus           = entity.SyncStatus;
            LastSyncErrorMessage = entity.LastSyncErrorMessage;
            Id = entity.Id;
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null : realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId);
            var skipProjectFetch = entity?.ProjectId == null || entity.ProjectId == 0;

            RealmProject = skipProjectFetch ? null : realm.All <RealmProject>().Single(x => x.Id == entity.ProjectId);
            var skipTaskFetch = entity?.TaskId == null || entity.TaskId == 0;

            RealmTask   = skipTaskFetch ? null : realm.All <RealmTask>().Single(x => x.Id == entity.TaskId);
            Billable    = entity.Billable;
            Start       = entity.Start;
            Stop        = entity.Stop;
            Description = entity.Description;
            RealmTags.Clear();
            if (entity.TagIds != null)
            {
                var allRealmTags = entity.TagIds.Select(id => realm.All <RealmTag>().Single(x => x.Id == id));
                foreach (var oneOfRealmTags in allRealmTags)
                {
                    RealmTags.Add(oneOfRealmTags);
                }
            }
            At = entity.At;
            ServerDeletedAt = entity.ServerDeletedAt;
            var skipUserFetch = entity?.UserId == null || entity.UserId == 0;

            RealmUser   = skipUserFetch ? null : realm.All <RealmUser>().Single(x => x.Id == entity.UserId);
            CreatedWith = entity.CreatedWith;
        }
Beispiel #2
0
 public void Reset()
 {
     Task.Run(() =>
     {
         RealmType.DeleteRealm(Config);
     });
 }
Beispiel #3
0
        protected static async Task <List <string> > GenerateRealmDB(Realms.Realm targetCache, int size)
        {
            var ret = new List <string>();

            // Write out in groups of 4096
            while (size > 0)
            {
                var toWriteSize = Math.Min(4096, size);
                var toWrite     = PerfHelper.GenerateRandomDatabaseContents(toWriteSize);

                await targetCache.WriteAsync((Realms.Realm realm) =>
                {
                    foreach (var item in toWrite)
                    {
                        var c   = new KeyValueRecord();
                        c.Key   = item.Key;
                        c.Value = item.Value;
                        realm.Manage <KeyValueRecord>(c);                        // update: false
                    }
                });

                foreach (var k in toWrite.Keys)
                {
                    ret.Add(k);
                }
                size -= toWrite.Count;
            }
            return(ret);
        }
Beispiel #4
0
        protected static async Task <List <string> > GenerateRealmDB(Realms.Realm targetCache, int size)
        {
            var ret = new List <string>();

            // Write out in groups of 4096
            while (size > 0)
            {
                var toWriteSize = Math.Min(4096, size);
                var toWrite     = PerfHelper.GenerateRandomDatabaseContents(toWriteSize);

                using (var rt = new RealmThread(targetCache.Config))
                {
                    await rt.InvokeAsync(async(Realms.Realm arg) =>
                    {
                        await arg.WriteAsync((r) =>
                        {
                            foreach (var item in toWrite)
                            {
                                var c = new KeyValueRecord {
                                    Key = item.Key, Value = item.Value
                                };
                                r.Add(c);                                 // update: false
                            }
                        });
                    });
                }
                foreach (var k in toWrite.Keys)
                {
                    ret.Add(k);
                }
                size -= toWrite.Count;
            }
            return(ret);
        }
Beispiel #5
0
        private void GetUserInfo()
        {
            Realms.Realm realm = Realms.Realm.GetInstance();
            CurrentUser = realm.All <User>().Last();

            UserEmail = CurrentUser.Email;
        }
Beispiel #6
0
        public RealmTimeEntry(ITimeEntry entity, Realms.Realm realm)
        {
            Id = entity.Id;
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null :realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId);
            var skipProjectFetch = entity?.ProjectId == null || entity.ProjectId == 0;

            RealmProject = skipProjectFetch ? null :realm.All <RealmProject>().Single(x => x.Id == entity.ProjectId);
            var skipTaskFetch = entity?.TaskId == null || entity.TaskId == 0;

            RealmTask       = skipTaskFetch ? null :realm.All <RealmTask>().Single(x => x.Id == entity.TaskId);
            Billable        = entity.Billable;
            Start           = entity.Start;
            Stop            = entity.Stop;
            Duration        = entity.Duration;
            Description     = entity.Description;
            Tags            = entity.Tags;
            TagIds          = entity.TagIds;
            At              = entity.At;
            ServerDeletedAt = entity.ServerDeletedAt;
            var skipUserFetch = entity?.UserId == null || entity.UserId == 0;

            RealmUser   = skipUserFetch ? null :realm.All <RealmUser>().Single(x => x.Id == entity.UserId);
            CreatedWith = entity.CreatedWith;
            IsDirty     = true;
        }
Beispiel #7
0
        public void SetPropertiesFrom(IDatabaseTimeEntry entity, Realms.Realm realm)
        {
            At = entity.At;
            ServerDeletedAt      = entity.ServerDeletedAt;
            IsDeleted            = entity.IsDeleted;
            SyncStatus           = entity.SyncStatus;
            LastSyncErrorMessage = entity.LastSyncErrorMessage;
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null : realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId || x.OriginalId == entity.WorkspaceId);
            var skipProjectFetch = entity?.ProjectId == null || entity.ProjectId == 0;

            RealmProject = skipProjectFetch ? null : realm.All <RealmProject>().SingleOrDefault(x => x.Id == entity.ProjectId || x.OriginalId == entity.ProjectId);
            var skipTaskFetch = RealmProject == null || entity?.TaskId == null || entity.TaskId == 0;

            RealmTask   = skipTaskFetch ? null : realm.All <RealmTask>().SingleOrDefault(x => x.Id == entity.TaskId || x.OriginalId == entity.TaskId);
            Billable    = entity.Billable;
            Start       = entity.Start;
            Duration    = entity.Duration;
            Description = entity.Description;

            var tags = entity.TagIds?.Select(id =>
                                             realm.All <RealmTag>().Single(x => x.Id == id || x.OriginalId == id)) ?? new RealmTag[0];

            RealmTags.Clear();
            tags.ForEach(RealmTags.Add);

            var skipUserFetch = entity?.UserId == null || entity.UserId == 0;

            RealmUser = skipUserFetch ? null : realm.All <RealmUser>().Single(x => x.Id == entity.UserId || x.OriginalId == entity.UserId);
        }
        public App(params INinjectModule[] patformModules)
        {
            InitializeComponent();
            var mainPage = new NavigationPage(new MainPage());

            // setup and get an instance to our current Realm
            CurrentRealm = Realms.Realm.GetInstance(new RealmConfiguration
            {
                SchemaVersion     = RealmConfigure.SchemaVersion,
                MigrationCallback = RealmConfigure.MigrationCallback,
            });

            CurrentRealm.Write(() =>
            {
                CurrentRealm.RemoveAll();
            });

            // Register all the our core services with the kernal
            Kernal = new StandardKernel(new CoreModule(), new NavigationModule(mainPage.Navigation));
            // Register all of our platform specific modules with the kernal
            Kernal.Load(patformModules);

            mainPage.BindingContext = Kernal.Get <MainViewModel>();
            MainPage = mainPage;
        }
Beispiel #9
0
        public void SetPropertiesFrom(IDatabaseProject entity, Realms.Realm realm)
        {
            At = entity.At;
            ServerDeletedAt      = entity.ServerDeletedAt;
            IsDeleted            = entity.IsDeleted;
            SyncStatus           = entity.SyncStatus;
            LastSyncErrorMessage = entity.LastSyncErrorMessage;
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null : realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId || x.OriginalId == entity.WorkspaceId);
            var skipClientFetch = entity?.ClientId == null || entity.ClientId == 0;

            RealmClient    = skipClientFetch ? null : realm.All <RealmClient>().Single(x => x.Id == entity.ClientId || x.OriginalId == entity.ClientId);
            Name           = entity.Name;
            IsPrivate      = entity.IsPrivate;
            Active         = entity.Active;
            Color          = entity.Color;
            Billable       = entity.Billable;
            Template       = entity.Template;
            AutoEstimates  = entity.AutoEstimates;
            EstimatedHours = entity.EstimatedHours;
            Rate           = entity.Rate;
            Currency       = entity.Currency;
            ActualHours    = entity.ActualHours;
        }
Beispiel #10
0
 public RealmTag(ITag entity, Realms.Realm realm)
 {
     Id             = entity.Id;
     RealmWorkspace = realm.All <RealmWorkspace>().Single(x => x.Id == WorkspaceId);
     Name           = entity.Name;
     At             = entity.At;
     IsDirty        = true;
 }
Beispiel #11
0
 public RealmClient(IClient entity, Realms.Realm realm)
 {
     Id              = entity.Id;
     RealmWorkspace  = realm.All <RealmWorkspace>().Single(x => x.Id == WorkspaceId);
     Name            = entity.Name;
     At              = entity.At;
     ServerDeletedAt = entity.ServerDeletedAt;
     IsDirty         = true;
 }
Beispiel #12
0
        public async Task <T> AddAsync <T>(T item, ITransaction transaction) where T : RealmObject
        {
            T?result = default;

            Realms.Realm realm = await GetRealmAsync();

            await this.RunInTransactionAsync(_ => { result = realm.Add(item); }, transaction);

            return(result !);
        }
Beispiel #13
0
        public RealmTag(ITag entity, Realms.Realm realm)
        {
            Id = entity.Id;
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null :realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId);
            Name           = entity.Name;
            At             = entity.At;
            IsDirty        = true;
        }
Beispiel #14
0
 public void SetPropertiesFrom(IDatabasePreferences entity, Realms.Realm realm)
 {
     IsDeleted            = entity.IsDeleted;
     SyncStatus           = entity.SyncStatus;
     LastSyncErrorMessage = entity.LastSyncErrorMessage;
     TimeOfDayFormat      = entity.TimeOfDayFormat;
     DateFormat           = entity.DateFormat;
     DurationFormat       = entity.DurationFormat;
     CollapseTimeEntries  = entity.CollapseTimeEntries;
 }
Beispiel #15
0
        private async Task <Realms.Realm> GetRealmAsync()
        {
            Realms.Realm realm = await _domainServiceLocator.Resolve <IRealmFactory>().GetDefaultSyncedRealmAsync();

            if (!_activeRealms.Contains(realm))
            {
                _activeRealms.Add(realm);
            }
            return(realm);
        }
Beispiel #16
0
        public void SetPropertiesFrom(IDatabaseWorkspaceFeatureCollection entity, Realms.Realm realm)
        {
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null : realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId || x.OriginalId == entity.WorkspaceId);
            foreach (var oneOfFeatures in entity.Features)
            {
                var oneOfRealmFeatures = RealmWorkspaceFeature.FindOrCreate(oneOfFeatures, realm);
                RealmWorkspaceFeatures.Add(oneOfRealmFeatures);
            }
        }
Beispiel #17
0
 public Task <T> Get <T>(string key)
 {
     return(Task.Run(() =>
     {
         using (var realm = RealmType.GetInstance(Config))
         {
             var result = realm.Find <LocalData>(key);
             return result == null ? default(T) : _jsonSerializer.Deserialize <T>(result.Data);
         }
     }));
 }
Beispiel #18
0
        public RealmClient(IClient entity, Realms.Realm realm)
        {
            Id = entity.Id;
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace  = skipWorkspaceFetch ? null :realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId);
            Name            = entity.Name;
            At              = entity.At;
            ServerDeletedAt = entity.ServerDeletedAt;
            IsDirty         = true;
        }
Beispiel #19
0
 public Task <bool> Exists(string key)
 {
     return(Task.Run(() =>
     {
         using (var realm = RealmType.GetInstance(Config))
         {
             var result = realm.Find <LocalData>(key);
             return result != null;
         }
     }));
 }
Beispiel #20
0
        public void SetPropertiesFrom(IDatabaseClient entity, Realms.Realm realm)
        {
            At = entity.At;
            ServerDeletedAt      = entity.ServerDeletedAt;
            IsDeleted            = entity.IsDeleted;
            SyncStatus           = entity.SyncStatus;
            LastSyncErrorMessage = entity.LastSyncErrorMessage;
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null : realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId || x.OriginalId == entity.WorkspaceId);
            Name           = entity.Name;
        }
 public void ConfigureInstance()
 {
     if (_config != null)
     {
         _realm = Realms.Realm.GetInstance(_config);
     }
     else
     {
         _realm = Realms.Realm.GetInstance();
     }
     _realm.Error += OnRealmError;
 }
        public void SetPropertiesFrom(IDatabaseTag entity, Realms.Realm realm)
        {
            IsDeleted            = entity.IsDeleted;
            SyncStatus           = entity.SyncStatus;
            LastSyncErrorMessage = entity.LastSyncErrorMessage;
            Id = entity.Id;
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null : realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId);
            Name           = entity.Name;
            At             = entity.At;
        }
Beispiel #23
0
 public RealmTask(ITask entity, Realms.Realm realm)
 {
     Id               = entity.Id;
     Name             = entity.Name;
     RealmProject     = realm.All <RealmProject>().Single(x => x.Id == ProjectId);
     RealmWorkspace   = realm.All <RealmWorkspace>().Single(x => x.Id == WorkspaceId);
     RealmUser        = realm.All <RealmUser>().Single(x => x.Id == UserId);
     EstimatedSeconds = entity.EstimatedSeconds;
     Active           = entity.Active;
     At               = entity.At;
     TrackedSeconds   = entity.TrackedSeconds;
     IsDirty          = true;
 }
Beispiel #24
0
 public void SetPropertiesFrom(IDatabaseUser entity, Realms.Realm realm)
 {
     At                   = entity.At;
     IsDeleted            = entity.IsDeleted;
     SyncStatus           = entity.SyncStatus;
     LastSyncErrorMessage = entity.LastSyncErrorMessage;
     ApiToken             = entity.ApiToken;
     DefaultWorkspaceId   = entity.DefaultWorkspaceId;
     Email                = entity.Email;
     Fullname             = entity.Fullname;
     BeginningOfWeek      = entity.BeginningOfWeek;
     Language             = entity.Language;
     ImageUrl             = entity.ImageUrl;
 }
Beispiel #25
0
        public Task <DateTimeOffset?> GetExpiration(string key)
        {
            return(Task.Run(() =>
            {
                using (var realm = RealmType.GetInstance(Config))
                {
                    var result = realm.Find <LocalData>(key);
                    if (result == null)
                    {
                        return default(DateTimeOffset?);
                    }

                    return DateTimeOffset.Parse(result.Timestamp, CultureInfo.InvariantCulture) as DateTimeOffset?;
                }
            }));
        }
        public DataOperation()
        {
            var realmConfig = new RealmConfiguration
            {
                ShouldDeleteIfMigrationNeeded = true,
                SchemaVersion = RealmVersion
            };

            _realm = Realms.Realm.GetInstance(realmConfig);

            _conversionRepository =
                new Lazy <IConversionRepository>(() => new RealmConversionRepository(_realm));
            _conversionsGroupRepository =
                new Lazy <IConversionsGroupRepository>(
                    () => new RealmConversionGroupRepository(_realm)
                    );
        }
Beispiel #27
0
        public static Realms.Realm GetInstance(RealmConfigurationBase config)
        {
            var context = SynchronizationContext.Current;

            SynchronizationContext.SetSynchronizationContext(null);

            Realms.Realm realm = null;
            try
            {
                realm = Realms.Realm.GetInstance(config);
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(context);
            }
            return(realm);
        }
Beispiel #28
0
        public RealmTask(ITask entity, Realms.Realm realm)
        {
            Id   = entity.Id;
            Name = entity.Name;
            var skipProjectFetch = entity?.ProjectId == null || entity.ProjectId == 0;

            RealmProject = skipProjectFetch ? null :realm.All <RealmProject>().Single(x => x.Id == entity.ProjectId);
            var skipWorkspaceFetch = entity?.WorkspaceId == null || entity.WorkspaceId == 0;

            RealmWorkspace = skipWorkspaceFetch ? null :realm.All <RealmWorkspace>().Single(x => x.Id == entity.WorkspaceId);
            var skipUserFetch = entity?.UserId == null || entity.UserId == 0;

            RealmUser        = skipUserFetch ? null :realm.All <RealmUser>().Single(x => x.Id == entity.UserId);
            EstimatedSeconds = entity.EstimatedSeconds;
            Active           = entity.Active;
            At             = entity.At;
            TrackedSeconds = entity.TrackedSeconds;
            IsDirty        = true;
        }
Beispiel #29
0
 public RealmTimeEntry(ITimeEntry entity, Realms.Realm realm)
 {
     Id              = entity.Id;
     RealmWorkspace  = realm.All <RealmWorkspace>().Single(x => x.Id == WorkspaceId);
     RealmProject    = realm.All <RealmProject>().Single(x => x.Id == ProjectId);
     RealmTask       = realm.All <RealmTask>().Single(x => x.Id == TaskId);
     Billable        = entity.Billable;
     Start           = entity.Start;
     Stop            = entity.Stop;
     Duration        = entity.Duration;
     Description     = entity.Description;
     Tags            = entity.Tags;
     TagIds          = entity.TagIds;
     At              = entity.At;
     ServerDeletedAt = entity.ServerDeletedAt;
     RealmUser       = realm.All <RealmUser>().Single(x => x.Id == UserId);
     CreatedWith     = entity.CreatedWith;
     IsDirty         = true;
 }
Beispiel #30
0
 public RealmWorkspace(IWorkspace entity, Realms.Realm realm)
 {
     Id                          = entity.Id;
     Name                        = entity.Name;
     Admin                       = entity.Admin;
     SuspendedAt                 = entity.SuspendedAt;
     ServerDeletedAt             = entity.ServerDeletedAt;
     DefaultHourlyRate           = entity.DefaultHourlyRate;
     DefaultCurrency             = entity.DefaultCurrency;
     OnlyAdminsMayCreateProjects = entity.OnlyAdminsMayCreateProjects;
     OnlyAdminsSeeBillableRates  = entity.OnlyAdminsSeeBillableRates;
     OnlyAdminsSeeTeamDashboard  = entity.OnlyAdminsSeeTeamDashboard;
     ProjectsBillableByDefault   = entity.ProjectsBillableByDefault;
     Rounding                    = entity.Rounding;
     RoundingMinutes             = entity.RoundingMinutes;
     At                          = entity.At;
     LogoUrl                     = entity.LogoUrl;
     IsDirty                     = true;
 }
Beispiel #31
0
 public override IDisposable OpenDB()
 {
     return this.realm = RealmType.GetInstance(RealmConfiguration.DefaultConfiguration.ConfigWithPath(this.Path));
 }