Skip to content

Commit

Permalink
code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Jul 31, 2023
1 parent e266e64 commit 18226fa
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal static List<FileIndexItem> WhichFilesNeedToBePushedForUpdates(List<Gene
{
var result = new List<FileIndexItem>();
var searchFor = getAllFilesAsync.Where(item =>
thumbs.FirstOrDefault(p => p.SubPath == item.FilePath && item.Tags != null)
thumbs.Find(p => p.SubPath == item.FilePath && item.Tags != null)
?.Success == true).DistinctBy(p => p.FilePath);
foreach ( var item in searchFor )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using starsky.foundation.database.Models;
using starsky.foundation.platform.Helpers;
Expand All @@ -24,6 +25,9 @@ public ToBase64DataUriList(IStorage iStorage, IStorage thumbnailStorage, IWebLog
_appSettings = appSettings;
}

[SuppressMessage("Usage", "S3966: Resource 'memoryStream' has " +
"already been disposed explicitly or through a using statement implicitly. " +
"Remove the redundant disposal.")]
public async Task<string[]> Create(List<FileIndexItem> fileIndexList)
{
var base64ImageArray = new string[fileIndexList.Count];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public DateTime ParseDateTimeFromFileName()

// Replace asterisk > escape all options
var structuredFileName = Structure.Split("/".ToCharArray()).LastOrDefault();
if ( structuredFileName == null || string.IsNullOrEmpty(fileName) ) return new DateTime();
if ( structuredFileName == null || string.IsNullOrEmpty(fileName) ) {
return new DateTime(0, DateTimeKind.Utc);
}
structuredFileName = structuredFileName.Replace("*", "");
structuredFileName = structuredFileName.Replace(".ext", string.Empty);
structuredFileName = structuredFileName.Replace("{filenamebase}", string.Empty);
Expand Down
4 changes: 3 additions & 1 deletion starsky/starsky.foundation.platform/Helpers/DateAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ internal static DateTime ParseBuildTime(string value)
}
value = value.Substring(index + buildVersionMetadataPrefix.Length);
return DateTime.TryParseExact(value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture,
DateTimeStyles.AssumeUniversal, out var result) ? result : new DateTime();
DateTimeStyles.AssumeUniversal, out var result) ?
result :
new DateTime(0, DateTimeKind.Utc);
}
}
}
33 changes: 22 additions & 11 deletions starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -23,6 +24,9 @@
[assembly: InternalsVisibleTo("starskytest")]
namespace starsky.foundation.readmeta.ReadMetaHelpers
{
[SuppressMessage("Usage", "S3966: Resource '_iStorage.ReadStream' has " +
"already been disposed explicitly or through a using statement implicitly. " +
"Remove the redundant disposal.")]
public sealed class ReadMetaExif
{
private readonly IStorage _iStorage;
Expand Down Expand Up @@ -346,7 +350,8 @@ private static string GetMakeModel(List<Directory> allExifItems, bool isMake)
}

var quickTimeMetaDataDirectory = allExifItems.OfType<QuickTimeMetadataHeaderDirectory>().FirstOrDefault();
var tagMakeModelQuickTime = isMake ? QuickTimeMetadataHeaderDirectory.TagMake : QuickTimeMetadataHeaderDirectory.TagModel;
var tagMakeModelQuickTime = isMake ?
QuickTimeMetadataHeaderDirectory.TagMake : QuickTimeMetadataHeaderDirectory.TagModel;

var captionQuickTime = quickTimeMetaDataDirectory?.GetDescription(tagMakeModelQuickTime);
return !string.IsNullOrEmpty(captionQuickTime) ? captionQuickTime : string.Empty;
Expand Down Expand Up @@ -418,7 +423,8 @@ private static string GetXmpData(Directory exifItem, string propertyPath)
if ( exifItem is not XmpDirectory xmpDirectory || xmpDirectory.XmpMeta == null )
return string.Empty;

return ( from property in xmpDirectory.XmpMeta.Properties.Where(p => !string.IsNullOrEmpty(p.Value))
return ( from property in xmpDirectory.XmpMeta.
Properties.Where(p => !string.IsNullOrEmpty(p.Value))
where property.Path == propertyPath select property.Value ).FirstOrDefault();
}

Expand Down Expand Up @@ -541,8 +547,8 @@ internal static DateTime ParseSubIfdDateTime(IEnumerable<Directory> allExifItems
var exifSubIfdList = allExifItems.OfType<ExifSubIfdDirectory>().ToList();
foreach ( var exifSubIfd in exifSubIfdList )
{
// https://odedcoster.com/blog/2011/12/13/date-and-time-format-strings-in-net-understanding-format-strings/
// 2018:01:01 11:29:36
// https://odedcoster.com/blog/2011/12/13/date-and-time-format-strings-in-net-understanding-format-strings/
// 2018:01:01 11:29:36
var tagDateTimeDigitized = exifSubIfd.GetDescription(ExifDirectoryBase.TagDateTimeDigitized);
DateTime.TryParseExact(tagDateTimeDigitized,
pattern, provider, DateTimeStyles.AdjustToUniversal, out var itemDateTimeDigitized);
Expand All @@ -560,15 +566,15 @@ internal static DateTime ParseSubIfdDateTime(IEnumerable<Directory> allExifItems
}
}

return new DateTime();
return new DateTime(0, DateTimeKind.Utc);
}

internal DateTime ParseQuickTimeDateTime(CameraMakeModel cameraMakeModel,
IEnumerable<Directory> allExifItems, IFormatProvider provider)
{
if ( _appSettings == null ) Console.WriteLine("[ParseQuickTimeDateTime] app settings is null");
if ( cameraMakeModel == null ) cameraMakeModel = new CameraMakeModel();
var useUseLocalTime = _appSettings?.VideoUseLocalTime?.Any(p =>
var useUseLocalTime = _appSettings?.VideoUseLocalTime?.Exists(p =>
string.Equals(p.Make, cameraMakeModel.Make, StringComparison.InvariantCultureIgnoreCase) && (
string.Equals(p.Model, cameraMakeModel.Model, StringComparison.InvariantCultureIgnoreCase) ||
string.IsNullOrEmpty(p.Model) ));
Expand Down Expand Up @@ -793,7 +799,8 @@ private static double GetGeoLocationLongitude(List<Directory> allExifItems)

if (!string.IsNullOrWhiteSpace(longitudeString))
{
var longitude = GeoParser.ConvertDegreeMinutesSecondsToDouble(longitudeString, longitudeRef);
var longitude = GeoParser.
ConvertDegreeMinutesSecondsToDouble(longitudeString, longitudeRef);
longitude = Math.Floor(longitude * 10000000000) / 10000000000;
return longitude;
}
Expand Down Expand Up @@ -914,7 +921,8 @@ private static double GetFocalLength(Directory exifItem)
focalLengthString = focalLengthString.Replace(" mm", string.Empty);

// Note: focalLengthString: (Dutch) 2,2 or (English) 2.2 based CultureInfo.CurrentCulture
float.TryParse(focalLengthString, NumberStyles.Number, CultureInfo.CurrentCulture, out var focalLength);
float.TryParse(focalLengthString, NumberStyles.Number,
CultureInfo.CurrentCulture, out var focalLength);

return Math.Round(focalLength, 5);
}
Expand Down Expand Up @@ -965,7 +973,8 @@ private static string GetShutterSpeedValue(Directory exifItem)

// XMP,http://ns.adobe.com/exif/1.0/,exif:ExposureTime,1/20
var exposureTimeXmp = GetXmpData(exifItem, "exif:ExposureTime");
if (string.IsNullOrEmpty(shutterSpeedString) && !string.IsNullOrEmpty(exposureTimeXmp) && exposureTimeXmp.Length <= 20)
if (string.IsNullOrEmpty(shutterSpeedString) &&
!string.IsNullOrEmpty(exposureTimeXmp) && exposureTimeXmp.Length <= 20)
{
return exposureTimeXmp;
}
Expand Down Expand Up @@ -998,8 +1007,10 @@ private static int GetIsoSpeedValue(Directory exifItem)
p.DirectoryName == "Canon Makernote" && p.Name == "Base ISO")?.Description;
if ( !string.IsNullOrEmpty(autoIso) && !string.IsNullOrEmpty(baseIso) )
{
int.TryParse(autoIso, NumberStyles.Number, CultureInfo.InvariantCulture, out var autoIsoSpeed);
int.TryParse(baseIso, NumberStyles.Number, CultureInfo.InvariantCulture, out var baseIsoSpeed);
int.TryParse(autoIso, NumberStyles.Number,
CultureInfo.InvariantCulture, out var autoIsoSpeed);
int.TryParse(baseIso, NumberStyles.Number,
CultureInfo.InvariantCulture, out var baseIsoSpeed);

Check warning on line 1013 in starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs

View check run for this annotation

Codecov / codecov/patch

starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs#L1010-L1013

Added lines #L1010 - L1013 were not covered by tests
return baseIsoSpeed * autoIsoSpeed / 100;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -312,6 +313,9 @@ bool LocalRun()
return RetryHelper.Do(LocalRun, TimeSpan.FromSeconds(2),5);
}

[SuppressMessage("Usage", "S3966: Resource '_iStorage.ReadStream' has " +
"already been disposed explicitly or through a using statement implicitly. " +
"Remove the redundant disposal.")]
public bool WriteStream(Stream stream, string path)
{
if ( !stream.CanRead ) return false;
Expand Down
2 changes: 1 addition & 1 deletion starsky/starsky.foundation.sync/Helpers/SyncCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task Sync(string[] args)
var stopWatch = Stopwatch.StartNew();
_console.WriteLine($"Start indexing {subPath}");
var result = await _synchronize.Sync(subPath);
if ( result.All(p => p.FilePath != subPath) )
if ( result.TrueForAll(p => p.FilePath != subPath) )
{
_console.WriteLine($"Not Found: {subPath}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal async Task<List<FileIndexItem>> SingleFile(string subPath,
var dbItems = await _query.GetObjectsByFilePathAsync(subPath,true);
foreach ( var item in statusItems )
{
var dbItem = dbItems.FirstOrDefault(p => item.FilePath == p.FilePath);
var dbItem = dbItems.Find(p => item.FilePath == p.FilePath);
if ( dbItem != null )
{
scanItems.Add(dbItem);
Expand Down

0 comments on commit 18226fa

Please sign in to comment.