Namespace: Soss.Client
Assembly: soss_namedcache (in soss_namedcache.dll) Version: 6.2.0.0
public static R ForEach<T, P, R>( this IQueryable<T> source, DistributedParallelOptions options, P param, Func<R> localInit, Func<T, P, BodyState, R, R> body, Func<R, R, R> merge )
Parameters
- source
- Type: System.Linq.IQueryable<T>
An enumerable source of data stored in the StateServer - options
- Type: Soss.Client.DistributedParallelOptions
DistributedParallelOptions values to use when executing this operation - param
- Type: P
a user-defined parameter which may be passed to all body delegates - localInit
- Type: System.Func<R>
a delegate which returns the initial state of the local data for each task - body
- Type: System.Func<T, P, BodyState, R, R>
the delegate that is invoked once per iteration - merge
- Type: System.Func<R, R, R>
the delegate that performs pairwise merging on the local states of each task
Type Parameters
- T
- the type of the data elements in source
- P
- the type of the parameter passed to the body delegates.
- R
- the type of the value returned from the localInit delegate that is passed to each body delegate and is subsequently merged via the merge delegate.
Return Value
Type: Rthe final merged value after all local results and all per-StateServer host results have been merged
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IQueryable<T>. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).The body delegate is invoked once for each element in the source enumerable. It is provided with the following parameters: the current element, the user-defined parameter value param, a BodyState instance, some local loop state that may be shared amongst iteration that execute on the same task.
The localInit delegate is invoked once for each task that participates in the loop's execution (on each host) and returns the initial local state for each of those tasks. These initial states are passed to the first body invocations on each task. Then ever subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. The BodyState parameter may be used to influence object disposition on the StateServer (e.g. update, delete).
Local state values from multiple tasks are passed in pairwise fashion to the merge delegate which merges the pair into a single value. Once all local state values from a given host have been merged, they're consolidated from across the distributed store by passing the per-host results in a pairwise fashion to merge delegates hosted on one or more of the StateServer hosts. When all localState values have been merged to a single value, it is returned as the result of the ForEach method.
The source parameter must be a QueryFilter instance initially returned from QueryObjects<T> () and possibly filtered via one or more Linq where clauses.