示例#1
0
 public static IEnumerable <DataModel> StreamProcessPhase2(IEnumerable <DataModel> models)
 {
     foreach (var model in models)
     {
         DataModelHelper.ProcessPhase2(model);
         yield return(model);
     }
 }
示例#2
0
 public void Test1()
 {
     foreach (var model in GetModels())
     {
         DataModelHelper.ProcessPhase1(model);
         DataModelHelper.ProcessPhase2(model);
         DataModelHelper.ProcessPhase3(model);
     }
 }
示例#3
0
 /// <summary>
 /// 串流處理:處理完一個物件的phase1,2,3才抓下一個物件
 /// WIP只會有一個
 /// </summary>
 private static void Demo2()
 {
     foreach (var model in GetModels())
     {
         DataModelHelper.ProcessPhase1(model);
         DataModelHelper.ProcessPhase2(model);
         DataModelHelper.ProcessPhase3(model);
     }
 }
示例#4
0
        public static IEnumerable <DataModel> BlockedCollectionProcessPhase2(IEnumerable <DataModel> models)
        {
            BlockingCollection <DataModel> result = new BlockingCollection <DataModel>(BLOCKING_COLLECTION_CAPACITY);

            Task.Run(() =>
            {
                foreach (var model in models)
                {
                    DataModelHelper.ProcessPhase2(model);
                    result.Add(model);
                }
                result.CompleteAdding();
            });
            return(result.GetConsumingEnumerable());
        }
示例#5
0
        private static void Main(string[] args)
        {
            var json       = JsonSerializer.Create();
            var jsonreader = new JsonTextReader(Console.In);

            jsonreader.SupportMultipleContent = true;

            while (jsonreader.Read())
            {
                var d = json.Deserialize <DataModel>(jsonreader);

                DataModelHelper.ProcessPhase2(d);

                json.Serialize(Console.Out, d);
            }
        }
示例#6
0
        private IEnumerable <DataModel> StreamAsyncProcessPhase2(IEnumerable <DataModel> models)
        {
            Task <DataModel> previous_result = null;

            foreach (var model in models)
            {
                if (previous_result != null)
                {
                    yield return(previous_result.Result);
                }
                previous_result = Task.Run <DataModel>(() => { DataModelHelper.ProcessPhase2(model); return(model); });
            }
            if (previous_result != null)
            {
                yield return(previous_result.GetAwaiter().GetResult());
            }
        }
示例#7
0
        /// <summary>
        /// 批次處理:依序執行所有物件的phase1,再做所有的phase2,最後做所有的phase3
        /// WIP與任務數量呈正比
        /// </summary>
        private static void Demo1()
        {
            DataModel[] models = GetModels().ToArray();

            foreach (var model in models)
            {
                DataModelHelper.ProcessPhase1(model);
            }

            foreach (var model in models)
            {
                DataModelHelper.ProcessPhase2(model);
            }

            foreach (var model in models)
            {
                DataModelHelper.ProcessPhase3(model);
            }
        }