Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
Library: whitespace & GraphLib bump
Browse files Browse the repository at this point in the history
  • Loading branch information
pschaeflein committed Mar 25, 2021
1 parent 63f695c commit b58d019
Show file tree
Hide file tree
Showing 17 changed files with 595 additions and 606 deletions.
8 changes: 0 additions & 8 deletions src/.editorconfig

This file was deleted.

18 changes: 9 additions & 9 deletions src/CommunityGraphClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static GraphServiceClient Create(CommunityGraphClientOptions options, IAu
/// The default implementation creates a new instance of <see cref="HttpClientHandler"/> for each HttpClient.</param>
/// <returns>A GraphServiceClient instance with the SharePoint handler configured.</returns>
public static GraphServiceClient Create(CommunityGraphClientOptions options, IHttpMessageLogger messageLogger, IAuthenticationProvider authenticationProvider, string version = "v1.0", string nationalCloud = "Global", IWebProxy proxy = null, HttpMessageHandler finalHandler = null)
{
{
LoggingMessageHandler loggingHandler = new LoggingMessageHandler(messageLogger);

var handlers = GraphClientFactory.CreateDefaultHandlers(authenticationProvider);
Expand Down Expand Up @@ -127,12 +127,12 @@ public static GraphServiceClient Create(CommunityGraphClientOptions options, ILi
ProductInfoHeaderValue defaultUserAgent = defaultDecoration.ToUserAgent();
ProductInfoHeaderValue specifiedUserAgent = default;

if (!options.UserAgentInfo.IsEmpty())
{
if (!options.UserAgentInfo.IsEmpty())
{
specifiedUserAgent = options.UserAgentInfo.ToUserAgent();
}
else
{
else
{
// if we got a user agent string, validate it
if (!string.IsNullOrEmpty(options.UserAgent))
{
Expand All @@ -148,10 +148,10 @@ public static GraphServiceClient Create(CommunityGraphClientOptions options, ILi

var httpClient = GraphClientFactory.Create(handlers, version, nationalCloud, proxy, finalHandler);

if (specifiedUserAgent !=null)
{
if (specifiedUserAgent != null)
{
httpClient.DefaultRequestHeaders.UserAgent.Add(specifiedUserAgent);
}
}

// if the provided string does not have the SharePoint throttling decoration, add the library user agent to the default.
// https://docs.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online#how-to-decorate-your-http-traffic-to-avoid-throttling
Expand All @@ -169,7 +169,7 @@ public static GraphServiceClient Create(CommunityGraphClientOptions options, ILi
}

private static void LogFactoryMethod(string authenticationProvider, bool loggingHandler)
{
{
var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
telemetryConfiguration.InstrumentationKey = "d882bd7a-a378-4117-bd7c-71fc95a44cd1";
var telemetryClient = new TelemetryClient(telemetryConfiguration);
Expand Down
26 changes: 13 additions & 13 deletions src/CommunityGraphClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ namespace Graph.Community
public class CommunityGraphClientOptions
{
/// <summary>
/// Set to true to disable telemetry
/// </summary>
/// Set to true to disable telemetry
/// </summary>
public bool DisableTelemetry { get; set; }
/// <summary>
/// The UserAgent to set on requests. Overridden by <see cref="UserAgentInfo"/>
/// </summary>
/// The UserAgent to set on requests. Overridden by <see cref="UserAgentInfo"/>
/// </summary>
public string UserAgent { get; set; }
/// <summary>
/// The UserAgentInfo for decorating SharePoint traffice. Overrides <see cref="UserAgent"/>
/// </summary>
/// The UserAgentInfo for decorating SharePoint traffice. Overrides <see cref="UserAgent"/>
/// </summary>
public SharePointThrottlingDecoration UserAgentInfo { get; set; }

public CommunityGraphClientOptions() { }
public CommunityGraphClientOptions(string companyName, string appName, string appVersion, bool isv)
{
{
this.UserAgentInfo = new SharePointThrottlingDecoration()
{
CompanyName = companyName,
Expand All @@ -38,22 +38,22 @@ public struct SharePointThrottlingDecoration
public string CompanyName { get; set; }
public string AppName { get; set; }
public string AppVersion { get; set; }
public bool ISV { get; set; }
public bool ISV { get; set; }

public bool IsEmpty()
{
{
return string.IsNullOrEmpty(CompanyName) &&
string.IsNullOrEmpty(AppName) &&
string.IsNullOrEmpty(AppName) &&
!ISV;
}
}

public ProductInfoHeaderValue ToUserAgent()
{
public ProductInfoHeaderValue ToUserAgent()
{
var isvDecoration = ISV ? "ISV" : "NONISV";
var product = $"{isvDecoration}|{CompanyName}|{AppName}";
return new ProductInfoHeaderValue(product, AppVersion);
}
}
}

}
4 changes: 2 additions & 2 deletions src/CommunityGraphConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Library
internal static readonly string VersionHeaderName = CommunityGraphConstants.Headers.CommunityLibraryVersionHeaderName;

/// The version for current assembly.
internal static string AssemblyVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(CommunityGraphConstants).Assembly.Location).ProductVersion;
internal static string AssemblyVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(CommunityGraphConstants).Assembly.Location).FileVersion;

/// The value for the SDK version header.
internal static string VersionHeaderValue = $"dotnet-{AssemblyVersion}";
Expand All @@ -28,7 +28,7 @@ public static class Headers
}

public static class TelemetryProperties
{
{
public const string ResourceUri = nameof(ResourceUri);
public const string RequestMethod = nameof(RequestMethod);
public const string ClientRequestId = nameof(ClientRequestId);
Expand Down
190 changes: 95 additions & 95 deletions src/Diagnostics/GraphCommunityEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Graph.Community.Diagnostics
{
[EventSource(Name = EventSourceName)]
internal sealed class GraphCommunityEventSource : EventSource
{
[EventSource(Name = EventSourceName)]
internal sealed class GraphCommunityEventSource : EventSource
{

/*
/*
* This is pretty generic stuff, copied from Azure.Core. Intended to support all the Azure SDKs...
*
*
Expand All @@ -29,95 +29,95 @@ internal sealed class GraphCommunityEventSource : EventSource



private const string EventSourceName = "Graph-Community";

private const int SharePointServiceHandlerPreprocessEvent = 1;
private const int SharePointServiceHandlerPostprocessEvent = 2;
private const int SharePointServiceHandlerNonsuccessEvent = 3;
private GraphCommunityEventSource()
: base(EventSourceName, EventSourceSettings.Default, GraphCommunityEventSourceListener.TraitName, GraphCommunityEventSourceListener.TraitValue)
{
}

public static GraphCommunityEventSource Singleton { get; } = new GraphCommunityEventSource();


[NonEvent]
public void SharePointServiceHandlerPreprocess(string resourceUri, GraphRequestContext context)
{
if (IsEnabled(EventLevel.Informational, EventKeywords.All))
{
SharePointServiceHandlerPreprocess(resourceUri, context.ClientRequestId);
}
}

[Event(SharePointServiceHandlerPreprocessEvent, Level = EventLevel.Informational, Message = "ResourceUri: {0} ClientRequestId: {1}")]
public void SharePointServiceHandlerPreprocess(string resourceUri, string clientRequestId)
{
WriteEvent(SharePointServiceHandlerPreprocessEvent, resourceUri, clientRequestId);
}

[NonEvent]
public void SharePointServiceHandlerPostprocess(string resourceUri, GraphRequestContext context, HttpStatusCode statusCode)
{
if (IsEnabled(EventLevel.Informational, EventKeywords.All))
{
SharePointServiceHandlerPostprocess(resourceUri, context.ClientRequestId, $"{statusCode} ({(int)statusCode}");
}
}

[Event(SharePointServiceHandlerPostprocessEvent, Level = EventLevel.Informational, Message = "ResourceUri: {0} ClientRequestId: {1} StatusCode: {2}")]
public void SharePointServiceHandlerPostprocess(string resourceUri, string clientRequestId, string statusCode)
{
WriteEvent(SharePointServiceHandlerPostprocessEvent, resourceUri, clientRequestId, statusCode);
}

[NonEvent]
public void SharePointServiceHandlerNonsuccess(string resourceUri, GraphRequestContext context, string rawResponseContent)
{
if (IsEnabled(EventLevel.Informational, EventKeywords.All))
{
SharePointServiceHandlerNonsuccess(resourceUri, context.ClientRequestId, rawResponseContent);
}
}

[Event(SharePointServiceHandlerNonsuccessEvent, Level = EventLevel.Informational, Message = "{0} returned non-success. RawResponse: {1} ClientRequestId: {2}")]
public void SharePointServiceHandlerNonsuccess(string resourceUri, string clientRequestId, string responseBody)
{
WriteEvent(SharePointServiceHandlerNonsuccessEvent, resourceUri, clientRequestId, responseBody);
}

[NonEvent]
private static string FormatException(Exception ex)
{
StringBuilder sb = new StringBuilder();
bool nest = false;
do
{
if (nest)
{
// Format how Exception.ToString() would.
sb.AppendLine()
.Append(" ---> ");
}
// Do not include StackTrace, but do include HResult (often useful for CryptographicExceptions or IOExceptions).
sb.Append(ex.GetType().FullName)
.Append(" (0x")
.Append(ex.HResult.ToString("x", CultureInfo.InvariantCulture))
.Append("): ")
.Append(ex.Message);
ex = ex.InnerException;
nest = true;
}
while (ex != null);
return sb.ToString();
}

[NonEvent]
private static string FormatStringArray(string[] array)
{
return new StringBuilder("[ ").Append(string.Join(", ", array)).Append(" ]").ToString();
}
}
private const string EventSourceName = "Graph-Community";

private const int SharePointServiceHandlerPreprocessEvent = 1;
private const int SharePointServiceHandlerPostprocessEvent = 2;
private const int SharePointServiceHandlerNonsuccessEvent = 3;

private GraphCommunityEventSource()
: base(EventSourceName, EventSourceSettings.Default, GraphCommunityEventSourceListener.TraitName, GraphCommunityEventSourceListener.TraitValue)
{
}

public static GraphCommunityEventSource Singleton { get; } = new GraphCommunityEventSource();


[NonEvent]
public void SharePointServiceHandlerPreprocess(string resourceUri, GraphRequestContext context)
{
if (IsEnabled(EventLevel.Informational, EventKeywords.All))
{
SharePointServiceHandlerPreprocess(resourceUri, context.ClientRequestId);
}
}

[Event(SharePointServiceHandlerPreprocessEvent, Level = EventLevel.Informational, Message = "ResourceUri: {0} ClientRequestId: {1}")]
public void SharePointServiceHandlerPreprocess(string resourceUri, string clientRequestId)
{
WriteEvent(SharePointServiceHandlerPreprocessEvent, resourceUri, clientRequestId);
}

[NonEvent]
public void SharePointServiceHandlerPostprocess(string resourceUri, GraphRequestContext context, HttpStatusCode statusCode)
{
if (IsEnabled(EventLevel.Informational, EventKeywords.All))
{
SharePointServiceHandlerPostprocess(resourceUri, context.ClientRequestId, $"{statusCode} ({(int)statusCode}");
}
}

[Event(SharePointServiceHandlerPostprocessEvent, Level = EventLevel.Informational, Message = "ResourceUri: {0} ClientRequestId: {1} StatusCode: {2}")]
public void SharePointServiceHandlerPostprocess(string resourceUri, string clientRequestId, string statusCode)
{
WriteEvent(SharePointServiceHandlerPostprocessEvent, resourceUri, clientRequestId, statusCode);
}

[NonEvent]
public void SharePointServiceHandlerNonsuccess(string resourceUri, GraphRequestContext context, string rawResponseContent)
{
if (IsEnabled(EventLevel.Informational, EventKeywords.All))
{
SharePointServiceHandlerNonsuccess(resourceUri, context.ClientRequestId, rawResponseContent);
}
}

[Event(SharePointServiceHandlerNonsuccessEvent, Level = EventLevel.Informational, Message = "{0} returned non-success. RawResponse: {1} ClientRequestId: {2}")]
public void SharePointServiceHandlerNonsuccess(string resourceUri, string clientRequestId, string responseBody)
{
WriteEvent(SharePointServiceHandlerNonsuccessEvent, resourceUri, clientRequestId, responseBody);
}

[NonEvent]
private static string FormatException(Exception ex)
{
StringBuilder sb = new StringBuilder();
bool nest = false;
do
{
if (nest)
{
// Format how Exception.ToString() would.
sb.AppendLine()
.Append(" ---> ");
}
// Do not include StackTrace, but do include HResult (often useful for CryptographicExceptions or IOExceptions).
sb.Append(ex.GetType().FullName)
.Append(" (0x")
.Append(ex.HResult.ToString("x", CultureInfo.InvariantCulture))
.Append("): ")
.Append(ex.Message);
ex = ex.InnerException;
nest = true;
}
while (ex != null);
return sb.ToString();
}

[NonEvent]
private static string FormatStringArray(string[] array)
{
return new StringBuilder("[ ").Append(string.Join(", ", array)).Append(" ]").ToString();
}
}
}
26 changes: 13 additions & 13 deletions src/Extensions/BaseRequestBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Graph.Community
{
public static class BaseRequestBuilderExtensions
{
/// <summary>
/// Returns the Path to use for the Resource property of Subscription object when creating a new subscription
/// </summary>
/// <param name="requestBuilder">Current request builder</param>
/// <returns>URL to use for the Resource property of Subscription object when creating a new subscription</returns>
public static string GetResourceSubscriptionPath(this IBaseRequestBuilder requestBuilder)
{
var pathAndQuery = new Uri(requestBuilder.RequestUrl).PathAndQuery;
return pathAndQuery.Substring(pathAndQuery.IndexOf('/', 1)); //skips first / to ignore the version
}
}
public static class BaseRequestBuilderExtensions
{
/// <summary>
/// Returns the Path to use for the Resource property of Subscription object when creating a new subscription
/// </summary>
/// <param name="requestBuilder">Current request builder</param>
/// <returns>URL to use for the Resource property of Subscription object when creating a new subscription</returns>
public static string GetResourceSubscriptionPath(this IBaseRequestBuilder requestBuilder)
{
var pathAndQuery = new Uri(requestBuilder.RequestUrl).PathAndQuery;
return pathAndQuery.Substring(pathAndQuery.IndexOf('/', 1)); //skips first / to ignore the version
}
}
}
24 changes: 12 additions & 12 deletions src/Extensions/BaseRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

namespace Graph.Community
{
public static class BaseRequestExtensions
{
public static T WithImmutableId<T>(this T baseRequest) where T : IBaseRequest
{
baseRequest.Headers.Add(
new HeaderOption(
RequestExtensionsConstants.Headers.PreferHeaderName,
RequestExtensionsConstants.Headers.PreferHeaderImmutableIdValue)
);
return baseRequest;
}
}
public static class BaseRequestExtensions
{
public static T WithImmutableId<T>(this T baseRequest) where T : IBaseRequest
{
baseRequest.Headers.Add(
new HeaderOption(
RequestExtensionsConstants.Headers.PreferHeaderName,
RequestExtensionsConstants.Headers.PreferHeaderImmutableIdValue)
);
return baseRequest;
}
}
}
Loading

0 comments on commit b58d019

Please sign in to comment.