Beispiel #1
0
        private static void OnViewModelClosed(object sender, EventArgs e)
        {
            var viewModel = (IViewModel)sender;

            AuditingManager.OnViewModelClosed(viewModel);

            UnsubscribeEvents(viewModel);
        }
Beispiel #2
0
        /// <summary>
        /// Registers the view model to the <see cref="AuditingManager"/>.
        /// <para />
        /// This helper will automatically unsubscribe from all events when the view model is closed.
        /// </summary>
        /// <param name="viewModel">The view model to register.</param>
        /// <remarks>
        /// This helper will call the <see cref="AuditingManager.OnViewModelCreating"/> and <see cref="AuditingManager.OnViewModelCreated"/>
        /// automatically.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        public static void RegisterViewModel(IViewModel viewModel)
        {
            Argument.IsNotNull("viewModel", viewModel);

            AuditingManager.OnViewModelCreating(viewModel.GetType());

            SubscribeEvents(viewModel);

            AuditingManager.OnViewModelCreated(viewModel.GetType());
        }
Beispiel #3
0
        private static Task OnViewModelClosingAsync(object sender, EventArgs e)
        {
            if (!AuditingManager.IsAuditingEnabled)
            {
                return(TaskHelper.Completed);
            }

            AuditingManager.OnViewModelClosing((IViewModel)sender);

            return(TaskHelper.Completed);
        }
Beispiel #4
0
        private static Task OnViewModelCommandExecutedAsync(object sender, CommandExecutedEventArgs e)
        {
            if (!AuditingManager.IsAuditingEnabled)
            {
                return(TaskHelper.Completed);
            }

            AuditingManager.OnCommandExecuted((IViewModel)sender, e.CommandPropertyName, e.Command, e.CommandParameter);

            return(TaskHelper.Completed);
        }
Beispiel #5
0
        private static void OnViewModelPropertyChanging(object sender, PropertyChangingEventArgs e)
        {
            var viewModel = (IViewModel)sender;

            object propertyValue = null;

            if (!string.IsNullOrEmpty(e.PropertyName))
            {
                PropertyHelper.TryGetPropertyValue(viewModel, e.PropertyName, out propertyValue);
            }

            AuditingManager.OnPropertyChanging(viewModel, e.PropertyName, propertyValue);
        }
Beispiel #6
0
        private static Task OnViewModelClosedAsync(object sender, EventArgs e)
        {
            if (!AuditingManager.IsAuditingEnabled)
            {
                return(TaskHelper.Completed);
            }

            var viewModel = (IViewModel)sender;

            AuditingManager.OnViewModelClosed(viewModel);

            UnsubscribeEvents(viewModel);

            return(TaskHelper.Completed);
        }
Beispiel #7
0
        /// <summary>
        /// Registers the view model to the <see cref="AuditingManager"/>.
        /// <para />
        /// This helper will automatically unsubscribe from all events when the view model is closed.
        /// </summary>
        /// <param name="viewModel">The view model to register.</param>
        /// <remarks>
        /// This helper will call the <see cref="AuditingManager.OnViewModelCreating"/> and <see cref="AuditingManager.OnViewModelCreated"/>
        /// automatically.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        public static void RegisterViewModel(IViewModel viewModel)
        {
            Argument.IsNotNull("viewModel", viewModel);

            var isAuditingEnabled = AuditingManager.IsAuditingEnabled;

            if (isAuditingEnabled)
            {
                AuditingManager.OnViewModelCreating(viewModel.GetType());
            }

            SubscribeEvents(viewModel);

            if (isAuditingEnabled)
            {
                AuditingManager.OnViewModelCreated(viewModel);
            }
        }
Beispiel #8
0
        private static void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (!AuditingManager.IsAuditingEnabled)
            {
                return;
            }

            var viewModel = (IViewModel)sender;

            object propertyValue = null;

            if (!string.IsNullOrEmpty(e.PropertyName) && !KnownIgnoredPropertyNames.Contains(e.PropertyName))
            {
                PropertyHelper.TryGetPropertyValue(viewModel, e.PropertyName, out propertyValue);
            }

            AuditingManager.OnPropertyChanged(viewModel, e.PropertyName, propertyValue);
        }
Beispiel #9
0
 private static void OnViewModelClosing(object sender, EventArgs e)
 {
     AuditingManager.OnViewModelClosing((IViewModel)sender);
 }
Beispiel #10
0
 private static void OnViewModelCommandExecuted(object sender, CommandExecutedEventArgs e)
 {
     AuditingManager.OnCommandExecuted((IViewModel)sender, e.CommandPropertyName, e.Command, e.CommandParameter);
 }