public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context) { if (string.IsNullOrEmpty(entityView?.Action) || !entityView.Action.Equals(context.GetPolicy <KnownJobSchedulerActionsPolicy>().AddJobConnection, StringComparison.OrdinalIgnoreCase)) { return(entityView); } var jobConnectionName = entityView.Properties.FirstOrDefault(p => p.Name.Equals("Name", StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(jobConnectionName?.Value)) { var str1 = jobConnectionName == null ? "Name" : jobConnectionName.DisplayName; var str2 = await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().ValidationError, "InvalidOrMissingPropertyValue", new object[1] { str1 }, "Invalid or missing value for property 'Name'."); return(entityView); } var type = entityView.Properties.FirstOrDefault(p => p.Name.Equals("Type", StringComparison.OrdinalIgnoreCase))?.Value; if (string.IsNullOrEmpty(type)) { var str = await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().ValidationError, "InvalidOrMissingPropertyValue", new object[1] { "Type" }, "Invalid or missing value for property 'Type'."); return(entityView); } var displayNameProperty = entityView.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName", StringComparison.OrdinalIgnoreCase)); var displayName = displayNameProperty?.Value; var descriptionProperty = entityView.Properties.FirstOrDefault(p => p.Name.Equals("Description", StringComparison.OrdinalIgnoreCase)); var description = descriptionProperty?.Value; var dbConnectionStringProperty = entityView.Properties.FirstOrDefault(p => p.Name.Equals("DbConnectionString", StringComparison.OrdinalIgnoreCase)); var dbConnectionString = dbConnectionStringProperty?.Value; var webServiceUrlProperty = entityView.Properties.FirstOrDefault(p => p.Name.Equals("WebServiceUrl", StringComparison.OrdinalIgnoreCase)); var webServiceUrl = webServiceUrlProperty?.Value; var usernameProperty = entityView.Properties.FirstOrDefault(p => p.Name.Equals("Username", StringComparison.OrdinalIgnoreCase)); var username = usernameProperty?.Value; var passwordProperty = entityView.Properties.FirstOrDefault(p => p.Name.Equals("Password", StringComparison.OrdinalIgnoreCase)); var password = passwordProperty?.Value; var addJobConnectionArgument = new AddJobConnectionArgument(jobConnectionName.Value, type) { Description = description, DisplayName = displayName, DbConnectionString = dbConnectionString, WebServiceUrl = webServiceUrl, Username = username, Password = password }; var jobConnection = await _addJobConnectionCommand.Process(context.CommerceContext, addJobConnectionArgument); return(entityView); }
/// <summary> /// The process of the command /// </summary> /// <param name="commerceContext"> /// The commerce context /// </param> /// <param name="addJobConnectionArgument"></param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <JobConnection> Process(CommerceContext commerceContext, AddJobConnectionArgument addJobConnectionArgument) { Condition.Requires(addJobConnectionArgument).IsNotNull("AddJobConnectionCommand: addJobConnectionArgument cannot be null."); using (var activity = CommandActivity.Start(commerceContext, this)) { var arg = addJobConnectionArgument; var result = await this._pipeline.Run(arg, new CommercePipelineExecutionContextOptions(commerceContext)); return(result); } }