This commit is contained in:
2020-05-02 15:46:09 +00:00
parent 975f108071
commit 891dbb9321
3 changed files with 821 additions and 40 deletions

View File

@@ -15,8 +15,8 @@ using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
//using HtmlAgilityPack;
//using ReverseMarkdown;
namespace AyaNova.PlugIn.V8
@@ -428,15 +428,15 @@ namespace AyaNova.PlugIn.V8
if (ShouldExportCustom)
d.customFields = CustomFieldData(c, DateCustomFields);
var a = await util.PostAsync("User", d.ToString());
long RavenId = util.IdFromResponse(a);
var rMainObject = await util.PostAsync("User", d.ToString());
long RavenId = util.IdFromResponse(rMainObject);
Map.Add(c.ID, RavenId);
//USER OPTIONS
if (c.ScheduleBackColor != 0 || !string.IsNullOrWhiteSpace(c.EmailAddress))
{
a = await util.GetAsync("UserOptions/" + RavenId.ToString());
d = a.ObjectResponse["data"];
var rOptions = await util.GetAsync("UserOptions/" + RavenId.ToString());
d = rOptions.ObjectResponse["data"];
d.uiColor = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(c.ScheduleBackColor));
d.emailAddress = string.IsNullOrWhiteSpace(c.EmailAddress) ? null : c.EmailAddress;
d.translationId = LocaleMap[c.DefaultLanguage];
@@ -448,7 +448,13 @@ namespace AyaNova.PlugIn.V8
await ExportAttachments(UserTID, progress);
//docs
await ExportDocs(UserTID, c.Docs, progress);
string NonFileUrls= await ExportDocs(UserTID, c.Docs, progress);
if (!string.IsNullOrEmpty(NonFileUrls)) {
//need to repost the user with the notes modified
d = rMainObject.ObjectResponse["data"];
d.notes = NonFileUrls + "\r\n-----------------\r\n" + d.notes;
await util.PutAsync("User", d.ToString());
}
}
@@ -1015,7 +1021,16 @@ namespace AyaNova.PlugIn.V8
formDataContent.Add(new StringContent(dFileData.ToString()), name: "FileData");
StreamContent AttachmentFile = new StreamContent(af.GetContent());
AttachmentFile.Headers.ContentType = new MediaTypeHeaderValue(af.mimeType);
//try to get a more accurate mimetype than was originally
//in v7 as it uses the same method but from long ago and far far away...
string MType = af.mimeType;
try
{
MType = MimeTypeMap.GetMimeType(Path.GetExtension(af.Name));//latest up to date mime type
}
catch { }
AttachmentFile.Headers.ContentType = new MediaTypeHeaderValue(MType);
AttachmentFile.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
AttachmentFile.Headers.ContentDisposition.FileName = af.Name;
@@ -1035,52 +1050,45 @@ namespace AyaNova.PlugIn.V8
#endregion attachments
#region Assigned docs exporter
private async System.Threading.Tasks.Task<List<string>> ExportDocs(TypeAndID tid, AssignedDocs docs, ProgressForm progress)
private async System.Threading.Tasks.Task<string> ExportDocs(TypeAndID tid, AssignedDocs docs, ProgressForm progress)
{
List<string> NonFileUrls = new List<string>();
if (!ExportAssignedDocs) return NonFileUrls;
if (docs.Count == 0) return NonFileUrls;
if (!ExportAssignedDocs) return null;
if (docs.Count == 0) return null;
string NonFileUrls = string.Empty;
//iterate the files
foreach (AssignedDoc doc in docs)
{
if (!progress.KeepGoing) return NonFileUrls;
if (!progress.KeepGoing) return null;
//is it a local file?
if (!new Uri(doc.URL).IsFile)
{
NonFileUrls.Add(doc.Description + "("+ImportTag+ ")\n" + doc.URL+"\n");
NonFileUrls+=(doc.Description + "("+ImportTag+ ")\n" + doc.URL+"\n");
continue;
}
//can we see it?
if (!File.Exists(doc.URL))
{
NonFileUrls.Add(ImportTag + " - Assigned doc. file not found:\n" + doc.Description + "\n" + doc.URL + "\n");
NonFileUrls+=(ImportTag + " - Assigned doc. file not found:\n" + doc.Description + "\n" + doc.URL + "\n");
continue;
}
progress.SubOp("Wikifile: \"" + af.Name + "\" " + AyaBizUtils.FileSizeDisplay((decimal)af.FileSize));
//get the file info
FileInfo fi = new FileInfo(doc.URL);
progress.SubOp("Assigned doc: \"" + doc.URL + "\" " + AyaBizUtils.FileSizeDisplay((decimal)fi.Length));
//Compile the FileData property
var sDate = i.LT_Common_Label_Created.ToString();
DateTimeOffset dtLastModified = DateTime.UtcNow;
if (sDate != null)
{
//parse out to UTC date
DateTime dt = new DateTime();
if (DateTime.TryParse(sDate, out dt))
{
dtLastModified = dt.ToUniversalTime();
}
}
DateTimeOffset dtLastModified = fi.LastWriteTimeUtc;
dynamic dFileData = new JArray();
dynamic dFile = new JObject();
dFile.name = af.Name;
dFile.name = fi.Name;
dFile.lastModified = dtLastModified.ToUnixTimeMilliseconds();
dFileData.Add(dFile);
@@ -1091,22 +1099,20 @@ namespace AyaNova.PlugIn.V8
//Form data like the bizobject type and id
formDataContent.Add(new StringContent(util.RootObjectToAyaType(tid.RootObjectType).ToString()), name: "AttachToObjectType");
formDataContent.Add(new StringContent(Map[tid.ID].ToString()), name: "AttachToObjectId");
formDataContent.Add(new StringContent(ImportTag), name: "Notes");
formDataContent.Add(new StringContent(doc.Description+" ("+ImportTag+")"), name: "Notes");
formDataContent.Add(new StringContent(dFileData.ToString()), name: "FileData");
StreamContent AttachmentFile = new StreamContent(af.GetContent());
AttachmentFile.Headers.ContentType = new MediaTypeHeaderValue(af.mimeType);
StreamContent AttachmentFile = new StreamContent(fi.OpenRead());
AttachmentFile.Headers.ContentType = new MediaTypeHeaderValue(MimeTypeMap.GetMimeType(fi.Extension));
AttachmentFile.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
AttachmentFile.Headers.ContentDisposition.FileName = af.Name;
AttachmentFile.Headers.ContentDisposition.FileName = fi.Name;
AttachmentFile.Headers.ContentDisposition.ModificationDate = dtLastModified;
formDataContent.Add(AttachmentFile);
//Upload
var a = await util.PostFormDataAsync("Attachment", formDataContent);
//Map it for later processing of wiki
var ravenId = a.ObjectResponse["data"][0]["id"].Value<long>();
Map.Add(af.ID, ravenId);
await util.PostFormDataAsync("Attachment", formDataContent);
//No need to map it or save response as long as it works that's all that matters
}