Exemple #1
0
 public HomeController(IPnPContextFactory pnpContextFactory,
                       ILogger <HomeController> logger,
                       ITokenAcquisition tokenAcquisition,
                       IOptions <PnPCoreOptions> pnpCoreOptions)
 {
     _pnpContextFactory = pnpContextFactory;
     _logger            = logger;
     _tokenAcquisition  = tokenAcquisition;
     _pnpCoreOptions    = pnpCoreOptions?.Value;
 }
Exemple #2
0
 public TransformTaskFunction(
     ITransformationExecutor executor,
     IPnPContextFactory pnpContextFactory,
     ITransformationStateManager transformationStateManager,
     ClientContext sourceContext)
 {
     this.executor                   = executor;
     this.pnpContextFactory          = pnpContextFactory;
     this.transformationStateManager = transformationStateManager;
     this.sourceContext              = sourceContext;
 }
Exemple #3
0
        public new IPnPContextFactory BuildContextFactory()
        {
            try
            {
                // If a test case is already initializing the factory then let's wait
                semaphoreSlimFactory.Wait();

                if (pnpContextFactoryCache != null)
                {
                    return(pnpContextFactoryCache);
                }

                var configuration = GetConfigurationSettings();

                if (RunningInGitHubWorkflow())
                {
                    // NOOP so far
                }

                var serviceProvider = new ServiceCollection()
                                      // Configuration
                                      .AddScoped <IConfiguration>(_ => configuration)
                                      // Logging service, get config from appsettings + add debug output handler
                                      .AddLogging(configure =>
                {
                    configure.AddConfiguration(configuration.GetSection("Logging"));
                    configure.AddDebug();
                })
                                      // Add the PnP Core SDK library services
                                      .AddPnPCore().Services
                                      // Add the PnP Core SDK library services configuration from the appsettings.json file
                                      .Configure <PnPCoreOptions>(configuration.GetSection("PnPCore"))
                                      // Add the PnP Core SDK Authentication Providers
                                      .AddPnPCoreAuthentication()
                                      .Configure <PnPCoreAuthenticationOptions>(configuration.GetSection("PnPCore"))
                                      .BuildServiceProvider();

                var pnpContextFactory = serviceProvider.GetRequiredService <IPnPContextFactory>();

                if (pnpContextFactoryCache == null)
                {
                    pnpContextFactoryCache = pnpContextFactory;
                }

                return(pnpContextFactory);
            }
            finally
            {
                semaphoreSlimFactory.Release();
            }
        }
Exemple #4
0
        private IPnPContextFactory BuildContextFactory()
        {
            try
            {
                // Ensure there's only one context factory building happening at any given time
                semaphoreSlimFactory.Wait();

                // Return the factory from cache if we already have one
                if (pnpContextFactoryCache != null)
                {
                    return(pnpContextFactoryCache);
                }

                // Build the service collection and load PnP Core SDK
                IServiceCollection services = new ServiceCollection();

                // To increase coverage of solutions providing tokens without graph scopes we turn of graphfirst for PnPContext created from PnP Framework
                services = services.AddPnPCore(options =>
                {
                    options.PnPContext.GraphFirst = false;
                }).Services;

                // Enables to plug in additional services into this service container
                if (OnDIContainerBuilding != null)
                {
                    OnDIContainerBuilding.Invoke(this, services);
                }

                var serviceProvider = services.BuildServiceProvider();

                // Get a PnP context factory
                var pnpContextFactory = serviceProvider.GetRequiredService <IPnPContextFactory>();

                // Chache the factory before returning it
                if (pnpContextFactoryCache == null)
                {
                    pnpContextFactoryCache = pnpContextFactory;
                }

                return(pnpContextFactory);
            }
            finally
            {
                semaphoreSlimFactory.Release();
            }
        }
Exemple #5
0
        private IPnPContextFactory BuildContextFactory()
        {
            try
            {
                // Ensure there's only one context factory building happening at any given time
                semaphoreSlimFactory.Wait();

                // Return the factory from cache if we already have one
                if (pnpContextFactoryCache != null)
                {
                    return(pnpContextFactoryCache);
                }

                // Build the service collection and load PnP Core SDK
                var serviceProvider = new ServiceCollection()
                                      .AddPnPCore(options =>
                {
                    options.PnPContext.GraphFirst = false;
                })
                                      .Services
                                      .BuildServiceProvider();

                // Get a PnP context factory
                var pnpContextFactory = serviceProvider.GetRequiredService <IPnPContextFactory>();

                // Chache the factory before returning it
                if (pnpContextFactoryCache == null)
                {
                    pnpContextFactoryCache = pnpContextFactory;
                }

                return(pnpContextFactory);
            }
            finally
            {
                semaphoreSlimFactory.Release();
            }
        }
        /// <summary>
        /// Creates a new transformation process for SharePoint
        /// </summary>
        /// <param name="transformationProcess">The process to use</param>
        /// <param name="pnpContextFactory">The context factory to use</param>
        /// <param name="sourceContext">The source context</param>
        /// <param name="targetName">The target site name</param>
        /// <param name="token">The cancellation token, if any</param>
        /// <returns></returns>
        public static async Task StartProcessAsync(
            this ITransformationProcess transformationProcess,
            IPnPContextFactory pnpContextFactory,
            ClientContext sourceContext,
            string targetName,
            CancellationToken token = default)
        {
            if (transformationProcess == null)
            {
                throw new ArgumentNullException(nameof(transformationProcess));
            }
            if (pnpContextFactory == null)
            {
                throw new ArgumentNullException(nameof(pnpContextFactory));
            }

            // Create context
            var targetContext = await pnpContextFactory.CreateAsync(targetName).ConfigureAwait(false);

            token.ThrowIfCancellationRequested();

            await transformationProcess.StartSharePointProcessAsync(sourceContext, targetContext, token).ConfigureAwait(false);
        }
 public PnPService(IPnPContextFactory pnpContextFactory)
 {
     _pnpContextFactory = pnpContextFactory;
 }
Exemple #8
0
        public MainWindow(IPnPContextFactory pnpFactory)
        {
            this.pnpContextFactory = pnpFactory;

            InitializeComponent();
        }
Exemple #9
0
 public CreateSite(IPnPContextFactory pnpContextFactory, ILoggerFactory loggerFactory, AzureFunctionSettings settings)
 {
     logger                = loggerFactory.CreateLogger <CreateSite>();
     contextFactory        = pnpContextFactory;
     azureFunctionSettings = settings;
 }
Exemple #10
0
 public CreateTerm(IPnPContextFactory pnpContextFactory, ILogger <CreateTerm> logger)
 {
     _pnpContextFactory = pnpContextFactory;
     _logger            = logger;
 }
 public GetSiteDocuments(IPnPContextFactory pnpContextFactory)
 {
     this.pnpContextFactory = pnpContextFactory;
 }
Exemple #12
0
 public ConsumeSPO(IPnPContextFactory pnpContextFactory)
 {
     _pnpContextFactory = pnpContextFactory;
 }
 public MyContextFactory(IPnPContextFactory contextFactory, IConfiguration configuration, IAuthenticationProvider msalAuthProvider)
 {
     _configuration    = configuration;
     _contextFactory   = contextFactory;
     _msalAuthProvider = msalAuthProvider;
 }
Exemple #14
0
        public static void DelegateToMockContext(bool runInIntegrationMode,
                                                 string siteUrl,
                                                 Action <PnPContext> contextAction,
                                                 [System.Runtime.CompilerServices.CallerFilePath] string mockFolderPath = null,
                                                 [System.Runtime.CompilerServices.CallerMemberName] string mockFileName = null)
        {
            string mockFilePath = mockFolderPath.Replace(".cs", $"\\{mockFileName}.json");
            var    hostBuilder  = Host.CreateDefaultBuilder().ConfigureServices((hostingContext, services) =>
            {
                services.AddPnPCore(options =>
                {
                    options.PnPContext.GraphFirst = true;
                });
                services.AddTransient <MockHttpHandler>((IServiceProvider provider) =>
                {
                    return(new MockHttpHandler(mockFilePath));
                });
                services.AddTransient <StoreResponseToAFile>((IServiceProvider provider) =>
                {
                    return(new StoreResponseToAFile(mockFilePath));
                });
                if (runInIntegrationMode)
                {
                    services.AddHttpClient("MockRESTClient", config =>
                    {
                    }).AddHttpMessageHandler <StoreResponseToAFile>()
                    .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
                    {
                        UseCookies = false
                    });
                }
                else
                {
                    services.AddHttpClient("MockRESTClient", config =>
                    {
                    }).AddHttpMessageHandler <MockHttpHandler>();
                }
                services.AddTransient <SharePointRestClient>((IServiceProvider provider) =>
                {
                    var client = provider.GetRequiredService <IHttpClientFactory>().CreateClient("MockRESTClient");
                    return(new SharePointRestClient(client, provider.GetRequiredService <ILogger <SharePointRestClient> >(), provider.GetRequiredService <IOptions <PnPGlobalSettingsOptions> >()));
                });
                services.AddTransient <MicrosoftGraphClient>((IServiceProvider provider) =>
                {
                    var client = provider.GetRequiredService <IHttpClientFactory>().CreateClient("MockRESTClient");
                    return(new MicrosoftGraphClient(client, provider.GetRequiredService <ILogger <MicrosoftGraphClient> >(), provider.GetRequiredService <IOptions <PnPGlobalSettingsOptions> >()));
                });
                services.AddTransient <IAuthenticationProvider>((IServiceProvider provider) =>
                {
                    if (runInIntegrationMode)
                    {
                        return(new UsernamePasswordAuthenticationProvider("31359c7f-bd7e-475c-86db-fdb8c937548e", "organizations", Common.User, EncryptionUtility.ToSecureString(Common.UserPassword)));
                    }
                    else
                    {
                        return(new MockAuthenticationProvider());
                    }
                });
            });
            IHost host = hostBuilder.Build();

            using (var scope = host.Services.CreateScope())
            {
                IPnPContextFactory pnpContextFactory = scope.ServiceProvider.GetRequiredService <IPnPContextFactory>();
                using (PnPContext context = pnpContextFactory.Create(new Uri(siteUrl), host.Services.GetRequiredService <IAuthenticationProvider>()))
                {
                    contextAction(context);
                }
            }
        }