Ejemplo n.º 1
0
 /// <summary>
 /// Invoke the <paramref name="action"/> if not null.
 /// </summary>
 /// <param name="action">Action to invoke</param>
 /// <param name="ct">A CanellationToken</param>
 /// <param name="param">Parameter of action</param>
 /// <returns></returns>
 public static async Task SafeInvoke <TParam>(this ActionAsync <TParam> action, CancellationToken ct, TParam param)
 {
     if (action != null)
     {
         await action(ct, param);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Invoke the <paramref name="action"/> if not null.
 /// </summary>
 /// <param name="action">Action to invoke</param>
 /// <param name="ct">A CanellationToken</param>
 /// <returns></returns>
 public static async Task SafeInvoke(this ActionAsync action, CancellationToken ct)
 {
     if (action != null)
     {
         await action(ct);
     }
 }
Ejemplo n.º 3
0
 public async Task ApplyAsync(ActionAsync action)
 {
     if (data?.Any() ?? false)
     {
         await action?.Invoke(data[0]);
     }
 }
Ejemplo n.º 4
0
 public async Task ForEachAsync(ActionAsync <C> action) //i think done.
 {
     foreach (C thisItem in _privateDict.Values)
     {
         await action.Invoke(thisItem);
     }
 }
Ejemplo n.º 5
0
        public AsyncTestRunner(ActionAsync <AsyncTestRunner> method = null, [CallerMemberName] string name = null, [CallerLineNumber] int line = -1, bool loop = false)
        {
            _loop       = loop;
            _identifier = $"{name}@{line}";
            ImmutableInterlocked.Update(ref _runners, r => r.Add(this));

            if (method != null)
            {
                Run(method);
            }
        }
Ejemplo n.º 6
0
 public AsyncCommand(ActionAsync <T> execute)
     : base(async(o) =>
 {
     if (IsValidParameter(o))
     {
         await execute((T)o);
     }
 })
 {
     if (execute == null)
     {
         throw new ArgumentNullException(nameof(execute));
     }
 }
        /// <summary>
        /// Constructor using an <see cref="IObjectSerializer"/> for persistence.
        /// </summary>
        public LockedFileDataPersister(
            string fullFilename,
            IObjectSerializer serializer,
            int numberOfRetries = 3,
            int retryDelay      = 100)
        {
            _committedFile   = new FileInfo(fullFilename /*.Validation().NotNull(nameof(fullFilename))*/).FullName;
            _read            = async(ct, stream) => (T)serializer.FromStream(stream, typeof(T));
            _write           = async(ct, entity, stream) => serializer.WriteToStream(entity, typeof(T), stream, canDisposeStream: true);
            _numberOfRetries = numberOfRetries;
            _retryDelay      = retryDelay;

            // Create other working file names
            _oldFile  = _committedFile + ".old";
            _newFile  = _committedFile + ".new";
            _lockFile = _committedFile + ".lck";
        }
        /// <summary>
        /// Constructor with callbacks for read & write operations.
        /// </summary>
        public LockedFileDataPersister(
            string fullFilename,
            FuncAsync <Stream, T> read,
            ActionAsync <T, Stream> write,
            int numberOfRetries = 3,
            int retryDelay      = 100)
        {
            _committedFile   = new FileInfo(fullFilename /*.Validation().NotNull(nameof(fullFilename))*/).FullName;
            _read            = read;
            _write           = write;
            _numberOfRetries = numberOfRetries;
            _retryDelay      = retryDelay;

            // Create other working file names
            _oldFile  = _committedFile + ".old";
            _newFile  = _committedFile + ".new";
            _lockFile = _committedFile + ".lck";
        }
Ejemplo n.º 9
0
        public Task Run(ActionAsync <AsyncTestRunner> method)
        {
            var item = new QueueItem(method);

            ImmutableInterlocked.Enqueue(ref _queue, item);

            if (_thread == null)
            {
                var thread = new Thread(RunLoop);
                if (Interlocked.CompareExchange(ref _thread, thread, null) == null)
                {
                    thread.Start();
                }
            }
            else
            {
                _queueEvent.Set();
            }

            return(item.Task);
        }
Ejemplo n.º 10
0
 public static ActionAsync CreateAsync(ActionAsync action)
 {
     return(action);
 }
 /// <summary>
 /// Adds a <see cref="AnalyticsDataLoaderStrategy"/> to this builder.
 /// </summary>
 /// <typeparam name="TBuilder">The type of the builder.</typeparam>
 /// <param name="builder">The builder.</param>
 /// <param name="onSuccess">The callback when the strategy loads successfully.</param>
 /// <param name="onError">The callback when the strategy fails to load.</param>
 /// <returns>The original builder.</returns>
 public static TBuilder WithAnalytics <TBuilder>(this TBuilder builder, ActionAsync <IDataLoaderRequest, object> onSuccess, ActionAsync <IDataLoaderRequest, Exception> onError)
     where TBuilder : IDataLoaderBuilder
 {
     return(builder.WithStrategy(new AnalyticsDataLoaderStrategy(onSuccess, onError)));
 }
 public AnalyticsDataLoaderStrategy(ActionAsync <IDataLoaderRequest, object> onSuccess, ActionAsync <IDataLoaderRequest, Exception> onError)
 {
     _onSuccess = onSuccess;
     _onError   = onError;
 }
Ejemplo n.º 13
0
 CurryLast <T1, T2, T3, T4>(this ActionAsync <T1, T2, T3, T4> action, T4 last)
 {
     return((CancellationToken ct, T1 first, T2 second, T3 third) => action(ct, first, second, third, last));
 }
Ejemplo n.º 14
0
 CurryFirst <T1, T2, T3>(this ActionAsync <T1, T2, T3> action, T1 first)
 {
     return((CancellationToken ct, T2 second, T3 last) => action(ct, first, second, last));
 }
Ejemplo n.º 15
0
 CurryLast <T1, T2>(this ActionAsync <T1, T2> action, T2 last)
 {
     return((CancellationToken ct, T1 first) => action(ct, first, last));
 }
Ejemplo n.º 16
0
 Curry <T>(this ActionAsync <T> action, T value)
 {
     return((CancellationToken ct) => action(ct, value));
 }
Ejemplo n.º 17
0
 public Task ForEachAsync(ActionAsync <D> action)
 {
     return(_privateList.ForEachAsync(action));
 }
Ejemplo n.º 18
0
 public static ActionAsync <T> CreateAsync <T>(ActionAsync <T> action)
 {
     return(action);
 }
Ejemplo n.º 19
0
 public Task ForConditionalItemsAsync(Predicate <D> match, ActionAsync <D> action)
 {
     return(_privateList.ForConditionalItemsAsync(match, action));
 }
Ejemplo n.º 20
0
 public QueueItem(ActionAsync <AsyncTestRunner> method)
 {
     _method = method;
 }
Ejemplo n.º 21
0
 public LambdaCommandAsync(ActionAsync execute, Func <bool> canExecute = null)
     : this(async p => await execute(), canExecute is null ? (Func <object, bool>)null : p => canExecute())
Ejemplo n.º 22
0
 public AsyncWeakEventHandler(ActionAsync callback)
 {
     _method          = callback.GetMethodInfo();
     _targetReference = new WeakReference(callback.Target, true);
 }