예제 #1
0
        public async Task <string> Run(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return("The name of the Workflow scheme is empty.");
            }

            var scheme = await _workflowSchemesRepository.FirstOrDefaultAsync(ws => ws.Code == code);

            if (scheme == null)
            {
                return("The name of the Workflow scheme was not found.");
            }

            var workflowAssociation = new WorkflowAssociation
            {
                Id = Guid.NewGuid(),

                SchemeCode = scheme.Code,

                Entity = "{}"
            };

            await _workflowAssociationsRepository.InsertAsync(workflowAssociation);

            await _workflowService.RunSchemeAsync(workflowAssociation.SchemeCode, workflowAssociation.Id);

            return("Your request has been added to the Workflow queue and will be processed soon.");
        }
예제 #2
0
        public async Task Fire(string name, [FromBody] JObject parameters)
        {
            var projectTrigger = await _projectTriggerRepository.Queryable().Include(pt => pt.Trigger).FirstOrDefaultAsync(pt => pt.Trigger.Name == name);

            if (projectTrigger == null)
            {
                throw new InvalidInputException(@"Trigger was not found.");
            }

            var schemes = await _workflowSchemesRepository.ToListAsync(ws => ws.TriggerId == projectTrigger.TriggerId);


            foreach (var scheme in schemes)
            {
                var workflowAssociation = new WorkflowAssociation
                {
                    //Id = Guid.NewGuid(),

                    SchemeCode = scheme.Code,

                    Entity = Convert.ToString(parameters)
                };

                await _workflowAssociationsRepository.InsertAsync(workflowAssociation);

                await _workflowService.RunSchemeAsync(scheme.Code, workflowAssociation.Id);
            }
        }
예제 #3
0
        public static void attachWorkflow(this List lst, ClientContext ctx, string cTemplateName)
        {
            try
            {
                Web web = lst.ParentWeb;

                ctx.Load(web, w => w.Url);
                ctx.ExecuteQuery();
                System.Diagnostics.Trace.WriteLine(web.Url);

                WorkflowTemplate wt = GetWorkflowTemplate(web, cTemplateName);

                WorkflowAssociationCreationInformation wfc = new WorkflowAssociationCreationInformation
                {
                    HistoryList = web.Lists.GetByTitle("Workflow History"),
                    Name        = cTemplateName,
                    TaskList    = web.Lists.GetByTitle("Workflow Tasks"),
                    Template    = wt
                };
                WorkflowAssociation wf = lst.WorkflowAssociations.Add(wfc);
                wf.AllowManual     = false; // is never updated
                wf.AutoStartChange = true;  // is never
                wf.AutoStartCreate = true;  // is never updated
                wf.Enabled         = true;  // is never updated
                                            //string assocData = GetAssociationXml(); // internal method
                                            // wf.AssociationData = assocData; // is never updated
                wf.Update();
                ctx.Load(wf);
                ctx.ExecuteQuery();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
예제 #4
0
        private void MapProperties(WorkflowAssociationDefinition definition, WorkflowAssociation association)
        {
            if (!string.IsNullOrEmpty(definition.Description))
            {
                association.Description = definition.Description;
            }

            if (!string.IsNullOrEmpty(definition.AssociationData))
            {
                association.AssociationData = definition.AssociationData;
            }

            if (definition.AllowManual.HasValue)
            {
                association.AllowManual = definition.AllowManual.Value;
            }

            if (definition.AutoStartChange.HasValue)
            {
                association.AutoStartChange = definition.AutoStartChange.Value;
            }

            if (definition.AutoStartCreate.HasValue)
            {
                association.AutoStartCreate = definition.AutoStartCreate.Value;
            }

            if (definition.Enabled.HasValue)
            {
                association.Enabled = definition.Enabled.Value;
            }
        }
        public static bool TriggerWorkflow(string SiteURL, string WorkflowName)
        {
            bool status = false;

            try
            {
                string siteUrl  = SiteURL;
                string userName = "******";
                string password = "******";

                //Name of the SharePoint 2010 Workflow to start.
                string workflowName = WorkflowName;

                using (ClientContext clientContext = new ClientContext(siteUrl))
                {
                    SecureString securePassword = new SecureString();

                    foreach (char c in password.ToCharArray())
                    {
                        securePassword.AppendChar(c);
                    }

                    clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

                    Web web = clientContext.Web;

                    //Workflow Services Manager which will handle all the workflow interaction.
                    WorkflowServicesManager wfServicesManager = new WorkflowServicesManager(clientContext, web);

                    //Will return all Workflow Associations which are running on the SharePoint 2010 Engine
                    WorkflowAssociationCollection wfAssociations = web.WorkflowAssociations;

                    //Get the required Workflow Association
                    WorkflowAssociation wfAssociation = wfAssociations.GetByName(workflowName);

                    clientContext.Load(wfAssociation);

                    clientContext.ExecuteQuery();

                    //Get the instance of the Interop Service which will be used to create an instance of the Workflow
                    InteropService workflowInteropService = wfServicesManager.GetWorkflowInteropService();

                    var initiationData = new Dictionary <string, object>();

                    //Start the Workflow
                    ClientResult <Guid> resultGuid = workflowInteropService.StartWorkflow(wfAssociation.Name, new Guid(), Guid.Empty, Guid.Empty, initiationData);

                    clientContext.ExecuteQuery();
                    status = true;
                }
            }
            catch (Exception ex)
            {
                status = false;
                throw;
            }
            return(status);
        }
        private Tuple <string, DateTime> LoadWorkflowDefinition(ClientContext cc, WorkflowAssociation workflowAssociation)
        {
            // Ensure the workflow library was loaded if not yet done
            LoadWorkflowLibrary(cc);
            try
            {
                return(GetFileInformation(cc.Web, $"{this.workflowList.RootFolder.ServerRelativeUrl}/{workflowAssociation.Name}/{workflowAssociation.Name}.xoml"));
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
예제 #7
0
        public static WorkflowAssociation CreateListWorkflowAssociation(this List list, WorkflowAssociationCreationInformation workflowAssociationCreation,
                                                                        bool allowManual, bool autoStartCreate, bool autoStartChange)
        {
            WorkflowAssociation wf = list.WorkflowAssociations.Add(workflowAssociationCreation);

            wf.AllowManual     = allowManual;
            wf.AutoStartChange = autoStartCreate;
            wf.AutoStartCreate = autoStartChange;
            wf.Enabled         = true;
            //string assocData = GetAssociationXml(); // internal method
            // wf.AssociationData = assocData; // is never updated
            wf.Update();

            list.Context.Load(wf);
            list.Context.ExecuteQuery();

            return(wf);
        }
        private void MapProperties(WorkflowAssociationDefinition definition, WorkflowAssociation association)
        {
            if (!string.IsNullOrEmpty(definition.Description))
                association.Description = definition.Description;

            if (!string.IsNullOrEmpty(definition.AssociationData))
                association.AssociationData = definition.AssociationData;

            if (definition.AllowManual.HasValue)
                association.AllowManual = definition.AllowManual.Value;

            if (definition.AutoStartChange.HasValue)
                association.AutoStartChange = definition.AutoStartChange.Value;

            if (definition.AutoStartCreate.HasValue)
                association.AutoStartCreate = definition.AutoStartCreate.Value;

            if (definition.Enabled.HasValue)
                association.Enabled = definition.Enabled.Value;
        }
예제 #9
0
        /// <summary>
        /// Imports new workflows to the target SharePoint.
        /// </summary>
        /// <exception cref="ElementsMigrationException">if migration fails</exception>
        private void ImportNewWorkflow()
        {
            Console.WriteLine("Import new WorkflowAssociations");
            WorkflowAssociationCollection sourceWorkflowAssociations = this.GetAllWorkflowAssociationCollection(this.SourceClientContext);
            WorkflowAssociationCollection targetWorkflowAssociations = this.GetAllWorkflowAssociationCollection(this.TargetClientContext);

            if (sourceWorkflowAssociations.Count == 0)
            {
                Logger.AddMessage("no workflows to migrate...");
                return;
            }

            HashSet <string> targetWorkflowNames = targetWorkflowAssociations.GetAllNames();

            foreach (var sourceWorkflowAssociation in sourceWorkflowAssociations)
            {
                if (!targetWorkflowNames.Contains(sourceWorkflowAssociation.Name))
                {
                    Console.WriteLine("import new workflow '{0}'", sourceWorkflowAssociation.Name);
                    Logger.AddMessage("import new workflow '" + sourceWorkflowAssociation.Name + "'");

                    WorkflowAssociationCreationInformation creationObject = new WorkflowAssociationCreationInformation();
                    creationObject.Name        = sourceWorkflowAssociation.Name;
                    creationObject.HistoryList = this.GetHistoryList(this.SourceClientContext);
                    creationObject.TaskList    = this.GetTaskList(this.SourceClientContext);
                    creationObject.Template    = this.GetTemplate();

                    WorkflowAssociation targetWorkflowAssociation = targetWorkflowAssociations.Add(creationObject);

                    try
                    {
                        targetWorkflowAssociation.AllowManual = sourceWorkflowAssociation.AllowManual;
                    }
                    catch (PropertyOrFieldNotInitializedException)
                    {
                    }

                    try
                    {
                        targetWorkflowAssociation.AutoStartChange = sourceWorkflowAssociation.AutoStartChange;
                    }
                    catch (PropertyOrFieldNotInitializedException)
                    {
                    }

                    try
                    {
                        targetWorkflowAssociation.AutoStartCreate = sourceWorkflowAssociation.AutoStartCreate;
                    }
                    catch (PropertyOrFieldNotInitializedException)
                    {
                    }

                    try
                    {
                        targetWorkflowAssociation.Enabled = sourceWorkflowAssociation.Enabled;
                    }
                    catch (PropertyOrFieldNotInitializedException)
                    {
                    }

                    try
                    {
                        targetWorkflowAssociation.AssociationData = sourceWorkflowAssociation.AssociationData;
                    }
                    catch (PropertyOrFieldNotInitializedException)
                    {
                    }
                }
                else
                {
                    Console.WriteLine("don't have to migrate workflow '{0}'", sourceWorkflowAssociation.Name);
                    Logger.AddMessage("don't have to migrate workflow '" + sourceWorkflowAssociation.Name + "'");
                }
            }

            try
            {
                this.TargetClientContext.ExecuteQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception during importing new Workflows.", e);
                Logger.AddMessage("Exception during importing new Workflows. Error = " + e.Message);
                throw new ElementsMigrationException("Exception during importing new Workflows.", e);
            }
        }
예제 #10
0
파일: Program.cs 프로젝트: re7w12u/gs-pm
        private static void StartWFOnPremise()
        {
            //Site Details
            string siteUrl  = "http://rdits-sp13-dev2/sites/gs/";
            string userName = "******";
            string password = "******";

            //Name of the SharePoint2010 List Workflow
            string workflowName = "Approbation 2010";

            //Name of the List to which the Workflow is Associated
            string targetListName = "cadeaux";

            //Guid of the List to which the Workflow is Associated
            Guid targetListGUID = new Guid("cb1ef47f-6fbf-4119-97c5-057006db6a13");

            //Guid of the ListItem on which to start the Workflow
            //Guid targetItemGUID = new Guid("B10F6CF0-86F2-4F6D-B982-BBF9FB38897E");
            Guid targetItemGUID = new Guid("31D3B801-5C0C-4758-8AE0-3BF23BD6E430");

            using (ClientContext clientContext = new ClientContext(siteUrl))
            {
                //SecureString securePassword = new SecureString();

                //foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);

                //clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

                Web web = clientContext.Web;

                List     list = web.Lists.GetByTitle(targetListName);
                ListItem item = list.GetItemById(19);

                clientContext.Load(item);
                clientContext.ExecuteQuery();

                string guid = item["GUID"].ToString();

                //Workflow Services Manager which will handle all the workflow interaction.
                WorkflowServicesManager wfServicesManager = new WorkflowServicesManager(clientContext, web);

                //Will return all Workflow Associations which are running on the SharePoint 2010 Engine
                WorkflowAssociationCollection wfAssociations = web.Lists.GetByTitle(targetListName).WorkflowAssociations;

                //Get the required Workflow Association
                WorkflowAssociation wfAssociation = wfAssociations.GetByName(workflowName);

                clientContext.Load(wfAssociation);

                clientContext.ExecuteQuery();

                //Get the instance of the Interop Service which will be used to create an instance of the Workflow
                InteropService workflowInteropService = wfServicesManager.GetWorkflowInteropService();

                var initiationData = new Dictionary <string, object>();
                initiationData.Add("DisplayName", "Julien Bessiere");
                initiationData.Add("AccountId", "i:0#.f|membership|[email protected]");
                initiationData.Add("AccountType", "User");

                //Start the Workflow
                ClientResult <Guid> resultGuid = workflowInteropService.StartWorkflow(wfAssociation.Name, new Guid(), targetListGUID, Guid.Parse(guid), initiationData);

                try
                {
                    clientContext.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
예제 #11
0
파일: Program.cs 프로젝트: re7w12u/gs-pm
        private static void StartWFOnLine()
        {
            //Site Details
            string siteUrl  = "https://jbes.sharepoint.com/sites/gosport";
            string userName = "******";
            string password = "******";

            //Name of the SharePoint2010 List Workflow
            string workflowName = "Approbation 2010";

            //Name of the List to which the Workflow is Associated
            string targetListName = "Liste des demandes";

            //Guid of the List to which the Workflow is Associated
            Guid targetListGUID = new Guid("cbe00484-055e-4dca-ade1-863ef7b202ba");

            //Guid of the ListItem on which to start the Workflow
            //Guid targetItemGUID = new Guid("");

            using (ClientContext clientContext = new ClientContext(siteUrl))
            {
                SecureString securePassword = new SecureString();

                foreach (char c in password.ToCharArray())
                {
                    securePassword.AppendChar(c);
                }

                clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

                Web web = clientContext.Web;

                List     list = web.Lists.GetByTitle(targetListName);
                ListItem item = list.GetItemById(1);

                clientContext.Load(item);
                clientContext.ExecuteQuery();

                string guid = item["GUID"].ToString();

                //Workflow Services Manager which will handle all the workflow interaction.
                WorkflowServicesManager wfServicesManager = new WorkflowServicesManager(clientContext, web);

                //Will return all Workflow Associations which are running on the SharePoint 2010 Engine
                WorkflowAssociationCollection wfAssociations = list.WorkflowAssociations;

                //Get the required Workflow Association
                WorkflowAssociation wfAssociation = wfAssociations.GetByName(workflowName);

                clientContext.Load(wfAssociation);

                clientContext.ExecuteQuery();

                //Get the instance of the Interop Service which will be used to create an instance of the Workflow
                InteropService workflowInteropService = wfServicesManager.GetWorkflowInteropService();

                var initiationData = new Dictionary <string, object>();

                //Start the Workflow
                ClientResult <Guid> resultGuid = workflowInteropService.StartWorkflow(wfAssociation.Name, new Guid(), targetListGUID, Guid.Parse(guid), initiationData);

                clientContext.ExecuteQuery();
            }
        }