public void SCFileReceiveMessage() { string aFileName = ClearEnvironmentForTest(); ContextClient contextClient = SetUpContextClient(); var sendMessageContextActivity = new SendMessageActivity { To = Test_SendDestination, Action = Test_SendMessage_Action, ArgumentsJson = Test_SendMessage_Arguments, ContextClient = new InArgument <ContextClient>((ctx) => contextClient) }; var receiveMessageContextActivity = new ReceiveMessageActivity { ContextClient = new InArgument <ContextClient>((ctx) => contextClient) }; WorkflowInvoker.Invoke(sendMessageContextActivity); var output = WorkflowInvoker.Invoke(receiveMessageContextActivity); contextClient.MyDispose(); string fileContents = File.ReadAllText(aFileName); Assert.IsTrue(output["Action"].ToString() == Test_SendMessage_Action); Assert.IsTrue(output["ArgumentsJson"].ToString() == Test_SendMessage_Arguments); Assert.IsTrue(output["To"].ToString() == Test_SendOrigin); Assert.IsTrue(output["From"].ToString() == Test_SendOrigin); Assert.IsTrue(((DateTime)output["TimeSent"]).ToString("YYYY-MM-DD") == DateTime.Now.ToString("YYYY-MM-DD")); Assert.IsTrue(!(bool)output["MessageQueueEmpty"]); Assert.IsTrue(fileContents == "{\"GlobalVariables\":{},\"Messages\":{\"DummyProcess\":[]}}"); }
public void SCFileGetVariable() { string aFileName = ClearEnvironmentForTest(); ContextClient contextClient = SetUpContextClient(); var setContextActivity = new SetVariableActivity { VariableName = Test_SetVariableName, VariableValue = Test_SetVariableValue, ContextClient = new InArgument <ContextClient>((ctx) => contextClient) }; var getContextActivity = new GetVariableActivity { VariableName = Test_SetVariableName, ContextClient = new InArgument <ContextClient>((ctx) => contextClient) }; WorkflowInvoker.Invoke(setContextActivity); var output = WorkflowInvoker.Invoke(getContextActivity); contextClient.MyDispose(); string fileContents = File.ReadAllText(aFileName); Assert.IsTrue(fileContents == "{\"GlobalVariables\":{\"aVariable123\":\"aValue456\"},\"Messages\":{}}"); Assert.IsTrue(output["VariableValue"].ToString() == Test_SetVariableValue); }
protected override void Execute(CodeActivityContext context) { ContextClient contextClient = null; if (ContextClient.Expression == null) { var ContextClientArgument = context.DataContext.GetProperties()["ContextClient"]; contextClient = ContextClientArgument.GetValue(context.DataContext) as ContextClient; if (contextClient == null) { throw (new ArgumentException("ContextClient was not provided and cannot be retrieved from the container.")); } } else { contextClient = ContextClient.Get(context); } var executorRuntime = context.GetExtension <IExecutorRuntime>(); string currentProcess; if (executorRuntime != null) { var jobInfo = executorRuntime.RunningJobInformation; currentProcess = jobInfo.ProcessName.ToString(); if (currentProcess.Contains("_")) { currentProcess = currentProcess.Split('_')[0]; } } else { currentProcess = "DummyProcess"; } ContextMessage aNewContextMessage = new ContextMessage(); if (contextClient.GetNextMessage(currentProcess, ref aNewContextMessage)) { this.Action.Set(context, aNewContextMessage.Action); this.ArgumentsJson.Set(context, aNewContextMessage.ArgumentsJson); this.From.Set(context, aNewContextMessage.From); this.TimeSent.Set(context, aNewContextMessage.DateSent); this.To.Set(context, currentProcess); this.MessageQueueEmpty.Set(context, false); } else { this.MessageQueueEmpty.Set(context, true); } }
protected ContextClient SetUpContextClient() { var aDictionary = new Dictionary <string, string>(); aDictionary["Retries"] = Test_Retries.ToString(); ContextClient aContext; aContext = new ContextClient(Test_ContextType, Test_ContextName, aDictionary, true); aContext.CreateClient(); return(aContext); }
protected override void Execute(NativeActivityContext context) { this._context = ContextName.Get(context); string aFolder = ""; if (Retries == null || Retries.Get(context) <= 0) { throw new Exception("Retries cannot be zero or negative."); } if (InputFolder != null) { aFolder = InputFolder.Get(context); } Dictionary <string, string> aArguments = new Dictionary <string, string>(); aArguments["Folder"] = aFolder; aArguments["Retries"] = Retries.Get(context).ToString(); try { aContext = new ContextClient(ContextType, this._context, aArguments, this.Debug); aContext.CreateClient(); if (ContextType == contextType.File && this.ClearContext) { aContext.ClearAll(); } if (Body != null) { //scheduling the execution of the child activities // and passing the value of the delegate argument context.ScheduleAction(Body, aContext, OnCompleted, OnFaulted); } } catch (Exception exception) { if (this.Debug) { Console.WriteLine("[SharedContext Scope] There is an error!!"); Console.WriteLine(exception.Message); } CleanupContext(); throw; } }
public void SCFileReceiveMessageEmpty() { string aFileName = ClearEnvironmentForTest(); ContextClient contextClient = SetUpContextClient(); var receiveMessageContextActivity = new ReceiveMessageActivity { ContextClient = new InArgument <ContextClient>((ctx) => contextClient) }; var output = WorkflowInvoker.Invoke(receiveMessageContextActivity); contextClient.MyDispose(); string fileContents = File.ReadAllText(aFileName); Assert.IsTrue((bool)output["MessageQueueEmpty"]); Assert.IsTrue(fileContents == "{\"GlobalVariables\":{},\"Messages\":{\"DummyProcess\":[]}}"); }
protected override void Execute(CodeActivityContext context) { ContextClient contextClient = null; if (ContextClient.Expression == null) { var ContextClientArgument = context.DataContext.GetProperties()["ContextClient"]; contextClient = ContextClientArgument.GetValue(context.DataContext) as ContextClient; if (contextClient == null) { throw (new ArgumentException("ContextClient was not provided and cannot be retrieved from the container.")); } } else { contextClient = ContextClient.Get(context); } contextClient.SetVariable(VariableName.Get(context), VariableValue.Get(context)); }
public void SCFileSendMessage() { string aFileName = ClearEnvironmentForTest(); ContextClient contextClient = SetUpContextClient(); var sendMessageContextActivity = new SendMessageActivity { To = Test_SendDestination, Action = Test_SendMessage_Action, ArgumentsJson = Test_SendMessage_Arguments, ContextClient = new InArgument <ContextClient>((ctx) => contextClient) }; var output = WorkflowInvoker.Invoke(sendMessageContextActivity); contextClient.MyDispose(); string fileContents = File.ReadAllText(aFileName); Assert.IsTrue(fileContents.Contains("{\"GlobalVariables\":{},\"Messages\":{\"DummyProcess\":[{\"From\":\"DummyProcess\",\"To\":\"DummyProcess\",\"Action\":\"Do-Something\",\"ArgumentsJson\":\"{\\\"some_argument\\\":\\\"aValue\\\"}\",\"DateSent\":")); }