private SortedList <int, ExaminationStudentsFilter> GetFirewalls(int numberofStdsInit, int MaxStdNum, string studentPassword, string instructorPassword, int step, FilterationSecurityLevel secLevel) { SortedList <int, ExaminationStudentsFilter> ret = new SortedList <int, ExaminationStudentsFilter>(); Parallel.ForEach(BetterEnumerable.SteppedRange(numberofStdsInit, MaxStdNum, step), (index) => { SortedList <string, ExaminationFilterRule> rules = new SortedList <string, ExaminationFilterRule>(); for (int i = 0; i < index; i++) { rules.Add($"Std{i}", new ExaminationFilterRule { StdID = $"Std{i}", StdName = $"StdName{i}", AllowSpecificIPs = false, AllowedIPs = new List <string> { "ANY", }, SharedKeyIS = $"Keyyyyyyy{i}", }); } lock (ret) { ret.Add(index, new ExaminationStudentsFilter(secLevel, studentPassword, instructorPassword, rules)); } }); return(ret); }
private SortedList <int, Exam> GetExams(int numberOfInitiaQuestions, int maxNumOfQuestions, int step = 10) { SortedList <int, Exam> ret = new SortedList <int, Exam>(); Parallel.ForEach(BetterEnumerable.SteppedRange(numberOfInitiaQuestions, maxNumOfQuestions, step), (index) => { var x = ExamHelper.GetRandomExamforTesting(index); lock (ret) { ret.Add(index, x); } }); //int tempInit = numberOfInitiaQuestions; //while (tempInit < maxNumOfQuestions) //{ // ret.Add(tempInit, ExamHelper.GetRandomExamforTesting(tempInit)); // tempInit += step; //} return(ret); }
public void RenderZoomLevels() { var sourceZoomLevel = this.NewInitialZoomLevel; var sourceDiameter = this.InitialDiameter; var sourceLevelXmin = XMin / ChunksPerDimension; var sourceLevelXmax = XMax / ChunksPerDimension; var sourceLevelZmin = ZMin / ChunksPerDimension; var sourceLevelZmax = ZMax / ChunksPerDimension; while (sourceZoomLevel > NewLastZoomLevel) { // Force garbage collection (may not be necessary) GC.Collect(); GC.WaitForPendingFinalizers(); var destDiameter = sourceDiameter / 2; var sourceZoom = sourceZoomLevel; var destZoom = sourceZoomLevel - 1; var linesRendered = 0; if (sourceLevelXmin.IsOdd()) // always start at an even coordinate { sourceLevelXmin--; } if (sourceLevelXmax.IsOdd()) { sourceLevelXmax++; } if (sourceLevelZmin.IsOdd()) // always start at an even coordinate { sourceLevelZmin--; } if (sourceLevelZmax.IsOdd()) { sourceLevelZmax++; } Console.WriteLine( $"\nRendering Level {destZoom} with source coordinates X {sourceLevelXmin} to {sourceLevelXmax}, Z {sourceLevelZmin} to {sourceLevelZmax}"); OuterLoopStrategy(BetterEnumerable.SteppedRange(sourceLevelXmin, sourceLevelXmax, 2), new ParallelOptions() { MaxDegreeOfParallelism = RenderSettings.MaxNumberOfThreads }, x => { for (int z = sourceLevelZmin; z < sourceLevelZmax; z += 2) { var b1 = LoadBitmap(sourceZoom, x, z, isUpdate); var b2 = LoadBitmap(sourceZoom, x + 1, z, isUpdate); var b3 = LoadBitmap(sourceZoom, x, z + 1, isUpdate); var b4 = LoadBitmap(sourceZoom, x + 1, z + 1, isUpdate); if (b1 != null || b2 != null || b3 != null || b4 != null) { var bfinal = graphics.CreateEmptyImage(TileSize, TileSize); { b1 = b1 ?? LoadBitmap(sourceZoom, x, z, false); b2 = b2 ?? LoadBitmap(sourceZoom, x + 1, z, false); b3 = b3 ?? LoadBitmap(sourceZoom, x, z + 1, false); b4 = b4 ?? LoadBitmap(sourceZoom, x + 1, z + 1, false); var halfTileSize = TileSize / 2; if (b1 != null) { graphics.DrawImage(bfinal, b1, 0, 0, halfTileSize, halfTileSize); } if (b2 != null) { graphics.DrawImage(bfinal, b2, halfTileSize, 0, halfTileSize, halfTileSize); } if (b3 != null) { graphics.DrawImage(bfinal, b3, 0, halfTileSize, halfTileSize, halfTileSize); } if (b4 != null) { graphics.DrawImage(bfinal, b4, halfTileSize, halfTileSize, halfTileSize, halfTileSize); } SaveBitmap(destZoom, x / 2, z / 2, isUpdate, bfinal); } // Dispose of any bitmaps, releasing memory foreach (var bitmap in new[] { b1, b2, b3, b4, bfinal }.OfType <Bitmap>()) { bitmap.Dispose(); } } } Interlocked.Add(ref linesRendered, 2); ZoomLevelRenderd?.Invoke(this, new ZoomRenderedEventArgs(linesRendered, sourceDiameter, destZoom)); }); sourceLevelZmin /= 2; sourceLevelZmax /= 2; sourceLevelXmin /= 2; sourceLevelXmax /= 2; sourceDiameter = destDiameter; sourceZoomLevel = destZoom; } }