Ejemplo n.º 1
0
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication parent = (SPWebApplication)properties.Feature.Parent;

            ActivityReference action = ActivityReferenceCollection.FindByAdapter(adapterType, adapterAssembly);

            if (action != null)
            {
                // Remove the action definition from the workflow configuration database if the Feature is not activated elsewhere
                if (!IsFeatureActivatedInAnyWebApp(parent, properties.Definition.Id))
                {
                    ActivityReferenceCollection.RemoveAction(action.ActivityId);
                }

                string activityTypeName  = string.Empty;
                string activityNamespace = string.Empty;
                Utility.ExtractNamespaceAndClassName(action.ActivityType, out activityTypeName, out activityNamespace);

                // Remove the web.config entry
                Collection <SPWebConfigModification> modifications = parent.WebConfigModifications;
                foreach (SPWebConfigModification modification in modifications)
                {
                    if (modification.Owner == AuthorisedTypes.OWNER_TOKEN) // OWNER_TOKEN is the owner for any web config modification added by Nintex Workflow
                    {
                        if (IsAuthorizedTypeMatch(modification.Value, action.ActivityAssembly, activityTypeName, activityNamespace))
                        {
                            modifications.Remove(modification);
                            parent.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication parent = (SPWebApplication)properties.Feature.Parent;

            // First step is register the action to the Nintex Workflow database
            XmlDocument nwaXml = GetNWADefinition(properties);

            ActivityReference newActivityReference = ActivityReference.ReadFromNWA(nwaXml);

            ActivityReference action = ActivityReferenceCollection.FindByAdapter(newActivityReference.AdapterType, newActivityReference.AdapterAssembly);

            if (action != null)
            {
                // update the details if the adapter already exists
                ActivityReferenceCollection.UpdateActivity(action.ActivityId, newActivityReference.Name, newActivityReference.Description, newActivityReference.Category, newActivityReference.ActivityAssembly, newActivityReference.ActivityType, newActivityReference.AdapterAssembly, newActivityReference.AdapterType, newActivityReference.HandlerUrl, newActivityReference.ConfigPage, newActivityReference.RenderBehaviour, newActivityReference.Icon, newActivityReference.ToolboxIcon, newActivityReference.WarningIcon, newActivityReference.QuickAccess, newActivityReference.ListTypeFilter);
            }
            else
            {
                ActivityReferenceCollection.AddActivity(newActivityReference.Name, newActivityReference.Description, newActivityReference.Category, newActivityReference.ActivityAssembly, newActivityReference.ActivityType, newActivityReference.AdapterAssembly, newActivityReference.AdapterType, newActivityReference.HandlerUrl, newActivityReference.ConfigPage, newActivityReference.RenderBehaviour, newActivityReference.Icon, newActivityReference.ToolboxIcon, newActivityReference.WarningIcon, newActivityReference.QuickAccess, newActivityReference.ListTypeFilter);
                action = ActivityReferenceCollection.FindByAdapter(newActivityReference.AdapterType, newActivityReference.AdapterAssembly);
            }

            // Second step is to modify the web.config file to allow use of the activity in declarative workflows
            string activityTypeName  = string.Empty;
            string activityNamespace = string.Empty;

            Utility.ExtractNamespaceAndClassName(action.ActivityType, out activityTypeName, out activityNamespace);
            AuthorisedTypes.InstallAuthorizedWorkflowTypes(parent, action.ActivityAssembly, activityNamespace, activityTypeName);

            // Third step is to activate the action for the farm
            ActivityActivationReference reference = new ActivityActivationReference(action.ActivityId, Guid.Empty, Guid.Empty);

            reference.AddOrUpdateActivationReference();
        }
Ejemplo n.º 3
0
        public async Task <ResourceResponse> UpdateTaskModuleActivityAsync(
            ITurnContext context,
            ActivityReference activityReference,
            AdaptiveCard updateAdaptiveCard,
            CancellationToken cancellationToken)
        {
            Activity reply = context.Activity.CreateReply();

            reply.Attachments = new List <Microsoft.Bot.Schema.Attachment>
            {
                new Microsoft.Bot.Schema.Attachment
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content     = updateAdaptiveCard
                },
            };

            var teamsChannelActivity = reply.CreateConversationToTeamsChannel(
                new TeamsChannelData
            {
                Channel = new ChannelInfo(id: activityReference.ThreadId),
            });

            var response = await _connectorClient.Conversations.UpdateActivityAsync(
                activityReference.ThreadId,
                activityReference.ActivityId,
                teamsChannelActivity,
                cancellationToken).ConfigureAwait(false);

            return(response);
        }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            // Retrieve a reference to the parent web application for the feature.
            SPWebApplication parent = (SPWebApplication)properties.Feature.Parent;

            foreach (var file in GetAllNwaFilesNWADefinition())
            {
                XmlDocument       nwaXml = GetNWADefinition(file);
                ActivityReference action = ActivityReference.ReadFromNWA(nwaXml);
                if (action != null)
                {
                    // If the feature is not activated in any other web application, remove the action
                    // definition from the configuration database.
                    if (!IsFeatureActivatedInAnyWebApp(parent, properties.Definition.Id))
                    {
                        ActivityReferenceCollection.RemoveAction(action.ActivityId);
                    }

                    // Remove the modification from the web.config file for the web application, to uninstall the
                    // custom workflow activity from the collection of authorized activity types for the
                    // web application.
                    string activityTypeName  = string.Empty;
                    string activityNamespace = string.Empty;

                    // Extract the type name and namespace name from the value of the ActivityType property.
                    Utility.ExtractNamespaceAndClassName(action.ActivityType, out activityTypeName, out activityNamespace);

                    // Identify and remove the modification from the web.config file.
                    Collection <SPWebConfigModification> modifications = parent.WebConfigModifications;
                    foreach (SPWebConfigModification modification in modifications)
                    {
                        // If the modification was added by Nintex Workflow, compare the assembly, namespace, and type of the workflow activity to the collection of
                        // authorized activity types in the modification. If they match, remove the modification.
                        // NOTE: AuthorizedTypes.OWNER_TOKEN is the owner token for any modification added by
                        // Nintex Workflow.
                        if (modification.Owner == AuthorisedTypes.OWNER_TOKEN)
                        {
                            if (IsAuthorizedTypeMatch(modification.Value, action.ActivityAssembly, activityTypeName, activityNamespace))
                            {
                                // Remove the modification.
                                modifications.Remove(modification);
                                // Apply the updated modifications to the SharePoint farm containing the web application.
                                parent.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                                break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static IWorkflowNode CompressActivityReference(ActivityReference activityReference, List <IWorkflowNode> toPrepend)
        {
            var args = activityReference.Arguments;

            if (args != null && args.Count() > 0)
            {
                var outArg = args.FirstOrDefault(a => a is WorkflowParser.OutArgument);

                if (!activityReference.AssemblyQualifiedName.Contains("Microsoft.Crm.Workflow.Activities."))
                {
                    var regex            = new Regex(@"[^\.][\w]+(?=,)");
                    var codeActivityName = regex.Match(activityReference.AssemblyQualifiedName).Value;
                    var inArguments      = args.Where(a => a is WorkflowParser.InArgument).ToDictionary(arg => arg.Key, arg => ParseCodeActivityArgument(arg.Value));
                    var outArguments     = args.Where(a => a is WorkflowParser.OutArgument).ToDictionary(a => a.Value.TrimEdge(), a => a.Key);
                    return(new CallCodeActivity(codeActivityName, inArguments, outArguments));
                }

                switch (args[0].Key)
                {
                case "ConditionOperator":
                    if (outArg == null)
                    {
                        throw new WorkflowException("Found no out argument, please check your workflow has the correct format");
                    }
                    if (args.Length == 4)
                    {
                        return(new ConditionExp(args[0].Value,
                                                CompressParameters(args[1].Value).ToArray(),
                                                args[2].Value.TrimEdge(),
                                                outArg.Value.TrimEdge()));
                    }
                    else
                    {
                        return(new ConditionExp(args[0].Value,
                                                null,
                                                args[1].Value.TrimEdge(),
                                                outArg.Value.TrimEdge()));
                    }

                case "ExpressionOperator":
                    if (outArg == null)
                    {
                        throw new WorkflowException("Found no out argument, please check your workflow has the correct format");
                    }
                    return(CompressExpressionOperator(args, outArg));

                case "Condition":
                    if (args[0].Value == "True" || args[0].Value == "False")
                    {
                        return(new Condition(args[0].Value,
                                             CompressActivity(activityReference.Properties[0]), CompressActivity(activityReference.Properties[1])));
                    }
                    return(new Condition(args[0].Value.TrimEdge(),
                                         CompressActivity(activityReference.Properties[0]), CompressActivity(activityReference.Properties[1])));

                case "Wait":
                    if (args[0].Value == "True")
                    {
                        var list = new List <IWorkflowNode>();
                        list.Add(new WaitStart());
                        list.AddRange(CompressActivityCollection(activityReference.Properties));
                        return(new ActivityList(list.ToArray()));
                    }
                    return(new ActivityList(CompressActivityCollection(activityReference.Properties).ToArray()));

                case "LogicalOperator":
                    return(new LogicalComparison(args[0].Value, args[1].Value.TrimEdge(), args[2].Value.TrimEdge(), outArg.Value.TrimEdge()));

                case "Value":
                    return(new ConvertType(args[0].Value.TrimEdge(), args[1].ReferenceLiteral.Value.Split(':')[1], outArg.Value.TrimEdge()));

                default:
                    throw new NotImplementedException($"No implementation for activityreference with key '{args[0].Key}'");
                }
            }

            return(new ActivityList(CompressActivityCollection(activityReference.Properties).ToArray()));
        }
Ejemplo n.º 6
0
 private static IWorkflowNode CompressActivityReference(ActivityReference activityReference)
 {
     return(CompressActivityReference(activityReference, new List <IWorkflowNode>()));
 }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            // Retrieve a reference to the parent web application for the feature.
            SPWebApplication parent = (SPWebApplication)properties.Feature.Parent;

            foreach (var file in GetAllNwaFilesNWADefinition())
            {
                // Retrieve the contents of the action definition file.
                XmlDocument nwaXml = GetNWADefinition(file);

                // Instantiate an ActivityReference object from the action definition file.
                ActivityReference newActivityReference = ActivityReference.ReadFromNWA(nwaXml);

                // Attempt to instantiate an ActivityReference object from the the workflow action adapter
                // identified by the AdapterType and AdapterAssembly elements from the action definition file.
                // For new deployments, action is set to null; otherwise, the existing ActivityReference
                // for the custom workflow action is retrieved.
                ActivityReference action = ActivityReferenceCollection.FindByAdapter(
                    newActivityReference.AdapterType, newActivityReference.AdapterAssembly);

                // If the custom workflow action has been previously deployed,
                // update the ActivityReference for the custom action; otherwise,
                // add a new Activityreference for the custom action and then
                // instantiate it.
                if (action != null)
                {
                    // Update the ActivityReference for the custom workflow action.
                    ActivityReferenceCollection.UpdateActivity(
                        action.ActivityId,
                        newActivityReference.Name,
                        newActivityReference.Description,
                        newActivityReference.Category,
                        newActivityReference.ActivityAssembly,
                        newActivityReference.ActivityType,
                        newActivityReference.AdapterAssembly,
                        newActivityReference.AdapterType,
                        newActivityReference.HandlerUrl,
                        newActivityReference.ConfigPage,
                        newActivityReference.RenderBehaviour,
                        newActivityReference.Icon,
                        newActivityReference.ToolboxIcon,
                        newActivityReference.WarningIcon,
                        newActivityReference.QuickAccess,
                        newActivityReference.ListTypeFilter);
                }
                else
                {
                    // Add a new ActivityReference for the custom workflow action.
                    ActivityReferenceCollection.AddActivity(
                        newActivityReference.Name,
                        newActivityReference.Description,
                        newActivityReference.Category,
                        newActivityReference.ActivityAssembly,
                        newActivityReference.ActivityType,
                        newActivityReference.AdapterAssembly,
                        newActivityReference.AdapterType,
                        newActivityReference.HandlerUrl,
                        newActivityReference.ConfigPage,
                        newActivityReference.RenderBehaviour,
                        newActivityReference.Icon,
                        newActivityReference.ToolboxIcon,
                        newActivityReference.WarningIcon,
                        newActivityReference.QuickAccess,
                        newActivityReference.ListTypeFilter);

                    // Instantiate the newly-added ActivityReference.
                    action = ActivityReferenceCollection.FindByAdapter(
                        newActivityReference.AdapterType, newActivityReference.AdapterAssembly);
                }


                // Add a modification to the web.config file for the web application, to install the
                // custom workflow activity to the collection of authorized activity types for the
                // web application.
                string activityTypeName  = string.Empty;
                string activityNamespace = string.Empty;

                // Extract the type name and namespace name from the value of the ActivityType property.
                Utility.ExtractNamespaceAndClassName(action.ActivityType, out activityTypeName, out activityNamespace);

                // Add the assembly, namespace, and type of the workflow activity to the collection of
                // authorized activity types for the web application.

                // Activate the custom workflow action.
                ActivityActivationReference reference = new ActivityActivationReference(
                    action.ActivityId, Guid.Empty, Guid.Empty);
                reference.AddOrUpdateActivationReference();
            }
        }