Пример #1
0
        static async Task Main(string[] args)
        {
            System.Console.WriteLine("Start TaskBatch Test!");
            System.Console.WriteLine("Input Example:");

            var array = new int[10] {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            foreach (var i in array)
            {
                System.Console.Write($"{i}:");
            }

            System.Console.WriteLine("");

            TaskBatch <ResultObject> taskBatch = new TaskBatch <ResultObject>(4);

            for (int index = 0; index < array.Length; index++)
            {
                await taskBatch.Add(NextSumValue(index, 10));
            }

            var result = await taskBatch.GetResults();

            System.Console.WriteLine("End TaskBatch process");
            System.Console.WriteLine("Example Result:");
            foreach (var r in result)
            {
                System.Console.Write($"{r.Value}:");
            }

            System.Console.ReadLine();
        }
Пример #2
0
    void createBatches()
    {
        VariableFetcher fetch = VariableFetcher.Get;

        batches = new TaskBatch[STANDARD_BATCH_COUNT + HYBRID_BATCH_COUNT];
        for (int i = START_BATCH; i <= STANDARD_BATCH_COUNT; i++)
        {
            int batchNum   = i;
            int batchIndex = batchNum - 1;
            fetch.GetBool(getImageCheckKey(batchNum), delegate(bool isImages)
            {
                string batchName = string.Format("{0}{1}", BATCH_KEY, batchNum);
                if (isImages)
                {
                    batches[batchIndex] = new ImageTaskBatch(batchName, processBatch);
                }
                else
                {
                    batches[batchIndex] = new TaskBatch(batchName, processBatch);
                }
                // In the Editor the arrays are not full initialized when all batches have been processed
                // So the post processing callback should run here, to ensure the array has been populated
                                        #if UNITY_EDITOR
                postProcessBatch();
                                        #endif
            });
        }
        randomBatch = UnityEngine.Random.Range(0, STANDARD_BATCH_COUNT);
    }
Пример #3
0
        public List <Task> Patch(TaskBatch request)
        {
            if (true != request?.Any())
            {
                throw new HttpError(HttpStatusCode.NotFound, "Request cannot be empty.");
            }

            var ret      = new List <Task>();
            var errors   = new List <ResponseError>();
            var errorMap = new Dictionary <string, string>();
            var i        = 0;

            request.ForEach(dto =>
            {
                try
                {
                    var obj = Patch(dto) as Task;
                    ret.Add(obj);
                    errorMap[$"{i}"] = $"true";
                }
                catch (Exception ex)
                {
                    errorMap[$"{i}"] = $"false";
                    errors.Add(new ResponseError()
                    {
                        Message   = $"{ex.Message}{Environment.NewLine}{ex.InnerException?.Message}",
                        ErrorCode = $"{i}"
                    });
                }
                i += 1;
            });
            base.Response.AddHeader("X-AutoBatch-Completed", $"{ret.Count} succeeded");
            if (errors.Any())
            {
                throw new HttpError(HttpStatusCode.BadRequest, $"{errors.Count} failed in batch")
                      {
                          Response = new ErrorResponse()
                          {
                              ResponseStatus = new ResponseStatus
                              {
                                  ErrorCode = nameof(HttpError),
                                  Meta      = errorMap,
                                  Message   = "Incomplete request",
                                  Errors    = errors
                              }
                          }
                      };
            }
            return(ret);
        }
Пример #4
0
 public void SetLabels(TaskBatch batch)
 {
     stimuli1Category1.text = batch.FirstStimuliCategory1;
     stimuli1Category2.text = batch.FirstStimuliCategory2;
     stimuli2Category1.text = batch.SecondStimuliCategory1;
     stimuli2Category2.text = batch.SecondStimuliCategory2;
     foreach (Text t in stimuli1)
     {
         t.text = batch.FirstStimuli;
     }
     foreach (Text t in stimuli2)
     {
         t.text = batch.SecondStimuli;
     }
 }
Пример #5
0
 public void SetPiece(TaskBatch batch, StimuliSet set)
 {
     if (batch is HybridTaskBatch)
     {
         setPieceHybrid(set as ImageStimuliSet);
     }
     else if (batch is ImageTaskBatch)
     {
         ImageStimuliSet imgSet = set as ImageStimuliSet;
         setPiece(imgSet.Stimuli1Img, imgSet.Stimuli2Img);
     }
     else
     {
         setPiece(set.Stimuli1, set.Stimuli2);
     }
     ToggleVisible(isVisibile: true);
 }
Пример #6
0
    bool isValidPlacementText(TSPieceID id, TaskBatch batch, TSGameTile targetTile)
    {
        switch (targetTile.GetMatchCondition)
        {
        case TSMatchCondition.Stimuli1Category1:
            return(batch.IsValidStimuli1Category1(id.Stimuli1));

        case TSMatchCondition.Stimuli1Category2:
            return(batch.IsValidStimuli1Category2(id.Stimuli1));

        case TSMatchCondition.Stimuli2Category1:
            return(batch.IsValidStimuli2Category1(id.Stimuli2));

        case TSMatchCondition.Stimuli2Category2:
            return(batch.IsValidStimuli2Category2(id.Stimuli2));

        default:
            return(false);
        }
    }
Пример #7
0
        public async Task Batching_Tasks_Greater_MaxBatch_Correct()
        {
            var array = new int[20] {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
            };
            var resultArray = new int[20] {
                10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
            };

            TaskBatch <ResultObject> taskBatching = new TaskBatch <ResultObject>(maxNumBatch: 5);

            for (int index = 0; index < array.Length; index++)
            {
                await taskBatching.Add(NextSumValue(index, 10));
            }

            var result = await taskBatching.GetResults();

            Assert.Equal(result.Select(r => r.Value), resultArray);
        }
Пример #8
0
        public async Task Batching_Tasks_Less_MaxBatch_Correct()
        {
            var array = new int[10] {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            var resultArray = new int[10] {
                10, 11, 12, 13, 14, 15, 16, 17, 18, 19
            };

            TaskBatch <ResultObject> taskBatch = new TaskBatch <ResultObject>(5);

            for (int index = 0; index < array.Length; index++)
            {
                await taskBatch.Add(NextSumValue(index, 10));
            }

            var result = await taskBatch.GetResults();

            Assert.Equal(result.Select(r => r.Value), resultArray);
        }
Пример #9
0
        public async Task Batching_Tasks_Greater_Parallel_MaxBatch_Correct()
        {
            var array = new int[20] {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
            };
            var resultArray = new int[20] {
                10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
            };

            TaskBatch <ResultObject> taskBatching = new TaskBatch <ResultObject>(maxNumBatch: 5);

            Parallel.For(0, array.Length, async(index, p) =>
            {
                await taskBatching.Add(NextSumValue(index, 10));
            });

            var result = await taskBatching.GetResults();

            Assert.True(result.All(e => resultArray.Contains(e.Value)));
        }
Пример #10
0
 public List <Task> Put(TaskBatch request)
 {
     return(Patch(request));
 }
 public HybridTaskBatch(TaskBatch batch1, TaskBatch batch2)
 {
     this.batch1 = batch1;
     this.batch2 = batch2;
 }