private void NewWorkflow(WorkflowTypes workflowType)
        {
            WorkflowViewModel       workspaceViewModel = new WorkflowViewModel(this.disableDebugViewOutput);
            WorkflowDocumentContent content            = new WorkflowDocumentContent(workspaceViewModel, workflowType);

            content.Title = workspaceViewModel.DisplayNameWithModifiedIndicator;
            content.Show(this.dockingManager);
            this.dockingManager.ActiveDocument = content;
            content.Closing += new EventHandler <CancelEventArgs>(workspaceViewModel.Closing);
            this.ViewPropertyInspector();
            this.ViewErrors();
            this.SetSelectedTab(ContentTypes.Errors);
        }
예제 #2
0
        public WorkflowDocumentContent(WorkflowViewModel model, WorkflowTypes workflowType)
            : base()
        {
            this.DataContext = model;

            string defaultWorkflowValue = ConfigurationManager.AppSettings["DefaultWorkflow"];

            if (!string.IsNullOrEmpty(defaultWorkflowValue))
            {
                this.defaultWorkflow = defaultWorkflowValue;
            }

            string defaultWorkflowServiceValue = ConfigurationManager.AppSettings["DefaultWorkflowService"];

            if (!string.IsNullOrEmpty(defaultWorkflowServiceValue))
            {
                this.defaultWorkflowService = defaultWorkflowServiceValue;
            }

            WorkflowDesigner designer = model.Designer;

            try
            {
                if (string.IsNullOrEmpty(model.FullFilePath))
                {
                    if (workflowType == WorkflowTypes.Activity)
                    {
                        designer.Load(Path.GetFullPath(this.defaultWorkflow));
                    }
                    else
                    {
                        designer.Load(Path.GetFullPath(this.defaultWorkflowService));
                    }
                }
                else
                {
                    designer.Load(model.FullFilePath);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format(Properties.Resources.ErrorLoadingDialogMessage, ExceptionHelper.FormatStackTrace(e)), Properties.Resources.ErrorLoadingDialogTitle, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            this.Content = model.Designer.View;

            model.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(this.Model_PropertyChanged);
        }
        public WorkflowDocumentContent(WorkflowViewModel model, WorkflowTypes workflowType)
            : base()
        {
            this.DataContext = model;

            string defaultWorkflowValue = ConfigurationManager.AppSettings["DefaultWorkflow"];
            if (!string.IsNullOrEmpty(defaultWorkflowValue))
            {
                this.defaultWorkflow = defaultWorkflowValue;
            }

            string defaultWorkflowServiceValue = ConfigurationManager.AppSettings["DefaultWorkflowService"];
            if (!string.IsNullOrEmpty(defaultWorkflowServiceValue))
            {
                this.defaultWorkflowService = defaultWorkflowServiceValue;
            }

            WorkflowDesigner designer = model.Designer;

            try
            {
                if (string.IsNullOrEmpty(model.FullFilePath))
                {
                    if (workflowType == WorkflowTypes.Activity)
                    {
                        
                        designer.Load(Path.GetFullPath(this.defaultWorkflow));
                    }
                    else
                    {
                        designer.Load(Path.GetFullPath(this.defaultWorkflowService));
                    }
                }
                else
                {
                    designer.Load(model.FullFilePath);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format(Properties.Resources.ErrorLoadingDialogMessage, ExceptionHelper.FormatStackTrace(e)), Properties.Resources.ErrorLoadingDialogTitle, MessageBoxButton.OK, MessageBoxImage.Error);
            }
                
            this.Content = model.Designer.View;

            model.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(this.Model_PropertyChanged);
        }
예제 #4
0
        private void ParseXmlNode(WorkflowTypes wfType, List <string> usedOOBWorkflowActivities, List <string> unsupportedOOBWorkflowActivities, ref int actionCounter, ref int knownActionCounter, ref int unsupportedActionCounter, XmlNode node)
        {
            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);
                    }
                }
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <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);
        }
 private void NewWorkflow(WorkflowTypes workflowType)
 {
     WorkflowViewModel workspaceViewModel = new WorkflowViewModel(this.disableDebugViewOutput);
     WorkflowDocumentContent content = new WorkflowDocumentContent(workspaceViewModel, workflowType);
     content.Title = workspaceViewModel.DisplayNameWithModifiedIndicator;
     content.Show(this.dockingManager);
     this.dockingManager.ActiveDocument = content;
     content.Closing += new EventHandler<CancelEventArgs>(workspaceViewModel.Closing);
     this.ViewPropertyInspector();
     this.ViewErrors();
     this.SetSelectedTab(ContentTypes.Errors);
 }
예제 #9
0
        // update constants in Suggestion database to current version defined in WorkflowConstants
        public bool VersionConstants(string me)
        {
            try
            {
                bool updateDB = false;
                if (Versions.Any(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == WorkflowConstants.ConstantsVersion) == false)
                {   // no database - create and lock the new version entry
                    TraceLog.TraceInfo(String.Format("Suggestions database version {0} not found", WorkflowConstants.ConstantsVersion));

                    // remove any existing database version (there should never be more than one)
                    foreach (var existingVersion in Versions.Where(v => v.VersionType == DatabaseVersion.Constants).ToList())
                    {
                        Versions.Remove(existingVersion);
                    }
                    SaveChanges();

                    // create the new version entry
                    DatabaseVersion ver = new DatabaseVersion()
                    {
                        VersionType   = DatabaseVersion.Constants,
                        VersionString = WorkflowConstants.ConstantsVersion,
                        Status        = me
                    };
                    Versions.Add(ver);
                    SaveChanges();
                    updateDB = true;
                }
                else
                {
                    var dbVersion = Versions.Single(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == WorkflowConstants.ConstantsVersion);
                    if (dbVersion.Status == DatabaseVersion.Corrupted)
                    {   // try to update the database again - take a lock
                        TraceLog.TraceInfo("Suggestions database corrupted");
                        dbVersion.Status = me;
                        SaveChanges();
                        updateDB = true;
                    }
                }
                if (updateDB == false)
                {
                    TraceLog.TraceInfo(String.Format("Suggestions database version {0} is up to date", WorkflowConstants.ConstantsVersion));
                    return(true);
                }
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("Could not find database version", ex);
                return(false);
            }

            // update the default database values
            DatabaseVersion           version        = null;
            SuggestionsStorageContext versionContext = Storage.NewSuggestionsContext;

            try
            {   // verify that this unit of execution owns the update lock for the database version
                version = versionContext.Versions.Single(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == WorkflowConstants.ConstantsVersion);
                if (version.Status != me)
                {
                    return(true);
                }

                TraceLog.TraceInfo(String.Format("{0} updating Suggestions database to version {1}", me, WorkflowConstants.ConstantsVersion));

                // remove existing intents
                foreach (var entity in Intents.ToList())
                {
                    Intents.Remove(entity);
                }
                var intents = WorkflowConstants.DefaultIntents();
                if (intents == null)
                {
                    TraceLog.TraceError("Could not find or load intents");
                    version.Status = DatabaseVersion.Corrupted;
                    versionContext.SaveChanges();
                    return(false);
                }
                // add current intents
                foreach (var entity in intents)
                {
                    Intents.Add(entity);
                }
                SaveChanges();
                TraceLog.TraceInfo("Replaced intents");

                // remove existing workflow types
                foreach (var entity in WorkflowTypes.ToList())
                {
                    WorkflowTypes.Remove(entity);
                }
                var workflowTypes = WorkflowConstants.DefaultWorkflowTypes();
                if (workflowTypes == null)
                {
                    TraceLog.TraceError("Could not find or load workflow definitions");
                    version.Status = DatabaseVersion.Corrupted;
                    versionContext.SaveChanges();
                    return(false);
                }
                // add current workflow types
                foreach (var entity in workflowTypes)
                {
                    WorkflowTypes.Add(entity);
                }
                SaveChanges();
                TraceLog.TraceInfo("Replaced workflow types");

                // save the new version number
                version.Status = DatabaseVersion.OK;
                versionContext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("VersionConstants failed", ex);
                // mark the version as corrupted
                version.Status = DatabaseVersion.Corrupted;
                versionContext.SaveChanges();
                return(false);
            }
        }