File size: 2,330 Bytes
b1b3bae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
using DWSIM.Interfaces;
using DWSIM.Simulate365.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DWSIM.Simulate365.Models
{
public class S365File : IVirtualFile
{
private string _localTmpFile;
public string ParentUniqueIdentifier { get; set; }
public string FileUniqueIdentifier { get; set; }
public string Filename { get; set; }
/// <summary>
/// Directory path on Simulate 365, doesn't contain file name
/// </summary>
public string FullPath { get; set; }
public UploadConflictAction? ConflictAction { get; set; }
public S365File(string localTmpFile)
{
_localTmpFile = localTmpFile;
}
public void Delete()
{
throw new NotImplementedException();
}
public bool Exists()
{
throw new NotImplementedException();
}
public string GetExtension()
{
return Path.GetExtension(Filename);
}
public Stream OpenRead()
{
return File.OpenRead(_localTmpFile);
}
public string ReadAllText()
{
return System.IO.File.ReadAllText(_localTmpFile);
}
public void Write(string localFilePath)
{
var file = FileUploaderService.UploadFile(FileUniqueIdentifier, ParentUniqueIdentifier, localFilePath, Filename, FullPath, ConflictAction ?? UploadConflictAction.Overwrite);
FileUniqueIdentifier = file.FileUniqueIdentifier;
Filename = file.Filename;
FullPath = file.FullPath;
FileManagementService.GetInstance().FileSavedToDashboard();
}
public void Write(System.IO.Stream stream)
{
var file = FileUploaderService.UploadFile(FileUniqueIdentifier, ParentUniqueIdentifier, stream, Filename, FullPath, ConflictAction ?? UploadConflictAction.Overwrite);
FileUniqueIdentifier = file.FileUniqueIdentifier;
Filename = file.Filename;
FullPath = file.FullPath;
FileManagementService.GetInstance().FileSavedToDashboard();
}
}
}
|