コード例 #1
0
        internal Entity ToResponsePropertyEntity(CustomAction action)
        {
            const string customapiresponseproperty = nameof(customapiresponseproperty);

            var apiProp = new Entity(customapiresponseproperty)
            {
                ["description"]       = Description,
                ["displayname"]       = Name,
                ["logicalentityname"] = BindingTargetType,
                ["name"]       = $"{action.MessageName}.{Name}",
                ["type"]       = TypeOptionSetValue,
                ["uniquename"] = Name
            };

            return(apiProp);
        }
コード例 #2
0
        internal Entity ToRequestParameterEntity(CustomAction action)
        {
            const string customapirequestparameter = nameof(customapirequestparameter);

            var apiParam = new Entity(customapirequestparameter)
            {
                ["description"]       = Description,
                ["displayname"]       = Name,
                ["isoptional"]        = !Required,
                ["logicalentityname"] = BindingTargetType,
                ["name"]       = $"{action.MessageName}.{Name}",
                ["type"]       = TypeOptionSetValue,
                ["uniquename"] = Name
            };

            return(apiParam);
        }
コード例 #3
0
        private void customActionListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            propertyGrid.SelectedObject = null;
            convertButton.Enabled       = false;

            if (customActionListView.SelectedItems.Count != 1)
            {
                return;
            }

            var sdkMessageId = (Guid)((Entity)customActionListView.SelectedItems[0].Tag).GetAttributeValue <AliasedValue>("msg.sdkmessageid").Value;

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Loading Custom Action Details...",
                Work    = (bw, args) =>
                {
                    var qry       = new QueryExpression("sdkmessage");
                    qry.ColumnSet = new ColumnSet("name");
                    qry.Criteria.AddCondition("sdkmessageid", ConditionOperator.Equal, sdkMessageId);
                    var workflowLink         = qry.AddLink("workflow", "sdkmessageid", "sdkmessageid");
                    workflowLink.EntityAlias = "wf";
                    workflowLink.Columns     = new ColumnSet("workflowid", "name", "description", "primaryentity", "xaml");
                    workflowLink.LinkCriteria.AddCondition("type", ConditionOperator.Equal, 1); // Definition

                    var workflowDetails = Service.RetrieveMultiple(qry).Entities.Single();

                    var reqParamQry       = new QueryExpression("sdkmessagerequestfield");
                    reqParamQry.Distinct  = true;
                    reqParamQry.ColumnSet = new ColumnSet("clrparser", "name", "optional", "parameterbindinginformation");
                    var reqLink           = reqParamQry.AddLink("sdkmessagerequest", "sdkmessagerequestid", "sdkmessagerequestid");
                    var pairLink          = reqLink.AddLink("sdkmessagepair", "sdkmessagepairid", "sdkmessagepairid");
                    pairLink.LinkCriteria.AddCondition("sdkmessageid", ConditionOperator.Equal, sdkMessageId);
                    pairLink.LinkCriteria.AddCondition("endpoint", ConditionOperator.Equal, "api/data");
                    reqParamQry.AddOrder("position", OrderType.Ascending);

                    var requestParameters = Service.RetrieveMultiple(reqParamQry);

                    var respParamQry       = new QueryExpression("sdkmessageresponsefield");
                    respParamQry.Distinct  = true;
                    respParamQry.ColumnSet = new ColumnSet("clrformatter", "formatter", "name", "parameterbindinginformation");
                    var respLink           = respParamQry.AddLink("sdkmessageresponse", "sdkmessageresponseid", "sdkmessageresponseid");
                    reqLink  = respLink.AddLink("sdkmessagerequest", "sdkmessagerequestid", "sdkmessagerequestid");
                    pairLink = reqLink.AddLink("sdkmessagepair", "sdkmessagepairid", "sdkmessagepairid");
                    pairLink.LinkCriteria.AddCondition("sdkmessageid", ConditionOperator.Equal, sdkMessageId);
                    pairLink.LinkCriteria.AddCondition("endpoint", ConditionOperator.Equal, "api/data");
                    respParamQry.AddOrder("position", OrderType.Ascending);

                    var responseParameters = Service.RetrieveMultiple(respParamQry);

                    var stepQry       = new QueryExpression("sdkmessageprocessingstep");
                    stepQry.ColumnSet = new ColumnSet("mode", "stage", "plugintypeid");
                    stepQry.Criteria.AddCondition("sdkmessageid", ConditionOperator.Equal, sdkMessageId);
                    stepQry.Criteria.AddCondition("stage", ConditionOperator.NotEqual, 30); // Exclude standard SyncWorkflowExecution plugin
                    var pluginLink         = stepQry.AddLink("plugintype", "plugintypeid", "plugintypeid");
                    pluginLink.EntityAlias = "plugin";
                    pluginLink.Columns     = new ColumnSet("name");
                    var pluginSteps        = Service.RetrieveMultiple(stepQry);

                    var xaml = (string)workflowDetails.GetAttributeValue <AliasedValue>("wf.xaml")?.Value;

                    var action = new CustomAction
                    {
                        WorkflowId        = (Guid)workflowDetails.GetAttributeValue <AliasedValue>("wf.workflowid").Value,
                        MessageName       = workflowDetails.GetAttributeValue <string>("name"),
                        Name              = (string)workflowDetails.GetAttributeValue <AliasedValue>("wf.name").Value,
                        Description       = (string)workflowDetails.GetAttributeValue <AliasedValue>("wf.description")?.Value,
                        HasWorkflow       = HasWorkflow(xaml),
                        PrimaryEntity     = (string)workflowDetails.GetAttributeValue <AliasedValue>("wf.primaryentity")?.Value,
                        RequestParameters = new ParameterCollection <RequestParameter>(requestParameters.Entities
                                                                                       .Select(param => new RequestParameter
                        {
                            Name               = param.GetAttributeValue <string>("name"),
                            Required           = !param.GetAttributeValue <bool>("optional"),
                            Type               = Type.GetType(param.GetAttributeValue <string>("clrparser")),
                            BindingInformation = param.GetAttributeValue <string>("parameterbindinginformation"),
                            Description        = GetDescription(xaml, param.GetAttributeValue <string>("name"), true)
                        })),
                        ResponseParameters = new ParameterCollection <ResponseParameter>(responseParameters.Entities
                                                                                         .Select(param => new ResponseParameter
                        {
                            Name = param.GetAttributeValue <string>("name"),
                            Type = Type.GetType(param.GetAttributeValue <string>("clrformatter")),
                            BindingInformation = param.GetAttributeValue <string>("parameterbindinginformation"),
                            Description        = GetDescription(xaml, param.GetAttributeValue <string>("name"), false)
                        })),
                        PluginSteps = pluginSteps.Entities
                                      .Select(step => new PluginStep
                        {
                            StepId     = step.Id,
                            PluginId   = step.GetAttributeValue <EntityReference>("plugintypeid").Id,
                            PluginName = (string)step.GetAttributeValue <AliasedValue>("plugin.name").Value,
                            Sync       = step.GetAttributeValue <OptionSetValue>("mode").Value == 0,
                            Stage      = step.GetAttributeValue <OptionSetValue>("stage").Value
                        })
                                      .ToList()
                    };

                    foreach (var boundParam in action.RequestParameters.Where(p => p.BindingInformation != null))
                    {
                        if (boundParam.BindingInformation == "Bound:TRUE")
                        {
                            boundParam.IsBindingTarget   = true;
                            boundParam.BindingTargetType = action.PrimaryEntity;
                        }
                        else if (boundParam.BindingInformation.StartsWith("OTC:") && Int32.TryParse(boundParam.BindingInformation.Substring(4), out var otc))
                        {
                            var metaQry = new RetrieveMetadataChangesRequest
                            {
                                Query = new EntityQueryExpression
                                {
                                    Properties = new MetadataPropertiesExpression
                                    {
                                        PropertyNames =
                                        {
                                            nameof(EntityMetadata.LogicalName)
                                        }
                                    },
                                    Criteria = new MetadataFilterExpression
                                    {
                                        Conditions =
                                        {
                                            new MetadataConditionExpression(nameof(EntityMetadata.ObjectTypeCode), MetadataConditionOperator.Equals, otc)
                                        }
                                    }
                                }
                            };
                            var meta = (RetrieveMetadataChangesResponse)Service.Execute(metaQry);

                            if (meta.EntityMetadata.Count == 1)
                            {
                                boundParam.BindingTargetType = meta.EntityMetadata[0].LogicalName;
                            }
                        }
                    }

                    // Autoselect the plugin if there is only one to choose from
                    var availablePlugins = action.PluginSteps.Where(step => step.Sync && step.Stage == 40).ToList();
                    if (availablePlugins.Count == 1)
                    {
                        action.Plugin = new EntityReference("plugintype", availablePlugins[0].PluginId)
                        {
                            Name = availablePlugins[0].PluginName
                        }
                    }
                    ;

                    // Autoselect the minimum amount of allowed custom processing steps
                    action.AllowedCustomProcessingStepType = action.GetAllowedCustomProcessingStepType()[0];

                    args.Result = action;
                },
                PostWorkCallBack = args =>
                {
                    selectedActionLabel.Text    = ((CustomAction)args.Result).MessageName;
                    propertyGrid.SelectedObject = args.Result;
                    convertButton.Enabled       = true;
                }
            });