/// <summary> /// Adds a value for a given input argument to this field. It is assumed the value will cast correctly. /// </summary> /// <param name="argumentName">Name of the input field, as declared in the schema, on the field being mocked.</param> /// <param name="value">A fully resolved value to use.</param> /// <returns>MockFieldRequest.</returns> public FieldContextBuilder AddInputArgument(string argumentName, object value) { var resolvedInputValue = new ResolvedInputArgumentValue(argumentName, value); var fieldArgument = _graphField.Arguments[argumentName]; var inputArgument = new InputArgument(fieldArgument, resolvedInputValue); _arguments.Add(inputArgument); return(this); }
/// <summary> /// Inspects the arguments supplied on the user's query document, merges them with those defaulted from the graph field itself /// and applies variable data as necessary to generate a single unified set of input arguments to be used when resolving a field of data. /// </summary> /// <param name="argumentContainer">The field selection.</param> /// <param name="querySuppliedArguments">The supplied argument collection parsed from the user query document.</param> /// <returns>Task<IInputArgumentCollection>.</returns> private IInputArgumentCollection CreateArgumentList( IGraphFieldArgumentContainer argumentContainer, IQueryInputArgumentCollection querySuppliedArguments) { var collection = new InputArgumentCollection(); var argGenerator = new ArgumentGenerator(_schema, querySuppliedArguments); foreach (var argument in argumentContainer.Arguments) { var argResult = argGenerator.CreateInputArgument(argument); if (argResult.IsValid) { collection.Add(new InputArgument(argument, argResult.Argument)); } else { _messages.Add(argResult.Message); } } return(collection); }
public static void ApplyAction(this Entity entity, KeyValuePair <string, string> action) { string[] actionArgs = action.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); switch (action.Key.ToUpper()) { case "APPLYWORKFLOW": InputArgumentCollection workflowArgs = null; if (actionArgs.Length > 1) { workflowArgs = new InputArgumentCollection(); for (int i = 1; i < actionArgs.Length; i++) { string[] workflowArg = actionArgs[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); workflowArgs.Add(workflowArg[0], workflowArg[1]); } } Guid g; if (Guid.TryParse(actionArgs[0], out g)) { XrmCore.ApplyWorkFlow(entity, g, workflowArgs); } else { XrmCore.ApplyWorkFlow(entity, actionArgs[0], workflowArgs); } break; case "ADDTOMARKETINGLIST": case "REMOVEFROMMARKETINGLIST": bool remove = action.Key.Equals("REMOVEFROMMARKETINGLIST", StringComparison.OrdinalIgnoreCase); for (int i = 0; i < actionArgs.Length; i++) { Entity list = XrmCore.RetrieveByAttribute("list", "listname", actionArgs[i], new ColumnSet("listid")).Entities.FirstOrDefault(); if (list == null) { throw new ArgumentException(string.Format("The Marketing list {0} could not be found", actionArgs[0])); } else { if (remove) { XrmMarketing.RemoveFromMarketingList(entity.Id, list.Id); } else { XrmMarketing.AddToMarketingList(new Guid[] { entity.Id }, list.Id); } } } break; case "ASSIGN": FilterExpression filter = new FilterExpression(LogicalOperator.Or); filter.AddCondition("fullname", ConditionOperator.Like, new object[] { actionArgs[0] }); filter.AddCondition("internalemailaddress", ConditionOperator.Like, new object[] { actionArgs[0] }); Entity owner = XrmCore.RetrieveByFilter("systemuser", filter, new ColumnSet("systemuserid")).Entities.FirstOrDefault(); if (owner == null) { throw new ArgumentException(string.Format("The System user with the name or email {0} could not be found", actionArgs[0])); } else { AssignRequest request = new AssignRequest() { Assignee = owner.ToEntityReference(), Target = entity.ToEntityReference() }; XrmCore.Execute <AssignRequest, AssignResponse>(request); } break; default: break; } }