private async void SaveUser() { try { UContact contact = new UContact(this.contact); contact.NickName = nickNameEntry.Text; contact.AlarmPermission = alarmSwitch.IsToggled; using (Context context = new Context(settings.Config)) { PushOperations.Update(context, contact, settings.UserPublicId, settings.UserPublicId); } if (contact.Trusted != trustedSwitch.IsToggled) { await SaveTrustification(trustedSwitch.IsToggled); } await Navigation.PopModalAsync(); } catch (Exception ex) { app.logger.LogException(this, ex); ShowError(ex.Source, ex.Message); } }
static void RenameThread(long threadId, string newName) { using (Context context = new Context(config)) { var toRename = new UMessageThread(context.MessagesThread .Where(u => u.Id == threadId) .Single(), settings.UserPublicId); toRename.Name = newName; PushOperations.Update(context, toRename, toRename.WithUser, settings.UserPublicId); context.SaveChanges(); } }
static void SetNickName(int userId, string nickName) { using (Context context = new Context(config)) { UContact contact = new UContact( context.Contacts .Where(u => u.PublicId == userId) .Single()); contact.NickName = nickName; PushOperations.Update(context, contact, settings.UserPublicId, settings.UserPublicId); } }
public int Pull() { int changes = 0; ThrowExceptionIfNotConnected(); lock (mutex) { Log("Sending PULL command."); BinaryEncoder.SendCommand(stream, ConnectionCommand.PULL); #if (DEBUG) Log("Sending ClientPullCapsula."); #endif ClientPullCapsula clientCapsula; using (Context context = new Context(config)) { clientCapsula = new ClientPullCapsula() { AesKeysUserIds = context.Contacts .Where(u => u.ReceiveAesKey == null) .Select(u => u.PublicId) .ToArray() }; } TextEncoder.SendJson(stream, clientCapsula); ServerPullCapsula capsula = TextEncoder.ReadJson <ServerPullCapsula>(stream); #if (DEBUG) Log("Received ServerPullCapsula."); #endif changes += capsula.AesKeysUserIds.Count; changes += capsula.Messages.Count; using (Context context = new Context(config)) { #if (DEBUG) Log("Receiving and saving AES keys."); #endif foreach (var id in capsula.AesKeysUserIds) { var user = new UContact(context.Contacts.Where(con => con.PublicId == id).SingleOrDefault()); try { user.ReceiveAesKey = RSAEncoder.DecryptAndVerify(BinaryEncoder.ReceiveBytes(stream), MyCertificate, X509Certificate2Utils.ImportFromPem(user.PublicCertificate)); } catch (Exception ex) { Log($"Loading of Receive AESKey from {user.PublicId} has failed."); logger.LogException(this, ex); } PushOperations.Update(context, user, UserId, UserId); } context.SaveChanges(); #if (DEBUG) Log("Receiving and saving messages."); #endif foreach (PullMessage metaMessage in capsula.Messages) { BlobMessages metaBlob = new BlobMessages() { PublicId = metaMessage.PublicId, SenderId = metaMessage.SenderId, Failed = 0, DoDelete = 0 }; context.BlobMessages.Add(metaBlob); context.SaveChanges(); try { PullMessageParser.ParseEncryptedMessage(context, BinaryEncoder.ReceiveBytes(stream), metaBlob.SenderId, metaBlob.Id, UserId); } catch (Exception ex) { Log($"Loading of message {metaMessage.PublicId} has failed."); metaBlob.Failed = 1; logger.LogException(this, ex); } context.SaveChanges(); } } Log("Pull have been done."); } return(changes); }