Пример #1
0
        /// <summary>
        /// Constructs the Microsoft Graph http client
        /// </summary>
        /// <param name="client">Http client instance</param>
        /// <param name="log">Logger</param>
        /// <param name="options">Settings to configure the http client</param>
        public MicrosoftGraphClient(HttpClient client, ILogger <MicrosoftGraphClient> log, IOptions <PnPGlobalSettingsOptions> options)
        {
            logger         = log;
            globalSettings = options?.Value;

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (globalSettings == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            client.BaseAddress = PnPConstants.MicrosoftGraphBaseUri;
            client.DefaultRequestHeaders.Add("Accept", "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=true");
            client.Timeout = globalSettings.GetHttpTimeout();

            if (!string.IsNullOrEmpty(globalSettings.HttpUserAgent))
            {
                client.DefaultRequestHeaders.Add("User-Agent", globalSettings.HttpUserAgent);
            }

            Client = client;
        }
Пример #2
0
        internal PnPContext(ILogger logger,
                            IAuthenticationProvider authenticationProvider,
                            SharePointRestClient sharePointRestClient,
                            MicrosoftGraphClient microsoftGraphClient,
                            PnPContextFactoryOptions contextOptions,
                            PnPGlobalSettingsOptions globalOptions,
                            TelemetryManager telemetryManager)
        {
            Id     = Guid.NewGuid();
            Logger = logger;

#if DEBUG
            Mode = TestMode.Default;
#endif
            AuthenticationProvider = authenticationProvider;
            RestClient             = sharePointRestClient;
            GraphClient            = microsoftGraphClient;
            this.GlobalOptions     = globalOptions;
            this.ContextOptions    = contextOptions;
            telemetry = telemetryManager;

            if (this.ContextOptions != null)
            {
                GraphFirst         = this.ContextOptions.GraphFirst;
                GraphAlwaysUseBeta = this.ContextOptions.GraphAlwaysUseBeta;
                GraphCanUseBeta    = this.ContextOptions.GraphCanUseBeta;
            }

            BatchClient = new BatchClient(this, this.GlobalOptions, telemetryManager);
        }
Пример #3
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="client">Http Client coming from the .Net http client factory</param>
        /// <param name="log">Logger service</param>
        /// <param name="options">Options service</param>
        public SharePointRestClient(HttpClient client, ILogger <SharePointRestClient> log, IOptions <PnPGlobalSettingsOptions> options)
        {
            logger         = log;
            globalSettings = options?.Value;

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (globalSettings == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            client.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose");
            client.Timeout = globalSettings.GetHttpTimeout();

            if (!string.IsNullOrEmpty(globalSettings.HttpUserAgent))
            {
                client.DefaultRequestHeaders.Add("User-Agent", globalSettings.HttpUserAgent);
            }

            if (!string.IsNullOrEmpty(globalSettings.VersionTag))
            {
                client.DefaultRequestHeaders.Add("X-ClientService-ClientTag", globalSettings.VersionTag);
            }

            Client = client;
        }
Пример #4
0
        public RetryHandlerBase(ILogger <RetryHandlerBase> log, PnPGlobalSettingsOptions globalSettings)
        {
            GlobalSettings = globalSettings;

            if (GlobalSettings != null && GlobalSettings.Logger == null)
            {
                GlobalSettings.Logger = log;
            }
        }
Пример #5
0
        internal TelemetryManager(PnPGlobalSettingsOptions globalOptions)
        {
            TelemetryConfiguration = TelemetryConfiguration.CreateDefault();
            TelemetryConfiguration.InstrumentationKey = InstrumentationKey;
            TelemetryClient = new TelemetryClient(TelemetryConfiguration);
            GlobalOptions   = globalOptions;

            Assembly coreAssembly = Assembly.GetExecutingAssembly();

            Version = ((AssemblyFileVersionAttribute)coreAssembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version;
        }
Пример #6
0
        internal TelemetryManager(PnPGlobalSettingsOptions globalOptions)
        {
            // Ensure there's only one telemetry client and configuration created in the current process
            // Otherwise we're running into possible memory leaks: https://briancaos.wordpress.com/2020/05/07/c-azure-telemetryclient-will-leak-memory-if-not-implemented-as-a-singleton/
            (TelemetryConfiguration, TelemetryClient) = TelemetryClientFactory.GetTelemetryClientAndConfiguration(InstrumentationKey);

            GlobalOptions = globalOptions;

            Assembly coreAssembly = Assembly.GetExecutingAssembly();

            Version = ((AssemblyFileVersionAttribute)coreAssembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version;
        }
Пример #7
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="client">Http Client coming from the .Net http client factory</param>
        /// <param name="log">Logger service</param>
        /// <param name="options">Options service</param>
        public SharePointRestClient(HttpClient client, ILogger <SharePointRestClient> log, IOptions <PnPGlobalSettingsOptions> options)
        {
            logger         = log;
            globalSettings = options?.Value;

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (globalSettings == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (globalSettings.Logger == null)
            {
                globalSettings.Logger = logger;
            }

            client.DefaultRequestHeaders.Add("Accept", "application/json;odata=nometadata");
#if NET5_0_OR_GREATER
            client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");
#else
            client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");
#endif

            client.Timeout = globalSettings.GetHttpTimeout();

            if (!string.IsNullOrEmpty(globalSettings.HttpUserAgent))
            {
                client.DefaultRequestHeaders.Add("User-Agent", globalSettings.HttpUserAgent);
            }

            if (!string.IsNullOrEmpty(globalSettings.VersionTag))
            {
                client.DefaultRequestHeaders.Add("X-ClientService-ClientTag", globalSettings.VersionTag);
            }

            Client = client;
        }
Пример #8
0
        internal PnPContext(ILogger logger,
                            IAuthenticationProvider authenticationProvider,
                            SharePointRestClient sharePointRestClient,
                            MicrosoftGraphClient microsoftGraphClient,
                            PnPContextFactoryOptions contextOptions,
                            PnPGlobalSettingsOptions globalOptions,
                            TelemetryManager telemetryManager)
        {
            Id     = Guid.NewGuid();
            Logger = logger;

#if DEBUG
            Mode = TestMode.Default;
#endif
            AuthenticationProvider = authenticationProvider;
            RestClient             = sharePointRestClient;
            GraphClient            = microsoftGraphClient;
            GlobalOptions          = globalOptions;
            ContextOptions         = contextOptions;
            telemetry = telemetryManager;

            if (ContextOptions != null)
            {
                GraphFirst         = ContextOptions.GraphFirst;
                GraphAlwaysUseBeta = ContextOptions.GraphAlwaysUseBeta;
                GraphCanUseBeta    = ContextOptions.GraphCanUseBeta;
            }

            if (globalOptions != null && globalOptions.Environment.HasValue)
            {
                Environment = globalOptions.Environment.Value;
                // Ensure the Microsoft Graph URL is set depending on the used cloud environment
                GraphClient.UpdateBaseAddress(CloudManager.GetMicrosoftGraphAuthority(Environment.Value));
            }

            BatchClient = new BatchClient(this, GlobalOptions, telemetryManager);
        }
Пример #9
0
 public RetryHandlerBase(PnPGlobalSettingsOptions globalSettings)
 {
     GlobalSettings = globalSettings;
 }