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; }
public void Reset() { Task.Run(() => { RealmType.DeleteRealm(Config); }); }
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); }
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); }
private void GetUserInfo() { Realms.Realm realm = Realms.Realm.GetInstance(); CurrentUser = realm.All <User>().Last(); UserEmail = CurrentUser.Email; }
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; }
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; }
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; }
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; }
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; }
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 !); }
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; }
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; }
private async Task <Realms.Realm> GetRealmAsync() { Realms.Realm realm = await _domainServiceLocator.Resolve <IRealmFactory>().GetDefaultSyncedRealmAsync(); if (!_activeRealms.Contains(realm)) { _activeRealms.Add(realm); } return(realm); }
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); } }
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); } })); }
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; }
public Task <bool> Exists(string key) { return(Task.Run(() => { using (var realm = RealmType.GetInstance(Config)) { var result = realm.Find <LocalData>(key); return result != null; } })); }
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; }
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; }
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; }
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) ); }
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); }
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; }
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; }
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; }
public override IDisposable OpenDB() { return this.realm = RealmType.GetInstance(RealmConfiguration.DefaultConfiguration.ConfigWithPath(this.Path)); }