Skip to content

Commit

Permalink
refactor: null checkers rework (#101)
Browse files Browse the repository at this point in the history
Co-authored-by: Petr Švihlík <rocky.intel@gmail.com>
  • Loading branch information
FrediKats and petrsvihlik authored Oct 24, 2020
1 parent 96c41b1 commit 7878304
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions WopiHost.Core/Controllers/FilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public class FilesController : WopiControllerBase

private HostCapabilities HostCapabilities => new HostCapabilities
{
SupportsCobalt = CobaltProcessor != null,
SupportsCobalt = CobaltProcessor is { },
SupportsGetLock = true,
SupportsLocks = true,
SupportsExtendedLockLength = true,
SupportsFolders = true,//?
SupportsCoauth = true,//?
SupportsUpdate = nameof(PutFile) != null //&& PutRelativeFile - usercannotwriterelative
SupportsUpdate = nameof(PutFile) is { } //&& PutRelativeFile - usercannotwriterelative
};

/// <summary>
Expand Down Expand Up @@ -87,7 +87,7 @@ public async Task<IActionResult> GetFile(string id)

// Check expected size
var maximumExpectedSize = HttpContext.Request.Headers[WopiHeaders.MAX_EXPECTED_SIZE].ToString().ToNullableInt();
if (maximumExpectedSize != null && file.GetCheckFileInfo(User, HostCapabilities).Size > maximumExpectedSize.Value)
if (maximumExpectedSize is { } && file.GetCheckFileInfo(User, HostCapabilities).Size > maximumExpectedSize.Value)
{
return new PreconditionFailedResult();
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task<IActionResult> ProcessCobalt(string id)

// TODO: remove workaround https://github.com/aspnet/Announcements/issues/342 (use FileBufferingWriteStream)
var syncIoFeature = HttpContext.Features.Get<IHttpBodyControlFeature>();
if (syncIoFeature != null)
if (syncIoFeature is { })
{
syncIoFeature.AllowSynchronousIO = true;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ public IActionResult ProcessLock(string id)

case "LOCK":
case "PUT":
if (oldLock == null)
if (oldLock is null)
{
// Lock / put
if (lockAcquired)
Expand Down
2 changes: 1 addition & 1 deletion WopiHost.Core/Controllers/WopiControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected WopiControllerBase(IWopiStorageProvider storageProvider, IWopiSecurity

protected string GetWopiUrl(string controller, string identifier = null, string accessToken = null)
{
identifier = identifier == null ? "" : "/" + Uri.EscapeDataString(identifier);
identifier = identifier is null ? "" : "/" + Uri.EscapeDataString(identifier);
accessToken = Uri.EscapeDataString(accessToken);
return $"{BaseUrl}/wopi/{controller}{identifier}?access_token={accessToken}";
}
Expand Down
2 changes: 1 addition & 1 deletion WopiHost.Core/FileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static CheckFileInfo GetCheckFileInfo(this IWopiFile file, ClaimsPrincipa
}

var checkFileInfo = new CheckFileInfo();
if (principal != null)
if (principal is { })
{
checkFileInfo.UserId = principal.FindFirst(ClaimTypes.NameIdentifier)?.Value.ToSafeIdentity();
checkFileInfo.UserFriendlyName = principal.FindFirst(ClaimTypes.Name)?.Value;
Expand Down
2 changes: 1 addition & 1 deletion WopiHost.Core/HttpHeaderAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public HttpHeaderAttribute(string header, params string[] values)

public bool Accept(ActionConstraintContext context)
{
return context != null && (context.RouteContext.HttpContext.Request.Headers.TryGetValue(Header, out var value) && Values.Contains(value[0]));
return (context is null) && (context.RouteContext.HttpContext.Request.Headers.TryGetValue(Header, out var value) && Values.Contains(value[0]));
}

public int Order => 0;
Expand Down
4 changes: 2 additions & 2 deletions WopiHost.Core/Results/FileResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public override async Task ExecuteResultAsync(ActionContext context)
var response = context.HttpContext.Response;
response.ContentType = ContentType;
var targetStream = response.Body;
if (CopyStream != null)
if (CopyStream is { })
{
await Task.Factory.StartNew(() =>
{
CopyStream(targetStream);
});
}
else if (Content != null)
else if (Content is { })
{
await targetStream.WriteAsync(Content, 0, Content.Length);
}
Expand Down
2 changes: 1 addition & 1 deletion WopiHost.Discovery/HttpDiscoveryFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public HttpDiscoveryFileProvider(HttpClient httpClient)
/// <inheritdoc />
public async Task<XElement> GetDiscoveryXmlAsync()
{
if (_discoveryXml == null)
if (_discoveryXml is null)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions WopiHost.Discovery/WopiDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task<bool> SupportsExtensionAsync(string extension)
{
var query = (await GetAppsAsync()).Elements()
.FirstOrDefault(e => (string)e.Attribute(AttrActionExtension) == extension);
return query != null;
return query is { };
}

///<inheritdoc />
Expand All @@ -92,7 +92,7 @@ public async Task<IEnumerable<string>> GetActionRequirementsAsync(string extensi
public async Task<bool> RequiresCobaltAsync(string extension, WopiActionEnum action)
{
var requirements = await GetActionRequirementsAsync(extension, action);
return requirements != null && requirements.Contains(AttrValCobalt);
return requirements is { } && requirements.Contains(AttrValCobalt);
}

///<inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion WopiHost.FileSystemProvider/WopiSecurityHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private SymmetricSecurityKey Key
{
get
{
if (_key == null)
if (_key is null)
{
//RandomNumberGenerator rng = RandomNumberGenerator.Create();
//byte[] key = new byte[128];
Expand Down
4 changes: 2 additions & 2 deletions WopiHost.Url/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public static class CollectionExtensions
/// <returns></returns>
public static IDictionary<TKey, TValue> Merge<TKey, TValue>(this IDictionary<TKey, TValue> dictA, IDictionary<TKey, TValue> dictB) where TValue : class
{
if (dictA == null)
if (dictA is null)
{
return dictB;
}
if (dictB == null)
if (dictB is null)
{
return dictA;
}
Expand Down
2 changes: 1 addition & 1 deletion WopiHost.Url/WopiUrlSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public WopiUrlSettings()

public WopiUrlSettings(IDictionary<string, string> settings)
{
if (settings != null)
if (settings is { })
{
foreach (var pair in settings)
{
Expand Down

0 comments on commit 7878304

Please sign in to comment.