public void TableAdd(int serverId, string dbSource, string dbDest, int dbId, bool isTwoDirection) { //clear old tables try { var tables = (from t in db.MergeTables where t.DatabaseId == dbId select t); db.MergeTables.DeleteAllOnSubmit(tables); db.SubmitChanges(); } catch (Exception) { } //get server ServerName objServer = db.ServerNames.Where(v => v.Id == serverId).First(); string serverSource = objServer.ServerSource; string serverDest = objServer.ServerDest; //update tables of the DB source/dest List <string> sourceTables = GetTables(serverSource + "." + dbSource, connSource); List <string> destTables = GetTables(serverDest + "." + dbDest, connDest); string query; foreach (string table in sourceTables) { if (destTables.IndexOf(table) != -1) { query = MergeTableQuery(serverSource + "." + dbSource + ".dbo." + table, serverDest + "." + dbDest + ".dbo." + table, "SourceId"); if (query != null) { MergeTable objTable = new MergeTable(); objTable.MergeQuery = query; objTable.DatabaseId = dbId; objTable.TableName = table; db.MergeTables.InsertOnSubmit(objTable); db.SubmitChanges(); } if (isTwoDirection) { query = MergeTableQuery(serverDest + "." + dbDest + ".dbo." + table, serverSource + "." + dbSource + ".dbo." + table, "SourceId"); if (query != null) { MergeTable objTable = new MergeTable(); objTable.MergeQuery = query; objTable.DatabaseId = dbId; objTable.TableName = table; db.MergeTables.InsertOnSubmit(objTable); db.SubmitChanges(); } } } } }
public MergerMovesResolver(GameState postArmyMovesState, IEnumerable <MergerMove> mergers) { // Need to make sure they're not merging a province they no longer own IEnumerable <MergerMove> validMoves = mergers.Where(item => ValidateItem(item, postArmyMovesState)).ToArray(); // Need to make sure chains of mergers happen in order IEnumerable <MergerChain> chains = GetMergerChains(validMoves); ProvinceMergerTables merger = new ProvinceMergerTables(postArmyMovesState, chains); NewGameState = new GameState(merger.NewProvinces); MergeTable = merger.MergeTable; }
private GameTurnTransition GetInitialState(IEnumerable <PlayerSetup> playerSetups, Map map) { IEnumerable <ProvinceState> provinces = GetInitialProvinces(playerSetups, map); GameState initialState = new GameState(provinces); MergeTable mergeTable = new MergeTable(new Dictionary <Province, Province>()); return(new GameTurnTransition( initialState, initialState, initialState, initialState, mergeTable, new War[0])); }
public GameTurnTransition(GameState beforEverything, GameState afterWars, GameState afterWarsAndUpgrades, GameState afterEverything, MergeTable mergeTable, IEnumerable <War> wars) { BeforeEverything = beforEverything; AfterWars = afterWars; AfterWarsAndUpgrades = afterWarsAndUpgrades; AfterEverything = afterEverything; MergeTable = mergeTable; Wars = wars; }
private void LoadGrid(MergeTable table) { var lastFrozenColIndex = table.ColFrozenCount - 1; var lastFrozenRowIndex = table.RowFrozenCount - 1; for (var col = 0; col < table.ColCount; col++) { var colHeader = table.ColHeaders?[col]; var colHeaderCell = colHeader == null ? null : new DataGridViewColumnHeaderCell { Style = HeaderStyles[colHeader.Type], Value = colHeader.Text }; var column = new DataGridViewColumn { Frozen = col <= lastFrozenColIndex, DividerWidth = col == lastFrozenColIndex ? FrozenDividerSize : 0, HeaderCell = colHeaderCell, CellTemplate = new DataGridViewTextBoxCell(), AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells }; grid.Columns.Add(column); } for (var row = 0; row < table.RowCount; row++) { var rowHeader = table.RowHeaders?[row]; var rowHeaderCell = rowHeader == null ? null : new DataGridViewRowHeaderCell { Style = HeaderStyles[rowHeader.Type], Value = rowHeader.Text }; var gridRow = new DataGridViewRow { Frozen = row <= lastFrozenRowIndex, DividerHeight = row == lastFrozenRowIndex ? FrozenDividerSize : 0, HeaderCell = rowHeaderCell }; for (var col = 0; col < table.ColCount; col++) { var cell = table.Cells[row, col]; var gridCell = new DataGridViewTextBoxCell { Value = cell.Text, Style = CellStyles[cell.Type] }; // We already set ReadOnly at grid level, so there is no need to do it here again. Also: ReadOnly of an individual grid CELL can only be set after adding it to a grid ROW. gridRow.Cells.Add(gridCell); } grid.Rows.Add(gridRow); } }
public ProvinceMergerTables(GameState state, IEnumerable <MergerChain> chains) { _oldNewDictionary = state.Provinces.ToDictionary(item => item.Identifier, item => item); Dictionary <Province, ProvinceState> changesTable = new Dictionary <Province, ProvinceState>(); foreach (MergerChain chain in chains) { ProvinceState mergeChainProduct = chain.GetCompletedMerger(state); foreach (Province province in chain.EliminatedProvinces) { ProvinceState toDelete = state.GetProvinceState(province); _oldNewDictionary.Remove(toDelete.Identifier); changesTable.Add(toDelete.Identifier, mergeChainProduct); } _oldNewDictionary[chain.SourceProvince] = mergeChainProduct; } MergeTable = new MergeTable(changesTable.ToDictionary(item => item.Key, item => item.Value.Identifier)); NewProvinces = _oldNewDictionary.Values.ToArray(); }
private MergeTable GetMergeTable(string title, IList <string> toBranches, IList <string> fromBranches, List <string[]> merged) { var lastCommitDates = GitGetter.BranchesByLastCommitDate(ProjectPath, Reporter); if (Reporter.HasError()) { return(null); } var table = new MergeTable(fromBranches.Count + 1, 1, toBranches.Count + 2, 2, hasRowHeaders: false, hasColHeaders: true); int row; int col; // Set column headers: col = 0; table.ColHeaders[col++] = new MergeHeader { Type = HeaderCellType.Title, Text = title }; table.ColHeaders[col++] = new MergeHeader { Type = HeaderCellType.Regular, Text = "" }; for (int i = 0; i < toBranches.Count; i++) { table.ColHeaders[col++] = new MergeHeader { Type = HeaderCellType.BranchName, Text = toBranches[i] } } ; if (col != table.ColHeaders.Length) { Reporter.ShowError("Invalid column header count. Expected: " + table.ColHeaders.Length + ", found: " + col + "."); return(null); } // Set row headers: // ********* Not present ********* // Set cells for first row: row = 0; col = 0; table.Cells[row, col++] = new MergeCell { Type = CellType.SubTitle, Text = "Branch" }; table.Cells[row, col++] = new MergeCell { Type = CellType.SubTitle, Text = "Last commit date" }; for (int i = 0; i < toBranches.Count; i++) { table.Cells[row, col++] = new MergeCell { Type = CellType.BranchDate, Text = GetDateString(lastCommitDates, toBranches[i]) } } ; // Set cells for next rows: for (var j = 0; j < fromBranches.Count; j++) { row++; col = 0; table.Cells[row, col++] = new MergeCell { Type = CellType.BranchName, Text = fromBranches[j] }; table.Cells[row, col++] = new MergeCell { Type = CellType.BranchDate, Text = GetDateString(lastCommitDates, fromBranches[j]) }; for (int i = 0; i < toBranches.Count; i++) { var cellType = toBranches[i] == fromBranches[j] ? CellType.SelfJoin : merged[i].Contains(fromBranches[j]) ? CellType.Merged : CellType.NotMerged; var cellText = cellType == CellType.SelfJoin ? "-" : cellType == CellType.Merged ? "✔" : "✘"; table.Cells[row, col++] = new MergeCell { Type = cellType, Text = cellText }; } } return(table); }