Пример #1
0
        private bool FilterWhere(ComplexObject defaultModel)
        {
            List <bool> generalStateFilter = new List <bool>();

            //Number of letter a must be >10
            bool nameOk = defaultModel.Name
                          .Where(x => x == 'A')
                          .Count() > 10;

            generalStateFilter.Add(nameOk);


            //Number must be divisible by 3
            bool numberOk = defaultModel.Number % 3 == 0;

            generalStateFilter.Add(numberOk);

            //LongNumber
            bool longNumerOk = Math.Sqrt(defaultModel.LongNumber) > 30.12345d;

            generalStateFilter.Add(longNumerOk);

            bool dateOk = defaultModel.Date > DateTime.Now;

            generalStateFilter.Add(dateOk);

            ComplexObjectBuilder complexObjectBuilder = new ComplexObjectBuilder();
            bool enumOk = complexObjectBuilder.DefaultsEnums.Contains(defaultModel.EnumDefault);

            generalStateFilter.Add(enumOk);

            return(!generalStateFilter.Any(x => x == false));
        }
Пример #2
0
        public void LoadData(int dataSize, int numberOfThreads, TaskCreationOptions taskCreationOptions)
        {
            if (numberOfThreads > MAX_THREAD_POOL || numberOfThreads < 1)
            {
                throw new Exception($"MIN THREAD POOL ALLOWED: 1 Threads || MAX THREAD POOL ALLOWED: {MAX_THREAD_POOL} Threads");
            }

            ConcurrentBag <ComplexObject> concurrentListCollectionObject = new ConcurrentBag <ComplexObject>();

            List <Task> taskList  = new List <Task>();
            int         batchSize = dataSize / numberOfThreads;

            for (int i = 1; i <= numberOfThreads; ++i)
            {
                taskList.Add(Task.Factory.StartNew(() =>
                {
                    int numberOfThread = GetThreadNumber();
                    ComplexObjectBuilder complexObjectBuilder = new ComplexObjectBuilder();

                    for (int itemsProcessed = 1; itemsProcessed <= batchSize; ++itemsProcessed)
                    {
                        //Notify the numbers of items processed
                        if (OnStatusProgress != null && (itemsProcessed % REFRESH_FRECUENCY == 0 || itemsProcessed == batchSize))
                        {
                            NotifyUtilities.Notify(OnStatusProgress, numberOfThread, Thread.CurrentThread.ManagedThreadId, itemsProcessed);
                        }

                        //Add generated items to collection
                        concurrentListCollectionObject.Add(complexObjectBuilder.GenerateRandomDefaultModel());
                    }
                }, taskCreationOptions));
            }

            //Wait for finish
            Task.WaitAll(taskList.ToArray());

            collectionObjects = new List <ComplexObject>(concurrentListCollectionObject);

            OnDataLoaded?.Invoke(this, null);
        }