Completata gestione allegati e riepilogo commessa
This commit is contained in:
@@ -57,9 +57,53 @@ public class AttachedService : IAttachedService
|
||||
Name = file.FileName,
|
||||
Path = file.FullPath,
|
||||
MimeType = file.ContentType,
|
||||
DimensionBytes= ms.Length,
|
||||
FileContent = ms.ToArray(),
|
||||
DimensionBytes = ms.Length,
|
||||
FileBytes = ms.ToArray(),
|
||||
Type = type
|
||||
};
|
||||
}
|
||||
|
||||
private static async Task<string?> SaveToTempStorage(Stream file, string fileName)
|
||||
{
|
||||
var cacheDirectory = FileSystem.CacheDirectory;
|
||||
var targetDirectory = Path.Combine(cacheDirectory, "file");
|
||||
|
||||
if (!Directory.Exists(targetDirectory)) Directory.CreateDirectory(targetDirectory);
|
||||
|
||||
var tempFilePath = Path.Combine(targetDirectory, fileName + ".temp");
|
||||
var filePath = Path.Combine(targetDirectory, fileName);
|
||||
|
||||
if (File.Exists(filePath)) return filePath;
|
||||
|
||||
try
|
||||
{
|
||||
await using var fileStream =
|
||||
new FileStream(tempFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
await file.CopyToAsync(fileStream);
|
||||
|
||||
File.Move(tempFilePath, filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Errore durante il salvataggio dello stream: {e.Message}");
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(tempFilePath)) File.Delete(tempFilePath);
|
||||
}
|
||||
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public async Task OpenFile(Stream file, string fileName)
|
||||
{
|
||||
var filePath = await SaveToTempStorage(file, fileName);
|
||||
|
||||
if (filePath is null) return;
|
||||
await Launcher.OpenAsync(new OpenFileRequest
|
||||
{
|
||||
File = new ReadOnlyFile(filePath)
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user