// ReSharper disable UnusedParameter.Global protected static IDictionary <string, object> RunActivity(ActivityImplementationBase activity, IDictionary <string, object> inputs, bool expectedToComplete = true) // ReSharper restore UnusedParameter.Global { Assert.IsFalse(activity is WorkflowImplementation, "Dont use RunActivity to run a workflow, use WorkflowRunner.Instance."); var invoker = new WorkflowInvoker(); // invoker.RunStateFactory = new TestRunStateFactory(); var workflowRun = ActivityTestHelper.CreateWfRunForActivity(activity); workflowRun.Name = "Dummy Run" + DateTime.Now; var convertedInputs = new ActivityInputs(activity.ActivityInstance.GetInputArguments(), inputs); var factory = new TestRunStateFactory(); // var runState = Factory.Current.Resolve<IRunStateFactory>().CreateRunState(new WorkflowMetadata(), workflowRun); var runState = factory.CreateRunState(new WorkflowMetadata(), workflowRun); runState.CurrentActivity = activity.ActivityInstance; bool hasCompleted = activity.Execute(runState, convertedInputs); if (expectedToComplete && !hasCompleted) { Assert.Fail("Unfinished activity"); } return(runState.GetResult(activity.ActivityInstance.GetOutputArguments())); }
/// <summary> /// Builds a request from the current state of the workflow run to initiate the appropriate action remotely. /// </summary> /// <param name="context">The workflow run context.</param> /// <param name="inputs">The activity input arguments.</param> /// <returns>The request object.</returns> protected override ApplicationOperationRequest GetRequest(IRunState context, ActivityInputs inputs) { var appId = Guid.Empty; var appTenant = GetArgumentValue <string>(inputs, ApplicationTenantArgumentAlias); object o; if (inputs.TryGetValue(GetArgumentKey(ApplicationIdArgumentAlias), out o)) { if (o != null) { appId = (Guid)o; } } if (appId == Guid.Empty) { throw new WorkflowRunException("Application identifier not found."); } return(new ApplicationOperationRequest { Operation = ApplicationOperation.Uninstall, Tenant = appTenant, Id = appId }); }
/// <summary> /// Builds a request from the current state of the workflow run to initiate the appropriate action remotely. /// </summary> /// <param name="context">The workflow run context.</param> /// <param name="inputs">The activity input arguments.</param> /// <returns>The request object.</returns> protected override LogRequest GetRequest(IRunState context, ActivityInputs inputs) { var message = GetArgumentValue <string>(inputs, MessageArgumentAlias); return(new LogRequest { Message = message }); }
/// <summary> /// Builds a request from the current state of the workflow run to initiate the appropriate action remotely. /// </summary> /// <param name="context">The workflow run context.</param> /// <param name="inputs">The activity input arguments.</param> /// <returns>The request object.</returns> protected override TenantOperationRequest GetRequest(IRunState context, ActivityInputs inputs) { var tenantName = GetArgumentValue <string>(inputs, TenantNameArgumentAlias); return(new TenantOperationRequest { Operation = Operation.Enable, Name = tenantName }); }
/// <summary> /// Responds to an activity being started. /// </summary> /// <param name="context">The current running context of the workflow.</param> /// <param name="inputs">Any inputs that have been provided to the activity by the workflow.</param> /// <returns>True if the activity has completed, false if it is paused.</returns> public bool OnStart(IRunState context, ActivityInputs inputs) { var done = false; using (Profiler.Measure("CastActivityImplementation.OnStart")) { try { LogToRun(context, string.Format("CAST Activity '{0}' is starting.", ActivityInstance.Name)); var dbid = string.Empty; if (!string.IsNullOrEmpty(DatabaseIdInputAlias)) { dbid = GetArgumentValue <string>(inputs, DatabaseIdInputAlias); } if (string.IsNullOrEmpty(dbid)) { throw new WorkflowRunException("Unable to determine client communication key."); } var request = GetRequest(context, inputs); request.Type = request.GetType().AssemblyQualifiedName; request.DatabaseId = dbid; request.RunStep = context.StepsTakenInSession; // send the request after the workflow run has been saved context.SetPostRunAction(() => { request.RunId = context.WorkflowRunId; Sender.Request(SpecialStrings.CastClientKeyPrefix + dbid.ToLowerInvariant(), request, this); }); } catch (Exception e) { EventLog.Application.WriteError("An unexpected error occurred when starting a CAST activity. {0}", e.ToString()); done = true; LogToRun(context, string.Format("CAST Activity '{0}' failed to start.", ActivityInstance.Name)); if (string.IsNullOrEmpty(FailureExitPointAlias)) { throw; } context.ExitPointId = new EntityRef(FailureExitPointAlias); } } return(done); }
/// <summary> /// Builds a request from the current state of the workflow run to initiate the appropriate action remotely. /// </summary> /// <param name="context">The workflow run context.</param> /// <param name="inputs">The activity input arguments.</param> /// <returns>The request object.</returns> protected override UserOperationRequest GetRequest(IRunState context, ActivityInputs inputs) { var userName = GetArgumentValue <string>(inputs, UserNameArgumentAlias); var userTenant = GetArgumentValue <string>(inputs, UserTenantArgumentAlias); return(new UserOperationRequest { Operation = Operation.Delete, User = userName, Tenant = userTenant }); }
/// <summary> /// Builds a request from the current state of the workflow run to initiate the appropriate action remotely. /// </summary> /// <param name="context">The workflow run context.</param> /// <param name="inputs">The activity input arguments.</param> /// <returns>The request object.</returns> protected override TenantOperationRequest GetRequest(IRunState context, ActivityInputs inputs) { var tenantId = GetArgumentValue <string>(inputs, TenantRemoteIdArgumentAlias); var tenantName = GetArgumentValue <string>(inputs, TenantNameArgumentAlias); long id; long.TryParse(tenantId, out id); return(new TenantOperationRequest { Operation = Operation.Rename, Id = id, Name = tenantName }); }
/// <summary> /// Builds a request from the current state of the workflow run to initiate the appropriate action remotely. /// </summary> /// <param name="context">The workflow run context.</param> /// <param name="inputs">The activity input arguments.</param> /// <returns>The request object.</returns> protected override UserOperationRequest GetRequest(IRunState context, ActivityInputs inputs) { var userName = GetArgumentValue <string>(inputs, UserNameArgumentAlias); var userPassword = GetArgumentValue <string>(inputs, UserPasswordArgumentAlias); var userTenant = GetArgumentValue <string>(inputs, UserTenantArgumentAlias); var userRoles = GetArgumentValue <IEnumerable <IEntity> >(inputs, UserRolesArgumentAlias); var roles = new RoleNames(); if (userRoles != null) { var managedRoles = userRoles.Select(u => u.As <ManagedRole>()); roles.AddRange(managedRoles.Where(m => m != null).Select(m => m.Name)); } return(new UserOperationRequest { Operation = Operation.Create, User = userName, Password = userPassword, Tenant = userTenant, Roles = roles }); }
/// <summary> /// Builds a request from the current state of the workflow run to initiate the appropriate action remotely. /// </summary> /// <param name="context">The workflow run context.</param> /// <param name="inputs">The activity input arguments.</param> /// <returns>The request object.</returns> protected abstract TRequest GetRequest(IRunState context, ActivityInputs inputs);
void IRunNowActivity.OnRunNow(IRunState context, ActivityInputs inputs) { Action(ActivityInstance.Id); }
/// <summary> /// Runs when the activity is run by the workflow. /// </summary> /// <param name="context">The run state.</param> /// <param name="inputs">The inputs.</param> public void OnRunNow(IRunState context, ActivityInputs inputs) { var startedKey = GetArgumentKey(StartedArgumentAlias); var listKey = GetArgumentKey(ListArgumentAlias); var appIdKey = GetArgumentKey(ApplicationIdArgumentAlias); var appVersionKey = GetArgumentKey(ApplicationVersionArgumentAlias); var ids = new List <Guid>(); var started = context.GetArgValue <bool?>(ActivityInstance, startedKey) ?? false; if (!started) { // set that the activity has started context.SetArgValue(ActivityInstance, startedKey, true); // retrieve the product var productSku = GetArgumentValue <string>(inputs, ProductSkuArgumentAlias); var product = MarketplaceService.GetProduct(productSku); if (product == null) { throw new WorkflowRunException("Product {0} was not found.", productSku); } // process the included apps and app versions and sort their ids ids.AddRange(GetSortedApplicationIds(product)); } else { // retrieve the current state of the ordered list from the context var list = context.GetArgValue <string>(ActivityInstance, listKey); if (!string.IsNullOrEmpty(list)) { ids.AddRange(list.Split(',').Select(Guid.Parse)); } } // loop over the next id on the list var current = ids.FirstOrDefault(); if (current != default(Guid)) { // set the application id and any specific version info on the output var variables = GetAppVariables(context, current); if (variables.Item1 != Guid.Empty) { context.SetArgValue(ActivityInstance, appIdKey, variables.Item1); context.SetArgValue(ActivityInstance, appVersionKey, variables.Item2); } // remove this id from the list and store it again ids = ids.Skip(1).ToList(); var list = string.Join(",", ids); context.SetArgValue(ActivityInstance, listKey, list); context.ExitPointId = new EntityRef(LoopExitPointAlias); } else { // we have finished context.SetArgValue(ActivityInstance, startedKey, false); context.SetArgValue(ActivityInstance, listKey, null); context.ExitPointId = new EntityRef(FinishedExitPointAlias); } }