private object GetProviderInstance(ExtensibilityHandler handler) { if (string.IsNullOrWhiteSpace(handler.Assembly)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); } if (string.IsNullOrWhiteSpace(handler.Type)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); } if (!handlerCache.ContainsKey(handler)) { // Does not work as the assembly was not loaded upfront // See https://jeremybytes.blogspot.com/2020/01/using-typegettype-with-net-core.html for some more context //var _instance = Activator.CreateInstance(handler.GetType()); var handlerAssemblyPath = AppDomain.CurrentDomain.BaseDirectory + handler.Assembly + ".dll"; var handlerAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(handlerAssemblyPath); var handlerType = handlerAssembly.ExportedTypes.Where(p => p.FullName == handler.Type).FirstOrDefault(); var _instance = Activator.CreateInstance(handlerType); handlerCache.Add(handler, _instance); } return(handlerCache[handler]); }
protected override void ProcessRecord() { ExtensibilityHandler handler = new ExtensibilityHandler(); handler.Assembly = Assembly; handler.Type = Type; handler.Configuration = Configuration; handler.Enabled = !Disabled; WriteObject(handler); }
protected override void ProcessRecord() { var handler = new ExtensibilityHandler { Assembly = Assembly, Type = Type, Configuration = Configuration, Enabled = !Disabled }; WriteObject(handler); }
/// <summary> /// Method to Invoke Custom Extraction Handlers. /// </summary> /// <remarks> /// Ensure the ClientContext is not disposed in the custom provider. /// </remarks> /// <param name="ctx">Authenticated ClientContext that is passed to the custom provider.</param> /// <param name="handler">A custom Extensibility Provisioning Provider</param> /// <param name="template">ProvisioningTemplate that is passed to the custom provider</param> /// <param name="creationInformation">The Provisioning Template creation information object</param> /// <param name="scope">The PnPMonitoredScope of the current step in the pipeline</param> /// <exception cref="ExtensiblityPipelineException"></exception> /// <exception cref="ArgumentException">Provider.Assembly or Provider.Type is NullOrWhiteSpace></exception> /// <exception cref="ArgumentNullException">ClientContext is Null></exception> public ProvisioningTemplate ExecuteExtensibilityExtractionCallOut(ClientContext ctx, ExtensibilityHandler handler, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInformation, PnPMonitoredScope scope) { var _loggingSource = "OfficeDevPnP.Core.Framework.Provisioning.Extensibility.ExtensibilityManager.ExecuteCallout"; if (ctx == null) throw new ArgumentNullException(CoreResources.Provisioning_Extensibility_Pipeline_ClientCtxNull); if (string.IsNullOrWhiteSpace(handler.Assembly)) throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); if (string.IsNullOrWhiteSpace(handler.Type)) throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); ProvisioningTemplate parsedTemplate = null; try { var _instance = GetProviderInstance(handler); if (_instance is IProvisioningExtensibilityHandler) { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, handler.Assembly, handler.Type); parsedTemplate = (_instance as IProvisioningExtensibilityHandler).Extract(ctx, template, creationInformation, scope, handler.Configuration); Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, handler.Assembly, handler.Type); } else { parsedTemplate = template; } } catch (Exception ex) { string _message = string.Format( CoreResources.Provisioning_Extensibility_Pipeline_Exception, handler.Assembly, handler.Type, ex); Log.Error(_loggingSource, _message); throw new ExtensiblityPipelineException(_message, ex); } return parsedTemplate; }
public void CanHandlerProvisioningCallOut() { var _mockProvider = new ExtensibilityHandler(); _mockProvider.Assembly = "OfficeDevPnP.Core.Tests"; _mockProvider.Type = "OfficeDevPnP.Core.Tests.Framework.ExtensibilityCallOut.ExtensibilityMockHandler"; _mockProvider.Configuration = ExtensibilityTestConstants.PROVIDER_MOCK_DATA; var _mockctx = new ClientContext(ExtensibilityTestConstants.MOCK_URL); var _mockTemplate = new ProvisioningTemplate(); _mockTemplate.Id = ExtensibilityTestConstants.PROVISIONINGTEMPLATE_ID; var _em = new ExtensibilityManager(); _em.ExecuteExtensibilityProvisionCallOut(_mockctx, _mockProvider, _mockTemplate, null, null, null); }
/// <summary> /// Method to Invoke Custom Provisioning Token Providers which implement the IProvisioningExtensibilityTokenProvider interface. /// Ensure the ClientContext is not disposed in the custom provider. /// </summary> /// <param name="ctx">Authenticated ClientContext that is passed to the custom provider.</param> /// <param name="provider">A custom Extensibility Provisioning Provider</param> /// <param name="template">ProvisioningTemplate that is passed to the custom provider</param> /// <exception cref="ExtensiblityPipelineException"></exception> /// <exception cref="ArgumentException">Provider.Assembly or Provider.Type is NullOrWhiteSpace></exception> /// <exception cref="ArgumentNullException">ClientContext is Null></exception> public IEnumerable<TokenDefinition> ExecuteTokenProviderCallOut(ClientContext ctx, ExtensibilityHandler provider, ProvisioningTemplate template) { var _loggingSource = "OfficeDevPnP.Core.Framework.Provisioning.Extensibility.ExtensibilityManager.ExecuteTokenProviderCallOut"; if (ctx == null) throw new ArgumentNullException(CoreResources.Provisioning_Extensibility_Pipeline_ClientCtxNull); if (string.IsNullOrWhiteSpace(provider.Assembly)) throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); if (string.IsNullOrWhiteSpace(provider.Type)) throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); try { var _instance = GetProviderInstance(provider) as IProvisioningExtensibilityTokenProvider; if (_instance != null) { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, provider.Assembly, provider.Type); var tokens = _instance.GetTokens(ctx, template, provider.Configuration); Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, provider.Assembly, provider.Type); return tokens; } return new List<TokenDefinition>(); } catch (Exception ex) { string _message = string.Format( CoreResources.Provisioning_Extensibility_Pipeline_Exception, provider.Assembly, provider.Type, ex); Log.Error(_loggingSource, _message); throw new ExtensiblityPipelineException(_message, ex); } }
private object GetProviderInstance(ExtensibilityHandler handler) { if (string.IsNullOrWhiteSpace(handler.Assembly)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); } if (string.IsNullOrWhiteSpace(handler.Type)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); } if (!handlerCache.ContainsKey(handler)) { var _instance = Activator.CreateInstance(handler.Assembly, handler.Type).Unwrap(); handlerCache.Add(handler, _instance); } return(handlerCache[handler]); }
public void ProvisioningCallOutThrowsExceptionOnUnavailableExtensibilityProvider() { var _mockProvider = new ExtensibilityHandler { Assembly = "NonexistingAssembly", Type = "PnP.Framework.Test.Framework.ExtensibilityCallOut.ExtensibilityMockHandler", Configuration = ExtensibilityTestConstants.PROVIDER_MOCK_DATA }; var _mockctx = new ClientContext(ExtensibilityTestConstants.MOCK_URL); var _mockTemplate = new ProvisioningTemplate { Id = ExtensibilityTestConstants.PROVISIONINGTEMPLATE_ID }; var _em = new ExtensibilityManager(); _em.ExecuteExtensibilityProvisionCallOut(_mockctx, _mockProvider, _mockTemplate, null, null, null); }
public void CanHandlerExtractionCallOut() { var _mockProvider = new ExtensibilityHandler { Assembly = "PnP.Framework.Test", Type = "PnP.Framework.Test.Framework.ExtensibilityCallOut.ExtensibilityMockHandler", Configuration = ExtensibilityTestConstants.PROVIDER_MOCK_DATA }; var _mockctx = new ClientContext(ExtensibilityTestConstants.MOCK_URL); var _mockTemplate = new ProvisioningTemplate { Id = ExtensibilityTestConstants.PROVISIONINGTEMPLATE_ID }; var _em = new ExtensibilityManager(); var template = _em.ExecuteExtensibilityExtractionCallOut(_mockctx, _mockProvider, _mockTemplate, null, null); Assert.IsTrue(template.Lists.Count == 1); }
private object GetProviderInstance(ExtensibilityHandler handler) { if (string.IsNullOrWhiteSpace(handler.Assembly)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); } if (string.IsNullOrWhiteSpace(handler.Type)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); } if (!handlerCache.ContainsKey(handler)) { #if NETSTANDARD2_0 var handlerType = Type.GetType($"{handler.Type}, {handler.Assembly}", true); var _instance = Activator.CreateInstance(handlerType); #else var _instance = Activator.CreateInstance(handler.Assembly, handler.Type).Unwrap(); #endif handlerCache.Add(handler, _instance); } return(handlerCache[handler]); }
/// <summary> /// Method to Invoke Custom Provisioning Token Providers which implement the IProvisioningExtensibilityTokenProvider interface. /// Ensure the ClientContext is not disposed in the custom provider. /// </summary> /// <param name="ctx">Authenticated ClientContext that is passed to the custom provider.</param> /// <param name="provider">A custom Extensibility Provisioning Provider</param> /// <param name="template">ProvisioningTemplate that is passed to the custom provider</param> /// <exception cref="ExtensiblityPipelineException"></exception> /// <exception cref="ArgumentException">Provider.Assembly or Provider.Type is NullOrWhiteSpace></exception> /// <exception cref="ArgumentNullException">ClientContext is Null></exception> public IEnumerable <TokenDefinition> ExecuteTokenProviderCallOut(ClientContext ctx, ExtensibilityHandler provider, ProvisioningTemplate template) { var _loggingSource = "PnP.Framework.Provisioning.Extensibility.ExtensibilityManager.ExecuteTokenProviderCallOut"; if (ctx == null) { throw new ArgumentNullException(nameof(ctx), CoreResources.Provisioning_Extensibility_Pipeline_ClientCtxNull); } if (string.IsNullOrWhiteSpace(provider.Assembly)) { throw new ArgumentException(String.Format("{0}.{1}", nameof(provider), nameof(provider.Assembly)), CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); } if (string.IsNullOrWhiteSpace(provider.Type)) { throw new ArgumentException(String.Format("{0}.{1}", nameof(provider), nameof(provider.Type)), CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); } try { var providerInstance = GetProviderInstance(provider); var extensibilityTokenProviderInstance = providerInstance as IProvisioningExtensibilityTokenProvider; if (extensibilityTokenProviderInstance != null) { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, provider.Assembly, provider.Type); var tokens = extensibilityTokenProviderInstance.GetTokens(ctx, template, provider.Configuration); Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, provider.Assembly, provider.Type); return(tokens); } else if (providerInstance != null) { throw new ArgumentOutOfRangeException(nameof(provider), string.Format(CoreResources.Provisioning_Extensibility_Invalid_Handler_Implementation, this.GetType().Assembly.GetName().Version.ToString(), provider.Assembly, provider.Type)); } return(new List <TokenDefinition>()); } catch (Exception ex) { Log.Error(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Exception, provider.Assembly, provider.Type, ex); string _message = string.Format( CoreResources.Provisioning_Extensibility_Pipeline_Exception, provider.Assembly, provider.Type, ex); throw new ExtensiblityPipelineException(_message, ex); } }
/// <summary> /// Method to Invoke Custom Extraction Handlers. /// </summary> /// <remarks> /// Ensure the ClientContext is not disposed in the custom provider. /// </remarks> /// <param name="ctx">Authenticated ClientContext that is passed to the custom provider.</param> /// <param name="handler">A custom Extensibility Provisioning Provider</param> /// <param name="template">ProvisioningTemplate that is passed to the custom provider</param> /// <param name="creationInformation">The Provisioning Template creation information object</param> /// <param name="scope">The PnPMonitoredScope of the current step in the pipeline</param> /// <exception cref="ExtensiblityPipelineException"></exception> /// <exception cref="ArgumentException">Provider.Assembly or Provider.Type is NullOrWhiteSpace></exception> /// <exception cref="ArgumentNullException">ClientContext is Null></exception> public ProvisioningTemplate ExecuteExtensibilityExtractionCallOut(ClientContext ctx, ExtensibilityHandler handler, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInformation, PnPMonitoredScope scope) { var _loggingSource = "PnP.Framework.Provisioning.Extensibility.ExtensibilityManager.ExecuteCallout"; if (ctx == null) { throw new ArgumentNullException(nameof(ctx), CoreResources.Provisioning_Extensibility_Pipeline_ClientCtxNull); } if (string.IsNullOrWhiteSpace(handler.Assembly)) { throw new ArgumentException(String.Format("{0}.{1}", nameof(handler), nameof(handler.Assembly)), CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); } if (string.IsNullOrWhiteSpace(handler.Type)) { throw new ArgumentException(String.Format("{0}.{1}", nameof(handler), nameof(handler.Type)), CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); } ProvisioningTemplate parsedTemplate = null; try { var _instance = GetProviderInstance(handler); if (_instance is IProvisioningExtensibilityHandler) { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, handler.Assembly, handler.Type); parsedTemplate = (_instance as IProvisioningExtensibilityHandler).Extract(ctx, template, creationInformation, scope, handler.Configuration); Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, handler.Assembly, handler.Type); } else if (_instance != null && !(_instance is IProvisioningExtensibilityTokenProvider)) { throw new ArgumentOutOfRangeException(nameof(handler), string.Format(CoreResources.Provisioning_Extensibility_Invalid_Handler_Implementation, this.GetType().Assembly.GetName().Version.ToString(), handler.Assembly, handler.Type)); } else { parsedTemplate = template; } } catch (Exception ex) { Log.Error(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Exception, handler.Assembly, handler.Type, ex); string _message = string.Format( CoreResources.Provisioning_Extensibility_Pipeline_Exception, handler.Assembly, handler.Type, ex); throw new ExtensiblityPipelineException(_message, ex); } return(parsedTemplate); }
/// <summary> /// Method to Invoke Custom Provisioning Handlers. /// </summary> /// <remarks> /// Ensure the ClientContext is not disposed in the custom provider. /// </remarks> /// <param name="ctx">Authenticated ClientContext that is passed to the custom provider.</param> /// <param name="handler">A custom Extensibility Provisioning Provider</param> /// <param name="template">ProvisioningTemplate that is passed to the custom provider</param> /// <param name="applyingInformation">The Provisioning Template application information object</param> /// <param name="tokenParser">The Token Parser used by the engine during template provisioning</param> /// <param name="scope">The PnPMonitoredScope of the current step in the pipeline</param> /// <exception cref="ExtensiblityPipelineException"></exception> /// <exception cref="ArgumentException">Provider.Assembly or Provider.Type is NullOrWhiteSpace></exception> /// <exception cref="ArgumentNullException">ClientContext is Null></exception> public void ExecuteExtensibilityProvisionCallOut(ClientContext ctx, ExtensibilityHandler handler, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation, TokenParser tokenParser, PnPMonitoredScope scope) { var _loggingSource = "PnP.Framework.Provisioning.Extensibility.ExtensibilityManager.ExecuteCallout"; if (ctx == null) { throw new ArgumentNullException(nameof(ctx), CoreResources.Provisioning_Extensibility_Pipeline_ClientCtxNull); } if (string.IsNullOrWhiteSpace(handler.Assembly)) { throw new ArgumentException(String.Format("{0}.{1}", nameof(handler), nameof(handler.Type)), CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); } if (string.IsNullOrWhiteSpace(handler.Type)) { throw new ArgumentException(String.Format("{0}.{1}", nameof(handler), nameof(handler.Type)), CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); } try { var _instance = GetProviderInstance(handler); #pragma warning disable 618 if (_instance is IProvisioningExtensibilityProvider) #pragma warning restore 618 { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, handler.Assembly, handler.Type); #pragma warning disable 618 (_instance as IProvisioningExtensibilityProvider).ProcessRequest(ctx, template, handler.Configuration); #pragma warning restore 618 Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, handler.Assembly, handler.Type); } else if (_instance is IProvisioningExtensibilityHandler) { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, handler.Assembly, handler.Type); (_instance as IProvisioningExtensibilityHandler).Provision(ctx, template, applyingInformation, tokenParser, scope, handler.Configuration); Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, handler.Assembly, handler.Type); } else if (_instance != null && !(_instance is IProvisioningExtensibilityTokenProvider)) { throw new ArgumentOutOfRangeException(nameof(handler), string.Format(CoreResources.Provisioning_Extensibility_Invalid_Handler_Implementation, this.GetType().Assembly.GetName().Version.ToString(), handler.Assembly, handler.Type)); } } catch (Exception ex) { Log.Error(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Exception, handler.Assembly, handler.Type, ex); string _message = string.Format( CoreResources.Provisioning_Extensibility_Pipeline_Exception, handler.Assembly, handler.Type, ex); throw new ExtensiblityPipelineException(_message, ex); } }
private object GetProviderInstance(ExtensibilityHandler handler) { if (string.IsNullOrWhiteSpace(handler.Assembly)) throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); if (string.IsNullOrWhiteSpace(handler.Type)) throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); if (!handlerCache.ContainsKey(handler)) { var _instance = Activator.CreateInstance(handler.Assembly, handler.Type).Unwrap(); handlerCache.Add(handler, _instance); } return handlerCache[handler]; }
//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); }
/// <summary> /// Method to Invoke Custom Provisioning Token Providers which implement the IProvisioningExtensibilityTokenProvider interface. /// Ensure the ClientContext is not disposed in the custom provider. /// </summary> /// <param name="ctx">Authenticated ClientContext that is passed to the custom provider.</param> /// <param name="provider">A custom Extensibility Provisioning Provider</param> /// <param name="template">ProvisioningTemplate that is passed to the custom provider</param> /// <exception cref="ExtensiblityPipelineException"></exception> /// <exception cref="ArgumentException">Provider.Assembly or Provider.Type is NullOrWhiteSpace></exception> /// <exception cref="ArgumentNullException">ClientContext is Null></exception> public IEnumerable <TokenDefinition> ExecuteTokenProviderCallOut(ClientContext ctx, ExtensibilityHandler provider, ProvisioningTemplate template) { var _loggingSource = "OfficeDevPnP.Core.Framework.Provisioning.Extensibility.ExtensibilityManager.ExecuteTokenProviderCallOut"; if (ctx == null) { throw new ArgumentNullException(CoreResources.Provisioning_Extensibility_Pipeline_ClientCtxNull); } if (string.IsNullOrWhiteSpace(provider.Assembly)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); } if (string.IsNullOrWhiteSpace(provider.Type)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); } try { var _instance = GetProviderInstance(provider) as IProvisioningExtensibilityTokenProvider; if (_instance != null) { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, provider.Assembly, provider.Type); var tokens = _instance.GetTokens(ctx, template, provider.Configuration); Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, provider.Assembly, provider.Type); return(tokens); } return(new List <TokenDefinition>()); } catch (Exception ex) { string _message = string.Format( CoreResources.Provisioning_Extensibility_Pipeline_Exception, provider.Assembly, provider.Type, ex); Log.Error(_loggingSource, _message); throw new ExtensiblityPipelineException(_message, ex); } }
public void ExecuteExtensibilityCallOut(ClientContext ctx, ExtensibilityHandler handler, ProvisioningTemplate template) { ExecuteExtensibilityProvisionCallOut(ctx, handler, template, null, null, null); }
/// <summary> /// Method to Invoke Custom Provisioning Handlers. /// </summary> /// <remarks> /// Ensure the ClientContext is not disposed in the custom provider. /// </remarks> /// <param name="ctx">Authenticated ClientContext that is passed to the custom provider.</param> /// <param name="handler">A custom Extensibility Provisioning Provider</param> /// <param name="template">ProvisioningTemplate that is passed to the custom provider</param> /// <param name="applyingInformation">The Provisioning Template application information object</param> /// <param name="tokenParser">The Token Parser used by the engine during template provisioning</param> /// <param name="scope">The PnPMonitoredScope of the current step in the pipeline</param> /// <exception cref="ExtensiblityPipelineException"></exception> /// <exception cref="ArgumentException">Provider.Assembly or Provider.Type is NullOrWhiteSpace></exception> /// <exception cref="ArgumentNullException">ClientContext is Null></exception> public void ExecuteExtensibilityProvisionCallOut(ClientContext ctx, ExtensibilityHandler handler, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation, TokenParser tokenParser, PnPMonitoredScope scope) { var _loggingSource = "OfficeDevPnP.Core.Framework.Provisioning.Extensibility.ExtensibilityManager.ExecuteCallout"; if (ctx == null) { throw new ArgumentNullException(CoreResources.Provisioning_Extensibility_Pipeline_ClientCtxNull); } if (string.IsNullOrWhiteSpace(handler.Assembly)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_AssemblyName); } if (string.IsNullOrWhiteSpace(handler.Type)) { throw new ArgumentException(CoreResources.Provisioning_Extensibility_Pipeline_Missing_TypeName); } try { var _instance = GetProviderInstance(handler); if (_instance is IProvisioningExtensibilityProvider) { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, handler.Assembly, handler.Type); (_instance as IProvisioningExtensibilityProvider).ProcessRequest(ctx, template, handler.Configuration); Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, handler.Assembly, handler.Type); } else if (_instance is IProvisioningExtensibilityHandler) { Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_BeforeInvocation, handler.Assembly, handler.Type); (_instance as IProvisioningExtensibilityHandler).Provision(ctx, template, applyingInformation, tokenParser, scope, handler.Configuration); Log.Info(_loggingSource, CoreResources.Provisioning_Extensibility_Pipeline_Success, handler.Assembly, handler.Type); } } catch (Exception ex) { string _message = string.Format( CoreResources.Provisioning_Extensibility_Pipeline_Exception, handler.Assembly, handler.Type, ex); Log.Error(_loggingSource, _message); throw new ExtensiblityPipelineException(_message, ex); } }