Beispiel #1
0
        public void Provision(ClientContext ctx, ProvisioningTemplate template,
                              ProvisioningTemplateApplyingInformation applyingInformation,
                              TokenParser tokenParser, PnPMonitoredScope scope, string configurationData)
        {
            if (!string.IsNullOrEmpty(configurationData))
            {
                Helpers         helper          = new Helpers();
                WorkflowHandler workflowHandler = new WorkflowHandler();
                var             reader          = new StringReader(configurationData);



                var           serializer    = new XmlSerializer(typeof(WorkflowCollection), providerNameSpace);
                var           workflowColl  = (WorkflowCollection)serializer.Deserialize(reader);
                ListWorkflows listWorkflows = workflowColl.ListWorkflows;
                Console.WriteLine("Processing List Workflows");
                //applyingInformation.ProgressDelegate = delegate (String message, Int32 progress, Int32 total)
                //{
                //    Console.Write("List Workflows", progress, total, "List Workflows");
                //};

                foreach (WorkflowInfo listWorkflow in listWorkflows.Workflows)
                {
                    string listName     = listWorkflow.ListName;
                    string wfFile       = listWorkflow.FilePath;
                    string workflowName = listWorkflow.Name;
                    string workflowXml  = helper.ReadWorkflowFile(wfFile, template.Connector);
                    try
                    {
                        Console.WriteLine("Processing List Workflow '" + workflowName + "'");
                        workflowHandler.publishWorkflowFromXml(ctx.Url, workflowXml, workflowName, listName);
                    }
                    catch
                    {
                        Console.WriteLine("ERROR! Could not publish workflow " + workflowName);
                    }
                }

                ContentTypeWorkflows contentTypeWorkflows = workflowColl.ContentTypeWorkflows;
                Console.WriteLine("Processing Reusable Workflows");
                foreach (WorkflowInfo contentTypeWorkflow in contentTypeWorkflows.Workflows)
                {
                    string wfFile       = contentTypeWorkflow.FilePath;
                    string workflowName = contentTypeWorkflow.Name;
                    string workflowXml  = helper.ReadWorkflowFile(wfFile, template.Connector);
                    try
                    {
                        Console.WriteLine("Processing Reusable Workflow '" + workflowName + "'");
                        workflowHandler.publishWorkflowFromXml(ctx.Url, workflowXml, workflowName, null);
                    }
                    catch
                    {
                        Console.WriteLine("ERROR! Could not publish workflow " + workflowName);
                    }
                }

                SiteWorkflows siteWorkflows = workflowColl.SiteWorkflows;
                Console.WriteLine("Processing Site Workflows");
                foreach (WorkflowInfo siteWorkflow in siteWorkflows.Workflows)
                {
                    string wfFile       = siteWorkflow.FilePath;
                    string workflowName = siteWorkflow.Name;
                    string workflowXml  = helper.ReadWorkflowFile(wfFile, template.Connector);
                    try
                    {
                        Console.WriteLine("Processing Site Workflow '" + workflowName + "'");
                        workflowHandler.publishWorkflowFromXml(ctx.Url, workflowXml, workflowName, null);
                    }
                    catch
                    {
                        Console.WriteLine("ERROR! Could not publish workflow " + workflowName);
                    }
                }

                WorkflowScheduleCollection workflowSchedules = workflowColl.WorkflowSchedules;
                Console.WriteLine("Processing Workflow Schedules");
                foreach (WorkflowSchedule schedule in workflowSchedules.WorkflowSchedules)
                {
                    try
                    {
                        workflowHandler.ScheduleWorkflow(ctx.Url, schedule.WorkflowName, schedule.StartData, schedule.MaximumRepeats, schedule.WorkDaysOnly, schedule.EndOn, schedule.StartTime, schedule.EndTime, schedule.RepeatInterval.CountBetweenIntervals, schedule.RepeatInterval.Type);
                    }
                    catch (Exception err)
                    {
                        Console.WriteLine("ERROR! Could not schedule workflow " + schedule.WorkflowName);
                        Console.WriteLine(err.InnerException);
                    }
                }
            }
        }
Beispiel #2
0
        //private void DownloadWorkflowFile(string workflowID, FileConnectorBase writer, Stream fileStream)
        //{
        //    writer.SaveFileStream(workflowID, workflowFolderName, fileStream);
        //}

        public ProvisioningTemplate Extract(ClientContext ctx, ProvisioningTemplate template,
                                            ProvisioningTemplateCreationInformation creationInformation,
                                            PnPMonitoredScope scope, string configurationData)
        {
            Helpers         helpers   = new Helpers();
            WorkflowHandler wfHandler = new WorkflowHandler();

            Console.WriteLine("Nintex");
            var currentTemplate             = creationInformation.BaseTemplate;
            ExtensibilityHandler sprHandler = creationInformation.ExtensibilityHandlers[0];

            //StreamReader test = new StreamReader("d:\\babcockgraph.txt");
            //DownloadWorkflowFile("gpj.txt", creationInformation.FileConnector, test.BaseStream);

            Web web = ctx.Web;

            ctx.Load(web);
            ctx.ExecuteQuery();
            ListCollection listColl = web.Lists;

            ctx.Load(listColl);
            ctx.ExecuteQuery();
            string configText = "";

            WorkflowCollection wfColl = new WorkflowCollection();

            ListWorkflows listWF = new ListWorkflows();

            SiteWorkflows siteWF = new SiteWorkflows();

            ContentTypeWorkflows contentTypeWF = new ContentTypeWorkflows();

            List <WorkflowInfo> wfInfoList        = new List <WorkflowInfo>();
            List <WorkflowInfo> wfInfoSite        = new List <WorkflowInfo>();
            List <WorkflowInfo> wfInfoContentType = new List <WorkflowInfo>();

            foreach (List list in listColl)
            {
                ctx.Load(list);


                ctx.Load(list.WorkflowAssociations);

                ctx.ExecuteQuery();
                string listName = list.Title;

                foreach (var wfAss in list.WorkflowAssociations)
                {
                    if (wfAss.Name.IndexOf("Previous Version") > -1)
                    {
                        break;
                    }
                    WorkflowInfo wfInfo = new WorkflowInfo();

                    wfInfo.ID   = wfAss.Id.ToString();
                    wfInfo.Name = wfAss.Name;
                    if (wfInfo.Name.IndexOf("Previous Version") > -1)
                    {
                        break;
                    }
                    wfInfo.InstantiationUrl = wfAss.InstantiationUrl;
                    wfInfo.BaseID           = wfAss.BaseId.ToString();
                    wfInfo.Scope            = WorkflowLevel.List.ToString();
                    wfInfo.ListID           = wfAss.ListId.ToString();
                    wfInfo.ListName         = listName;
                    wfInfo.AssociationData  = wfAss.AssociationData;
                    if (wfAss.InstantiationUrl.IndexOf(workflowProviderName) > -1)
                    {
                        wfInfo.Type = WorkflowType.Nintex;
                    }
                    else
                    {
                        wfInfo.Type = WorkflowType.SharePoint;
                    }
                    wfInfo.FilePath = workflowFolderName + "\\" + wfAss.BaseId.ToString() + ".xml";
                    try
                    {
                        Stream wfStream = wfHandler.getWorkflowXMStream(ctx.Url, wfInfo.Name, listName, WorkflowHandler.WorkflowType.list);
                        helpers.DownloadWorkflowFile(wfAss.BaseId.ToString(), creationInformation.FileConnector, wfStream, WorkflowLevel.List);
                    }
                    catch
                    {
                        Console.WriteLine("ERROR!!! Could not export workflow Name " + wfAss.Name);
                    }
                    wfInfoList.Add(wfInfo);
                }
            }
            listWF.Workflows = wfInfoList;

            var siteWorkflows = web.WorkflowAssociations;

            ctx.Load(siteWorkflows);
            ctx.ExecuteQuery();
            foreach (var wfAss in siteWorkflows)
            {
                if (wfAss.Name.IndexOf("Previous Version") > -1)
                {
                    break;
                }
                WorkflowInfo wfInfo = new WorkflowInfo();

                wfInfo.ID               = wfAss.Id.ToString();
                wfInfo.Name             = wfAss.Name;
                wfInfo.InstantiationUrl = wfAss.InstantiationUrl;
                wfInfo.BaseID           = wfAss.BaseId.ToString();
                wfInfo.Scope            = WorkflowLevel.ContentType.ToString();
                wfInfo.AssociationData  = wfAss.AssociationData;
                if (wfAss.InstantiationUrl.IndexOf(workflowProviderName) > -1)
                {
                    wfInfo.Type = WorkflowType.Nintex;
                }
                else
                {
                    wfInfo.Type = WorkflowType.SharePoint;
                }
                wfInfo.FilePath = workflowFolderName + "\\" + wfAss.BaseId.ToString() + ".xml";
                try
                {
                    Stream wfStream = wfHandler.getWorkflowXMStream(ctx.Url, wfInfo.Name, null, WorkflowHandler.WorkflowType.site);
                    helpers.DownloadWorkflowFile(wfAss.BaseId.ToString(), creationInformation.FileConnector, wfStream, WorkflowLevel.Site);
                }
                catch
                {
                    Console.WriteLine("ERROR!!! Could not export workflow Name " + wfAss.Name);
                }

                wfInfoSite.Add(wfInfo);
            }

            siteWF.Workflows = wfInfoSite;

            Microsoft.SharePoint.Client.ContentTypeCollection contentTypes = web.ContentTypes;
            ctx.Load(contentTypes);
            ctx.ExecuteQuery();
            foreach (Microsoft.SharePoint.Client.ContentType cType in contentTypes)
            {
                ctx.Load(cType.WorkflowAssociations);
                ctx.ExecuteQuery();
                foreach (var wfAss in cType.WorkflowAssociations)
                {
                    if (wfAss.Name.IndexOf("Previous Version") > -1)
                    {
                        break;
                    }

                    WorkflowInfo wfInfo = new WorkflowInfo();

                    wfInfo.ID               = wfAss.Id.ToString();
                    wfInfo.Name             = wfAss.Name;
                    wfInfo.InstantiationUrl = wfAss.InstantiationUrl;
                    wfInfo.BaseID           = wfAss.BaseId.ToString();
                    wfInfo.Scope            = WorkflowLevel.ContentType.ToString();;
                    wfInfo.AssociationData  = wfAss.AssociationData;
                    if (wfAss.InstantiationUrl.IndexOf(workflowProviderName) > -1)
                    {
                        wfInfo.Type = WorkflowType.Nintex;
                    }
                    else
                    {
                        wfInfo.Type = WorkflowType.SharePoint;
                    }
                    wfInfo.FilePath = workflowFolderName + "\\" + wfAss.BaseId.ToString() + ".xml";
                    try
                    {
                        Stream wfStream = wfHandler.getWorkflowXMStream(ctx.Url, wfInfo.Name, null, WorkflowHandler.WorkflowType.globallyreusable);
                        helpers.DownloadWorkflowFile(wfAss.BaseId.ToString(), creationInformation.FileConnector, wfStream, WorkflowLevel.ContentType);
                    }
                    catch
                    {
                        Console.WriteLine("ERROR!!! Could not export workflow Name " + wfAss.Name);
                    }
                    wfInfoContentType.Add(wfInfo);
                }
            }


            contentTypeWF.Workflows = wfInfoContentType;

            wfColl.ListWorkflows        = listWF;
            wfColl.SiteWorkflows        = siteWF;
            wfColl.ContentTypeWorkflows = contentTypeWF;

            #region schedules
            //List<WorkflowSchedule> schedulesList = new List<WorkflowSchedule>();
            //WorkflowScheduleCollection schedules = new WorkflowScheduleCollection();
            //WorkflowSchedule schedule = new WorkflowSchedule();
            //schedule.WorkflowName = "SITE Workflow";
            //schedule.MaximumRepeats = 0;
            //schedule.WorkDaysOnly = false;
            //schedule.EndOn = "NoLimit";
            //schedule.EndTime = DateTime.Now.AddYears(1).ToUniversalTime();
            //schedule.StartTime = DateTime.Now.ToUniversalTime();
            //RepeatInterval interval = new RepeatInterval();
            //interval.CountBetweenIntervals = 7;
            //interval.Type = "Daily";
            //schedule.RepeatInterval = interval;
            //schedulesList.Add(schedule);
            //schedules.WorkflowSchedules = schedulesList;
            //wfColl.WorkflowSchedules = schedules;
            #endregion

            XmlSerializer sprHandlerXML = new XmlSerializer(typeof(WorkflowCollection), providerNameSpace);
            StringWriter  xmlWriter     = new StringWriter();
            sprHandlerXML.Serialize(xmlWriter, wfColl);
            configText = xmlWriter.ToString();

            sprHandler.Configuration = configText;

            ProvisioningTemplate newtemplate = template;
            newtemplate.ExtensibilityHandlers.Add(creationInformation.ExtensibilityHandlers[0]);
            return(newtemplate);
        }