Ejemplo n.º 1
0
        /// <summary>
        /// Handles updating the value of <see cref="FieldEditorViewModel"/>.
        /// This is asynchronous so cannot be done with a property setter.
        /// </summary>
        /// <param name="value">The new ViewModel value.</param>
        /// <returns>A task that completes when the update is finished.</returns>
        private async Task UpdateFieldEditorViewModel(IFieldEditorViewModel value)
        {
            IFieldEditorViewModel oldViewModel = this._fieldEditorViewModel;

            if (oldViewModel != value)
            {
                this._fieldEditorViewModel = value;
                if (oldViewModel != null)
                {
                    await oldViewModel.SuspendAsync();

                    oldViewModel.CommitCommand.CanExecuteChanged -= FieldEditViewModelCanCommitChanged;
                }

                if (value != null)
                {
                    value.CommitCommand.CanExecuteChanged += FieldEditViewModelCanCommitChanged;
                    await value.ActivateAsync();
                }

                OnPropertyChanged(nameof(FieldEditorViewModel));
                this.commitFieldCommand.RaiseCanExecuteChanged();
            }
        }
Ejemplo n.º 2
0
        public void Initialize()
        {
            IRandomNumberGenerator rng = new Salsa20(new byte[32]);

            IResourceProvider resourceProvider = new MockResourceProvider();

            this.parentEntry = new MockEntry();
            this.parentEntry.Fields.Add(
                new KdbxString(ExistingFieldKey, ExistingFieldValue, rng, ExistingFieldProtected)
                );

            MethodInfo testMethod = GetType().GetRuntimeMethod(
                TestContext.TestName, new Type[0]
                );

            DetailsForAttribute specAttr = testMethod.GetCustomAttribute <DetailsForAttribute>();

            if (specAttr == null)
            {
                return;
            }
            else
            {
                if (specAttr.IsNew)
                {
                    this.viewModel = new FieldEditorViewModel(rng, resourceProvider);
                }
                else
                {
                    this.originalString = new KdbxString(EditedFieldKey, EditedFieldValue, rng, EditedFieldProtected);
                    this.parentEntry.Fields.Add(this.originalString);

                    this.viewModel = new FieldEditorViewModel(this.originalString, resourceProvider);
                }
            }
        }