Esempio n. 1
0
        public async Task <bool> SyncCipherAsync(string id)
        {
            if (!_authService.IsAuthenticated)
            {
                return(false);
            }

            SyncStarted();

            var cipher = await _cipherApiRepository.GetByIdAsync(id).ConfigureAwait(false);

            if (!CheckSuccess(cipher))
            {
                return(false);
            }

            try
            {
                var existingCipher = await _cipherService.GetByIdAsync(cipher.Result.Id);

                var cipherData = new CipherData(cipher.Result, _authService.UserId);
                await _cipherService.UpsertDataAsync(cipherData, true, existingCipher == null).ConfigureAwait(false);

                var localAttachments = (await _attachmentRepository.GetAllByCipherIdAsync(cipherData.Id)
                                        .ConfigureAwait(false));

                if (cipher.Result.Attachments != null)
                {
                    var attachmentData = cipher.Result.Attachments.Select(a => new AttachmentData(a, cipherData.Id));
                    await _cipherService.UpsertAttachmentDataAsync(attachmentData).ConfigureAwait(false);
                }

                if (localAttachments != null)
                {
                    foreach (var attachment in localAttachments
                             .Where(a => !cipher.Result.Attachments.Any(sa => sa.Id == a.Id)))
                    {
                        try
                        {
                            await _cipherService.DeleteAttachmentDataAsync(attachment.Id).ConfigureAwait(false);
                        }
                        catch (SQLite.SQLiteException) { }
                    }
                }
            }
            catch (SQLite.SQLiteException)
            {
                SyncCompleted(false);
                return(false);
            }

            SyncCompleted(true);
            return(true);
        }
Esempio n. 2
0
        private async Task LoadAttachmentsAsync()
        {
            _cipher = await _cipherService.GetByIdAsync(_cipherId);

            if (_cipher == null)
            {
                await Navigation.PopForDeviceAsync();

                return;
            }

            var attachmentsToAdd = _cipher.Attachments
                                   .Select(a => new VaultAttachmentsPageModel.Attachment(a, _cipher.OrganizationId))
                                   .OrderBy(s => s.Name);

            PresentationAttchments.ResetWithRange(attachmentsToAdd);
            AdjustContent();
        }
Esempio n. 3
0
        private void Init()
        {
            Cipher = _cipherService.GetByIdAsync(_cipherId).GetAwaiter().GetResult();
            if (Cipher == null)
            {
                // TODO: handle error. navigate back? should never happen...
                return;
            }

            // Name
            NameCell            = new FormEntryCell(AppResources.Name);
            NameCell.Entry.Text = Cipher.Name?.Decrypt(Cipher.OrganizationId);

            // Notes
            NotesCell             = new FormEditorCell(Keyboard.Text, Cipher.Type == CipherType.SecureNote ? 500 : 180);
            NotesCell.Editor.Text = Cipher.Notes?.Decrypt(Cipher.OrganizationId);

            // Folders
            var folderOptions = new List <string> {
                AppResources.FolderNone
            };

            Folders = _folderService.GetAllAsync().GetAwaiter().GetResult()
                      .OrderBy(f => f.Name?.Decrypt()).ToList();
            int selectedIndex = 0;
            int i             = 0;

            foreach (var folder in Folders)
            {
                i++;
                if (folder.Id == Cipher.FolderId)
                {
                    selectedIndex = i;
                }

                folderOptions.Add(folder.Name.Decrypt());
            }
            FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());
            FolderCell.Picker.SelectedIndex = selectedIndex;

            // Favorite
            FavoriteCell = new ExtendedSwitchCell
            {
                Text = AppResources.Favorite,
                On   = Cipher.Favorite
            };

            // Delete
            DeleteCell = new ExtendedTextCell {
                Text = AppResources.Delete, TextColor = Color.Red
            };

            InitTable();
            InitSave();

            Title   = AppResources.EditItem;
            Content = Table;
            if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
            {
                ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
            }
        }
Esempio n. 4
0
        public static async Task <ASPasswordCredentialIdentity> GetCipherIdentityAsync(string cipherId, ICipherService cipherService)
        {
            var cipher = await cipherService.GetByIdAsync(cipherId);

            return(ToCredentialIdentity(cipher));
        }