Ejemplo n.º 1
0
 private IEnumerable <DataModel> StreamProcessPhase3(IEnumerable <DataModel> models)
 {
     foreach (var model in models)
     {
         DataModelHelper.ProcessPhase3(model);
         yield return(model);
     }
 }
Ejemplo n.º 2
0
 public void Test1()
 {
     foreach (var model in GetModels())
     {
         DataModelHelper.ProcessPhase1(model);
         DataModelHelper.ProcessPhase2(model);
         DataModelHelper.ProcessPhase3(model);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 4
0
        public static IEnumerable <DataModel> BlockedCollectionProcessPhase3(IEnumerable <DataModel> models)
        {
            BlockingCollection <DataModel> result = new BlockingCollection <DataModel>(BLOCKING_COLLECTION_CAPACITY);

            Task.Run(() =>
            {
                foreach (var model in models)
                {
                    DataModelHelper.ProcessPhase3(model);
                    result.Add(model);
                }
                result.CompleteAdding();
            });
            return(result.GetConsumingEnumerable());
        }
Ejemplo n.º 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.ProcessPhase3(d);

                json.Serialize(Console.Out, d);
            }
        }
Ejemplo n.º 6
0
        private IEnumerable <DataModel> StreamAsyncProcessPhase3(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.ProcessPhase3(model); return(model); });
            }
            if (previous_result != null)
            {
                yield return(previous_result.GetAwaiter().GetResult());
            }
        }
Ejemplo n.º 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);
            }
        }