Skip to content

Commit

Permalink
remove sync class && make async && change palintextfilehelper
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Jan 18, 2024
1 parent c2ad509 commit 4b78270
Show file tree
Hide file tree
Showing 92 changed files with 483 additions and 441 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ internal static async Task<bool> DownloadAsync(AppSettings appSettings,
continue;
}

var result = await PlainTextFileHelper.StreamToStringAsync(
var result = await StreamToStringHelper.StreamToStringAsync(
hostStorage.ReadStream(settingsJsonFullPath));

var data = Deserialize(result, webLogger, hostStorage, settingsJsonFullPath);
Expand Down
2 changes: 1 addition & 1 deletion starsky/starsky.feature.export/Services/ExportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public async Task CreateZip(List<FileIndexItem> fileIndexResultsList, bool thumb
// Write a single file to be sure that writing is ready
var doneFileFullPath = Path.Combine(_appSettings.TempFolder,zipOutputFileName) + ".done";
await _hostFileSystemStorage.
WriteStreamAsync(PlainTextFileHelper.StringToStream("OK"), doneFileFullPath);
WriteStreamAsync(StringToStreamHelper.StringToStream("OK"), doneFileFullPath);
if(_appSettings.IsVerbose()) _logger.LogInformation("[CreateZip] Zip done: " + doneFileFullPath);
}

Expand Down
5 changes: 3 additions & 2 deletions starsky/starsky.feature.geolookup/Interfaces/IGeoIndexGpx.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using starsky.foundation.database.Models;

namespace starsky.feature.geolookup.Interfaces
{
public interface IGeoIndexGpx
{
List<FileIndexItem>
LoopFolder(List<FileIndexItem> metaFilesInDirectory);
Task<List<FileIndexItem>> LoopFolderAsync(
List<FileIndexItem> metaFilesInDirectory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public async Task<List<FileIndexItem>> GeoBackgroundTaskAsync(
var listOfFiles = _iStorage.GetAllFilesInDirectory(f)
.Where(ExtensionRolesHelper.IsExtensionSyncSupported).ToList();

var fileIndexList = _readMeta
.ReadExifAndXmpFromFileAddFilePathHash(listOfFiles);
var fileIndexList = await _readMeta
.ReadExifAndXmpFromFileAddFilePathHashAsync(listOfFiles);

var toMetaFilesUpdate = new List<FileIndexItem>();
if ( index )
{
toMetaFilesUpdate =
_geoIndexGpx
.LoopFolder(fileIndexList);
await _geoIndexGpx
.LoopFolderAsync(fileIndexList);

if ( _appSettings.IsVerbose() ) Console.Write("¬");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public GeoCacheStatus Status(string path)
var result = new GeoCacheStatus();

if(_cache.TryGetValue(totalCacheName, out var statusObjectTotal) &&
TryParse(statusObjectTotal.ToString(), out var totalStatus))
TryParse(statusObjectTotal?.ToString(), out var totalStatus))
{
result.Total = totalStatus;
}

var currentCacheName = nameof(GeoCacheStatus) + path + StatusType.Current;
if(_cache.TryGetValue(currentCacheName, out var statusObjectCurrent) &&
TryParse(statusObjectCurrent.ToString(), out var currentStatus))
TryParse(statusObjectCurrent?.ToString(), out var currentStatus))
{
result.Current = currentStatus;
}
Expand Down
6 changes: 3 additions & 3 deletions starsky/starsky.feature.geolookup/Services/GeoCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public GeoCli(IGeoReverseLookup geoReverseLookup,
_geoLocationWrite = geoLocationWrite;
_iStorage = selectorStorage.Get(SelectorStorage.StorageServices.SubPath);
_thumbnailStorage = selectorStorage.Get(SelectorStorage.StorageServices.Thumbnail);
_readMeta = new ReadMeta(_iStorage, appSettings, null, logger);
_readMeta = new ReadMeta(_iStorage, appSettings, null!, logger);
_appSettings = appSettings;
_console = console;
_exifToolDownload = exifToolDownload;
Expand Down Expand Up @@ -122,7 +122,7 @@ public async Task CommandLineAsync(string[] args)
var listOfFiles = _iStorage.GetAllFilesInDirectory("/")
.Where(ExtensionRolesHelper.IsExtensionSyncSupported).ToList();

var fileIndexList = _readMeta.ReadExifAndXmpFromFileAddFilePathHash(listOfFiles);
var fileIndexList = await _readMeta.ReadExifAndXmpFromFileAddFilePathHashAsync(listOfFiles);

var toMetaFilesUpdate = new List<FileIndexItem>();
if ( ArgsHelper.GetIndexMode(args) )
Expand All @@ -131,7 +131,7 @@ public async Task CommandLineAsync(string[] args)
_console.WriteLine($"Folder: {inputPath}");

var geoIndexGpx = new GeoIndexGpx(_appSettings, _iStorage, _logger);
toMetaFilesUpdate = geoIndexGpx.LoopFolder(fileIndexList);
toMetaFilesUpdate = await geoIndexGpx.LoopFolderAsync(fileIndexList);

_console.Write("¬");
await _geoLocationWrite.LoopFolderAsync(toMetaFilesUpdate, false);
Expand Down
10 changes: 5 additions & 5 deletions starsky/starsky.feature.geolookup/Services/GeoIndexGpx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using starsky.feature.geolookup.Interfaces;
using starsky.feature.geolookup.Models;
Expand All @@ -11,7 +12,6 @@
using starsky.foundation.platform.Models;
using starsky.foundation.readmeta.Models;
using starsky.foundation.readmeta.ReadMetaHelpers;
using starsky.foundation.readmeta.Services;
using starsky.foundation.storage.Interfaces;

[assembly: InternalsVisibleTo("starskytest")]
Expand Down Expand Up @@ -42,7 +42,7 @@ private static List<FileIndexItem> GetNoLocationItems(IEnumerable<FileIndexItem>
.ToList();
}

private List<GeoListItem> GetGpxFile(List<FileIndexItem> metaFilesInDirectory)
private async Task<List<GeoListItem>> GetGpxFileAsync(List<FileIndexItem> metaFilesInDirectory)
{
var geoList = new List<GeoListItem>();
foreach (var metaFileItem in metaFilesInDirectory)
Expand All @@ -54,7 +54,7 @@ private List<GeoListItem> GetGpxFile(List<FileIndexItem> metaFilesInDirectory)

using ( var stream = _iStorage.ReadStream(metaFileItem.FilePath!) )
{
geoList.AddRange(new ReadMetaGpx(_logger).ReadGpxFile(stream, geoList));
geoList.AddRange(await new ReadMetaGpx(_logger).ReadGpxFileAsync(stream, geoList));
}
}
return geoList;
Expand Down Expand Up @@ -82,11 +82,11 @@ internal DateTime ConvertTimeZone(DateTime valueDateTime, string subPath = "")
_appSettings.CameraTimeZoneInfo, TimeZoneInfo.Utc);
}

public List<FileIndexItem> LoopFolder(List<FileIndexItem> metaFilesInDirectory)
public async Task<List<FileIndexItem>> LoopFolderAsync(List<FileIndexItem> metaFilesInDirectory)
{
var toUpdateMetaFiles = new List<FileIndexItem>();

var gpxList = GetGpxFile(metaFilesInDirectory);
var gpxList = await GetGpxFileAsync(metaFilesInDirectory);
if(!gpxList.Any()) return toUpdateMetaFiles;

metaFilesInDirectory = GetNoLocationItems(metaFilesInDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public async Task<KeyValuePair<UpdateStatus, string>> IsUpdateNeeded(string curr
if ( _cache.TryGetValue(QueryCheckForUpdatesCacheName,
out var cacheResult) )
{
cacheResult ??= new List<ReleaseModel>();
return Parse(( List<ReleaseModel> ) cacheResult, currentVersion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal async Task<FileIndexItem> UpdateTransformations(

var exifToolCmdHelper = new ExifToolCmdHelper(_exifTool,
_subPathStorage, _thumbnailStorage,
new ReadMeta(_subPathStorage, _appSettings, null, _logger),
new ReadMeta(_subPathStorage, _appSettings, null!, _logger),
_thumbnailQuery);
await exifToolCmdHelper.UpdateAsync(fileIndexItem, comparedNamesList);

Expand Down
8 changes: 4 additions & 4 deletions starsky/starsky.feature.import/Services/Import.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Import(
_thumbnailStorage = selectorStorage.Get(SelectorStorage.StorageServices.Thumbnail);

_appSettings = appSettings;
_readMetaHost = new ReadMeta(_filesystemStorage, appSettings, null, logger);
_readMetaHost = new ReadMeta(_filesystemStorage, appSettings, null!, logger);
_exifTool = exifTool;
_query = query;
_console = console;
Expand Down Expand Up @@ -366,11 +366,11 @@ internal async Task<ImportIndexItem> PreflightPerFile(KeyValuePair<string,bool>

// Only accept files with correct meta data
// Check if there is a xmp file that contains data
var fileIndexItem = _readMetaHost.ReadExifAndXmpFromFile(inputFileFullPath.Key);
var fileIndexItem = await _readMetaHost.ReadExifAndXmpFromFileAsync(inputFileFullPath.Key);

// Parse the filename and create a new importIndexItem object
var importIndexItem = ObjectCreateIndexItem(inputFileFullPath.Key, imageFormat,
hashList.Key, fileIndexItem, importSettings.ColorClass,
hashList.Key, fileIndexItem!, importSettings.ColorClass,
_filesystemStorage.Info(inputFileFullPath.Key).Size);

// Update the parent and filenames
Expand Down Expand Up @@ -638,7 +638,7 @@ private async Task CreateSideCarFile(ImportIndexItem importIndexItem, bool xmpEx
{
var exifCopy = new ExifCopy(_subPathStorage,
_thumbnailStorage, _exifTool, new ReadMeta(_subPathStorage,
_appSettings, null, _logger),_thumbnailQuery);
_appSettings, null!, _logger),_thumbnailQuery);
await exifCopy.XmpSync(importIndexItem.FileIndexItem!.FilePath);
}
}
Expand Down
4 changes: 3 additions & 1 deletion starsky/starsky.feature.metaupdate/Interfaces/IMetaInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using starsky.foundation.database.Models;

namespace starsky.feature.metaupdate.Interfaces
{
public interface IMetaInfo
{
List<FileIndexItem> GetInfo(List<string> inputFilePaths, bool collections);
Task<List<FileIndexItem>> GetInfoAsync(List<string> inputFilePaths,
bool collections);
}
}
9 changes: 5 additions & 4 deletions starsky/starsky.feature.metaupdate/Services/MetaInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using starsky.feature.metaupdate.Interfaces;
using starsky.foundation.database.Helpers;
Expand Down Expand Up @@ -31,7 +32,7 @@ public MetaInfo(IQuery query, AppSettings appSettings, ISelectorStorage selector
_statusCodeHelper = new StatusCodesHelper(appSettings);
}

public List<FileIndexItem> GetInfo(List<string> inputFilePaths, bool collections)
public async Task<List<FileIndexItem>> GetInfoAsync(List<string> inputFilePaths, bool collections)
{
// the result list
var fileIndexResultsList = new List<FileIndexItem>();
Expand Down Expand Up @@ -62,7 +63,7 @@ public List<FileIndexItem> GetInfo(List<string> inputFilePaths, bool collections
&& !ExtensionRolesHelper.IsExtensionSidecar(detailView.FileIndexItem!.FileName))
{
StatusCodesHelper.ReturnExifStatusError(
new FileIndexItemJsonParser(_iStorage).Read(detailView.FileIndexItem),
await new FileIndexItemJsonParser(_iStorage).ReadAsync(detailView.FileIndexItem),
FileIndexItem.ExifStatus.ExifWriteNotSupported,
fileIndexResultsList);
continue;
Expand All @@ -78,9 +79,9 @@ public List<FileIndexItem> GetInfo(List<string> inputFilePaths, bool collections

foreach ( var collectionSubPath in collectionSubPathList )
{
var collectionItem = _readMeta.ReadExifAndXmpFromFile(collectionSubPath);
var collectionItem = await _readMeta.ReadExifAndXmpFromFileAsync(collectionSubPath);

collectionItem.Status = statusResults;
collectionItem!.Status = statusResults;
collectionItem.CollectionPaths = collectionSubPathList;
collectionItem.ImageFormat =
ExtensionRolesHelper.MapFileTypesToExtension(collectionSubPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<string> DeviceId(OSPlatform? currentPlatform )

if ( currentPlatform == OSPlatform.Linux || currentPlatform == OSPlatform.FreeBSD)
{
id = DeviceIdLinuxBsd();
id = await DeviceIdLinuxBsdAsync();
}

// For privacy reason this content of this id will be anonymous
Expand All @@ -73,23 +73,23 @@ internal async Task<string> DeviceIdDatabaseId()
return generatedString;
}

private string DeviceIdLinuxBsd()
private async Task<string> DeviceIdLinuxBsdAsync()
{
if ( _hostStorage.ExistFile(DbusMachineIdPath) )
{
var stream = _hostStorage.ReadStream(DbusMachineIdPath);
return PlainTextFileHelper.StreamToString(stream);
return await StreamToStringHelper.StreamToStringAsync(stream);
}

if ( _hostStorage.ExistFile(MachineIdPath2) )
{
var stream = _hostStorage.ReadStream(MachineIdPath2);
return PlainTextFileHelper.StreamToString(stream);
return await StreamToStringHelper.StreamToStringAsync(stream);
}

if ( !_hostStorage.ExistFile(BsdHostIdPath) ) return string.Empty;
var streamBsd = _hostStorage.ReadStream(BsdHostIdPath);
return PlainTextFileHelper.StreamToString(streamBsd);
return await StreamToStringHelper.StreamToStringAsync(streamBsd);
}

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions starsky/starsky.feature.webftppublish/Helpers/WebFtpCli.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Threading.Tasks;
using starsky.feature.webftppublish.FtpAbstractions.Interfaces;
using starsky.feature.webftppublish.Models;
using starsky.feature.webftppublish.Services;
Expand Down Expand Up @@ -30,7 +31,7 @@ public WebFtpCli(AppSettings appSettings, ISelectorStorage selectorStorage, ICon
_webRequestFactory = webRequestFactory;
}

public void Run(string[] args)
public async Task RunAsync(string[] args)
{
_appSettings.Verbose = ArgsHelper.NeedVerbose(args);

Expand Down Expand Up @@ -75,8 +76,8 @@ public void Run(string[] args)
return;
}

var settings =
new DeserializeJson(_hostStorageProvider).Read<FtpPublishManifestModel>(
var settings = await
new DeserializeJson(_hostStorageProvider).ReadAsync<FtpPublishManifestModel>(
settingsFullFilePath);

var ftpService = new FtpService(_appSettings,_hostStorageProvider,
Expand Down
4 changes: 2 additions & 2 deletions starsky/starsky.feature.webhtmlpublish/Helpers/PublishCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public async Task Publisher(string[] args)
var listOfFiles = _subPathStorage.GetAllFilesInDirectory("/")
.Where(ExtensionRolesHelper.IsExtensionExifToolSupported).ToList();

var fileIndexList = new ReadMeta(_subPathStorage, _appSettings, null, _logger)
.ReadExifAndXmpFromFileAddFilePathHash(listOfFiles);
var fileIndexList = await new ReadMeta(_subPathStorage, _appSettings, null, _logger)
.ReadExifAndXmpFromFileAddFilePathHashAsync(listOfFiles);

// todo introduce selector
var profileName = new PublishPreflight(_appSettings,_console, _storageSelector, _logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void ExportManifest( string parentFullFilePath, string itemName,
var outputLocation = Path.Combine(parentFullFilePath, ManifestName);

_storage.FileDelete(outputLocation);
_storage.WriteStream(PlainTextFileHelper.StringToStream(output), outputLocation);
_storage.WriteStream(StringToStreamHelper.StringToStream(output), outputLocation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ internal async Task<Dictionary<string, bool>> GenerateWebHtml(List<AppSettingsPu
var embeddedResult = await new ParseRazor(_hostFileSystemStorage, _logger)
.EmbeddedViews(currentProfile.Template, viewModel);

var stream = PlainTextFileHelper.StringToStream(embeddedResult);
var stream = StringToStreamHelper.StringToStream(embeddedResult);
await _hostFileSystemStorage.WriteStreamAsync(stream,
Path.Combine(outputParentFullFilePathFolder, currentProfile.Path));

Expand Down Expand Up @@ -408,7 +408,7 @@ public async Task GenerateZip(string fullFileParentFolderPath, string itemName,
// Write a single file to be sure that writing is ready
var doneFileFullPath = Path.Combine(_appSettings.TempFolder, slugItemName) + ".done";
await _hostFileSystemStorage.
WriteStreamAsync(PlainTextFileHelper.StringToStream("OK"), doneFileFullPath);
WriteStreamAsync(StringToStreamHelper.StringToStream("OK"), doneFileFullPath);

Check warning on line 411 in starsky/starsky.feature.webhtmlpublish/Services/WebHtmlPublishService.cs

View check run for this annotation

Codecov / codecov/patch

starsky/starsky.feature.webhtmlpublish/Services/WebHtmlPublishService.cs#L411

Added line #L411 was not covered by tests

if ( deleteFolderAfterwards )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public TelemetryServiceException(string message)
/// <param name="info"></param>
/// <param name="context"></param>
protected TelemetryServiceException(SerializationInfo info, StreamingContext context)
#pragma warning disable SYSLIB0051
: base(info, context)
#pragma warning restore SYSLIB0051
{
}
}
Expand Down
Loading

0 comments on commit 4b78270

Please sign in to comment.