コード例 #1
0
        public ITuple ToTuple(IConcurrentDataReader reader)
        {
            var dic = new Dictionary <String, Object>();

            for (int i = 0; i < ColumnNames.Length; i++)
            {
                dic.Add(ColumnNames[i], Values[i]);
            }

            return(new Tuple(dic, reader));
        }
コード例 #2
0
ファイル: DataRow.cs プロジェクト: stalinvr007/VoDB
        public ITuple ToTuple(IConcurrentDataReader reader)
        {
            var dic = new Dictionary<String, Object>();

            for (int i = 0; i < ColumnNames.Length; i++)
            {
                dic.Add(ColumnNames[i], Values[i]);
            }

            return new Tuple(dic, reader);
        }
コード例 #3
0
        /// <summary>
        /// Iterates the reader and transforms the ITuple instance into TModel type.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="reader">The reader.</param>
        /// <param name="transform">The transform.</param>
        /// <param name="maxThreads">The max threads.</param>
        /// <returns><code>IEnumerable<TModel></code> With the same order as the records were read.</returns>
        public static IEnumerable <TModel> Transform <TModel>(this IConcurrentDataReader reader, Func <ITuple, TModel> transform, int maxThreads) where TModel : class, new()
        {
            ConcurrentDictionary <ITuple, TModel> models = new ConcurrentDictionary <ITuple, TModel>();

            reader.ForEach(r =>
            {
                var data     = r.GetData();
                models[data] = transform(data);
            }, maxThreads);

            return(reader.GetTuples().Select(t => models[t]));
        }
コード例 #4
0
        /// <summary>
        /// Iterates the reader and calls the action for every record.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="action">The action.</param>
        /// <param name="maxThreads">The max threads.</param>
        /// <returns></returns>
        public static IEnumerable <ITuple> ForEach(this IConcurrentDataReader reader, Action <IConcurrentDataReader> action, int maxThreads)
        {
            var ts = new HashSet <Task>();

            for (int i = 0; i < maxThreads; i++)
            {
                ts.Add(Task.Factory.StartNew(() =>
                {
                    while (reader.Read())
                    {
                        action(reader);
                    }
                }));
            }

            reader.Close();

            Task.WaitAll(ts.ToArray());

            return(reader.GetTuples());
        }
コード例 #5
0
ファイル: Tuple.cs プロジェクト: erisonliang/ConcurrentReader
 public Tuple(IDictionary <String, Object> data, IConcurrentDataReader reader)
 {
     this.data = data;
     Reader    = reader;
 }
コード例 #6
0
 public static IEnumerable <TModel> ParallelTransform <TModel>(this IConcurrentDataReader reader, Func <ITuple, TModel> transform) where TModel : class, new()
 {
     return(reader.AsParallel().Transform <TModel>(transform));
 }
コード例 #7
0
 /// <summary>
 /// Cache the readers data.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns></returns>
 public static IConcurrentDataReader Load(this IConcurrentDataReader reader)
 {
     reader.ForEach(r => { });
     return(reader);
 }
コード例 #8
0
 /// <summary>
 /// Iterates the reader and transforms the ITuple instance into TModel type.
 /// </summary>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <param name="reader">The reader.</param>
 /// <param name="transform">The transform.</param>
 /// <returns><code>IEnumerable<TModel></code> With the same order as the records were read.</returns>
 public static IEnumerable <TModel> Transform <TModel>(this IConcurrentDataReader reader, Func <ITuple, TModel> transform) where TModel : class, new()
 {
     return(reader.Transform(transform, Environment.ProcessorCount));
 }
コード例 #9
0
 /// <summary>
 /// Iterates the reader and calls the action for every record.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="action">The action.</param>
 public static IEnumerable <ITuple> ForEach(this IConcurrentDataReader reader, Action <IConcurrentDataReader> action)
 {
     return(reader.ForEach(action, Environment.ProcessorCount));
 }