public void TestCancelLogUpdateMessageStatusError() { Guid id = Guid.NewGuid(); ResultCodeEnum res = HistoryLogger.UpdateMessageStatus("TRAIN1", id, MessageStatusType.InstantMessageDistributionReceived); Assert.AreNotEqual(ResultCodeEnum.RequestAccepted, res); }
}//AMAbuy public static void AMA_Sell(int commodity, int desiredPrice, int amount) { FLAG_isRunning = true; NotOverLoadServer(); MarketClientClass client = new MarketClientClass(); MarketUserData userData = client.SendQueryUserRequest(); NotOverLoadServer(); if (userData.Error != null) { FLAG_isRunning = false; return; } foreach (int cmdty in userData.Commodities.Keys) //passing on all commodities { if (cmdty == commodity && userData.Commodities[cmdty] > 0) //check if we own that commodity { //if item is the right commodity & we own it if (amount > userData.Commodities[cmdty] || amount == -1) //we cant sell more than we have OR -1 is our sign to sell ALL amount = userData.Commodities[cmdty]; MarketBuySell sellreq = client.SendSellRequest(desiredPrice, commodity, amount); NotOverLoadServer(); if (sellreq.Error == null) //the sell req is successfuly passed to the server HistoryLogger.WriteHistory(sellreq.Id, "Sell", commodity, desiredPrice, amount); } } FLAG_isRunning = false; return; }//AMAsell
public void TestCancelLogTrainError() { Guid id = Guid.NewGuid(); ResultCodeEnum res = HistoryLogger.CancelLog(id, CommandType.CancelScheduledMessage, "", MessageStatusType.InstantMessageDistributionProcessing); Assert.AreNotEqual(ResultCodeEnum.RequestAccepted, res); }
public void FixtureInit() { _databaseName = "TestDatabase"; string _executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", string.Empty); string databaseFolderPath = _executionPath + "\\"; _databaseFilePath = databaseFolderPath + _databaseName + ".mdf"; _databaseLogPath = databaseFolderPath + _databaseName + "_log.ldf"; HistoryLoggerConfiguration.SqlConnectionString = "Server=.\\SQLExpress;AttachDbFilename=" + _databaseFilePath + "; Database=" + _databaseName + ";Trusted_Connection=Yes;Connect Timeout=200"; HistoryLoggerConfiguration.SqlCreateDbConnectionString = "Server=.\\SQLExpress;Integrated security=SSPI;database=master;Connect Timeout=200"; HistoryLoggerConfiguration.CreateTableScriptPath = _executionPath + "\\..\\..\\..\\..\\" + "Services\\Maintenance\\App_Data\\HistoryLogDataBaseScript.sql"; HistoryLoggerConfiguration.LogBackupPath = databaseFolderPath; HistoryLoggerConfiguration.Valid = true; HistoryLoggerConfiguration.Used = true; HistoryLoggerConfiguration.LogDataBaseStructureVersion = "4.0"; HistoryLoggerConfiguration.MaximumLogMessageSize = 10; DropTestDb(); HistoryLogger.Initialize(); }
/// <summary> /// Verifies the train baseline status in history log. /// </summary> /// <param name="systemId">The system identifier.</param> /// <param name="expectedOnlineStatus">if set to <c>true</c> [expected online status].</param> /// <param name="expectedBaselineVersion">The expected baseline version.</param> /// <param name="expectedFutureVersion">The expected future version.</param> /// <param name="expectedRequestId">The expected request identifier.</param> /// <param name="expectedTaskId">The expected task identifier.</param> /// <param name="expectedProgress">The expected progress.</param> /// <remarks>This function check up to 8 times in 2 seconds before failing. The reason is that baselines statutes might be updated with a delay.</remarks> protected void VerifyTrainBaselineStatusInHistoryLog(string systemId, bool expectedOnlineStatus, string expectedBaselineVersion, string expectedFutureVersion, Guid expectedRequestId, int expectedTaskId, BaselineProgressStatusEnum expectedProgress) { Dictionary <string, TrainBaselineStatusData> statuses; bool isOk = false; int count = 0; do { try { HistoryLogger.GetTrainBaselineStatus(out statuses); TrainBaselineStatusData analysedTrain; Assert.IsTrue(statuses.TryGetValue(systemId, out analysedTrain), "History log database integrity error for train '{0}': no data found", systemId); AssertAll( () => Assert.AreEqual(expectedOnlineStatus, analysedTrain.OnlineStatus, "History log database integrity error for train '{0}': online status differ than expected", systemId), () => Assert.AreEqual(expectedRequestId, analysedTrain.RequestId, "History log database integrity error for train '{0}': request id differ than expected", systemId), () => Assert.AreEqual(expectedTaskId, analysedTrain.TaskId, "History log database integrity error for train '{0}': task id differ than expected", systemId), () => Assert.AreEqual(expectedProgress, analysedTrain.ProgressStatus, "History log database integrity error for train '{0}': progress status differ than expected", systemId), () => Assert.AreEqual(expectedBaselineVersion, analysedTrain.CurrentBaselineVersion, "History log database integrity error for train '{0}': current baseline version differ than expected", systemId), () => Assert.AreEqual(expectedFutureVersion, analysedTrain.FutureBaselineVersion, "History log database integrity error for train '{0}': future baseline version differ than expected", systemId)); isOk = true; } catch { if (++count > 8) { throw; } Thread.Sleep(250); } } while (!isOk); }
/// <summary> /// checks if the input is valid and if so intilazing a sell request with the gven parameters. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SellButton_Click(object sender, RoutedEventArgs e) { if (!(Int32.TryParse(SellCommodityField.Text, out int Commodity)) && Commodity > 9) { MessageBox.Show("Invalid Commodity", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Error); } if (!(Int32.TryParse(SellPriceField.Text, out int Price))) { MessageBox.Show("Invalid Price", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Error); } if (!(Int32.TryParse(SellAmountField.Text, out int Amount)) && Amount == 0) { MessageBox.Show("Invalid Amount", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Error); } if (Commodity > 0 || Price > 0 || Amount > 0) { MarketBuySell marketBuySell = market.SendSellRequest(Price, Commodity, Amount); if (marketBuySell.Error == null) { MessageBox.Show("Sucsess!! Your Sell request has been placed. your id is: " + marketBuySell.Id); HistoryLogger.WriteHistory(marketBuySell.Id, "Sell", Commodity, Price, Amount); Updater(); } else { MessageBox.Show(marketBuySell.ToString()); } } else { MessageBox.Show("Invalid Input", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Information); } }
public void TearDown() { if (HistoryLogger.EmptyDatabase() != ResultCodeEnum.RequestAccepted) { throw new Exception("Cannot empty the history database"); } }
public void TestMethodMarkPendingMessagesAsCanceledByStartup_BehaveAsExpected_WhenDatabaseContainOneRecordInProgressState() { Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(0), "Expect that table MessageContext is empty"); Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(0), "Expect that table MessageRequest is empty"); Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(0), "Expect that table MessageStatus is empty"); string messageText = "This is a scheduledMessage in progress"; Guid requestId = Guid.NewGuid(); string trainId = "TRAIN-1"; DateTime startDate = DateTime.UtcNow; DateTime endDate = startDate + new TimeSpan(1, 0, 0, 0); ResultCodeEnum result = HistoryLogger.WriteLog(messageText, requestId, CommandType.SendScheduledMessage, trainId, MessageStatusType.InstantMessageDistributionProcessing, startDate, endDate); Expect(result, Is.EqualTo(ResultCodeEnum.RequestAccepted), "Failed to insert schedule message into the history log"); Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(1), "Table MessageContext wasn't updated as expected by method HistoryLogger.WriteLog"); Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(1), "Table MessageRequest wasn't updated as expected by method HistoryLogger.WriteLog"); Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(1), "Table MessageStatus wasn't updated as expected by method HistoryLogger.WriteLog"); TestDelegate method = () => HistoryLogger.MarkPendingMessagesAsCanceledByStartup(); Assert.That <TestDelegate>(ref method, Throws.Nothing, "Method MarkPendingMessagesAsCanceledByStartup failed while expecting not"); Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(1), "Table MessageContext has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not"); Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(1), "Table MessageRequest has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not"); Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(2), "Table MessageStatus wasn't updated as expected by method MarkPendingMessagesAsCanceledByStartup"); }
public void TestClearAllError() { Guid id = Guid.NewGuid(); List <CommandType> lst = new List <CommandType>(); ResultCodeEnum res = HistoryLogger.CleanLog(lst); Assert.AreNotEqual(ResultCodeEnum.RequestAccepted, res); }
public void TestGetAllLogDateError() { List <CommandType> lst = new List <CommandType>(); string str; ResultCodeEnum res = HistoryLogger.GetAllLog(lst, DateTime.UtcNow, DateTime.UtcNow, 0, out str); Assert.AreNotEqual(ResultCodeEnum.InvalidCommandType, res); }
public void TestGetOldestLogError() { List <CommandType> lst = new List <CommandType>(); string str; ResultCodeEnum res = HistoryLogger.GetOldestLog(lst, out str); Assert.AreNotEqual(ResultCodeEnum.InvalidCommandType, res); }
protected void WaitTrainBaselineStatusesEquals(Dictionary <string, TrainBaselineStatusData> expectedStatuses, string message) { Dictionary <string, TrainBaselineStatusData> statuses = null; ActualValueDelegate comparer = () => { HistoryLogger.GetTrainBaselineStatus(out statuses); return(AreDictionariesEquals(expectedStatuses, statuses)); }; AssertAll(() => Assert.That(comparer, Is.True.After(5 * ONE_SECOND, ONE_SECOND / 2), "Train baseline status wasn't updated as expected"), () => AssertDictionariesEqual(expectedStatuses, statuses, message)); }
/// <summary> /// Gets the baseline progress in history log for a train. /// </summary> /// <param name="trainName">Name of the train to query.</param> /// <param name="defaultValue">The value to return if train is unknown in history log database.</param> /// <returns>The baseline progress status. defaultValue if train name has no progress information</returns> protected BaselineProgressStatusEnum GetBaselineProgress(string trainName, BaselineProgressStatusEnum defaultValue) { Dictionary <string, TrainBaselineStatusData> statuses; HistoryLogger.GetTrainBaselineStatus(out statuses); TrainBaselineStatusData trainStatus; return(statuses.TryGetValue(trainName, out trainStatus) ? trainStatus.ProgressStatus : defaultValue); }
public void TestClearAll() { Guid id = Guid.NewGuid(); List <CommandType> lst = new List <CommandType>(); lst.Add(CommandType.CancelScheduledMessage); ResultCodeEnum res = HistoryLogger.CleanLog(lst); Assert.AreEqual(ResultCodeEnum.RequestAccepted, res); }
public void TestGetAllLog() { List <CommandType> lst = new List <CommandType>(); lst.Add(CommandType.SendScheduledMessage); string str; ResultCodeEnum res = HistoryLogger.GetAllLog(lst, DateTime.Now, DateTime.Now, 0, out str); Assert.AreEqual(ResultCodeEnum.RequestAccepted, res); }
public void TestWriteLogMuiltiTrainUpateEmptyError() { Guid id = Guid.NewGuid(); HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN1", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now); ResultCodeEnum res = HistoryLogger.UpdateMessageStatus("", id, MessageStatusType.InstantMessageDistributionWaitingToSend); Assert.AreNotEqual(ResultCodeEnum.RequestAccepted, res); }
/// <summary>Method to update the message status.</summary> /// <param name="trainId">list of train ids.</param> /// <param name="requestId">request id of the message.</param> /// <param name="messageStatus">message status.</param> /// <param name="commandType">Type of message to update.</param> /// <returns>Error code if any.</returns> public static ResultCodeEnum UpdateMessageStatus(string trainId, Guid requestId, MessageStatusType messageStatus, CommandType commandType) { if (HistoryLoggerConfiguration.Used) { return(HistoryLogger.UpdateMessageStatus(trainId, requestId, messageStatus, commandType)); } else { return(ResultCodeEnum.RequestAccepted); } }
/// <summary> /// Method used to cancel history log details. /// </summary> /// <param name="requestId">request id of the message</param> /// <param name="commandType">command type</param> /// <param name="trainId">list of train ids</param> /// <returns>Error code if any</returns> public static ResultCodeEnum CancelLog(Guid requestId, PIS.Ground.Core.Data.CommandType commandType, string trainId, MessageStatusType messageStatus) { if (HistoryLoggerConfiguration.Used) { return(HistoryLogger.CancelLog(requestId, commandType, trainId, messageStatus)); } else { return(ResultCodeEnum.RequestAccepted); } }
/// <summary> /// Clean the Baseline progress status /// </summary> /// <param name="trainId">train id.</param> /// <returns>Error code if any</returns> public static ResultCodeEnum CleanTrainBaselineStatus(string trainId) { ResultCodeEnum resultCode = ResultCodeEnum.RequestAccepted; if (HistoryLoggerConfiguration.Used) { resultCode = HistoryLogger.CleanTrainBaselineStatus(trainId); } return(resultCode); }
/// <summary> /// Clean the history log database /// </summary> /// <param name="commandList">list of commands</param> /// <returns>Error code if any</returns> public static ResultCodeEnum CleanLog(List <PIS.Ground.Core.Data.CommandType> commandList) { if (HistoryLoggerConfiguration.Used) { return(HistoryLogger.CleanLog(commandList)); } else { return(ResultCodeEnum.RequestAccepted); } }
/// <summary> /// Method used to write history log details. /// </summary> /// <param name="context"> message details</param> /// <param name="requestId">request id of the message</param> /// <param name="commandType">command type</param> /// <param name="trainId">list of train ids</param> /// <param name="messageStatus">message status</param> /// <param name="startDate"> start date of activation</param> /// <param name="endDate">end date of activation</param> /// <returns>Error code if any</returns> public static ResultCodeEnum WriteLog(string context, Guid requestId, PIS.Ground.Core.Data.CommandType commandType, string trainId, MessageStatusType messageStatus, DateTime startDate, DateTime endDate) { if (HistoryLoggerConfiguration.Used) { return(HistoryLogger.WriteLog(context, requestId, commandType, trainId, messageStatus, startDate, endDate)); } else { return(ResultCodeEnum.RequestAccepted); } }
public void TestGetOldestLog() { Guid id = Guid.NewGuid(); List <CommandType> lst = new List <CommandType>(); lst.Add(CommandType.SendScheduledMessage); string str; ResultCodeEnum res = HistoryLogger.GetOldestLog(lst, out str); Assert.AreEqual(ResultCodeEnum.RequestAccepted, res); }
/// <summary> /// Method used to get all the log message /// </summary> /// <param name="commandList">command list</param> /// <param name="startDateTime">start date time to be considered</param> /// <param name="endDateTime">end date time to be considered</param> /// <param name="language">language code</param> /// <param name="logResponse">output log response</param> /// <returns>Error code if any</returns> public static ResultCodeEnum GetAllLog(List <PIS.Ground.Core.Data.CommandType> commandList, DateTime startDateTime, DateTime endDateTime, uint language, out string logResponse) { logResponse = string.Empty; if (HistoryLoggerConfiguration.Used) { return(HistoryLogger.GetAllLog(commandList, startDateTime, endDateTime, language, out logResponse)); } else { return(ResultCodeEnum.RequestAccepted); } }
/// <summary> /// Method used to get the oldest message DateTime /// </summary> /// <param name="commandList">list of commands</param> /// <param name="logResponse">The oldest message</param> /// <returns>Error code if any</returns> public static ResultCodeEnum GetOldestLogDateTime(List <PIS.Ground.Core.Data.CommandType> commandList, out string logResponse) { logResponse = string.Empty; if (HistoryLoggerConfiguration.Used) { return(HistoryLogger.GetOldestLogDateTime(commandList, out logResponse)); } else { return(ResultCodeEnum.RequestAccepted); } }
/// <summary> /// Method to insert the Database Version. /// </summary> /// <param name="version">Database version</param> /// <returns>Error code if any</returns> public static ResultCodeEnum InsertDatabaseVersion(string version) { if (HistoryLoggerConfiguration.Used) { return(HistoryLogger.InsertDatabaseVersion(version)); } else { version = ""; return(ResultCodeEnum.RequestAccepted); } }
public void TestGetAllLogMultiCommand() { Guid id = Guid.NewGuid(); List <CommandType> lst = new List <CommandType>(); lst.Add(CommandType.SendScheduledMessage); lst.Add(CommandType.CancelScheduledMessage); string str; ResultCodeEnum res = HistoryLogger.GetAllLog(lst, DateTime.Parse("2012-06-26"), DateTime.Parse("2012-06-28"), 0, out str); Assert.AreEqual(ResultCodeEnum.RequestAccepted, res); }
/// <summary> /// Method used to get all the status of the baselines /// </summary> /// <param name="dictionaryResponse">output dictionary response</param> /// <returns>Error code if any</returns> public static ResultCodeEnum GetTrainBaselineStatus(out Dictionary <string, TrainBaselineStatusData> dictionaryResponse) { ResultCodeEnum resultCode = ResultCodeEnum.RequestAccepted; dictionaryResponse = null; if (HistoryLoggerConfiguration.Used) { resultCode = HistoryLogger.GetTrainBaselineStatus(out dictionaryResponse); } return(resultCode); }
public void TestCancelLog() { Guid id = Guid.NewGuid(); HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN1", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now); HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN2", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now); HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN3", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now); HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN4", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now); ResultCodeEnum res = HistoryLogger.CancelLog(id, CommandType.CancelScheduledMessage, "TRAIN1", MessageStatusType.InstantMessageDistributionProcessing); Assert.AreEqual(ResultCodeEnum.RequestAccepted, res); }
public static void AMA_Buy(int commodity, int desiredPrice, int amount) { FLAG_isRunning = true; notOverLoadServer(); MarketClientClass client = new MarketClientClass(); AllMarketRequest all = client.QueryAllMarketRequest(); counter++; foreach (ItemAskBid item in all.MarketInfo) { if (item.Id == commodity && item.Info.Ask <= desiredPrice) { //if item is the right commodity & right price MarketUserData userData = client.SendQueryUserRequest(); counter++; List <int> l = userData.Requests; if (l.Count != 0) //there are open requests in server //if USER dont have enough money, we'll cancel his open buy requests- hoping after that he'll have enough { for (int i = l.Count; i >= 0 & userData.Funds < (item.Info.Ask * amount); i--) //going from end so in delete won't change index of l { notOverLoadServer(); int reqID = l[i]; //saving the ID just for simplicity MarketItemQuery request = client.SendQueryBuySellRequest(l[i]); counter++; if (request.Type.Equals("buy")) //Note: check with roey { client.SendCancelBuySellRequest(reqID); HistoryLogger.WriteHistory("Cancel," + request.Commodity + "," + request.Price + "," + request.Amount + "," + reqID); counter++; } } } if (userData.Funds >= item.Info.Ask * amount) { int ID = client.SendBuyRequest(item.Info.Ask + 1, commodity, amount).Id; HistoryLogger.WriteHistory("Buy," + commodity + "," + (item.Info.Ask + 1) + "," + amount + "," + ID); counter++; } }//bigIf } FLAG_isRunning = false; return; }//AMAbuy
public void TestMethodMarkPendingMessagesAsCanceledByStartup_BehaveAsExpected_WhenDatabaseIsEmpty() { Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(0), "Expect that table MessageContext is empty"); Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(0), "Expect that table MessageRequest is empty"); Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(0), "Expect that table MessageStatus is empty"); TestDelegate method = () => HistoryLogger.MarkPendingMessagesAsCanceledByStartup(); Assert.That <TestDelegate>(ref method, Throws.Nothing, "Method MarkPendingMessagesAsCanceledByStartup failed while expecting not"); Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(0), "Table MessageContext has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not"); Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(0), "Table MessageRequest has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not"); Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(0), "Table MessageStatus has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not"); }