/// <summary> /// Handles an instant message received event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Customer_MessageReceived(object sender, InstantMessageReceivedEventArgs e) { this.m_lastImReceivedTime = DateTime.Now; this.NoInputCount = 0; this.Result = e.TextBody.TrimEnd(); if (this.NoRecoCount < this.MaxNoRecoAttempts) { if (ExpectedInput.Contains(this.Result, StringComparer.OrdinalIgnoreCase)) { this.HandleMessageReceivedComplete(); } else { this.HandleNoRecognition(); } } else { this.HandleMessageReceivedComplete(); } }
/// <summary> /// Checks for existing array or def with specified ID. /// If ExpectedInput type is custom, will not be validated. Must be overriden. /// </summary> /// <param name="container">KScriptContainer object</param> /// <param name="caller">Object calling method</param> /// <returns>If the check was successfull</returns> public bool IsExpectedInput(KScriptContainer container, KScriptBaseObject caller) { ExpectedInput x = expected_input; switch (x) { case ExpectedInput.ArrayID: string array_id = GetPropertyValue(caller); return(container.ArraysGet().ContainsKey(array_id)); case ExpectedInput.DefID: if (container.Properties.DynamicDefs) { return(true); } string def_id = GetPropertyValue(caller); return(container.GetDefs().ContainsKey(def_id)); case ExpectedInput.DirectoryLocation: string directory = GetPropertyValue(caller); return(Directory.Exists(directory)); case ExpectedInput.FileLocation: string file = GetPropertyValue(caller); return(File.Exists(file)); case ExpectedInput.URL: string url = GetPropertyValue(caller); return(Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out _)); case ExpectedInput.Number: return(int.TryParse(GetPropertyValue(caller), out _)); case ExpectedInput.Bool: bool isBool = KScriptBoolHandler.IsBool(GetPropertyValue(caller)); return(isBool); } return(true); }
static void Main(string[] args) { System.Console.WriteLine("Hello user"); var calculator = new Logic.Calculator(); ExpectedInput expectedInput = ExpectedInput.Operant; string[] operationSymbols = { "+", "-", "*", "/" }; PrintMenu(); while (true) { string usersInput = System.Console.ReadLine(); if (string.Compare(usersInput, "Q", true, CultureInfo.InvariantCulture) == 0) { System.Console.WriteLine("Goodbye!"); break; } if (expectedInput == ExpectedInput.Operant) { if (!float.TryParse(usersInput, out float operand1)) { System.Console.WriteLine("Entered number is not valid. Please enter valid number"); System.Console.WriteLine("Press Q to exit"); } else { expectedInput = ExpectedInput.Operation; calculator.Operand1 = operand1; System.Console.WriteLine("Enter operation type "); } } else if (expectedInput == ExpectedInput.Operation) { string userInputTrimmed = usersInput.Trim(); if (operationSymbols.Contains(userInputTrimmed)) { int index = operationSymbols.ToList().IndexOf(userInputTrimmed); calculator.OperationType = (OperationType)(index + 1); expectedInput = ExpectedInput.Operant2; System.Console.WriteLine("Enter second operant "); } else { System.Console.WriteLine("Entered operation type is not valid. Please enter valid operation"); System.Console.WriteLine("Press Q to exit"); } } else if (expectedInput == ExpectedInput.Operant2) { if (!float.TryParse(usersInput, out float operand2)) { System.Console.WriteLine("Entered number is not valid. Please enter valid number"); } else { expectedInput = ExpectedInput.Result; calculator.Operand2 = operand2; float result = calculator.PerfomeAction(); calculator.Result = result; string history = calculator.ShowHistory(); System.Console.WriteLine($"Result is: {history} = {result}"); System.Console.WriteLine("Press Enter to start over"); } } else if (expectedInput == ExpectedInput.Result) { expectedInput = ExpectedInput.Operation; calculator.Operand1 = calculator.Result; System.Console.WriteLine(calculator.Result); System.Console.WriteLine("Enter operation type "); } } }
public KScriptValidationObject(string property_name, bool can_be_empty, ExpectedInput expected_input) { this.property_name = property_name; this.can_be_empty = can_be_empty; this.expected_input = expected_input; }
public async Task <WorkflowOutput> GetWorkflowOutput(string instanceId, WorkflowCore.Models.Workflow workFlow, object dataObject, string publishedEvent = null) { var pointer = new WorkflowCore.Models.ExecutionPointer(); var workflowStatus = WorkflowCore.Models.WorkflowStatus.Running; string eventName = string.Empty; var expectedInputs = new List <ExpectedInput>(); var inputs = new List <string>(); var WorkflowInstance = await _workflowStore.GetWorkflowInstance(instanceId); if (WorkflowInstance != null) { workflowStatus = WorkflowInstance.Status; pointer = WorkflowInstance.ExecutionPointers.Last(); while ((pointer.Status == WorkflowCore.Models.PointerStatus.Pending || pointer.Status == WorkflowCore.Models.PointerStatus.Running) || (pointer.Status == WorkflowCore.Models.PointerStatus.Complete && workflowStatus == WorkflowCore.Models.WorkflowStatus.Running) || (pointer.Status == WorkflowCore.Models.PointerStatus.WaitingForEvent && pointer.EventName == publishedEvent)) { WorkflowInstance = await _workflowStore.GetWorkflowInstance(instanceId); workflowStatus = WorkflowInstance.Status; pointer = WorkflowInstance.ExecutionPointers.Last(); } } if ((pointer.Status == WorkflowCore.Models.PointerStatus.WaitingForEvent) && (!pointer.EventPublished)) { eventName = pointer.EventName; var step = workFlow.Definition.Steps.Where(s => s.Name == pointer.StepName).FirstOrDefault(); if (step.Outputs != null) { var outputs = step.Outputs; foreach (var item in outputs) { inputs.Add(item.Key); } } } foreach (var input in inputs) { var type = dataObject.GetType().GetProperty(input); if (type != null) { var expectedInput = new ExpectedInput { Name = input, DataType = type.PropertyType.Name }; expectedInputs.Add(expectedInput); } } WorkflowOutput output = new WorkflowOutput { InstanceId = instanceId, WorkflowStatus = workflowStatus.ToString(), LastStepName = pointer.StepName, StepStatus = pointer.Status.ToString(), EventName = eventName, ExpectedInputs = expectedInputs }; return(output); }