public void TestMethodResourceForPatientWthFlu()
        {
            var patient           = new Patient("Test Patient", PatientCondition.Flu);
            var resourceAllocator = new ResourceAllocator();

            var consultation =
                new ConsultationRecord(patient, null, null, DateTime.Now.Date, DateTime.MinValue);
            ResourceAllocatorResult r = new ResourceAllocatorResult(false, consultation);

            ManualResetEvent done = new ManualResetEvent(false);

            resourceAllocator.RequestResources(patient, (result) =>
            {
                r = result;
                done.Set();
            });

            done.WaitOne();
            resourceAllocator.Dispose();

            Assert.IsTrue(r.Status, "Failed to get Resource..");
            Assert.IsTrue(r.Consultation.TreatmentRoom != null, "Failed to get Treatment Room..");
            Assert.IsTrue(r.Consultation.Doctor != null, "Failed to get Doctor..");
            Assert.IsTrue(r.Consultation.DateRegistered == consultation.DateRegistered, "Registration date is incorrect.");
            Assert.IsTrue(r.Consultation.ConsulatationDate != DateTime.MinValue, "Consultation date is incorrect.");
        }
Example #2
0
 public RenderSystem(ICamera camera)
 {
     _camera            = camera;
     _resourceAllocator = new ResourceAllocator(new OpenGlResourceFactory());
     _simpleMaterial    = new SimpleMaterial();
     _simpleMaterial.Create();
     _normalDebugProgram = new NormalDebugProgram();
     _normalDebugProgram.Create();
 }
        public Cube()
        {
            _simpleMaterial = new SimpleMaterial();
            var resourceAllocator = new ResourceAllocator(new OpenGlResourceFactory());

            _simpleMaterial.Create();

            var mesh = MeshCreator.CreateXZGrid(10, 10);

            _renderable = resourceAllocator.AllocateResourceFor(mesh);
            _renderable.CreateVAO();
        }
Example #4
0
        private IEnumerable <T> MergeSortParallel(IEnumerable <T>[] streams, ResourceAllocator threadsAllocator, int recursionLevel)
        {
            var blockingCollection = new BlockingCollection <T>(parallelStreamBufferSize);

            Task.Factory.StartNew(() =>
            {
                var result = MergeSort(streams, threadsAllocator, recursionLevel);
                foreach (var line in result)
                {
                    blockingCollection.Add(line);
                }

                blockingCollection.CompleteAdding();
                threadsAllocator.Deallocate();
            },
                                  TaskCreationOptions.LongRunning
                                  );

            return(blockingCollection.GetConsumingEnumerable());
        }
Example #5
0
 public void Init()
 {
     this.runtimeGrammar = new RuntimeGrammar(data.Grammar);
     this.allocator      = new ResourceAllocator(runtimeGrammar);
 }
Example #6
0
        private IEnumerable <T> MergeSort(IEnumerable <T>[] streams, ResourceAllocator threadsAllocator, int recursionLevel)
        {
            if (streams.Length > 2)
            {
                if (recursionLevel >= MAX_RECURSION_LEVEL)
                {
                    Console.WriteLine("MergeSort: max recursion level is reached. Applying heap merge sort");

                    var result = HeapMergeSort(streams);
                    foreach (var value in result)
                    {
                        yield return(value);
                    }
                }
                else
                {
                    var part1 = new IEnumerable <T> [streams.Length / 2];
                    var part2 = new IEnumerable <T> [streams.Length - part1.Length];
                    Array.Copy(streams, 0, part1, 0, part1.Length);
                    Array.Copy(streams, part1.Length, part2, 0, part2.Length);

                    var part1ExecuteInParallel = threadsAllocator.Allocate();
                    var part2ExecuteInParallel = threadsAllocator.Allocate();

                    var part1Result = part1ExecuteInParallel
                        ? MergeSortParallel(part1, threadsAllocator, recursionLevel + 1)
                        : MergeSort(part1, threadsAllocator, recursionLevel + 1);

                    var part2Result = part2ExecuteInParallel
                        ? MergeSortParallel(part2, threadsAllocator, recursionLevel + 1)
                        : MergeSort(part2, threadsAllocator, recursionLevel + 1);

                    var result = MergeSort(new[] { part1Result, part2Result }, threadsAllocator, recursionLevel + 1);
                    foreach (var value in result)
                    {
                        yield return(value);
                    }
                }
            }
            else if (streams.Length == 2)
            {
                using var enumerator1 = streams[0].GetEnumerator();
                using var enumerator2 = streams[1].GetEnumerator();

                bool enumerator1HasData = enumerator1.MoveNext();
                bool enumerator2HasData = enumerator2.MoveNext();

                while (enumerator1HasData && enumerator2HasData)
                {
                    var value1 = enumerator1.Current;
                    var value2 = enumerator2.Current;

                    var compareResult = this.comparer.Compare(value1, value2);
                    if (compareResult < 0)
                    {
                        yield return(value1);

                        enumerator1HasData = enumerator1.MoveNext();
                    }
                    else if (compareResult > 0)
                    {
                        yield return(value2);

                        enumerator2HasData = enumerator2.MoveNext();
                    }
                    else
                    {
                        yield return(value1);

                        yield return(value2);

                        enumerator1HasData = enumerator1.MoveNext();
                        enumerator2HasData = enumerator2.MoveNext();
                    }
                }

                while (enumerator1HasData)
                {
                    yield return(enumerator1.Current);

                    enumerator1HasData = enumerator1.MoveNext();
                }

                while (enumerator2HasData)
                {
                    yield return(enumerator2.Current);

                    enumerator2HasData = enumerator2.MoveNext();
                }
            }
            else if (streams.Length == 1)
            {
                var stream = streams[0];
                foreach (var line in stream)
                {
                    yield return(line);
                }
            }
        }
 public void Initialize()
 {
     _allocator  = new ResourceAllocator();
     _fakeOutput = new StringBuilder();
     Console.SetOut(new StringWriter(_fakeOutput));
 }