public static void HandleMVCGrid(IApplicationBuilder app) { app.Run(async context => { string path = context.Request.PathBase.Value; if (path.Contains(".gif") || path.Contains(".png") || path.Contains(".jpg")) { path = "Images" + path.Replace("/MVCGridHandler.axd", string.Empty); byte[] image = GetResourceFileContentAsByteArray("MVCGrid.NetCore", path); context.Response.ContentType = "image/png"; await context.Response.Body.WriteAsync(image, 0, image.Length); } else { HttpRequest httpRequest = context.Request; string gridName = httpRequest.Query["Name"]; int statusCode; string html = GridHelpers.GenerateGrid(gridName, out statusCode, httpRequest.ToNameValueCollection()); if (statusCode != 0) { context.Response.StatusCode = statusCode; await context.Response.WriteAsync(html); } } }); }
//note that if the interval id passed through is null, it returns the whole shift. public static Cycle[] SelectByInterval( string operation, DateTime dateOp, string shift, string tabKey, ProductionEntryInterval entryInterval, ColumnFilter[] filters, SortBy[] sortBy) { if (entryInterval == null) { return(Select(operation, dateOp, shift, tabKey, filters, sortBy)); } using (var connection = Utility.GetConnection <Cycle> ()) { var list = new SelectAll <Cycle> () .WherePropertyEquals("Operation", operation) .WherePropertyEquals("DateOp", dateOp) .WherePropertyEquals("Shift", shift) .WherePropertyBetween("DateTimeStart", entryInterval.IntervalStartUtc, entryInterval.IntervalEndUtc) .WherePropertyEquals("DataEntryTab", tabKey) .WherePropertyEquals("Datasource", DatasourceValidator.ManualEntry); ColumnFilter[] unknownFilters; GridHelpers.ApplyFiltersToSelectAll(list, new [] { new UnitHierarchyImplementation(new [] { operation }) }, filters, out unknownFilters); GridHelpers.ApplySortByToSelectAll(list, sortBy, "DateTimeModified"); return(list.Execute(connection)); } }
public static Cycle[] SelectByIntervalShift( string operation, ShiftInterval shiftInterval, string tabKey, ColumnFilter[] filters, SortBy[] sortBy) { using (var connection = Utility.GetConnection <Cycle> ()) { var list = new SelectAll <Cycle> () .WherePropertyEquals("Operation", operation) .WherePropertyEquals("DateOp", shiftInterval.DateOp) .WherePropertyEquals("Shift", shiftInterval.Shift) .WherePropertyBetween("DateTimeStart", shiftInterval.GetIntervalStartTimeUtc(operation), shiftInterval.GetIntervalEndTimeUtc(operation)) .WherePropertyEquals("DataEntryTab", tabKey) .WherePropertyEquals("Datasource", DatasourceValidator.ManualEntry); GridHelpers.ApplyFiltersToSelectAll( list, new [] { new UnitHierarchyImplementation(new [] { operation }) }, filters, out ColumnFilter[] unknownFilters); GridHelpers.ApplySortByToSelectAll(list, sortBy, "DateTimeModified"); return(list.Execute(connection)); } }
public void MiddleMiddleSurroundingPoints() { var point = new List <Point> { _rightTop, _rightMiddle, _rightBottom, _centerTop, _centerBottom, _leftTop, _leftMiddle, _leftBottom }; Assert.Equal(point, GridHelpers.DetermineValidRadialPoints(_currentTest, _centerMiddle)); }
public void TopRightSurroundingPoints() { var point = new List <Point> { _rightMiddle, _centerTop, _centerMiddle, }; Assert.Equal(point, GridHelpers.DetermineValidRadialPoints(_currentTest, _rightTop)); }
public void BottomleftSurroundingPoints() { var point = new List <Point> { _centerMiddle, _centerBottom, _leftMiddle }; Assert.Equal(point, GridHelpers.DetermineValidRadialPoints(_currentTest, _leftBottom)); }
private void LoadData(string path, bool doubleSolve = false) { GridHelpers.ResetCache(); _grid = new PicrossGrid(path, GridInitializerEnum.ImageFilePath); _solver = new PicrossSolver(_grid.RowCount, _grid.ColumnCount, _grid.Rows, _grid.Columns); _solver.Solve(); if (doubleSolve) { _solver.Solve(); } Rows = new List <RowPresenter>(); for (int i = 0; i < _grid.RowCount; i++) { Rows.Add(new RowPresenter(_solver.WorkingGrid.GetRow(i))); } Notify(() => Rows); RowClassifiers = _solver.Rows.Select(r => new ClassifierPresenter(r)).ToList(); ColumnClassifiers = _solver.Columns.Select(c => new ClassifierPresenter(c)).ToList(); }
public void Execute(Entity entity, int index, ref Translation translation, ref GridPosition gridPosition, [ReadOnly] ref Movable movable) { if (movable.direction == Direction.NONE) { //Entity is static return; } //Spawn follow juice Entity newJuiceEntity = CommandBuffer.Instantiate(index, spawner.prefabFollowJuice); int layer = Root.ConfigManager.LayersConfig.LayerForEntity(EntityType.FOLLOW_JUICE); int2 juiceGridPosition = gridPosition.Value; float3 juiceTranslation = GridConfig.PositionForCoordinates(juiceGridPosition.x, juiceGridPosition.y, layer); CommandBuffer.SetComponent(index, newJuiceEntity, new GridPosition { Value = juiceGridPosition, layer = layer}); CommandBuffer.SetComponent(index, newJuiceEntity, new Translation() { Value = juiceTranslation}); int2 offset = GridHelpers.DirectionToInt2(movable.direction); //Wrap around the grid int wrappedX = gridPosition.Value.x + offset.x; int wrappedY = gridPosition.Value.y + offset.y; if (gridPosition.Value.x < 0) { wrappedX = GridConfig.width - 1; } else if (GridConfig.width <= gridPosition.Value.x) { wrappedX = 0; } else if (gridPosition.Value.y < 0) { wrappedY = GridConfig.height - 1; } else if (GridConfig.height <= gridPosition.Value.y) { wrappedY = 0; } gridPosition.Value = new int2(wrappedX, wrappedY); translation.Value = GridConfig.PositionForCoordinates(wrappedX, wrappedY, gridPosition.layer); }
internal static SignalRGridResponse GenerateSignalRGrid(string gridName, GridGenerationType type) { string html = string.Empty; string summaryhtml = string.Empty; int statusCode = 0; NameValueCollection nameValueCollection = new NameValueCollection(); html = GridHelpers.GenerateGrid(gridName, out statusCode, nameValueCollection); if (type == GridGenerationType.Row) { var doc = new HtmlDocument(); doc.LoadHtml(html); List <HtmlNode> trNodes = doc.DocumentNode.Descendants("tr").ToList(); HtmlNode trNode = trNodes.LastOrDefault(); HtmlNode summaryNode = doc.GetElementbyId($"MVCGridTable_{gridName}_Summary"); if (trNode != null) { html = trNode.OuterHtml; if (html.Contains("noresults") == true) { html = string.Empty; } } if (summaryNode != null) { summaryhtml = summaryNode.OuterHtml; } } return(new SignalRGridResponse() { Type = Enum.GetName(typeof(GridGenerationType), type), Gridname = gridName, Html = html, SummaryHtml = summaryhtml, }); }
public PicrossGrid(string initString, GridInitializerEnum initializer) { switch (initializer) { case GridInitializerEnum.GridString: AnswerGrid = GridHelpers.InitFromGridString(initString, rowCount: out RowCount, colCount: out ColumnCount); break; case GridInitializerEnum.ImageFilePath: AnswerGrid = GridHelpers.InitFromImg(initString, rowCount: out RowCount, colCount: out ColumnCount); break; default: throw new Exception("Unknown initializer"); } UsedColors = GridHelpers.GetUsedColorsFromGrid(AnswerGrid); if (UsedColors.Count > 4) { throw new Exception(string.Format("To many colors detected! Detected a total of {0} colors", UsedColors.Count)); } GenerateRowClassifiers(); GenerateColumnClassifiers(); }
private void InitializeUserinteface(int LevelNumber = 0) { int iRow = -1; int iCol = -1; if (LevelNumber > JsonLevels.Count) { LevelNumber = 0; } int LevelRows = JsonLevels.Level(LevelNumber).Rows; int LevelColumns = JsonLevels.Level(LevelNumber).Columns; GridHelpers.SetRowCount(GamePanel, LevelRows); GridHelpers.SetColumnCount(GamePanel, LevelColumns); this.Width = LevelColumns * new KeyControl().PanelWidth; this.Height = LevelRows * new KeyControl().PanelHeight + 50; while (GamePanel.Children.Count > 0) { GamePanel.Children.Remove(GamePanel.Children[0]); } while (StatusPanel.Children.Count > 0) { StatusPanel.Children.Remove(StatusPanel.Children[0]); } foreach (RowDefinition row in GamePanel.RowDefinitions) { iRow++; iCol = -1; foreach (ColumnDefinition col in GamePanel.ColumnDefinitions) { iCol++; KeyControl Key = new KeyControl(); Key.Tag = iRow * LevelColumns + iCol; RemoveLogicalChild(Key); GamePanel.Children.Add(Key); Grid.SetColumn(Key, iCol); Grid.SetRow(Key, iRow); Key.OnSwitch += OnKeySwitched; } } WinTextBoard.MouseUp += WinTextBoard_MouseUp; trophyControl = new ResultControl("Trophy.txt"); switchControl = new ResultControl("Switch.txt"); trophyControl.ImageIndex = 0; switchControl.ImageIndex = 1; Grid.SetColumn(trophyControl, 0); Grid.SetColumn(switchControl, 1); StatusPanel.Children.Add(trophyControl); StatusPanel.Children.Add(switchControl); this.WindowStartupLocation = WindowStartupLocation.CenterScreen; this.ResizeMode = ResizeMode.CanMinimize; this.WindowStyle = WindowStyle.ToolWindow; this.Title = "LightOFF (Level" + (LevelNumber + 1) + ")"; }
protected void Run(bool doubleSolve = false) { var errorSb = new StringBuilder(); var errorLevels = new List <string>(); var inconclusiveLevels = new List <string>(); var inconclusiveSb = new StringBuilder(); foreach (var level in Levels) { GridHelpers.ResetCache(); var levelName = level.Identifier; var initializer = level.Initializer; var step = Step.Setup; try { Setup(initializer); step = Step.ManualSetup; if (ManualSetup != null) { ManualSetup(); } step = Step.Solve; Solver.Solve(); if (doubleSolve) { Solver.Solve(); } step = Step.Assert; AssertMatrix(); } catch (Exception ex) { if (ex.Message.Contains("Invalid color!")) { inconclusiveLevels.Add(levelName); AppendLog(inconclusiveSb, ex, step, level); } else { errorLevels.Add(levelName); AppendLog(errorSb, ex, step, level); } } } var totalOutput = Environment.NewLine; if (errorSb.Length != 0) { totalOutput += string.Format("Number of failing levels: {0}{1}", errorLevels.Count, Environment.NewLine); errorSb.AppendLine(HorizontalSplitter); } if (inconclusiveSb.Length != 0) { totalOutput += string.Format("Number of inconclusive levels: {0}{1}", inconclusiveLevels.Count, Environment.NewLine); inconclusiveSb.AppendLine(HorizontalSplitter); } totalOutput += HorizontalSplitter + errorSb + inconclusiveSb; if (errorLevels.Any()) { Assert.Fail(totalOutput); } if (inconclusiveLevels.Any()) { Assert.Inconclusive(totalOutput); } }