示例#1
0
        /// <summary>
        /// Creates and attaches the instance of <see cref="T:HomeCloud.DataStorage.Business.Handlers.IDataCommandHandler" /> type to execute data command.
        /// </summary>
        /// <typeparam name="T">The type of the handler derived from <see cref="T:HomeCloud.DataStorage.Business.Handlers.IDataCommandHandler" />.</typeparam>
        /// <returns>
        /// The instance of <see cref="T:HomeCloud.DataStorage.Business.Handlers.IDataCommandHandler" />.
        /// </returns>
        public IDataCommandHandler CreateDataHandler <T>() where T : IDataCommandHandler
        {
            IDataCommandHandler handler = this.commandHandlerFactory.Get <T>() as IDataCommandHandler;

            if (handler != null)
            {
                this.AddHandler(handler);
            }

            return(handler);
        }
示例#2
0
        /// <summary>
        /// Creates the asynchronous data command executed against each item in the list of instances of <see cref="T" /> type.
        /// </summary>
        /// <typeparam name="T">The type of item in the list of <see cref="IEnumerable{T}"/> type.</typeparam>
        /// <typeparam name="TDataProvider">The type of the data provider.</typeparam>
        /// <param name="handler">The handler.</param>
        /// <param name="items">The list of instances of <see cref="IEnumerable{T}"/> type.</param>
        /// <param name="executeAsyncAction">The asynchronous action to execute.</param>
        /// <param name="undoAsyncAction">The asynchronous action to undo.</param>
        /// <returns>
        /// The current instance of <see cref="IDataCommandHandler" />.
        /// </returns>
        public static IDataCommandHandler CreateAsyncCommandFor <T, TDataProvider>(this IDataCommandHandler handler, IEnumerable <T> items, Func <IDataProvider, T, Task> executeAsyncAction, Func <IDataProvider, T, Task> undoAsyncAction)
            where TDataProvider : IDataProvider
        {
            if (items is null)
            {
                return(handler);
            }

            foreach (T item in items)
            {
                handler.CreateAsyncCommand <TDataProvider>(
                    provider => executeAsyncAction?.Invoke(provider, item),
                    provider => undoAsyncAction?.Invoke(provider, item));
            }

            return(handler);
        }