private static TableHistory NewHistoryRecord(object obj) { TableHistory hist = new TableHistory(); Type type = obj.GetType(); PropertyInfo[] keys; keys = type.GetProperties().Where(o => AttrIsPrimaryKey(o)).ToArray(); if (keys.Length > KeyMax) { throw new HistoryException("object has more than " + KeyMax.ToString() + " keys."); } for (int i = 1; i <= keys.Length; i++) { typeof(TableHistory) .GetProperty("Key" + i.ToString()) .SetValue(hist, keys[i - 1].GetValue(obj, null).ToString(), null); } hist.TableName = type.Name; hist.ParentID = ((IHistory)obj).ParentID.ToString(); return(hist); }
public int AddTableMigration(TableHistory tHistory, int siteId) { int result = 0; if (siteId != 0) { var dh = db.DatabaseHistories.FirstOrDefault(f => f.SiteId == siteId); if (dh != null) { var tb = dh.TableHistories.FirstOrDefault(f => f.TableName == tHistory.TableName); if (tb == null) { dh.TableHistories.Add(tHistory); } else { tb.FirebirdRecordCount = tHistory.FirebirdRecordCount; tb.MigratedRecordCount = tHistory.MigratedRecordCount; tb.LastMigrationDate = DateTime.Now; } result = db.SaveChanges(); } } return(result); }
public void CheckSpecialHands2() { GamingTable gamingTable = new GamingTable(); Dictionary <int, HandWarGame <CardWarGame> > players = new Dictionary <int, HandWarGame <CardWarGame> >(); HandWarGame <CardWarGame> Hand1 = new HandWarGame <CardWarGame>(); HandWarGame <CardWarGame> Hand2 = new HandWarGame <CardWarGame>(); Hand2.AddCard(new CardWarGame(CardValueEnum.Five, CardColorEnum.Spade)); Hand2.AddCard(new CardWarGame(CardValueEnum.Six, CardColorEnum.Spade)); Hand2.AddCard(new CardWarGame(CardValueEnum.Seven, CardColorEnum.Spade)); Hand2.AddCard(new CardWarGame(CardValueEnum.Height, CardColorEnum.Spade)); HandWarGame <CardWarGame> Hand3 = new HandWarGame <CardWarGame>(); players.Add(1, Hand1); players.Add(2, Hand2); players.Add(3, Hand3); TableHistory tableHistory = gamingTable.PlayGameWhithGivenHand(players); Assert.AreEqual(2, tableHistory.GetHistories()[0].GetWinner()); }
public static List <TableHistory> GetLinqUpdateChangeList(MainDataContext dbo, Models.Admin user, object oldObj, object newObj) { List <TableHistory> histList = new List <TableHistory>(); Type type = oldObj.GetType(); if (newObj.GetType() != type) { throw new HistoryException("type mismatch between old object and new object."); } var changed = from pi in type.GetProperties() where pi.PropertyType.Namespace == "System" && String.Format("{0}", pi.GetValue(oldObj, null)) != String.Format("{0}", pi.GetValue(newObj, null)) select pi; foreach (PropertyInfo pi in changed) { TableHistory hist = NewHistoryRecord(oldObj); hist.ActionType = "UPDATE"; hist.Property = pi.Name; hist.OldValue = pi.GetValue(oldObj, null) == null ? "NULL" : TruncateCharactersPastLimit(pi.GetValue(oldObj, null).ToString()); hist.NewValue = pi.GetValue(newObj, null) == null ? "NULL" : TruncateCharactersPastLimit(pi.GetValue(newObj, null).ToString()); hist.ActionUserName = user.LoggerName; hist.ActionDateTime = dbo.GetSystemDate(); hist.ParentID = ((IHistory)newObj).ParentID.ToString(); histList.Add(hist); } return(histList); }
public static void RecordLinqInsert(MainDataContext dbo, Models.Admin Admin, object obj) { TableHistory hist = NewHistoryRecord(obj); hist.ActionType = "INSERT"; hist.ActionUserName = Admin.DisplayName + " " + Admin.ID.ToString(); hist.ActionDateTime = dbo.GetSystemDate(); hist.ParentID = ((IHistory)obj).ParentID.ToString(); hist.OldValue = SimpleSerialize(obj); dbo.TableHistories.InsertOnSubmit(hist); }
public static void RecordLinqDelete(Models.Admin user, object obj) { MainDataContext dbo = new MainDataContext(); TableHistory hist = NewHistoryRecord(obj); hist.ActionType = "DELETE"; hist.ActionUserName = user.LoggerName; hist.ActionDateTime = dbo.GetSystemDate(); hist.OldValue = SimpleSerialize(obj); dbo.TableHistories.InsertOnSubmit(hist); dbo.SubmitChanges(); }
public static void PlayMultipleGames() //NOT SAFE AT ALL. If wrong input exceptions not caught at all. { Console.WriteLine("You selected Play multiple games"); Console.WriteLine("Select number of players : "); int numberPlayers = int.Parse(Console.ReadLine()); Console.WriteLine("Select number of games to play : "); int numberGamesToPlay = int.Parse(Console.ReadLine()); IGamingTable gamingTable = new GamingTable.GamingTable(); TableHistory tableHistory = gamingTable.PlayMultipleGames(numberPlayers, numberGamesToPlay); tableHistory.PrintDetailledHistory(); }
[TestMethod, Timeout(50 * numberGamesToPlay)] // ms public void CheckNoInfiniteLoop() { IGamingTable gamingTable = new GamingTable(); TableHistory tableHistory = gamingTable.PlayMultipleGames(2, numberGamesToPlay); int sum = 0; foreach (GameHistory gameHistory in tableHistory.GetHistories()) { sum += gameHistory.GetNumberOfFolds(); } Console.WriteLine("Average number of fold per game : " + sum / numberGamesToPlay); tableHistory.PrintScoreBoard(); }
public static void RecordLinqInsertAll(MainDataContext dbo, IIdentity user, IEnumerable ie) { List <TableHistory> histList = new List <TableHistory>(); string userName = user.Name; DateTime systemDate = dbo.GetSystemDate(); foreach (object obj in ie) { TableHistory hist = NewHistoryRecord(obj); hist.ActionType = "INSERT"; hist.ActionUserName = userName; hist.ActionDateTime = systemDate; histList.Add(hist); } dbo.TableHistories.InsertAllOnSubmit(histList); }
private static TableHistory NewHistoryRecord(string tableName, IOrderedDictionary keys) { TableHistory hist = new TableHistory(); if (keys.Count > KeyMax) { throw new HistoryException("object has more than " + KeyMax.ToString() + " keys."); } for (int i = 1; i <= keys.Count; i++) { typeof(TableHistory) .GetProperty("Key" + i.ToString()) .SetValue(hist, keys[i - 1].ToString(), null); } hist.TableName = tableName; return(hist); }
public static void RecordLinqDeleteAll(MainDataContext dbo, Models.Admin user, IEnumerable ie) { List <TableHistory> histList = new List <TableHistory>(); string userName = user.LoggerName; DateTime systemDate = dbo.GetSystemDate(); foreach (object obj in ie) { TableHistory hist = NewHistoryRecord(obj); hist.ActionType = "DELETE"; hist.ActionUserName = user.LoggerName; hist.ActionDateTime = systemDate; hist.ParentID = ((IHistory)obj).ParentID.ToString(); histList.Add(hist); } dbo.TableHistories.InsertAllOnSubmit(histList); }
public void CheckSpecialHands3() { IGamingTable gamingTable = new GamingTable(); Dictionary <int, HandWarGame <CardWarGame> > players = new Dictionary <int, HandWarGame <CardWarGame> >(); HandWarGame <CardWarGame> Hand1 = new HandWarGame <CardWarGame>(); HandWarGame <CardWarGame> Hand2 = new HandWarGame <CardWarGame>(); HandWarGame <CardWarGame> Hand3 = new HandWarGame <CardWarGame>(); players.Add(1, Hand1); players.Add(2, Hand2); players.Add(3, Hand3); TableHistory tableHistory = gamingTable.PlayGameWhithGivenHand(players); Assert.AreEqual(-1, tableHistory.GetHistories()[0].GetWinner()); //No winner }
/// <summary> /// Обновление данных OBDII /// </summary> /// <param name="model"></param> private void Instance_OBDLoaded(OBDHistoryDataModel model) { if (SelectedHistoryRow == null || !model.DT.ToDate.Equals(SelectedHistoryRow.Date)) { return; } var obd = new OBDHistoryDataModel { DevID = model.DevID, DT = model.DT }; var slowTask = new Task(delegate { for (var i = 0; i < DayStates.Count; i++) { var item = DayStates[i]; var next = i + 1 < DayStates.Count ? DayStates[i + 1].Date : DateTime.Now; var dt = new DateTime(item.Date.Year, item.Date.Month, item.Date.Day); var list = model.Data.Where(o => dt + o.Time.ToTimeSpan() >= item.Date && dt + o.Time.ToTimeSpan() < next); foreach (var el in list) { obd.Data.Add(el); } } }); slowTask.ContinueWith(obj => { if (_dispatcher != null) { _dispatcher.BeginInvoke(new Action(() => { OBDHistory = obd; TableHistory.Update(obd); OnPropertyChanged("TableHistory"); })); } }); slowTask.Start(); }
public static void PlayGameWhithGivenHand() //NOT SAFE AT ALL. If wrong input exceptions not caught at all. { Console.WriteLine("You selected Play game with given hand"); Console.WriteLine("Select number of players : "); int numberPlayers = int.Parse(Console.ReadLine()); Dictionary <int, HandWarGame <CardWarGame> > players = new Dictionary <int, HandWarGame <CardWarGame> >(); for (int i = 1; i <= numberPlayers; i++) { Console.WriteLine("Select cards with an input like '4H 3S 1C 13D ...' for player " + i + " :"); List <String> cardsToConvert = Console.ReadLine().Split(" ").ToList(); //not safe HandWarGame <CardWarGame> cards = HandWarGame <CardWarGame> .ConvertStringsToCards(cardsToConvert); // should be done with a proper dsl players.Add(i, cards); } IGamingTable gamingTable = new GamingTable.GamingTable(); TableHistory tableHistory = gamingTable.PlayGameWhithGivenHand(players); tableHistory.PrintDetailledHistory(); }
public static void RecordSqlUpdate(Models.Admin user, string tableName, IOrderedDictionary keys, IOrderedDictionary oldObj, IOrderedDictionary newObj) { MainDataContext dbo = new MainDataContext(); List <TableHistory> histList = new List <TableHistory>(); foreach (DictionaryEntry entry in oldObj) { if (String.Format("{0}", entry.Value) == String.Format("{0}", newObj[entry.Key])) { continue; } TableHistory hist = NewHistoryRecord(tableName, keys); hist.ActionType = "UPDATE"; hist.Property = entry.Key.ToString(); hist.OldValue = TruncateCharactersPastLimit(String.Format("{0}", entry.Value)); hist.NewValue = TruncateCharactersPastLimit(String.Format("{0}", newObj[entry.Key])); hist.ActionUserName = user.LoggerName; hist.ActionDateTime = dbo.GetSystemDate(); histList.Add(hist); } dbo.TableHistories.InsertAllOnSubmit(histList); dbo.SubmitChanges(); }
private void barButtonItem39_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { TableHistory th = new TableHistory(); th.ShowDialog(); }