Skip to content

Commit

Permalink
added converted to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry.lahoda committed Dec 8, 2018
1 parent fd69857 commit 7ce3452
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build-run.cmd
@@ -1,4 +1,4 @@
:: build and runs whole site
dotnet restore
npm install
npm install src/ClientApp/
dotnet run --project src --launch-profile=src
2 changes: 1 addition & 1 deletion integration/ExtractorTest.cs
Expand Up @@ -12,7 +12,7 @@ public async Task Word()
string rootFolder = @"D:/shared-src/chaintrack/src/Converter/";
string inputFilePath = @"D:/shared-src/chaintrack/data/2_аренда_хакатон.doc";

var converted = await new ConvertToTxt(rootFolder).Convert(inputFilePath);
var converted = await new ConvertToTxt(rootFolder).ConvertAsync(inputFilePath);

Assert.NotNull(converted);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Service/DocumentMetadata.cs
Expand Up @@ -15,5 +15,8 @@ public class DocumentMetadata

[BsonElement("FileName")]
public string FileName { get; set; }

[BsonElement("FileNameTxt")]
public string FileNameTxt { get; set; }
}
}
11 changes: 6 additions & 5 deletions src/Service/Upload/ConvertToTxt.cs
Expand Up @@ -12,7 +12,7 @@ public class ConvertToTxt : IConvertToTxt

// TODO: uses env variables for program, check of uno path,
private const string DefaultPathToLiberOffice = @"C:/Program Files/LibreOffice/program/python.exe";
private const string DefaultPathToUnoconv = "unoconv/unoconv";
private const string DefaultPathToUnoconv = "Converter/unoconv/unoconv";

/// <summary>
/// Gets or sets the custom unoconv path.
Expand Down Expand Up @@ -42,7 +42,7 @@ public ConvertToTxt(string rootFolder)
// "C:/Program Files/LibreOffice/program/python.exe" src/Converter/unoconv/unoconv --verbose --doctype=document --format=text --output="data/.data/2_аренда_хакатон.doc.txt" "data/2_аренда_хакатон.doc"
// --verbose --doctype=document --format=text --output="data/.data/2_аренда_хакатон.doc.txt" "data/2_аренда_хакатон.doc"

public async Task<string> Convert(string inputFilePath)
public async Task<string> ConvertAsync(string inputFilePath)
{
if (!File.Exists(inputFilePath))
{
Expand Down Expand Up @@ -86,10 +86,11 @@ private Task RunProcessAsync(Process process)
{
return Task.Run(() =>
{
DataReceivedEventHandler errorRecievedEventHandler = (sender, args) => Debug.WriteLine(args.Data);
DataReceivedEventHandler outputStringBuilderHandler = (sender, args) => Debug.WriteLine(args.Data);
DataReceivedEventHandler errorRecievedEventHandler =
(sender, args) => Console.WriteLine(args.Data);
DataReceivedEventHandler outputStringBuilderHandler = (sender, args) => Console.WriteLine(args.Data);
process.Exited += (s, ea) => Debug.WriteLine(process);
process.Exited += (s, ea) => Console.WriteLine(process);
if (process.Start())
{
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Upload/IConvertToTxt.cs
Expand Up @@ -5,6 +5,6 @@ namespace src.Service.Upload
{
public interface IConvertToTxt
{
Task<string> Convert(string inputFilePath);
Task<string> ConvertAsync(string inputFilePath);
}
}
8 changes: 6 additions & 2 deletions src/Service/Upload/UploadDocumentService.cs
Expand Up @@ -11,17 +11,19 @@ public class UploadDocumentService : IUploadDocumentService
{
public IMongoDatabase mongoDatabase;
private IStorage storage;
private IConvertToTxt converter;

public UploadDocumentService(IMongoDatabase mongoDatabase, IStorage storage)
public UploadDocumentService(IMongoDatabase mongoDatabase, IStorage storage, IConvertToTxt converter)
{
this.mongoDatabase = mongoDatabase;
this.storage = storage;
this.converter = converter;
}

public async Task<string> CreateDocument(UploadFileRequest file)
{
var id = ObjectId.GenerateNewId();
await storage.SaveAsync(id.ToString(), file.Content, file.Name);
var path = await storage.SaveAsync(id.ToString(), file.Content, file.Name);
var mongoDocument = new DocumentMetadata
{
Id = ObjectId.GenerateNewId(),
Expand All @@ -30,6 +32,8 @@ public async Task<string> CreateDocument(UploadFileRequest file)
FileName = file.Name,
};

mongoDocument.FileNameTxt = await converter.ConvertAsync(path);

// autocreates collection locally
var collection = mongoDatabase.GetCollection<DocumentMetadata>("documents");

Expand Down
4 changes: 4 additions & 0 deletions src/Startup.cs
Expand Up @@ -42,6 +42,10 @@ public void ConfigureServices(IServiceCollection services)
});
services.AddTransient<IUploadDocumentService, UploadDocumentService>();
services.AddTransient<IStorage, Storage>();
services.AddTransient<IStorage, Storage>();
services.AddSingleton<IConvertToTxt>(new ConvertToTxt());


// In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
Expand Down

0 comments on commit 7ce3452

Please sign in to comment.