diff --git a/starsky/starsky.feature.health/HealthCheck/DiskStorageHealthCheck.cs b/starsky/starsky.feature.health/HealthCheck/DiskStorageHealthCheck.cs index 7826d8bb8d..bb2dba5e4b 100644 --- a/starsky/starsky.feature.health/HealthCheck/DiskStorageHealthCheck.cs +++ b/starsky/starsky.feature.health/HealthCheck/DiskStorageHealthCheck.cs @@ -59,8 +59,9 @@ private static (bool Exists, long ActualFreeMegabytes) GetSystemDriveInfo(string return ( false, 0L ); } - var driveInfo = drivesList.FirstOrDefault( - drive => string.Equals(drive.Name, driveName, StringComparison.InvariantCultureIgnoreCase)); + var driveInfo = Array.Find(drivesList, + drive => string.Equals(drive.Name, driveName, + StringComparison.InvariantCultureIgnoreCase)); return driveInfo?.AvailableFreeSpace != null ? (true, driveInfo.AvailableFreeSpace / 1024L / 1024L) : (false, 0L); } } diff --git a/starsky/starsky.feature.health/HealthCheck/PathExistHealthCheck.cs b/starsky/starsky.feature.health/HealthCheck/PathExistHealthCheck.cs index 704ef39231..7ee4d4d437 100644 --- a/starsky/starsky.feature.health/HealthCheck/PathExistHealthCheck.cs +++ b/starsky/starsky.feature.health/HealthCheck/PathExistHealthCheck.cs @@ -33,7 +33,7 @@ public Task CheckHealthAsync( $"Not configured")); return Task.FromResult( - resultsList.Any(p => p == FolderOrFileModel.FolderOrFileTypeList.Deleted) ? + resultsList.Exists(p => p == FolderOrFileModel.FolderOrFileTypeList.Deleted) ? new HealthCheckResult(context.Registration.FailureStatus, $"Configured path is not present on system") : HealthCheckResult.Healthy("Configured path is present")); } diff --git a/starsky/starsky.feature.health/UpdateCheck/Models/ReleaseModel.cs b/starsky/starsky.feature.health/UpdateCheck/Models/ReleaseModel.cs index f98d219707..2f3655cd86 100644 --- a/starsky/starsky.feature.health/UpdateCheck/Models/ReleaseModel.cs +++ b/starsky/starsky.feature.health/UpdateCheck/Models/ReleaseModel.cs @@ -29,7 +29,7 @@ public string TagName { set { if ( string.IsNullOrWhiteSpace(value)) return; - if ( !value.StartsWith("v") ) Console.WriteLine($"{_tagName} Should start with v"); + if ( !value.StartsWith('v') ) Console.WriteLine($"{_tagName} Should start with v"); _tagName = value; } } diff --git a/starsky/starsky.feature.health/UpdateCheck/Services/CheckForUpdates.cs b/starsky/starsky.feature.health/UpdateCheck/Services/CheckForUpdates.cs index cfc7ef561e..7b0e6d06b8 100644 --- a/starsky/starsky.feature.health/UpdateCheck/Services/CheckForUpdates.cs +++ b/starsky/starsky.feature.health/UpdateCheck/Services/CheckForUpdates.cs @@ -72,8 +72,11 @@ internal static KeyValuePair Parse(IEnumerable p.TagName); var tagName = orderedReleaseModelList.FirstOrDefault(p => !p.Draft && !p.PreRelease)?.TagName; - if ( string.IsNullOrWhiteSpace(tagName) || !tagName.StartsWith("v") ) + if ( string.IsNullOrWhiteSpace(tagName) || + !tagName.StartsWith('v') ) + { return new KeyValuePair(UpdateStatus.NoReleasesFound,string.Empty); + } try { diff --git a/starsky/starsky.feature.import/Services/Import.cs b/starsky/starsky.feature.import/Services/Import.cs index 0c0c68bce9..8404fc1282 100644 --- a/starsky/starsky.feature.import/Services/Import.cs +++ b/starsky/starsky.feature.import/Services/Import.cs @@ -142,7 +142,7 @@ public async Task> Preflight(List fullFilePathsLis var parentFolder = Directory.GetParent(itemSourceFullFilePath) ?.FullName; - if ( parentFolders.All(p => p.Item1 != parentFolder) ) + if ( parentFolders.TrueForAll(p => p.Item1 != parentFolder) ) { parentFolders.Add(new Tuple>(parentFolder, new List{itemSourceFullFilePath})); continue; @@ -157,10 +157,16 @@ public async Task> Preflight(List fullFilePathsLis var fileStorageInfo = _filesystemStorage.Info(parentFolder.Item1!); if ( fileStorageInfo.IsFolderOrFile != FolderOrFileModel.FolderOrFileTypeList.Folder || - fileStorageInfo.IsFileSystemReadOnly != true ) continue; + fileStorageInfo.IsFileSystemReadOnly != true ) + { + continue; + } + + var items = parentFolder.Item2.Select(parentItem => + Array.Find(importIndexItemsList.ToArray(), + p => p.SourceFullFilePath == parentItem)).Cast(); - foreach ( var item in parentFolder.Item2.Select(parentItem => importIndexItemsList.FirstOrDefault(p => - p.SourceFullFilePath == parentItem)).Where(item => item != null).Cast() ) + foreach ( var item in items ) { importIndexItemsList[importIndexItemsList.IndexOf(item)] .Status = ImportStatus.ReadOnlyFileSystem; @@ -229,7 +235,7 @@ internal List CheckForDuplicateNaming(List imp var currentDirectoryContent = directoriesContent[importIndexItem.FileIndexItem.ParentDirectory!]; - if ( currentDirectoryContent.Any(p => p == updatedFilePath) ) + if ( currentDirectoryContent.Contains(updatedFilePath) ) { indexer++; continue; @@ -291,7 +297,7 @@ private List> AppendDirectoryFilePaths(List fu internal async Task PreflightPerFile(KeyValuePair inputFileFullPath, ImportSettingsModel importSettings) { - if ( _appSettings.ImportIgnore.Any(p => inputFileFullPath.Key.Contains(p)) ) + if ( _appSettings.ImportIgnore.Exists(p => inputFileFullPath.Key.Contains(p)) ) { ConsoleIfVerbose($"❌ skip due rules: {inputFileFullPath.Key} "); return new ImportIndexItem{ diff --git a/starsky/starsky.feature.metaupdate/Helpers/AddNotFoundInIndexStatus.cs b/starsky/starsky.feature.metaupdate/Helpers/AddNotFoundInIndexStatus.cs index b65dba2c28..65124442d0 100644 --- a/starsky/starsky.feature.metaupdate/Helpers/AddNotFoundInIndexStatus.cs +++ b/starsky/starsky.feature.metaupdate/Helpers/AddNotFoundInIndexStatus.cs @@ -13,7 +13,7 @@ internal static void Update(IEnumerable inputFilePaths, List p.FilePath == subPath) ) + if ( fileIndexResultsList.Exists(p => p.FilePath == subPath) ) { continue; } diff --git a/starsky/starsky.feature.metaupdate/Services/MetaReplaceService.cs b/starsky/starsky.feature.metaupdate/Services/MetaReplaceService.cs index 89575d65a9..2fd6041d57 100644 --- a/starsky/starsky.feature.metaupdate/Services/MetaReplaceService.cs +++ b/starsky/starsky.feature.metaupdate/Services/MetaReplaceService.cs @@ -135,8 +135,10 @@ public static List SearchAndReplace(List fileIndex var propertiesA = new FileIndexItem().GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance); - var property = propertiesA.FirstOrDefault(p => string.Equals( - p.Name, fieldName, StringComparison.InvariantCultureIgnoreCase)); + + var property = Array.Find(propertiesA, p => string.Equals( + p.Name, fieldName, + StringComparison.InvariantCultureIgnoreCase)); if ( property?.PropertyType == typeof(string)) { diff --git a/starsky/starsky.feature.packagetelemetry/Services/PackageTelemetry.cs b/starsky/starsky.feature.packagetelemetry/Services/PackageTelemetry.cs index 113a7b7179..e4675c7a0a 100644 --- a/starsky/starsky.feature.packagetelemetry/Services/PackageTelemetry.cs +++ b/starsky/starsky.feature.packagetelemetry/Services/PackageTelemetry.cs @@ -127,7 +127,7 @@ internal List> AddAppSettingsData( List x is PackageTelemetryAttribute); + var someAttribute = Array.Find(Attribute.GetCustomAttributes(property), x => x is PackageTelemetryAttribute); if ( someAttribute == null ) { continue; diff --git a/starsky/starsky.feature.search/ViewModels/SearchViewModel.cs b/starsky/starsky.feature.search/ViewModels/SearchViewModel.cs index c339b38871..1cda83a4dd 100644 --- a/starsky/starsky.feature.search/ViewModels/SearchViewModel.cs +++ b/starsky/starsky.feature.search/ViewModels/SearchViewModel.cs @@ -503,9 +503,14 @@ public static SearchViewModel NarrowSearch(SearchViewModel model) for ( var i = 0; i < model.SearchIn.Count; i++ ) { - var propertyStringName = FileIndexItem.FileIndexPropList().FirstOrDefault(p => - string.Equals(p, model.SearchIn[i], StringComparison.InvariantCultureIgnoreCase)); - if ( string.IsNullOrEmpty(propertyStringName) ) continue; + var propertyStringName = FileIndexItem.FileIndexPropList().Find( p => + string.Equals(p, model.SearchIn[i], + StringComparison.InvariantCultureIgnoreCase)); + + if ( string.IsNullOrEmpty(propertyStringName) ) + { + continue; + } var property = new FileIndexItem().GetType().GetProperty(propertyStringName)!; @@ -518,7 +523,7 @@ public static SearchViewModel NarrowSearch(SearchViewModel model) } // hide xmp files in default view - if ( model.SearchIn.All(p => !string.Equals(p, nameof(SearchInTypes.imageformat), + if ( model.SearchIn.TrueForAll(p => !string.Equals(p, nameof(SearchInTypes.imageformat), StringComparison.InvariantCultureIgnoreCase))) { model.FileIndexItems = model.FileIndexItems! diff --git a/starsky/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationService.cs b/starsky/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationService.cs index 4855fcffb5..32a52bd3ed 100644 --- a/starsky/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationService.cs +++ b/starsky/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationService.cs @@ -81,7 +81,7 @@ internal async Task> WorkThumbnailGeneration( foreach ( var item in chuckedItems ) { - var fileIndexItem = fileIndexItems.FirstOrDefault(p => p.FileHash == item.FileHash); + var fileIndexItem = fileIndexItems.Find(p => p.FileHash == item.FileHash); if ( fileIndexItem?.FilePath == null || fileIndexItem.Status != FileIndexItem.ExifStatus.Ok ) { diff --git a/starsky/starsky.feature.webhtmlpublish/Services/WebHtmlPublishService.cs b/starsky/starsky.feature.webhtmlpublish/Services/WebHtmlPublishService.cs index ecb486b9be..a6c431c36a 100644 --- a/starsky/starsky.feature.webhtmlpublish/Services/WebHtmlPublishService.cs +++ b/starsky/starsky.feature.webhtmlpublish/Services/WebHtmlPublishService.cs @@ -97,7 +97,7 @@ internal List AddFileHashIfNotExist(List fileIndex internal bool ShouldSkipExtraLarge(string publishProfileName) { var skipExtraLarge = _publishPreflight?.GetPublishProfileName(publishProfileName)? - .All(p => p.SourceMaxWidth <= 1999); + .TrueForAll(p => p.SourceMaxWidth <= 1999); return skipExtraLarge == true; } @@ -156,9 +156,10 @@ private async Task> Render(List fileIndex // Order alphabetically // Ignore Items with Errors - fileIndexItemsList = fileIndexItemsList.OrderBy(p => p.FileName) + fileIndexItemsList = fileIndexItemsList .Where(p=> p.Status == FileIndexItem.ExifStatus.Ok || - p.Status == FileIndexItem.ExifStatus.ReadOnly).ToList(); + p.Status == FileIndexItem.ExifStatus.ReadOnly) + .OrderBy(p => p.FileName).ToList(); var copyResult = new Dictionary(); diff --git a/starsky/starsky.foundation.accountmanagement/Services/UserManager.cs b/starsky/starsky.foundation.accountmanagement/Services/UserManager.cs index 70be87ba48..24d2bc746d 100644 --- a/starsky/starsky.foundation.accountmanagement/Services/UserManager.cs +++ b/starsky/starsky.foundation.accountmanagement/Services/UserManager.cs @@ -164,7 +164,7 @@ internal async Task AddUserToCache(User user) if ( !IsCacheEnabled() ) return; var allUsers = (await AllUsersAsync()).Users; var index = allUsers.Find(p => p.Id == user.Id); - if ( allUsers.Any(p => p.Id == user.Id) && index != null ) + if ( allUsers.Exists(p => p.Id == user.Id) && index != null ) { var indexOf = allUsers.IndexOf(index); allUsers[indexOf] = user; @@ -211,7 +211,7 @@ private async Task RemoveUserFromCacheAsync(User user) } var users = (await AllUsersAsync()).Users; - return users.FirstOrDefault(p => p.Id == userTableId); + return users.Find(p => p.Id == userTableId); } /// @@ -284,7 +284,7 @@ public async Task SignUpAsync(string name, } // Add a user role based on a user id - var roleToAdd = roles.FirstOrDefault(p => p.Code == GetRoleAddToUser(identifier,user)); + var roleToAdd = roles.Find(p => p.Code == GetRoleAddToUser(identifier,user)); AddToRole(user, roleToAdd); if (credentialType == null) @@ -555,7 +555,7 @@ public async Task ValidateAsync(string credentialTypeCode, return new ValidateResult(success: false, error: ValidateResultError.SecretNotValid); } - var userData = (await AllUsersAsync()).Users.FirstOrDefault(p => p.Id == credential.UserId); + var userData = (await AllUsersAsync()).Users.Find(p => p.Id == credential.UserId); if ( userData == null ) { return new ValidateResult(success: false, error: ValidateResultError.UserNotFound); diff --git a/starsky/starsky.foundation.database/Helpers/FileIndexCompareHelper.cs b/starsky/starsky.foundation.database/Helpers/FileIndexCompareHelper.cs index dc66dac5ca..c5e53f5554 100644 --- a/starsky/starsky.foundation.database/Helpers/FileIndexCompareHelper.cs +++ b/starsky/starsky.foundation.database/Helpers/FileIndexCompareHelper.cs @@ -102,13 +102,13 @@ public static List Compare(FileIndexItem sourceIndexItem, FileIndexItem? } // Last Edited is not needed - if ( differenceList.Any(p => p == nameof(FileIndexItem.LastEdited).ToLowerInvariant()) ) + if ( differenceList.Exists(p => p == nameof(FileIndexItem.LastEdited).ToLowerInvariant()) ) { differenceList.Remove(nameof(FileIndexItem.LastEdited).ToLowerInvariant()); } // Last Changed is a generated list - if ( differenceList.Any(p => p == nameof(FileIndexItem.LastChanged).ToLowerInvariant()) ) + if ( differenceList.Exists(p => p == nameof(FileIndexItem.LastChanged).ToLowerInvariant()) ) { differenceList.Remove(nameof(FileIndexItem.LastChanged).ToLowerInvariant()); } @@ -134,7 +134,7 @@ public static FileIndexItem Set(FileIndexItem? sourceIndexItem, string fieldName PropertyInfo[] propertiesA = new FileIndexItem().GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance); - var property = propertiesA.FirstOrDefault(p => + var property = Array.Find(propertiesA,p => string.Equals(p.Name, fieldName, StringComparison.InvariantCultureIgnoreCase)); var fieldType = fieldContent.GetType(); @@ -158,7 +158,7 @@ public static FileIndexItem Set(FileIndexItem? sourceIndexItem, string fieldName { PropertyInfo[] propertiesA = new FileIndexItem().GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance); - return propertiesA.FirstOrDefault(p => + return Array.Find(propertiesA,p => string.Equals(p.Name, fieldName, StringComparison.InvariantCultureIgnoreCase))? .GetValue(sourceIndexItem, null); } diff --git a/starsky/starsky.foundation.database/Models/ImportIndexItem.cs b/starsky/starsky.foundation.database/Models/ImportIndexItem.cs index 9a35249d5c..3fc95dd6ae 100644 --- a/starsky/starsky.foundation.database/Models/ImportIndexItem.cs +++ b/starsky/starsky.foundation.database/Models/ImportIndexItem.cs @@ -118,7 +118,10 @@ public DateTime ParseDateTimeFromFileName() { // Depends on 'AppSettingsProvider.Structure' // depends on SourceFullFilePath - if(string.IsNullOrEmpty(SourceFullFilePath)) {return new DateTime();} + if ( string.IsNullOrEmpty(SourceFullFilePath) ) + { + return new DateTime(0, DateTimeKind.Utc); + } var fileName = Path.GetFileNameWithoutExtension(SourceFullFilePath); diff --git a/starsky/starsky.foundation.database/Query/Query.cs b/starsky/starsky.foundation.database/Query/Query.cs index 7e98e87325..4da9419b78 100644 --- a/starsky/starsky.foundation.database/Query/Query.cs +++ b/starsky/starsky.foundation.database/Query/Query.cs @@ -93,7 +93,6 @@ internal static string GetObjectByFilePathAsyncCacheName(string subPath) _cache.TryGetValue( GetObjectByFilePathAsyncCacheName(filePath), out var data) ) { - _logger.LogInformation("Get from cache " + GetObjectByFilePathAsyncCacheName(filePath)); if ( !(data is FileIndexItem fileIndexItem) ) return null; fileIndexItem.Status = FileIndexItem.ExifStatus.OkAndSame; return fileIndexItem; @@ -478,7 +477,7 @@ public void CacheUpdateItem(List updateStatusContent) // make it a list to avoid enum errors displayFileFolders = displayFileFolders.ToList(); - var obj = displayFileFolders.FirstOrDefault(p => p.FilePath == item.FilePath); + var obj = displayFileFolders.Find(p => p.FilePath == item.FilePath); if ( obj != null ) { // remove add again diff --git a/starsky/starsky.foundation.database/Query/QueryGetObjectsByFileHashAsync.cs b/starsky/starsky.foundation.database/Query/QueryGetObjectsByFileHashAsync.cs index 1c5ced78f6..de086a0fea 100644 --- a/starsky/starsky.foundation.database/Query/QueryGetObjectsByFileHashAsync.cs +++ b/starsky/starsky.foundation.database/Query/QueryGetObjectsByFileHashAsync.cs @@ -27,7 +27,7 @@ async Task> LocalQuery(ApplicationDbContext context) fileHashesList.Contains(p.FileHash!)).ToListAsync(); foreach ( var fileHash in fileHashesList ) { - if ( result.FirstOrDefault(p => p.FileHash == fileHash) == null ) + if ( result.Find(p => p.FileHash == fileHash) == null ) { result.Add(new FileIndexItem(){FileHash = fileHash, Status = FileIndexItem.ExifStatus.NotFoundNotInIndex}); diff --git a/starsky/starsky.foundation.database/Query/QuerySingleItem.cs b/starsky/starsky.foundation.database/Query/QuerySingleItem.cs index c5196df275..71141fa31f 100644 --- a/starsky/starsky.foundation.database/Query/QuerySingleItem.cs +++ b/starsky/starsky.foundation.database/Query/QuerySingleItem.cs @@ -88,7 +88,7 @@ public partial class Query }; } - var currentFileIndexItem = fileIndexItemsList.FirstOrDefault(p => p.FileName == fileName); + var currentFileIndexItem = fileIndexItemsList.Find(p => p.FileName == fileName); // Could be not found or not in directory cache if ( currentFileIndexItem == null ) diff --git a/starsky/starsky.foundation.database/Thumbnails/ThumbnailQuery.cs b/starsky/starsky.foundation.database/Thumbnails/ThumbnailQuery.cs index 6945aded65..add67183b3 100644 --- a/starsky/starsky.foundation.database/Thumbnails/ThumbnailQuery.cs +++ b/starsky/starsky.foundation.database/Thumbnails/ThumbnailQuery.cs @@ -32,7 +32,7 @@ public ThumbnailQuery(ApplicationDbContext context, IServiceScopeFactory? scopeF public Task?> AddThumbnailRangeAsync(List thumbnailItems) { - if ( thumbnailItems.Any(p => string.IsNullOrEmpty(p.FileHash) ) ) + if ( thumbnailItems.Exists(p => string.IsNullOrEmpty(p.FileHash) ) ) { throw new ArgumentNullException(nameof(thumbnailItems), "[AddThumbnailRangeAsync] FileHash is null or empty"); } @@ -208,8 +208,8 @@ private static async Task RenameInternalAsync(ApplicationDbContext dbConte var beforeOrNewItems = await dbContext.Thumbnails.Where(p => p.FileHash == beforeFileHash || p.FileHash == newFileHash).ToListAsync(); - var beforeItem = beforeOrNewItems.FirstOrDefault(p => p.FileHash == beforeFileHash); - var newItem = beforeOrNewItems.FirstOrDefault(p => p.FileHash == newFileHash); + var beforeItem = beforeOrNewItems.Find(p => p.FileHash == beforeFileHash); + var newItem = beforeOrNewItems.Find(p => p.FileHash == newFileHash); if ( beforeItem == null) return false; diff --git a/starsky/starsky.foundation.injection/ServiceCollectionExtensions.cs b/starsky/starsky.foundation.injection/ServiceCollectionExtensions.cs index 1553fb58ab..127abeffb3 100644 --- a/starsky/starsky.foundation.injection/ServiceCollectionExtensions.cs +++ b/starsky/starsky.foundation.injection/ServiceCollectionExtensions.cs @@ -138,7 +138,7 @@ private static List GetEntryAssemblyReferencedAssemblies(List p.FullName == assemblyName.FullName); + var isThere = assemblies.Exists(p => p.FullName == assemblyName.FullName); if (IsWildcardMatch(assemblyName.Name!, assemblyFilter) && !isThere ) { assemblies.Add(AppDomain.CurrentDomain.Load(assemblyName)); @@ -165,7 +165,7 @@ private static Assembly[] GetReferencedAssemblies(List assemblies, IEn foreach ( var referencedAssembly in assembly.GetReferencedAssemblies() ) { if ( IsWildcardMatch(referencedAssembly.Name!, assemblyFilter) - && assemblies.All(p => p.FullName != referencedAssembly.FullName) ) + && assemblies.TrueForAll(p => p.FullName != referencedAssembly.FullName) ) { assemblies.Add(Assembly.Load(referencedAssembly)); } diff --git a/starsky/starsky.foundation.platform/Helpers/AppSettingsCompareHelper.cs b/starsky/starsky.foundation.platform/Helpers/AppSettingsCompareHelper.cs index b11aaa5ad5..e459c40209 100644 --- a/starsky/starsky.foundation.platform/Helpers/AppSettingsCompareHelper.cs +++ b/starsky/starsky.foundation.platform/Helpers/AppSettingsCompareHelper.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -28,7 +29,7 @@ public static List Compare(AppSettings sourceIndexItem, object? updateOb foreach ( var propertyB in propertiesB ) { // only for when TransferObject is Nullable and AppSettings is bool - var propertyInfoFromA = propertiesA.FirstOrDefault(p => p.Name == propertyB.Name); + var propertyInfoFromA = Array.Find(propertiesA, p => p.Name == propertyB.Name); if ( propertyInfoFromA == null ) continue; if (propertyInfoFromA.PropertyType == typeof(bool?) && propertyB.PropertyType == typeof(bool?)) { @@ -277,8 +278,7 @@ internal static void CompareInt(string propertyName, AppSettings sourceIndexItem /// private static object? GetPropertyValue(object car, string propertyName) { - return car.GetType().GetProperties() - .FirstOrDefault(pi => pi.Name == propertyName)? + return Array.Find(car.GetType().GetProperties(), pi => pi.Name == propertyName)? .GetValue(car, null); } diff --git a/starsky/starsky.foundation.platform/Helpers/DateAssembly.cs b/starsky/starsky.foundation.platform/Helpers/DateAssembly.cs index 4e433f6fe7..ad18d92022 100644 --- a/starsky/starsky.foundation.platform/Helpers/DateAssembly.cs +++ b/starsky/starsky.foundation.platform/Helpers/DateAssembly.cs @@ -20,7 +20,11 @@ public static DateTime GetBuildDate(Assembly assembly) // build$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss")) // var attribute = assembly.GetCustomAttribute(); - if ( attribute?.InformationalVersion == null ) return new DateTime(); + if ( attribute?.InformationalVersion == null ) + { + return new DateTime(0, DateTimeKind.Utc); + } + var value = attribute.InformationalVersion; return ParseBuildTime(value); } @@ -29,7 +33,10 @@ internal static DateTime ParseBuildTime(string value) { const string buildVersionMetadataPrefix = "+build"; var index = value.IndexOf(buildVersionMetadataPrefix, StringComparison.Ordinal); - if ( index <= 0 ) return new DateTime(); + if ( index <= 0 ) + { + return new DateTime(0, DateTimeKind.Utc); + } value = value.Substring(index + buildVersionMetadataPrefix.Length); return DateTime.TryParseExact(value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var result) ? result : new DateTime(); diff --git a/starsky/starsky.foundation.platform/Models/AppSettings.cs b/starsky/starsky.foundation.platform/Models/AppSettings.cs index e4d36ca24e..0691d15a75 100644 --- a/starsky/starsky.foundation.platform/Models/AppSettings.cs +++ b/starsky/starsky.foundation.platform/Models/AppSettings.cs @@ -519,7 +519,7 @@ public bool IsReadOnly(string f) { if (!ReadOnlyFolders.Any() ) return false; - var result = ReadOnlyFolders.FirstOrDefault(f.Contains); + var result = ReadOnlyFolders.Find(f.Contains); return result != null; } @@ -1038,9 +1038,9 @@ public string DatabasePathToFilePath(string databaseFilePath, bool checkIfExist /// /// the input, the env should start with a $ /// the value or the input when nothing is found - internal string ReplaceEnvironmentVariable(string input) + internal static string ReplaceEnvironmentVariable(string input) { - if ( string.IsNullOrEmpty(input) || !input.StartsWith("$") ) return input; + if ( string.IsNullOrEmpty(input) || !input.StartsWith('$') ) return input; var value = Environment.GetEnvironmentVariable(input.Remove(0, 1)); return string.IsNullOrEmpty(value) ? input : value; } diff --git a/starsky/starsky.foundation.readmeta/Helpers/GeoParser.cs b/starsky/starsky.foundation.readmeta/Helpers/GeoParser.cs index a9566e176b..b40a83a0d4 100644 --- a/starsky/starsky.foundation.readmeta/Helpers/GeoParser.cs +++ b/starsky/starsky.foundation.readmeta/Helpers/GeoParser.cs @@ -88,7 +88,7 @@ public static GeoListItem ParseIsoString(string isoStr) // Check for minimum length // Check for trailing slash - if ( isoStr.Length < 18 || !isoStr.EndsWith("/") ) + if ( isoStr.Length < 18 || !isoStr.EndsWith('/') ) { return geoListItem; } diff --git a/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs b/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs index 3e451c4bf4..8463cf5043 100644 --- a/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs +++ b/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs @@ -284,16 +284,16 @@ private static string GetSonyMakeLensModel(List allExifItems, string private static ExtensionRolesHelper.ImageFormat GetFileSpecificTags(List allExifItems) { - if ( allExifItems.Any(p => p.Name == "JPEG") ) + if ( allExifItems.Exists(p => p.Name == "JPEG") ) return ExtensionRolesHelper.ImageFormat.jpg; - if ( allExifItems.Any(p => p.Name == "PNG-IHDR") ) + if ( allExifItems.Exists(p => p.Name == "PNG-IHDR") ) return ExtensionRolesHelper.ImageFormat.png; - if ( allExifItems.Any(p => p.Name == "BMP Header") ) + if ( allExifItems.Exists(p => p.Name == "BMP Header") ) return ExtensionRolesHelper.ImageFormat.bmp; - if ( allExifItems.Any(p => p.Name == "GIF Header") ) + if ( allExifItems.Exists(p => p.Name == "GIF Header") ) return ExtensionRolesHelper.ImageFormat.gif; return ExtensionRolesHelper.ImageFormat.unknown; diff --git a/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaGpx.cs b/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaGpx.cs index 4a872950d9..da7807deaa 100644 --- a/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaGpx.cs +++ b/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaGpx.cs @@ -51,7 +51,7 @@ public FileIndexItem ReadGpxFromFileReturnAfterFirstField(Stream? stream, } var title = readGpxFile.FirstOrDefault()?.Title ?? string.Empty; - var dateTime = readGpxFile.FirstOrDefault()?.DateTime ?? new DateTime(); + var dateTime = readGpxFile.FirstOrDefault()?.DateTime ?? new DateTime(0, DateTimeKind.Utc); var latitude = readGpxFile.FirstOrDefault()?.Latitude ?? 0d; var longitude = readGpxFile.FirstOrDefault()?.Longitude ?? 0d; var altitude = readGpxFile.FirstOrDefault()?.Altitude ?? 0d; diff --git a/starsky/starsky.foundation.storage/ArchiveFormats/TarBal.cs b/starsky/starsky.foundation.storage/ArchiveFormats/TarBal.cs index a59ea0457c..a7dcfce089 100644 --- a/starsky/starsky.foundation.storage/ArchiveFormats/TarBal.cs +++ b/starsky/starsky.foundation.storage/ArchiveFormats/TarBal.cs @@ -110,7 +110,7 @@ private async Task CreateFileOrDirectory(string outputDir, string name, long siz _storage.CreateDirectory(FilenamesHelper.GetParentPath(output)); } - if (!name.EndsWith("/")) //Directories are zero size and don't need anything written + if (!name.EndsWith('/')) // Directories are zero size and don't need anything written { var str = new MemoryStream(); var buf = new byte[size]; diff --git a/starsky/starsky.foundation.storage/Services/StructureService.cs b/starsky/starsky.foundation.storage/Services/StructureService.cs index 5612b88db1..5c96bc4788 100644 --- a/starsky/starsky.foundation.storage/Services/StructureService.cs +++ b/starsky/starsky.foundation.storage/Services/StructureService.cs @@ -141,7 +141,7 @@ private StringBuilder MatchChildDirectories(StringBuilder parentFolderBuilder, S // should return a list of: var childDirectories = _storage.GetDirectories(parentFolderBuilder.ToString()).ToList(); - var matchingFoldersPath= childDirectories.FirstOrDefault(p => + var matchingFoldersPath= childDirectories.Find(p => MatchChildFolderSearch(parentFolderBuilder,currentChildFolderBuilder,p) ); @@ -182,7 +182,13 @@ private static string RemoveAsteriskFromString(StringBuilder input ) /// When not start with / or is /.ext or not end with .ext private void CheckStructureFormat() { - if (!string.IsNullOrEmpty(_structure) && _structure.StartsWith("/") && _structure.EndsWith(".ext") && _structure != "/.ext" ) return; + if ( !string.IsNullOrEmpty(_structure) && + _structure.StartsWith('/') && _structure.EndsWith(".ext") && + _structure != "/.ext" ) + { + return; + } + throw new FieldAccessException("Structure is not right formatted, please read the documentation"); } @@ -252,7 +258,7 @@ private static string OutputStructureRangeItemParser(string pattern, DateTime da foreach ( Match match in matchCollection ) { // Ignore escaped items - if ( !match.Value.StartsWith("\\") && match.Index == 0 && match.Length == pattern.Length ) + if ( !match.Value.StartsWith('\\') && match.Index == 0 && match.Length == pattern.Length ) { return dateTime.ToString(pattern, CultureInfo.InvariantCulture); } diff --git a/starsky/starsky.foundation.thumbnailmeta/Services/OffsetDataMetaExifThumbnail.cs b/starsky/starsky.foundation.thumbnailmeta/Services/OffsetDataMetaExifThumbnail.cs index dee871a22a..a4e484ea97 100644 --- a/starsky/starsky.foundation.thumbnailmeta/Services/OffsetDataMetaExifThumbnail.cs +++ b/starsky/starsky.foundation.thumbnailmeta/Services/OffsetDataMetaExifThumbnail.cs @@ -46,7 +46,7 @@ public OffsetDataMetaExifThumbnail(ISelectorStorage selectorStorage, IWebLogger var allExifItems = ImageMetadataReader.ReadMetadata(stream).ToList(); var exifThumbnailDir = - allExifItems.FirstOrDefault(p => + allExifItems.Find(p => p.Name == "Exif Thumbnail") as ExifThumbnailDirectory; return ( allExifItems, exifThumbnailDir); diff --git a/starsky/starsky/Controllers/DeleteController.cs b/starsky/starsky/Controllers/DeleteController.cs index 0ee33f8a30..91a1df3aa2 100644 --- a/starsky/starsky/Controllers/DeleteController.cs +++ b/starsky/starsky/Controllers/DeleteController.cs @@ -36,8 +36,12 @@ public async Task Delete(string f, bool collections = false) var fileIndexResultsList = await _deleteItem.DeleteAsync(f, collections); // When all items are not found // ok = file is deleted - if (fileIndexResultsList.All(p => p.Status != FileIndexItem.ExifStatus.Ok)) - return NotFound(fileIndexResultsList); + if ( fileIndexResultsList.TrueForAll(p => + p.Status != FileIndexItem.ExifStatus.Ok) ) + { + return NotFound(fileIndexResultsList); + } + return Json(fileIndexResultsList); } diff --git a/starsky/starsky/Controllers/DiskController.cs b/starsky/starsky/Controllers/DiskController.cs index 95e18aeaf9..1c2f63cb42 100644 --- a/starsky/starsky/Controllers/DiskController.cs +++ b/starsky/starsky/Controllers/DiskController.cs @@ -88,7 +88,7 @@ await _query.AddItemAsync(new FileIndexItem(subPath) } // When all items are not found - if (syncResultsList.All(p => p.Status != FileIndexItem.ExifStatus.Ok)) + if (syncResultsList.TrueForAll(p => p.Status != FileIndexItem.ExifStatus.Ok)) Response.StatusCode = 409; // A conflict, Directory already exist await SyncMessageToSocket(syncResultsList, ApiNotificationType.Mkdir); @@ -141,7 +141,7 @@ public async Task Rename(string f, string to, bool collections = var rename = await new RenameService(_query, _iStorage).Rename(f, to, collections); // When all items are not found - if (rename.All(p => p.Status != FileIndexItem.ExifStatus.Ok)) + if (rename.TrueForAll(p => p.Status != FileIndexItem.ExifStatus.Ok)) return NotFound(rename); var webSocketResponse = diff --git a/starsky/starsky/Controllers/ExportController.cs b/starsky/starsky/Controllers/ExportController.cs index fc59d82698..1a147e8bc4 100644 --- a/starsky/starsky/Controllers/ExportController.cs +++ b/starsky/starsky/Controllers/ExportController.cs @@ -49,7 +49,7 @@ public async Task CreateZip(string f, bool collections = true, bo // When all items are not found // allow read only - if (fileIndexResultsList.All(p => p.Status != FileIndexItem.ExifStatus.Ok) ) + if (fileIndexResultsList.TrueForAll(p => p.Status != FileIndexItem.ExifStatus.Ok) ) return NotFound(fileIndexResultsList); // NOT covered: when try to export for example image thumbnails of xml file diff --git a/starsky/starsky/Controllers/ImportController.cs b/starsky/starsky/Controllers/ImportController.cs index b3bb0522d6..d71515f6be 100644 --- a/starsky/starsky/Controllers/ImportController.cs +++ b/starsky/starsky/Controllers/ImportController.cs @@ -88,13 +88,13 @@ await _bgTaskQueue.QueueBackgroundWorkItemAsync(async _ => // When all items are already imported if ( importSettings.IndexMode && - fileIndexResultsList.All(p => p.Status != ImportStatus.Ok) ) + fileIndexResultsList.TrueForAll(p => p.Status != ImportStatus.Ok) ) { Response.StatusCode = 206; } // Wrong input (extension is not allowed) - if ( fileIndexResultsList.All(p => p.Status == ImportStatus.FileError) ) + if ( fileIndexResultsList.TrueForAll(p => p.Status == ImportStatus.FileError) ) { Response.StatusCode = 415; } diff --git a/starsky/starsky/Controllers/MetaInfoController.cs b/starsky/starsky/Controllers/MetaInfoController.cs index 6ac38d2918..aa86dc1ea7 100644 --- a/starsky/starsky/Controllers/MetaInfoController.cs +++ b/starsky/starsky/Controllers/MetaInfoController.cs @@ -40,15 +40,19 @@ public IActionResult Info(string f, bool collections = true) var fileIndexResultsList = _metaInfo.GetInfo(inputFilePaths, collections); // returns read only - if (fileIndexResultsList.All(p => p.Status == FileIndexItem.ExifStatus.ReadOnly)) + if (fileIndexResultsList.TrueForAll(p => p.Status == FileIndexItem.ExifStatus.ReadOnly)) { Response.StatusCode = 203; // is readonly return Json(fileIndexResultsList); } // When all items are not found - if (fileIndexResultsList.All(p => (p.Status != FileIndexItem.ExifStatus.Ok && p.Status != FileIndexItem.ExifStatus.Deleted))) - return NotFound(fileIndexResultsList); + if ( fileIndexResultsList.TrueForAll(p => + ( p.Status != FileIndexItem.ExifStatus.Ok && + p.Status != FileIndexItem.ExifStatus.Deleted )) ) + { + return NotFound(fileIndexResultsList); + } return Json(fileIndexResultsList); } diff --git a/starsky/starsky/Controllers/MetaUpdateController.cs b/starsky/starsky/Controllers/MetaUpdateController.cs index d42a5b3379..375fd55ab5 100644 --- a/starsky/starsky/Controllers/MetaUpdateController.cs +++ b/starsky/starsky/Controllers/MetaUpdateController.cs @@ -98,7 +98,7 @@ await _bgTaskQueue.QueueBackgroundWorkItemAsync(async _ => new StopWatchLogger(_logger).StopUpdateReplaceStopWatch("update", f,collections, stopwatch); // When all items are not found - if ( fileIndexResultsList.All(p => + if ( fileIndexResultsList.TrueForAll(p => p.Status != FileIndexItem.ExifStatus.Ok && p.Status != FileIndexItem.ExifStatus.Deleted) ) { diff --git a/starsky/starsky/Controllers/PublishController.cs b/starsky/starsky/Controllers/PublishController.cs index d89b7fbe64..fc7ca4f19c 100644 --- a/starsky/starsky/Controllers/PublishController.cs +++ b/starsky/starsky/Controllers/PublishController.cs @@ -84,7 +84,7 @@ public async Task PublishCreateAsync(string f, string itemName, _webLogger.LogInformation($"[/api/publish/create] Press publish: {itemName} {f} {DateTime.UtcNow}"); var inputFilePaths = PathHelper.SplitInputFilePaths(f).ToList(); var info = _metaInfo.GetInfo(inputFilePaths, false); - if ( info.All(p => + if ( info.TrueForAll(p => p.Status != FileIndexItem.ExifStatus.Ok && p.Status != FileIndexItem.ExifStatus.ReadOnly) ) { diff --git a/starsky/starsky/Controllers/SearchController.cs b/starsky/starsky/Controllers/SearchController.cs index 70bf023ce8..0c03330417 100644 --- a/starsky/starsky/Controllers/SearchController.cs +++ b/starsky/starsky/Controllers/SearchController.cs @@ -86,10 +86,10 @@ public async Task SearchRelative(string f, string t, int p = 0) /// int as index, fallback == -1 internal static int GetIndexFilePathFromSearch(SearchViewModel searchViewModel, string f) { - var result = searchViewModel.FileIndexItems.FirstOrDefault(p => p.FilePath == f); - var photoIndexOfQuery = searchViewModel.FileIndexItems.IndexOf(result); - if ( result == null ) return -1; - return photoIndexOfQuery; + var result = searchViewModel.FileIndexItems?.Find(p => p.FilePath == f); + var photoIndexOfQuery = searchViewModel.FileIndexItems?.IndexOf(result); + if ( result == null || photoIndexOfQuery == null) return -1; + return photoIndexOfQuery.Value; } /// diff --git a/starsky/starsky/Controllers/UploadController.cs b/starsky/starsky/Controllers/UploadController.cs index f7fdadcd9a..0e8554e55f 100644 --- a/starsky/starsky/Controllers/UploadController.cs +++ b/starsky/starsky/Controllers/UploadController.cs @@ -161,7 +161,7 @@ public async Task UploadToFolder() await _metaUpdateStatusThumbnailService.UpdateStatusThumbnail(metaResultsList); // Wrong input (extension is not allowed) - if ( fileIndexResultsList.All(p => p.Status == ImportStatus.FileError) ) + if ( fileIndexResultsList.TrueForAll(p => p.Status == ImportStatus.FileError) ) { _logger.LogInformation($"Wrong input extension is not allowed" + $" {string.Join(",",fileIndexResultsList.Select(p => p.FilePath))}"); diff --git a/starsky/starsky/clientapp/src/components/atoms/button-styled/button-styled.tsx b/starsky/starsky/clientapp/src/components/atoms/button-styled/button-styled.tsx index 835f440356..c91bc07ae3 100644 --- a/starsky/starsky/clientapp/src/components/atoms/button-styled/button-styled.tsx +++ b/starsky/starsky/clientapp/src/components/atoms/button-styled/button-styled.tsx @@ -14,7 +14,7 @@ export interface IButtonProps { const ButtonStyled: React.FunctionComponent = memo((props) => { return (