public bool ModifyUser(int userID, AccessLevelEnum newAccessLevel, bool logOff, int logOffTimeout, int newPrevilages) { _logger.Info($"Method for modifying existing user in Db fired. User ID = {userID}, Access level = {newAccessLevel.ToString()}."); try { UserDefinition user = _realm.All <UserDefinition>().ToList().Single(x => x.Identity == userID); using (var trans = _realm.BeginWrite()) { user.AccessLevel = GetAccessLevelInt(newAccessLevel); user.LogoutEnabled = logOff; user.LogoutTime = logOffTimeout; user.LanguageEditorPrevilages = newPrevilages; trans.Commit(); } _logger.Info($"Modifying exisng user data in DB successfull."); return(true); } catch (Exception ex) { _logger.Error($"Error while trying to modify existing user data: {ex.Message}."); return(false); } }
public bool DeleteExistingSMSrecipient(int identity) { _logger.Info($"Method for deleting existing SMS recipient from DB fired."); try { SMSrecipientDefinition definition = _realm.All <SMSrecipientDefinition>().Single(x => x.Identity == identity); using (var trans = _realm.BeginWrite()) { _realm.Remove(definition); trans.Commit(); } _logger.Info($"Deleting of SMS recipient with ID = {identity} successfull."); DeleteRecipientFromGroups(identity); return(true); } catch (Exception ex) { _logger.Error($"Error while trying to delete existing SMS recipient from DB: {ex.Message}."); return(false); } }
public void AddPage(RealmPage page) { transaction = realm.BeginWrite(); var entry = realm.Add(page); transaction.Commit(); }
public void BindingPerformanceTest(int totalRecs, int recsPerTrans) { Console.WriteLine($"Binding-based performance check for {totalRecs:n} entries at {recsPerTrans} ops per transaction -------------"); var s = "String value"; var sw = Stopwatch.StartNew(); var numRecs = totalRecs / recsPerTrans; for (var rowIndex = 0; rowIndex < numRecs; rowIndex++) { using (var trans = _realm.BeginWrite()) { var hangOntoObjectsUntilCommit = new List <RealmObject>(); for (var iTrans = 0; iTrans < recsPerTrans; ++iTrans) { var p = _realm.CreateObject <Person>(); p.FirstName = s; p.IsInteresting = true; hangOntoObjectsUntilCommit.Add(p); } trans.Commit(); } } sw.Stop(); Console.WriteLine("Time spent: " + sw.Elapsed); Console.WriteLine("Kilo-iterations per second: {0:0.00}", (numRecs / 1000) / sw.Elapsed.TotalSeconds); }
/// <summary> /// Updates the value. /// </summary> /// <returns><c>true</c>, if value was updated, <c>false</c> otherwise.</returns> /// <param name="key">Key.</param> /// <param name="value">Value.</param> public bool UpdateDBValue(string key, string value) { try { var valueObject = (from k in realmDB.All <DBSettingsObjekt>() where k.Key == key select k); if (valueObject.Any()) { if (valueObject != null) { using (var trans = realmDB.BeginWrite()) { valueObject.First().Value = value; trans.Commit(); return(true); } } } else { this.SaveDBValue(key, value); return(true); } return(false); } catch { return(false); } }
//method for modifying main definition of alarm profile private bool ModifyMainDefinition(int identity, string comment, string modifiedBy) { _logger.Info($"Method for modifying main alarm profile definition fired. Identoty = {identity}."); try { AlarmProfileDefinition definition = _realm.All <AlarmProfileDefinition>().Single(x => x.Identity == identity); using (var trans = _realm.BeginWrite()) { definition.ModifiedBy = modifiedBy; definition.ProfileComment = comment; trans.Commit(); } _logger.Info($"Modifying main alarm profile definition successfull."); return(true); } catch (Exception ex) { _logger.Error($"Error while trying to modify alarm profile of identity: {identity} : {ex.Message}."); return(false); } }
public void Done(Todo task) { using (var trans = _instance.BeginWrite()) { task.Status = 0; trans.Commit(); } }
/// <summary> /// Removes (soft delete) a sensor /// </summary> /// <param name="id">The sensor id to soft delete</param> public void Remove(Sensor toDelete) { using (var trans = realm.BeginWrite()) { toDelete.IsDeleted = true; trans.Commit(); } }
public void DeleteBook(Book book) { using (var trans = _realm.BeginWrite()) { _realm.Remove(book); trans.Commit(); } }
public void Done(Todo task) { task.DeleteNotification(); using (var trans = _instance.BeginWrite()) { task.Status = 0; trans.Commit(); } }
public bool SaveItem(ShoppingItem item) { using (var trans = _realm.BeginWrite()) { _realm.Manage(item); trans.Commit(); } return(item.IsValid); }
public void Remove <T>(T item) where T : RealmObject { // Delete an object with a transaction using (var trans = database.BeginWrite()) { database.Remove(item); trans.Commit(); } }
/// <summary> /// This method change the sensor calibration values /// </summary> /// <param name="sourcedValue">The calibration source values (measured by the sensor)</param> /// <param name="revisedValue">The calibration revised (measured by the user by another way)</param> public void UpdateSensorCalibration(UserSettings entity, float sourcedValue, float revisedValue) { using (var trans = realm.BeginWrite()) { entity.CalibrationSourcedValue = sourcedValue; entity.CalibrationRevisedValue = revisedValue; entity.MeasureOffset += revisedValue - sourcedValue; trans.Commit(); } }
public void AddClicked() { var transaction = _realm.BeginWrite(); FirstViewModel firstViewModel = new FirstViewModel(true, transaction) { Navigation = Navigation }; Navigation.PushAsync(new FirstView(firstViewModel)); }
private void AddEntry() { var transaction = _realm.BeginWrite(); var entry = _realm.CreateObject <JournalEntry>(); entry.Date = DateTimeOffset.Now; var page = new JournalEntryDetailsPage(new JournalEntryDetailsViewModel(entry, transaction)); Navigation.PushAsync(page); }
/// <summary> /// Update the measure offset for a GlucoseMeasure /// </summary> /// <param name="measure">The measure to update</param> /// <param name="offsetValue">The offset value coming from the calibration</param> /// <param name="appSettings">The appSettings</param> public GlucoseMeasure UpdateMeasureOffset(GlucoseMeasure measure, float calibrationOffset, AppSettings appSettings) { using (var trans = realm.BeginWrite()) { measure.CalibrationOffset = calibrationOffset; measure.GlucoseLevelMGDL = (float)Math.Round((decimal)measure.GlucoseLevelRaw / 10) + calibrationOffset; measure.GlucoseLevelMMOL = (float)FreeStyleLibreUtils.ConvertMGDLToMMolPerLiter(appSettings, measure.GlucoseLevelMGDL); trans.Commit(); } return(measure); }
protected void MakeThreePeople() { Person p1, p2, p3; using (var transaction = _realm.BeginWrite()) { p1 = _realm.CreateObject <Person>(); p1.FirstName = "John"; p1.LastName = "Smith"; p1.IsInteresting = true; p1.Email = "*****@*****.**"; p1.Salary = 30000; p1.Score = -0.9907f; p1.Latitude = 51.508530; p1.Longitude = 0.076132; p1.Birthday = new DateTimeOffset(1959, 3, 13, 0, 0, 0, TimeSpan.Zero); p1.PublicCertificateBytes = new byte[] { 0xca, 0xfe, 0xba, 0xbe }; p1.OptionalAddress = "12 Cosgrove St."; p1.IsAmbivalent = true; transaction.Commit(); } using (var transaction = _realm.BeginWrite()) { p2 = _realm.CreateObject <Person>(); p2.FullName = "John Doe"; // uses our setter whcih splits and maps to First/Lastname p2.IsInteresting = false; p2.Email = "*****@*****.**"; p2.Salary = 60000; p2.Score = 100; p2.Latitude = 40.7637286; p2.Longitude = -73.9748113; p2.Birthday = new DateTimeOffset(1963, 4, 14, 0, 0, 0, TimeSpan.Zero); p2.PublicCertificateBytes = new byte[] { 0xde, 0xad, 0xbe, 0xef }; p2.OptionalAddress = string.Empty; p2.IsAmbivalent = false; transaction.Commit(); } using (var transaction = _realm.BeginWrite()) { p3 = _realm.CreateObject <Person>(); p3.FullName = "Peter Jameson"; p3.Email = "*****@*****.**"; p3.Salary = 87000; p3.IsInteresting = true; p3.Score = 42.42f; p3.Latitude = 37.7798657; p3.Longitude = -122.394179; p3.Birthday = new DateTimeOffset(1989, 2, 25, 0, 0, 0, TimeSpan.Zero); transaction.Commit(); } }
void btnAdicionar_Clicked(object sender, System.EventArgs e) { SistemaOperacional iOS; //Transação que implementa IDispose , Necessario Commit using (var transaction = _realm.BeginWrite()) { iOS = new SistemaOperacional { Nome = "iOS", Versao = 11.3, Id = 1 }; _realm.Add(iOS); transaction.Commit(); } SistemaOperacional Android; //Transação implícita será comitada por padrão _realm.Write(() => { Android = new SistemaOperacional { Nome = "Android", Versao = 8.1, Id = 2 }; _realm.Add(Android); }); SistemaOperacional WindowsPhone = new SistemaOperacional { Nome = "WindowsPhone", Versao = 10, Id = 3 }; _realm.Write(() => { WindowsPhone = _realm.Add(WindowsPhone); }); ExibeSistemasOperacionais(); }
public void SetAndGetValue(string propertyName, object propertyValue) { AllTypesObject ato; using (var transaction = _realm.BeginWrite()) { ato = _realm.CreateObject <AllTypesObject>(); TestHelpers.SetPropertyValue(ato, propertyName, propertyValue); transaction.Commit(); } Assert.That(TestHelpers.GetPropertyValue(ato, propertyName), Is.EqualTo(propertyValue)); }
private void AddEntry() { var transaction = _realm.BeginWrite(); var entry = _realm.CreateObject <JournalEntry>(); var metadata = _realm.CreateObject <EntryMetadata>(); metadata.Date = DateTimeOffset.Now; metadata.Author = AuthorName; entry.Metadata = metadata; var page = new JournalEntryDetailsPage(new JournalEntryDetailsViewModel(entry, transaction)); Navigation.PushAsync(page); }
/// <inheritdoc /> public T SaveItem <T>(T item) where T : RealmObject { if (item == null) { return(null); } var newItem = new object(); using (var trans = _realm.BeginWrite()) { newItem = _realm.Add(item, true); trans.Commit(); } return((T)newItem); }
public void CreateObjectRealm() { Stopwatch watchRealm = Stopwatch.StartNew(); transaction = connection.BeginWrite(); for (int i = 0; i < 1000; i++) { connection.Add(new ObjetoRealmN(i, i)); } transaction.Commit(); watchRealm.Stop(); Tiempos.watchRealmCreate = watchRealm.ElapsedMilliseconds; // Console.WriteLine(Tiempos.watchRealmCreate.ToString()); }
private static void AddDummyData(Realm realm, bool singleTransaction) { Action <Action> write; Transaction currentTransaction = null; if (singleTransaction) { write = action => action(); currentTransaction = realm.BeginWrite(); } else { write = realm.Write; } for (var i = 0; i < DummyDataSize; i++) { write(() => { realm.Add(new ObjectIdPrimaryKeyWithValueObject { StringValue = "Super secret product " + i }); }); } if (singleTransaction) { currentTransaction.Commit(); currentTransaction = realm.BeginWrite(); } var objs = realm.All <ObjectIdPrimaryKeyWithValueObject>(); for (var i = 0; i < DummyDataSize / 2; i++) { write(() => { var item = objs.ElementAt(i); realm.Remove(item); }); } if (singleTransaction) { currentTransaction.Commit(); } }
private bool ModifyGroup(int identity, string modifiedBy, byte[] recipientsArray, int amountOfRecipients) { _logger.Info($"Method for modifying SMS recipients group with ID: {identity} started."); try { SMSrecipientsGroupDefinition definition = _realm.All <SMSrecipientsGroupDefinition>().Single(x => x.Identity == identity); using (var trans = _realm.BeginWrite()) { definition.ModifiedBy = modifiedBy; definition.RecipientsArray = recipientsArray; definition.AmountOfRecipients = amountOfRecipients; trans.Commit(); } _logger.Info($"Modifying SMS recipients group with ID = {identity} successfull."); return(true); } catch (Exception ex) { _logger.Error($"Error while trying to modify existing SMS recipients group with ID: {identity}. Exception: {ex.Message}."); return(false); } }
public async Task <bool> RemoveEmployee(EmployeeViewModel employee) { try { _realm = Realm.GetInstance("RealmTest"); _realm.Refresh(); int employeeID = employee.EmployeeID; var originalEmployee = _realm.All <Employee>().First(x => x.EmployeeID == employeeID); // NOTE: Cascading deletes are not currently supported with Realm using (var trans = _realm.BeginWrite()) { _realm.Remove(originalEmployee); trans.Commit(); } Device.BeginInvokeOnMainThread(() => { Employees.Remove(employee); }); } catch (Exception ex) { //throw ex; return(false); } return(true); }
private void doInTransaction(Action <object, object> action, object o1, object o2) { var transaction = realm.BeginWrite(); action.DynamicInvoke(o1, o2); transaction.Commit(); }
public bool ModifyNlogConfigDefinition(int identity, string modifiedBy, bool deleteOldLogs, int deleteOldLogDays, int hoursToNewLogFile, bool activated, bool dontChangeModifiedBy) { _logger.Info($"Method for NLog configuration modification fired. Identity = {identity}, change only acivitiness = {dontChangeModifiedBy}."); try { NLogConfigurationDefinition definition = _realm.All <NLogConfigurationDefinition>().Single(x => x.Identity == identity); using (var trans = _realm.BeginWrite()) { if (!dontChangeModifiedBy) { definition.ModifiedBy = modifiedBy; } definition.OldLogDeletion = deleteOldLogs; definition.OldLogDeletionDays = deleteOldLogDays; definition.HoursToCreateNewLogFile = hoursToNewLogFile; definition.ConfigActivated = activated; trans.Commit(); } _logger.Info("Changing NLog configuration successfull."); return(true); } catch (Exception ex) { _logger.Error($"Error while trying to modify existing Nlog config definition: {ex.Message}."); return(false); } }
//Insertar nueva mascota public void InsertarMascota(Mascota m) { transaction = conexionRealm.BeginWrite(); var entry = conexionRealm.Add(m); transaction.Commit(); }
public async Task InitListView() { Realm RealmContext = null; try { if (User.AllLoggedIn.Count() > 1) { foreach (var _u in User.AllLoggedIn) { await _u.LogOutAsync(); } } if (User.Current == null) { if (await MyRealm.Login(API_USERNAME, API_PASSWORD) == null) { return; } } RealmContext = MyRealm.RealmContext; using (var transaction = RealmContext.BeginWrite()) { RealmContext.RemoveAll <TrackMessage>(); RealmContext.Add(new TrackMessage { Id = 0, Text = "Please wait, service starting" }); transaction.Commit(); } listView.ItemsSource = TrackMessage = RealmContext.All <TrackMessage>(); } catch (Exception e) { Console.WriteLine($"{Constants.TAG} Erreur {e.GetType().FullName} {e.Message}"); } }
private void performBasicWrite(Realm realm) { var transaction = realm.BeginWrite(); realm.Add(new BeatmapInfo("test1")); transaction.Commit(); }
public void SetUp() { Realm.DeleteRealm(RealmConfiguration.DefaultConfiguration); realm = Realm.GetInstance(); // we don't keep any variables pointing to these as they are all added to Realm using (var trans = realm.BeginWrite()) { var o1 = realm.Add(new Owner { Name = "Tim" }); var d1 = realm.Add(new Dog { Name = "Bilbo Fleabaggins", Color = "Black" }); o1.TopDog = d1; // set a one-one relationship o1.Dogs.Add(d1); var d2 = realm.Add(new Dog { Name = "Earl Yippington III", Color = "White" }); o1.Dogs.Add(d2); // lonely people and dogs realm.Add(new Owner { Name = "Dani" // the dog-less }); realm.Add(new Dog // will remain unassigned { Name = "Maggie Mongrel", Color = "Grey" }); trans.Commit(); } }