public void AddItem(Common.Item.Item item, Containers container = Containers.Inventory) { item.CharID = chara.CharID; OperationResults res = chara.Inventory.AddItem(container, item, out List <Common.Item.Item> affected); if (affected.Count > 0) { CharacterSession.Instance.SaveItem(affected); } if (res != OperationResults.FAILED) { if (item.Count > 0) { affected.Add(item); } switch (res) { case OperationResults.NEW_INDEX: SendItemUpdate(ItemUpdateMethod.Add, affected); break; case OperationResults.STACK_UPDATE: SendItemUpdate(ItemUpdateMethod.Update, affected); break; } if (res == OperationResults.NEW_INDEX && item.Count > 0) { CharacterSession.Instance.CreateItem(item); } } }
public void OnItemBuyBack(CM_ITEM_BUYBACK p) { if (map.GetActor(p.ActorID) is ActorNPC npc) { if (NPC.NPCStoreFactory.Instance.Stores.ContainsKey(npc.BaseData.StoreID)) { NPC.NPCStore store = NPC.NPCStoreFactory.Instance[npc.BaseData.StoreID]; if (p.Slot < chara.Inventory.SoldItems.Count) { Common.Item.Item item = chara.Inventory.SoldItems[p.Slot]; if (item != null) { int price = (int)(item.BaseData.Price * store.BuyBackRate) * item.Count; if (chara.Gold > price) { Interlocked.Add(ref chara.Gold, -price); chara.Inventory.SoldItems.RemoveAt(p.Slot); OperationResults res = chara.Inventory.AddItem(Containers.Inventory, item, out List <Common.Item.Item> affected); if (affected.Count > 0) { CharacterSession.Instance.SaveItem(affected); } if (res != OperationResults.FAILED) { if (item.Count > 0) { affected.Add(item); } switch (res) { case OperationResults.NEW_INDEX: SendItemUpdate(ItemUpdateMethod.Add, affected); break; case OperationResults.STACK_UPDATE: SendItemUpdate(ItemUpdateMethod.Update, affected); break; } if (res == OperationResults.NEW_INDEX && item.Count > 0) { CharacterSession.Instance.SaveItem(item); } if (item.Count == 0) { List <Common.Item.Item> remove = new List <Common.Item.Item>(); remove.Add(item); CharacterSession.Instance.DeleteItem(remove); } } SendPlayerGold(); SendItemBuyBackList(); } } } } } }
/// <summary> /// Secures the volume's encryption key with a specially formatted 48-digit password /// </summary> /// <param name="VolumeKeyProtectorID">After execution, assigns the new volume key protector ID.</param> /// <returns>The Win32 return code</returns> public OperationResults ProtectKeyWithNumericalPassword(out string VolumeKeyProtectorID) { ManagementBaseObject oResults; OperationResults iResult = ExecuteMethod("ProtectKeyWithNumericalPassword", m_oWMIObj.GetMethodParameters("ProtectKeyWithNumericalPassword"), out oResults); VolumeKeyProtectorID = (string)oResults["VolumeKeyProtectorID"]; return(iResult); }
public XResiliant(int retries = 1, int retryTimeout = 1000, OperationResults allowedResultsCodes = OperationResults.Success | OperationResults.NotAuthorised | OperationResults.NotFound, bool exceptionsOnly = false) { Retries = retries; RetryTimeout = retryTimeout; AllowedResultCodes = allowedResultsCodes; ExceptionsOnly = exceptionsOnly; }
public XResult(string message, OperationResults result, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0 ) { ResultCode = result; Message = message; _setCallerInformation(memberName, sourceFilePath, sourceLineNumber); }
/// <summary> /// Uses the new passphrase to obtain a new derived key. /// </summary> /// <param name="NewPassphrase">An updated string that specifies the passphrase.</param> /// <returns>The Win32 Return Code</returns> public OperationResults ChangePassphrase(string NewPassphrase) { // change the PIN ManagementBaseObject oInParams = m_oEncryptedDrive.GetMethodInputParameters("ChangePassphrase"); oInParams["VolumeKeyProtectorID"] = m_sVolumeKeyProtectorID; oInParams["NewPassphrase"] = NewPassphrase; // check if the drive is currently protected if (m_oEncryptedDrive.ProtectionStatus == ProtectionStatus.ProtectionOn) { // disable protection ManagementBaseObject oDisableResults; if (m_oEncryptedDrive.ExecuteMethod("DisableKeyProtectors", m_oEncryptedDrive.GetMethodInputParameters("DisableKeyProtectors"), out oDisableResults) != OperationResults.S_OK) { throw new InvalidOperationException("Could not disable the key protectors."); } oDisableResults = null; } // execute the method ManagementBaseObject oResults; OperationResults iResult = m_oEncryptedDrive.ExecuteMethod("ChangePassphrase", oInParams, out oResults); if (iResult == OperationResults.S_OK) { // change the internal identifier m_sVolumeKeyProtectorID = (string)oResults["NewProtectorID"]; } // check if the drive is currently protected if (m_oEncryptedDrive.ProtectionStatus == ProtectionStatus.ProtectionOff) { // disable protection ManagementBaseObject oEnableResults; if (m_oEncryptedDrive.ExecuteMethod("EnableKeyProtectors", m_oEncryptedDrive.GetMethodInputParameters("EnableKeyProtectors"), out oEnableResults) != OperationResults.S_OK) { throw new InvalidOperationException("Could not enable the key protectors."); } oEnableResults = null; } // release and return oResults = null; oInParams = null; return(iResult); }
internal OperationResults ExecuteMethod(string MethodName, ManagementBaseObject InParams, out ManagementBaseObject OutputParameters) { // invoke the method ManagementBaseObject outParams = m_oWMIObj.InvokeMethod( MethodName, InParams, null); // read the return code and copy the results to the output variable OperationResults rtnCode = (OperationResults)((uint)outParams["returnValue"]); OutputParameters = outParams; // return to caller return(rtnCode); }
public void ChangeBaGua(CM_BAGUA_SET_CHANGE p) { chara.SendRemove = false; while (chara.StillProcess) { } foreach (KeyValuePair <ushort, byte> i in p.EquipItems) { Common.Item.Item bagua = chara.Inventory.Container[Containers.Inventory][i.Key]; if (bagua?.BaseData.ItemType == ItemType.Bagua) { OperationResults res = chara.Inventory.EquipItem(bagua, out Common.Item.Item oldItem); if (res != OperationResults.FAILED) { if (oldItem != null) { PC.Status.EquipItem(chara, oldItem, false); List <Common.Item.Item> list = new List <Common.Item.Item>(); list.Add(bagua); list.Add(oldItem); SendItemUpdate(ItemUpdateMethod.Move, list); PC.Status.EquipItem(chara, bagua, true); } else { SendItemUpdate(ItemUpdateMethod.Move, bagua); PC.Status.EquipItem(chara, bagua, true); } } } } SM_BAGUA_SET_CHANGE r = new SM_BAGUA_SET_CHANGE(); Network.SendPacket(r); PC.Status.CalcStatus(chara); SendPlayerStats(); UpdateEvent evt = new UpdateEvent() { Actor = chara, Target = chara, UpdateType = UpdateTypes.Actor }; evt.AddActorPara(Common.Packets.GameServer.PacketParameter.HP, chara.HP); //evt.AddActorPara(Common.Packets.GameServer.PacketParameter.MaxHP, chara.MaxHP); map.SendEventToAllActorsWhoCanSeeActor(MapEvents.EVENT_BROADCAST, evt, chara, true); }
public static OperationResults[] GetOperationResultsesMqReceiveBody(byte[] body) { string json = Encoding.UTF8.GetString(body); if (string.IsNullOrEmpty(json)) { return(new OperationResults[0]); } var result = VirtualRoot.JsonSerializer.Deserialize <OperationResults[]> (json); if (result == null) { result = new OperationResults[0]; } return(result); }
/// <summary> /// Deletes a given key protector for the volume. /// </summary> /// <returns>The Win32 Return Code</returns> public OperationResults Delete() { // delete the key protector ManagementBaseObject oInParams = m_oEncryptedDrive.GetMethodInputParameters("DeleteKeyProtector"); oInParams["VolumeKeyProtectorID"] = m_sVolumeKeyProtectorID; // execute the method ManagementBaseObject oResults; OperationResults iResult = m_oEncryptedDrive.ExecuteMethod("DeleteKeyProtector", oInParams, out oResults); // release and return oResults = null; oInParams = null; return(iResult); }
/// <summary> /// Changes a PIN associated with an encrypted volume. /// </summary> /// <param name="NewPIN">A user-specified personal identification string. This string must consist of a sequence of 4 to 20 digits or, if the "Allow enhanced PINs for startup" group policy is enabled, 4 to 20 letters, symbols, spaces, or numbers.</param> /// <returns>The Win32 Return Code</returns> public OperationResults ChangePIN(string NewPIN) { // change the PIN ManagementBaseObject oInParams = m_oEncryptedDrive.GetMethodInputParameters("ChangePIN"); oInParams["VolumeKeyProtectorID"] = m_sVolumeKeyProtectorID; oInParams["NewPIN"] = NewPIN; // execute the method ManagementBaseObject oResults; OperationResults iResult = m_oEncryptedDrive.ExecuteMethod("ChangePIN", oInParams, out oResults); // release and return oResults = null; oInParams = null; return(iResult); }
public Common.Item.Item AddItem(uint itemID, ushort count = 1, Containers container = Containers.Inventory) { Common.Item.Item item = ItemFactory.Instance.CreateNewItem(itemID); item.CharID = chara.CharID; item.Container = container; item.Count = count; OperationResults res = chara.Inventory.AddItem(container, item, out List <Common.Item.Item> affected); if (affected.Count > 0) { CharacterSession.Instance.SaveItem(affected); } if (res != OperationResults.FAILED) { if (item.Count > 0) { affected.Add(item); } switch (res) { case OperationResults.NEW_INDEX: SendItemUpdate(ItemUpdateMethod.Add, affected); break; case OperationResults.STACK_UPDATE: SendItemUpdate(ItemUpdateMethod.Update, affected); break; } if (res == OperationResults.NEW_INDEX && item.Count > 0) { CharacterSession.Instance.CreateItem(item); } } return(item); }
/// <summary> /// Saves all external keys and related information that is needed for recovery to the Active Directory. /// </summary> /// <returns>The Win32 return code</returns> public OperationResults BackupRecoveryInformationToActiveDirectory() { OperationResults iResults = OperationResults.S_OK; // loop each numerical key protector foreach (KeyProtector oKeyProtector in KeyProtectors) { if (oKeyProtector.Type == KeyProtectorType.NumericalPassword) { ManagementBaseObject oOutput; ManagementBaseObject oInParams = m_oWMIObj.GetMethodParameters("BackupRecoveryInformationToActiveDirectory"); oInParams["VolumeKeyProtectorID"] = oKeyProtector.VolumeKeyProtectorID; OperationResults iIndResults = ExecuteMethod("BackupRecoveryInformationToActiveDirectory", oInParams, out oOutput); if (iIndResults != OperationResults.S_OK) { iResults = iIndResults; } } } // release and return return(iResults); }
public static string GetCard(OperationResults opsResults) { var resultsCardTitleText = Resources.ResultsCardTitleText; var operationTypeText = string.Format(Resources.OperationTypeText, opsResults.OperationType); var inputLineText = string.Format(Resources.InputLineText, opsResults.Input); var outputResultText = string.Format(Resources.OutputResultTypeText, opsResults.ResultType, opsResults.NumericalResult); var variablesToValues = new Dictionary <string, string>() { { "resultsCardTitleText", resultsCardTitleText }, { "operationTypeText", operationTypeText }, { "inputLineText", inputLineText }, { "outputResultText", outputResultText } }; var cardBody = CardTemplate; foreach (var kvp in variablesToValues) { cardBody = cardBody.Replace($"%{kvp.Key}%", kvp.Value); } return(cardBody); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Arithmetic; decimal quotient = 0; if (InputInts.Length == 2 && InputInts[1] != 0) { quotient = Convert.ToDecimal(InputInts[0]) / InputInts[1]; var resultsType = ResultTypes.Quotient; var results = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(quotient, 2).ToString(), OutputMsg = $"Given the list of {InputString}; the quotient = {decimal.Round(quotient, 2)}", OperationType = operationType.GetDescription(), ResultType = resultsType.GetDescription() }; #region Creating the adaptive card IMessageActivity reply = context.MakeMessage(); var resultsCard = OperationResultsAdaptiveCard.GetCard(results); reply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsCard) } }; #endregion await context.PostAsync(reply); } else { var errorType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "The list may be too long, or one of the elements could be 0 - please try again later.", OperationType = operationType.GetDescription(), ResultType = errorType.GetDescription() }; #region Creating the adaptive card IMessageActivity errorReply = context.MakeMessage(); var errorResultsCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorResultsCard) } }; #endregion // Send the message that you need more elements to calculate the sum await context.PostAsync(errorReply); } // Return back to the root dialog - popping this child dialog from the dialog stack context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length > 1 && InputInts.Length == 4) { int x1 = InputInts[0]; int y1 = InputInts[1]; var point1 = $"({x1}, {y1})"; int x2 = InputInts[2]; int y2 = InputInts[3]; var point2 = $"({x2},{y2})"; var deltaX = x2 - x1; var deltaY = y2 - y1; var calculation = Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)); var distanceFormula = Convert.ToDecimal(calculation); var resultsType = ResultTypes.Distance; var successResults = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(distanceFormula, 2).ToString(), OutputMsg = $"Given the points: {point1} and {point2}, the distance = {distanceFormula}", OperationType = operationType.GetDescription(), ResultType = resultsType.GetDescription() }; IMessageActivity successReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResults); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(successReply); } else { var errorResultType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "There needs to be exactly 4 elements to calculate the midpoint. Please try again later", OperationType = operationType.GetDescription(), ResultType = errorResultType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorResultsAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorResultsAdaptiveCard) } }; await context.PostAsync(errorReply); } // Returning back to the main root dialog stack context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Statistical; if (InputInts.Length > 1) { int product = InputInts[0]; for (int i = 1; i < InputInts.Length; i++) { if (InputInts[i] != 0) { product *= InputInts[i]; } else { break; } } // Calculating the Geometric mean here decimal geometricMean = Convert.ToDecimal(Math.Pow(product, 1 / InputInts.Length)); var resultType = ResultTypes.GeometricMean; var results = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(geometricMean, 2).ToString(), OutputMsg = $"Given the list: {InputString}; the geometric mean = ${geometricMean.ToString()}", OperationType = operationType.GetDescription(), ResultType = resultType.GetDescription() }; IMessageActivity opsReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(results); opsReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(opsReply); } else { var errorResType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "Your list may be too small to calculate the geometric mean. Please try again later", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorOpsAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorOpsAdaptiveCard) } }; await context.PostAsync(errorReply); } // Returning back to the RootDialog context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } // TODO: Complete the Rectangle area (success and failure cases) // TODO2: May want to also consider the square here var operationType = CalculationTypes.Geometric; if (InputInts.Length != 2) { var errorResultType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"The input list: {InputString} may not be valid. Please try again", OperationType = operationType.GetDescription(), ResultType = errorResultType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorResultsAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorResultsAdaptiveCard) } }; await context.PostAsync(errorReply); } else if (InputInts[0] == InputInts[1]) { var squareAreaResult = Convert.ToDecimal(Math.Pow(InputInts[0], 2)); var successResultType = ResultTypes.SquareArea; var successResults = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(squareAreaResult, 2).ToString(), OutputMsg = $"Given the inputs: {InputString}, the output = {decimal.Round(squareAreaResult, 2).ToString()}", OperationType = operationType.GetDescription(), ResultType = successResultType.GetDescription() }; IMessageActivity squareSuccessReply = context.MakeMessage(); var successResultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResults); squareSuccessReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(successResultsAdaptiveCard) } }; await context.PostAsync(squareSuccessReply); } else { var rectangleAreaResult = Convert.ToDecimal(InputInts[0] * InputInts[1]); var successResultType = ResultTypes.RectangleArea; var successResults = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(rectangleAreaResult, 2).ToString(), OutputMsg = $"Given the inputs: {InputString}, the output = {decimal.Round(rectangleAreaResult, 2).ToString()}", OperationType = operationType.GetDescription(), ResultType = successResultType.GetDescription() }; IMessageActivity successReply = context.MakeMessage(); var successResultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResults); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(successResultsAdaptiveCard) } }; await context.PostAsync(successReply); } }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Statistical; if (InputInts.Length > 1) { int sum = InputInts[0]; foreach (int item in InputInts) { sum += item; } double mean = Convert.ToDouble(sum) / InputInts.Length; decimal variance = CalculateVariance(mean, InputInts); var successResultType = ResultTypes.Variance; #region Building the results var results = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(variance, 2).ToString(), OutputMsg = $"Given the list: {InputString}; the variance = {decimal.Round(variance, 2)}", OperationType = operationType.GetDescription(), ResultType = successResultType.GetDescription() }; IMessageActivity resultsReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(results); resultsReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; #endregion await context.PostAsync(resultsReply); } else { var errorResType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "Your list may be too small to calculate the variance. Please try again later.", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorReplyAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorReplyAdaptiveCard) } }; await context.PostAsync(errorReply); } // Popping back to the root dialog context.Done <object>(null); }
public static void OperationResults(OperationResults operationResults) { lock (_lockForOperationResultses) { _operationResultses.Add(operationResults); } }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length != 4) { var errorResultType = ResultTypes.Error; var errorResult = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"Your input: {InputString} is not valid. Please try again later!", OperationType = operationType.GetDescription(), ResultType = errorResultType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResult); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorAdaptiveCard) } }; await context.PostAsync(errorReply); } else { // Looking to see if all the values are the same var isSquare = InputInts[0] == InputInts[1] && InputInts[1] == InputInts[2] && InputInts[2] == InputInts[3]; if (!isSquare) { var totalPerimeter = InputInts.Sum(); var totalPerimResultType = ResultTypes.QuadPerimeter; var totalPerimResult = new OperationResults() { Input = InputString, NumericalResult = totalPerimeter.ToString(), OperationType = operationType.GetDescription(), OutputMsg = $"Given the input list: {InputString}, the perimeter = {totalPerimeter}", ResultType = totalPerimResultType.GetDescription() }; IMessageActivity perimeterReply = context.MakeMessage(); var totalPerimAdaptiveCard = OperationResultsAdaptiveCard.GetCard(totalPerimResult); perimeterReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(totalPerimAdaptiveCard) } }; await context.PostAsync(perimeterReply); } else { var squarePerimeter = 4 * InputInts[0]; var totalPerimResultType = ResultTypes.QuadPerimeter; var squarePerimResult = new OperationResults() { Input = InputString, NumericalResult = squarePerimeter.ToString(), OperationType = operationType.GetDescription(), OutputMsg = $"Given the input list: {InputString}, the perimeter = {squarePerimeter}", ResultType = totalPerimResultType.GetDescription() }; IMessageActivity squarePerimReply = context.MakeMessage(); var squarePerimAdaptiveCard = OperationResultsAdaptiveCard.GetCard(squarePerimResult); squarePerimReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(squarePerimAdaptiveCard) } }; await context.PostAsync(squarePerimReply); } } }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Statistical; if (InputInts.Length >= 2) { var inputIntMax = InputInts.Max(); var inputIntMin = InputInts.Min(); // Conduct the range calculation as max - min var range = inputIntMax - inputIntMin; var successResType = ResultTypes.Range; var successResult = new OperationResults() { Input = InputString, NumericalResult = range.ToString(), OutputMsg = $"Given the list: {InputString}; the range = {range}", OperationType = operationType.GetDescription(), ResultType = successResType.GetDescription() }; #region Having the adaptive card created IMessageActivity reply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResult); reply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; #endregion // Sending out the reply with the card await context.PostAsync(reply); } else { var errorResType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "The list may be too short, try again with more numbers.", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; #region Having the adaptive card created IMessageActivity errorReply = context.MakeMessage(); var errorReplyAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorReplyAdaptiveCard) } }; #endregion // Sending the error card await context.PostAsync(errorReply); } // Popping back to the root dialog context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { var calculationType = CalculationTypes.Arithmetic; if (context == null) { throw new ArgumentNullException(nameof(context)); } if (InputInts.Length > 1) { #region Before using adaptive cards int sum = InputInts[0]; for (int i = 1; i < InputInts.Length; i++) { sum += InputInts[i]; } #endregion var resType = ResultTypes.Sum; var results = new OperationResults() { Input = InputString, NumericalResult = sum.ToString(), OutputMsg = $"Given the list of {InputString}; the sum = {sum}", OperationType = calculationType.GetDescription(), ResultType = resType.GetDescription() }; #region Creating the adaptive card IMessageActivity reply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(results); reply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; #endregion await context.PostAsync(reply); } else { var errorResType = ResultTypes.Error; // Building the error results object for the creation of the error card var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"The input list: {InputString} is too short - please provide more numbers", OperationType = calculationType.GetDescription(), ResultType = errorResType.GetDescription() }; #region Creating the adaptive card IMessageActivity errorReply = context.MakeMessage(); var errorAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorAdaptiveCard) } }; #endregion // Send the message that you need more elements to calculate the sum await context.PostAsync(errorReply); } // Return back to the RootDialog - popping this child dialog off the stack context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length > 3) { var errorListTooLongResType = ResultTypes.Error; // Error condition here var errorListTooLongResults = new OperationResults() { Input = InputString, NumericalResult = "DNE", OutputMsg = $"The input list: {InputString} could be too long - there needs to be 3 numbers exactly", OperationType = operationType.GetDescription(), ResultType = errorListTooLongResType.GetDescription() }; IMessageActivity errorListTooLongReply = context.MakeMessage(); var errorListTooLongAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorListTooLongResults); errorListTooLongReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorListTooLongAdaptiveCard) } }; await context.PostAsync(errorListTooLongReply); } else if (InputInts.Length < 3) { var errorListTooShortResType = ResultTypes.Error; var errorListTooShortResults = new OperationResults() { Input = InputString, NumericalResult = "DNE", OutputMsg = $"The input list: {InputString} could be too short - there needs to be 3 numbers exactly", OperationType = operationType.GetDescription(), ResultType = errorListTooShortResType.GetDescription() }; IMessageActivity errorListTooShortReply = context.MakeMessage(); var errorListTooShortAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorListTooShortResults); errorListTooShortReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorListTooShortAdaptiveCard) } }; await context.PostAsync(errorListTooShortReply); } else { int a = InputInts[0]; int b = InputInts[1]; int c = InputInts[2]; int discriminantValue = FindDiscriminant(a, b, c); var resultMsg = ""; var resultsType = ResultTypes.Discriminant; if (discriminantValue > 0) { resultMsg = $"Given your values: a = {a}, b = {b}, c = {c} - the discriminant = {discriminantValue} which means there are 2 roots"; } else if (discriminantValue == 0) { resultMsg = $"Given your values: a = {a}, b = {b}, c = {c} - the discriminant = {discriminantValue} which means there is 1 root"; } else { resultMsg = $"Given your values: a = {a}, b = {b}, c = {c} - the discriminant = {discriminantValue} which means there are no real roots"; } #region Generate the reply, operation results, card, and send out the message var discrimResults = new OperationResults() { Input = InputString, OperationType = operationType.GetDescription(), OutputMsg = resultMsg, NumericalResult = discriminantValue.ToString(), ResultType = resultsType.GetDescription() }; IMessageActivity discrimReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(discrimResults); discrimReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(discrimReply); #endregion } context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length != 3) { var errorResultType = ResultTypes.Error; var errorResult = new OperationResults() { Input = InputString, NumericalResult = "0", OperationType = operationType.GetDescription(), OutputMsg = $"Your input list: {InputString} is not valid, please check the input list and try again", ResultType = errorResultType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResult); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorAdaptiveCard) } }; await context.PostAsync(errorReply); } else { var isEquilateral = InputInts[0] == InputInts[1] && InputInts[1] == InputInts[2] && InputInts[0] == InputInts[2]; // Add all sides - for the scalene and isoceles cases if (!isEquilateral) { var perimeter = InputInts.Sum(); var perimResultType = ResultTypes.TrianglePerimeter; var perimResults = new OperationResults() { Input = InputString, NumericalResult = perimeter.ToString(), OperationType = operationType.GetDescription(), OutputMsg = $"Given the inputs: {InputString}, the perimeter = {perimeter}", ResultType = perimResultType.GetDescription() }; IMessageActivity perimSuccessReply = context.MakeMessage(); var perimSuccessAdaptiveCard = OperationResultsAdaptiveCard.GetCard(perimResults); perimSuccessReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(perimSuccessAdaptiveCard) } }; await context.PostAsync(perimSuccessReply); } else { var equiPerim = 3 * InputInts[0]; var perimResultType = ResultTypes.TrianglePerimeter; var perimResults = new OperationResults() { Input = InputString, NumericalResult = equiPerim.ToString(), OperationType = operationType.GetDescription(), OutputMsg = $"Given the inputs: {InputString}, the perimeter = {equiPerim}", ResultType = perimResultType.GetDescription() }; IMessageActivity equiPerimSuccessReply = context.MakeMessage(); var perimSuccessAdaptiveCard = OperationResultsAdaptiveCard.GetCard(perimResults); equiPerimSuccessReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(perimSuccessAdaptiveCard) } }; await context.PostAsync(equiPerimSuccessReply); } } }
private static void SerialDataReceived(int port) { Thread.Sleep(10); try { int len = Device.GetIqueue; if (len <= 0) { try { OverTimer.Stop(); switch (m_Bytes[0]) { case 10: if (m_Bytes[1] == 8) { JavascriptEvent.OperationOver(); } else { DataManager.VerifyingRepetition(m_Bytes); OverTimer.start(); } break; case 30: if (m_Bytes[1] == 8) { OperationResult = OperationResults.Fail; } else { OperationResult = OperationResults.Success; } break; case 43: bool ret = m_Bytes[1] != 8; JavascriptEvent.EndMessage(ret); if (ret) { JavascriptEvent.IncrementingNumber(); } break; case 160: JavascriptEvent.OperationOver(); if (m_Bytes[1] == 0) { JavascriptEvent.NewsMessage("发行器编号设置成功。"); } else { JavascriptEvent.NewsMessage("发行器编号设置失败,请重新操作。"); } break; } } catch (Exception ex) { Log4Helper.ErrorInfo(ex.Message, ex); JavascriptEvent.ErrorMessage(ex.Message); } finally { m_Bytes.Clear(); } return; } byte[] by = Device.Read(len); if (m_Bytes == null) { m_Bytes = new List <byte>(); } m_Bytes.AddRange(by); } catch (Exception ex) { Log4Helper.ErrorInfo(ex.Message, ex); JavascriptEvent.ErrorMessage(ex.Message); } }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Statistical; // Again making sure to conduct the appropriate things if (InputInts.Length > 2) { List <int> originalList = new List <int>(InputInts); List <int> modesList = new List <int>(); // Using LINQ in the lines below var query = from numbers in originalList group numbers by numbers into groupedNumbers select new { Number = groupedNumbers.Key, Count = groupedNumbers.Count() }; int max = query.Max(g => g.Count); if (max == 1) { int mode = 0; modesList.Add(mode); } else { modesList = query.Where(x => x.Count == max).Select(x => x.Number).ToList(); } var outputArray = modesList.ToArray(); var successResType = ResultTypes.Mode; #region Having the results object var successResult = new OperationResults() { Input = InputString, NumericalResult = outputArray.Length > 1 ? string.Join(",", outputArray) : outputArray[0].ToString(), OutputMsg = $"Given the list: {InputString}; the mode = {(outputArray.Length > 1 ? string.Join(",", outputArray) : outputArray[0].ToString())}", OperationType = operationType.GetDescription(), ResultType = successResType.GetDescription() }; IMessageActivity successReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResult); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; #endregion await context.PostAsync(successReply); } else { var errorResType = ResultTypes.Error; // Building out the error object, reply and card var errorResult = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"Please check your input list: {InputString} and try again later", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorReplyAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResult); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorReplyAdaptiveCard) } }; await context.PostAsync(errorReply); } // Returning back to the RootDialog - popping this child dialog off the stack context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length > 3) { var errorResType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "Your list may be too large to calculate the roots. Please try again later!", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; IMessageActivity errorListReply = context.MakeMessage(); var errorListAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorListReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorListAdaptiveCard) } }; await context.PostAsync(errorListReply); } else { double a = Convert.ToDouble(InputInts[0]); double b = Convert.ToDouble(InputInts[1]); double c = Convert.ToDouble(InputInts[2]); // The two roots of the quadratic equation double r1, r2; var discriminant = Math.Pow(b, 2) - (4 * a * c); int m; if (a == 0) { m = 1; } else if (discriminant > 0) { m = 2; } else if (discriminant == 0) { m = 3; } else { m = 4; } switch (m) { case 1: var opsErrorResultType = ResultTypes.Error; var opsError = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "The information provided may lead to a linear equation!", OperationType = CalculationTypes.Geometric.ToString(), ResultType = opsErrorResultType.GetDescription() }; IMessageActivity opsErrorReply = context.MakeMessage(); var opsErrorAdaptiveCard = OperationErrorAdaptiveCard.GetCard(opsError); opsErrorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(opsErrorAdaptiveCard) } }; await context.PostAsync(opsErrorReply); break; case 2: r1 = (-b + Math.Sqrt(discriminant)) / (2 * a); r2 = (-b - Math.Sqrt(discriminant)) / (2 * a); var successResultType = ResultTypes.EquationRoots; var successResults = new OperationResults() { Input = InputString, NumericalResult = $"{r1}, {r2}", OutputMsg = $"The roots are Real and Distinct - Given the list of: {InputString}, the roots are [{r1}, {r2}]", OperationType = operationType.GetDescription(), ResultType = successResultType.GetDescription() }; IMessageActivity opsSuccessReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResults); opsSuccessReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(opsSuccessReply); break; case 3: r1 = r2 = (-b) / (2 * a); var successOpsOneRootResultType = ResultTypes.EquationRoots; var successOpsOneRoot = new OperationResults() { Input = InputString, NumericalResult = $"{r1}, {r2}", OutputMsg = $"The roots are Real and Distinct - Given the list of: {InputString}, the roots are [{r1}, {r2}]", OperationType = operationType.GetDescription(), ResultType = successOpsOneRootResultType.GetDescription() }; IMessageActivity opsSuccessOneRootReply = context.MakeMessage(); var successOpsOneRootAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successOpsOneRoot); opsSuccessOneRootReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(successOpsOneRootAdaptiveCard) } }; await context.PostAsync(opsSuccessOneRootReply); break; case 4: var rootsDesc = "Roots are imaginary"; r1 = (-b) / (2 * a); r2 = Math.Sqrt(-discriminant) / (2 * a); var root1Str = string.Format("First root is {0:#.##} + {1:#.##}i", r1, r2); var root2Str = string.Format("Second root is {0:#.##} - {1:#.##}i", r1, r2); var root1 = string.Format("{0:#.##} + {1:#.##}i", r1, r2); var root2 = string.Format("{0:#.##} - {1:#.##}i", r1, r2); var imaginaryRootsResult = ResultTypes.EquationRoots; var opsSuccessImaginRootsResults = new OperationResults() { Input = InputString, NumericalResult = $"{root1}, {root2}", OutputMsg = rootsDesc + " " + root1Str + " " + root2Str, OperationType = operationType.GetDescription(), ResultType = imaginaryRootsResult.GetDescription() }; IMessageActivity opsSuccessImagReply = context.MakeMessage(); var opsSuccessImaginRootCard = OperationResultsAdaptiveCard.GetCard(opsSuccessImaginRootsResults); opsSuccessImagReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(opsSuccessImaginRootCard) } }; await context.PostAsync(opsSuccessImagReply); break; default: await context.PostAsync("Sorry I'm not sure what is going on here"); break; } } context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length != 1) { var errorResultType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"The input list: {InputString} may not be valid. Please try again", OperationType = operationType.GetDescription(), ResultType = errorResultType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorResultsAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorResultsAdaptiveCard) } }; await context.PostAsync(errorReply); } else if (InputInts.Length == 1 && InputInts[0] == 0) { var noCircumError = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"The input list: {InputString} may not be valid. Please try again", OperationType = operationType.GetDescription(), ResultType = noCircumError.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorResultsAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorResultsAdaptiveCard) } }; await context.PostAsync(errorReply); } else { var circumferenceResult = Convert.ToDecimal(2 * Math.PI * InputInts[0]); var successResultType = ResultTypes.Circumference; var successResult = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(circumferenceResult, 2).ToString(), OutputMsg = $"Given the input: {InputString}, the circumference = {decimal.Round(circumferenceResult, 2).ToString()}", OperationType = operationType.GetDescription(), ResultType = successResultType.GetDescription() }; IMessageActivity successReply = context.MakeMessage(); var successAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResult); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(successAdaptiveCard) } }; await context.PostAsync(successReply); } }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Statistical; if (InputInts.Length > 1) { int sum = InputInts[0]; for (int i = 0; i < InputInts.Length; i++) { sum += InputInts[i]; } var mean = Convert.ToDouble(sum) / InputInts.Length; var variance = CalculateVariance(mean, InputInts); var standardDev = Math.Sqrt((double)variance); var successResultType = ResultTypes.StandardDeviation; var results = new OperationResults() { Input = InputString, NumericalResult = standardDev.ToString(), OutputMsg = $"Given the list: {InputString}; the standard deviation = {standardDev}", OperationType = operationType.GetDescription(), ResultType = successResultType.GetDescription() }; // Sending out the reply IMessageActivity successReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(results); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(successReply); } else { var errorResType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "Your list may be too small to calculate the standard deviation. Please try again later", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorReplyAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorReplyAdaptiveCard) } }; await context.PostAsync(errorReply); } // Popping back after the completion of this dialog context.Done <object>(null); }