This commit is contained in:
2020-05-03 15:04:43 +00:00
parent 8ab96ab1a5
commit 44019869cb

View File

@@ -261,8 +261,8 @@ namespace AyaNova.PlugIn.V8
await ExportProjects(progress);
await ExportPurchaseOrders(progress);
await ExportUnits(progress);
//await ExportUnitModels(progress);
//await ExportVendors(progress);
await ExportUnitModels(progress);
await ExportVendors(progress);
//workorders once work out the actual objects and routes at server end
@@ -1089,7 +1089,155 @@ namespace AyaNova.PlugIn.V8
}
#endregion Units
#region UnitModels
private async System.Threading.Tasks.Task ExportUnitModels(ProgressForm progress)
{
if (!progress.KeepGoing) return;
var ObjectTypeName = "UnitModel";
//Step 1: export the CustomFields to FormCustom if applicable so that when doing individual items we can export their custom data too
var ocf = ObjectHasCustomFieldDataToExport(ObjectTypeName);
bool ShouldExportCustom = ocf != null;
var DateCustomFields = await ExportCustomFieldSchema(ocf, ObjectTypeName, ObjectTypeName);
//Step 2: export the objects
PickListAutoComplete pl = PickListAutoComplete.GetList("**", "unitmodel");
progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + "s");
foreach (PickListAutoComplete.PickListAutoCompleteInfo i in pl)
{
if (!progress.KeepGoing) return;
List<string> tags = new List<string>();
tags.Add(ImportTag);
UnitModel c = UnitModel.GetItem(i.ID);
var ObjectTID = new TypeAndID(RootObjectTypes.UnitModel, c.ID);
dynamic d = new JObject();
d.name = c.Name;
progress.Op(ObjectTypeName + " " + d.name);
d.active = c.Active;
d.notes = c.Notes;
Tagit(c.UnitModelCategoryID, tags);
SetTags(d, tags);
//Custom fields?
if (ShouldExportCustom)
d.customFields = CustomFieldData(c, DateCustomFields);
var rMainObject = await util.PostAsync(ObjectTypeName, d.ToString());
long RavenId = util.IdFromResponse(rMainObject);
Map.Add(c.ID, RavenId);
//Attachments / FILES
await ExportAttachments(ObjectTID, progress);
//-----
bool repost = false;
d = rMainObject.ObjectResponse["data"];
// wiki
if (WikiPage.HasWiki(c.ID))
{
// await ExportAttachments(ObjectTID, progress);
d.wiki = GetWikiContent(ObjectTID);
repost = true;
}
//docs
string NonFileUrls = await ExportDocs(ObjectTID, c.Docs, progress);
if (!string.IsNullOrEmpty(NonFileUrls))
{
//need to repost the user with the notes modified
d.login = null;
d.password = null;
d.notes = NonFileUrls + "\n-----------------\n" + d.notes;
repost = true;
}
if (repost)
await util.PutAsync(ObjectTypeName + "/" + RavenId.ToString(), d.ToString());
//-----
//Event log fixup
await util.EventLog(util.AyaType.UnitModel, RavenId, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified);
}
}
#endregion UnitModels
#region Vendors
private async System.Threading.Tasks.Task ExportVendors(ProgressForm progress)
{
if (!progress.KeepGoing) return;
var ObjectTypeName = "Vendor";
//Step 1: export the CustomFields to FormCustom if applicable so that when doing individual items we can export their custom data too
var ocf = ObjectHasCustomFieldDataToExport(ObjectTypeName);
bool ShouldExportCustom = ocf != null;
var DateCustomFields = await ExportCustomFieldSchema(ocf, ObjectTypeName, ObjectTypeName);
//Step 2: export the objects
PickListAutoComplete pl = PickListAutoComplete.GetList("**", "vendor");
progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + "s");
foreach (PickListAutoComplete.PickListAutoCompleteInfo i in pl)
{
if (!progress.KeepGoing) return;
List<string> tags = new List<string>();
tags.Add(ImportTag);
Vendor c = Vendor.GetItem(i.ID);
var ObjectTID = new TypeAndID(RootObjectTypes.Vendor, c.ID);
dynamic d = new JObject();
d.name = c.Name;
progress.Op(ObjectTypeName + " " + d.name);
d.active = c.Active;
d.notes = c.Notes;
SetTags(d, tags);
//Custom fields?
if (ShouldExportCustom)
d.customFields = CustomFieldData(c, DateCustomFields);
var rMainObject = await util.PostAsync(ObjectTypeName, d.ToString());
long RavenId = util.IdFromResponse(rMainObject);
Map.Add(c.ID, RavenId);
//Attachments / FILES
await ExportAttachments(ObjectTID, progress);
//-----
bool repost = false;
d = rMainObject.ObjectResponse["data"];
// wiki
if (WikiPage.HasWiki(c.ID))
{
// await ExportAttachments(ObjectTID, progress);
d.wiki = GetWikiContent(ObjectTID);
repost = true;
}
//docs
string NonFileUrls = await ExportDocs(ObjectTID, c.Docs, progress);
if (!string.IsNullOrEmpty(NonFileUrls))
{
//need to repost the user with the notes modified
d.login = null;
d.password = null;
d.notes = NonFileUrls + "\n-----------------\n" + d.notes;
repost = true;
}
if (repost)
await util.PutAsync(ObjectTypeName + "/" + RavenId.ToString(), d.ToString());
//-----
//Event log fixup
await util.EventLog(util.AyaType.Vendor, RavenId, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified);
}
}
#endregion Vendors