public static void LoadContentTypes(TreeNode parentNode, SPClient.ContentTypeCollection contentTypes, MainBrowser form, LoadType loadType) { try { SPClient.ClientContext ctx = GetClientContext(parentNode); ctx.Load(contentTypes); ctx.ExecuteQuery(); int total = contentTypes.Count; int current = 0; foreach (SPClient.ContentType ct in contentTypes) { TreeNode node = parentNode.Nodes.Add(string.Format("{0} ({1})", ct.Name, ct.Group)); node.ImageKey = Constants.IMAGE_CONTENT_TYPE; node.SelectedImageKey = Constants.IMAGE_CONTENT_TYPE; node.Tag = ct; node.ContextMenuStrip = form.mnContextItem; if (ct.Hidden) { node.ForeColor = Color.Gray; } // Add group node TreeNode groupNode = parentNode.Nodes.OfType <TreeNode>().SingleOrDefault(n => n.Text.Equals(ct.Group)); if (groupNode == null) { groupNode = new TreeNode(ct.Group); groupNode.ImageKey = Constants.IMAGE_CONTENT_TYPE_GROUP; groupNode.SelectedImageKey = Constants.IMAGE_CONTENT_TYPE_GROUP; groupNode.Tag = LoadType.GeneralGroup; parentNode.Nodes.Add(groupNode); } groupNode.Nodes.Add((TreeNode)node.Clone()); // Update progress current++; ItemLoaded(null, new ItemLoadedEventArgs() { TotalItem = total, CurrentItem = current }); } } catch (Exception ex) { MessageBox.Show(ex.Message, form.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); AddLoadingNode(parentNode, loadType); } }
private void LoadContentTypes(SP.List list) { cmbFilterContentType.Enabled = false; cmbFilterContentType.Items.Clear(); if (cmbLists.SelectedIndex >= 0) { string webUrl = txtUrl.Text; List <string> contentTypes = new List <string>(); contentTypes.Add(""); using (SP.ClientContext ctx = GetClientContext(webUrl)) { Web oWebsite = ctx.Web; SP.List list1 = oWebsite.Lists.GetById(list.Id); ctx.Load(list1); SP.ContentTypeCollection coll = list1.ContentTypes; ctx.Load(coll, cts => cts.Include( ct => ct.Name , ct => ct.Description , ct => ct.SchemaXml )); ctx.ExecuteQuery(); progressBar1.Value++; StringBuilder sb = new StringBuilder(); sb.Append("<ContentTypes>"); foreach (var item in coll) { contentTypes.Add(item.Name + " ( " + item.Description + " )"); sb.Append(item.SchemaXml); } sb.Append("</ContentTypes>"); allContentTypes = sb.ToString(); txtContentTypes.Text = FormatXml(allContentTypes); contentTypes.Sort(); cmbFilterContentType.Items.AddRange(contentTypes.ToArray()); } cmbFilterContentType.Enabled = true; } }
//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); }