public void MoveDocument(
            DocumentName documentName,
            Directory source,
            Directory target)
        {
            var oldPath = PathOfFileInDirectory(documentName.ToString(), source);
            var newPath = PathOfFileInDirectory(documentName.ToString(), target);

            File.Move(oldPath, newPath);
        }
        public async Task WriteDocumentAsync(
            Directory directory,
            DocumentName documentName,
            Stream stream)
        {
            var filePath = PathOfFileInDirectory(documentName.ToString(), directory);

            using var fileStream = File.Create(filePath);
            await stream.CopyToAsync(fileStream);

            fileStream.Close();
        }
        public async Task <Result> GetResultAsync(DocumentName documentName)
        {
            var result =
                await File.ReadAllTextAsync(
                    PathOfFileInDirectory(
                        documentName.ToString() + ".json",
                        Directory.Result));

            var serializableResult =
                System.Text.Json.JsonSerializer.Deserialize <SerializableResult>(result);

            return(new Result(
                       serializableResult.status,
                       serializableResult.text,
                       DateTimeOffset.FromUnixTimeSeconds(serializableResult.processingStartTime).UtcDateTime,
                       DateTimeOffset.FromUnixTimeSeconds(serializableResult.processingEndTime).UtcDateTime));
        }
Exemple #4
0
        public async Task <DocumentName> Put(string fileName, Stream stream)
        {
            var documentName =
                new DocumentName(
                    new Timestamp(DateTime.Now),
                    Guid.NewGuid(),
                    new FileName(fileName));
            await _documentStorage.WriteDocumentAsync(
                DocumentStorage.Directory.Temporary,
                documentName,
                stream);

            _documentStorage.MoveDocument(
                documentName,
                DocumentStorage.Directory.Temporary,
                DocumentStorage.Directory.Queued);
            return(documentName);
        }