/// <summary> /// Analysis a workflow definition and returns the used OOB actions /// </summary> /// <param name="workflowDefinition">Workflow definition to analyze</param> /// <param name="wfType">2010 or 2013 workflow</param> /// <returns>List of OOB actions used in the workflow</returns> public WorkflowActionAnalysis ParseWorkflowDefinition(string workflowDefinition, WorkflowTypes wfType) { try { if (string.IsNullOrEmpty(workflowDefinition)) { return(null); } var xmlDoc = new XmlDocument(); xmlDoc.Load(WebpartMappingLoader.GenerateStreamFromString(workflowDefinition)); //determine whether document contains namespace string namespaceName = ""; if (wfType == WorkflowTypes.SP2010) { namespaceName = "ns0"; } else if (wfType == WorkflowTypes.SP2013) { namespaceName = "local"; } var namespacePrefix = string.Empty; XmlNamespaceManager nameSpaceManager = null; if (xmlDoc.FirstChild.Attributes != null) { var xmlns = xmlDoc.FirstChild.Attributes[$"xmlns:{namespaceName}"]; if (xmlns != null) { nameSpaceManager = new XmlNamespaceManager(xmlDoc.NameTable); nameSpaceManager.AddNamespace(namespaceName, xmlns.Value); namespacePrefix = namespaceName + ":"; } } // Grab all nodes with the workflow action namespace (ns0/local) var nodes = xmlDoc.SelectNodes($"//{namespacePrefix}*", nameSpaceManager); // Iterate over the nodes and "identify the OOB activities" List <string> usedOOBWorkflowActivities = new List <string>(); List <string> unsupportedOOBWorkflowActivities = new List <string>(); int actionCounter = 0; int knownActionCounter = 0; int unsupportedActionCounter = 0; foreach (XmlNode node in nodes) { actionCounter++; WorkflowAction defaultOOBWorkflowAction = null; if (wfType == WorkflowTypes.SP2010) { defaultOOBWorkflowAction = this.defaultWorkflowActions.SP2010DefaultActions.Where(p => p.ActionNameShort == node.LocalName).FirstOrDefault(); } else if (wfType == WorkflowTypes.SP2013) { defaultOOBWorkflowAction = this.defaultWorkflowActions.SP2013DefaultActions.Where(p => p.ActionNameShort == node.LocalName).FirstOrDefault(); } if (defaultOOBWorkflowAction != null) { knownActionCounter++; if (!usedOOBWorkflowActivities.Contains(defaultOOBWorkflowAction.ActionNameShort)) { usedOOBWorkflowActivities.Add(defaultOOBWorkflowAction.ActionNameShort); } if (wfType == WorkflowTypes.SP2010) { if (!WorkflowManager.SP2010SupportedFlowActions.Contains(defaultOOBWorkflowAction.ActionName)) { unsupportedActionCounter++; unsupportedOOBWorkflowActivities.Add(defaultOOBWorkflowAction.ActionNameShort); } } else if (wfType == WorkflowTypes.SP2013) { if (!WorkflowManager.SP2013SupportedFlowActions.Contains(defaultOOBWorkflowAction.ActionName)) { unsupportedActionCounter++; unsupportedOOBWorkflowActivities.Add(defaultOOBWorkflowAction.ActionNameShort); } } } } return(new WorkflowActionAnalysis() { WorkflowActions = usedOOBWorkflowActivities, ActionCount = knownActionCounter, UnsupportedActions = unsupportedOOBWorkflowActivities, UnsupportedAccountCount = unsupportedActionCounter }); } catch (Exception ex) { // TODO // Eat exception for now } return(null); }
private List <string> LoadDefaultActions(WorkflowTypes wfType) { List <string> wfActionsList = new List <string>(); string fileName = null; if (wfType == WorkflowTypes.SP2010) { fileName = "SharePoint.Modernization.Scanner.Workflow.sp2010wfmodel.xml"; } else if (wfType == WorkflowTypes.SP2013) { fileName = "SharePoint.Modernization.Scanner.Workflow.sp2013wfmodel.xml"; } var wfModelString = ""; using (Stream stream = typeof(WorkflowManager).Assembly.GetManifestResourceStream(fileName)) { using (StreamReader reader = new StreamReader(stream)) { wfModelString = reader.ReadToEnd(); } } if (!string.IsNullOrEmpty(wfModelString)) { if (wfType == WorkflowTypes.SP2010) { SP2010.WorkflowInfo wfInformation; using (var stream = WebpartMappingLoader.GenerateStreamFromString(wfModelString)) { XmlSerializer xmlWorkflowInformation = new XmlSerializer(typeof(SP2010.WorkflowInfo)); wfInformation = (SP2010.WorkflowInfo)xmlWorkflowInformation.Deserialize(stream); } foreach (var wfAction in wfInformation.Actions.Action) { if (!wfActionsList.Contains(wfAction.ClassName)) { wfActionsList.Add(wfAction.ClassName); } } } else if (wfType == WorkflowTypes.SP2013) { SP2013.WorkflowInfo wfInformation; using (var stream = WebpartMappingLoader.GenerateStreamFromString(wfModelString)) { XmlSerializer xmlWorkflowInformation = new XmlSerializer(typeof(SP2013.WorkflowInfo)); wfInformation = (SP2013.WorkflowInfo)xmlWorkflowInformation.Deserialize(stream); } foreach (var wfAction in wfInformation.Actions.Action) { if (!wfActionsList.Contains(wfAction.ClassName)) { wfActionsList.Add(wfAction.ClassName); } } } } return(wfActionsList); }
/// <summary> /// Analysis a workflow definition and returns the used OOB actions /// </summary> /// <param name="workflowDefinition">Workflow definition to analyze</param> /// <param name="wfType">2010 or 2013 workflow</param> /// <returns>List of OOB actions used in the workflow</returns> public WorkflowActionAnalysis ParseWorkflowDefinition(string workflowDefinition, WorkflowTypes wfType) { try { if (string.IsNullOrEmpty(workflowDefinition)) { return(null); } var xmlDoc = new XmlDocument(); xmlDoc.Load(WebpartMappingLoader.GenerateStreamFromString(workflowDefinition)); //determine whether document contains namespace string namespaceName = ""; if (wfType == WorkflowTypes.SP2010) { namespaceName = "ns0"; } else if (wfType == WorkflowTypes.SP2013) { namespaceName = "local"; } var namespacePrefix = string.Empty; var namespacePrefix1 = string.Empty; XmlNamespaceManager nameSpaceManager = null; if (xmlDoc.FirstChild.Attributes != null) { var xmlns = xmlDoc.FirstChild.Attributes[$"xmlns:{namespaceName}"]; if (xmlns != null) { nameSpaceManager = new XmlNamespaceManager(xmlDoc.NameTable); nameSpaceManager.AddNamespace(namespaceName, xmlns.Value); namespacePrefix = namespaceName + ":"; } } // Grab all nodes with the workflow action namespace (ns0/local) var nodes = xmlDoc.SelectNodes($"//{namespacePrefix}*", nameSpaceManager); XmlNodeList ns1Nodes = null; if (wfType == WorkflowTypes.SP2010) { var xmlns = xmlDoc.FirstChild.Attributes["xmlns:ns1"]; if (xmlns != null) { nameSpaceManager.AddNamespace("ns1", xmlns.Value); namespacePrefix1 = "ns1:"; ns1Nodes = xmlDoc.SelectNodes($"//{namespacePrefix1}*", nameSpaceManager); } } // Iterate over the nodes and "identify the OOB activities" List <string> usedOOBWorkflowActivities = new List <string>(); List <string> unsupportedOOBWorkflowActivities = new List <string>(); int actionCounter = 0; int knownActionCounter = 0; int unsupportedActionCounter = 0; foreach (XmlNode node in nodes) { ParseXmlNode(wfType, usedOOBWorkflowActivities, unsupportedOOBWorkflowActivities, ref actionCounter, ref knownActionCounter, ref unsupportedActionCounter, node); } if (wfType == WorkflowTypes.SP2010 && ns1Nodes != null && ns1Nodes.Count > 0) { foreach (XmlNode node in ns1Nodes) { ParseXmlNode(wfType, usedOOBWorkflowActivities, unsupportedOOBWorkflowActivities, ref actionCounter, ref knownActionCounter, ref unsupportedActionCounter, node); } } return(new WorkflowActionAnalysis() { WorkflowActions = usedOOBWorkflowActivities, ActionCount = knownActionCounter, UnsupportedActions = unsupportedOOBWorkflowActivities, UnsupportedAccountCount = unsupportedActionCounter }); } catch (Exception ex) { // TODO // Eat exception for now } return(null); }