From 22b71af0ec288521a6ef88ce1fba93eafc0ddd58 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Sat, 2 May 2020 23:06:02 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 86 +++++++++++++++++++++----- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 6d66fbc..9557f5b 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -18,7 +18,6 @@ using System.Net.Http.Headers; - namespace AyaNova.PlugIn.V8 { class V8 : IAyaNovaPlugin @@ -255,6 +254,7 @@ namespace AyaNova.PlugIn.V8 await ExportLocales(progress); await ExportUsers(progress); await ExportClients(progress); + await ExportHeadOffices(progress); //NOTE: when get to PRIORITY, or WORKORDER STATUS be sure to add color code as per already done in USER export @@ -538,6 +538,76 @@ namespace AyaNova.PlugIn.V8 } #endregion clients + #region Headoffices + private async System.Threading.Tasks.Task ExportHeadOffices(ProgressForm progress) + { + if (!progress.KeepGoing) return; + var ObjectTypeName = "HeadOffice"; + //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("**", "headoffice"); + + + + progress.Append("Exporting " + pl.Count.ToString() + ObjectTypeName + "s"); + + foreach (PickListAutoComplete.PickListAutoCompleteInfo i in pl ) + { + if (!progress.KeepGoing) return; + List tags = new List(); + tags.Add(ImportTag); + + HeadOffice c = HeadOffice.GetItem(i.ID); + var ObjectTID = new TypeAndID(RootObjectTypes.HeadOffice, 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.RegionID, tags); + Tagit(c.ClientGroupID, tags); + SetTags(d, tags); + + var hasWiki = WikiPage.HasWiki(c.ID); + if (hasWiki) + { + //await ExportAttachments(ObjectTID, progress); + d.wiki = GetWikiContent(ObjectTID); + } + + //Custom fields? + if (ShouldExportCustom) + d.customFields = CustomFieldData(c, DateCustomFields); + + var rMainObject = await util.PostAsync("HeadOffice", d.ToString()); + long RavenId = util.IdFromResponse(rMainObject); + Map.Add(c.ID, RavenId); + + //Attachments / FILES + await ExportAttachments(ObjectTID, progress); + + //docs + string NonFileUrls = await ExportDocs(ObjectTID, c.Docs, progress); + if (!string.IsNullOrEmpty(NonFileUrls)) + { + //need to repost the object with the notes modified + d = rMainObject.ObjectResponse["data"]; + d.notes = NonFileUrls + "\n-----------------\n" + d.notes; + await util.PutAsync("HeadOffice/" + RavenId.ToString(), d.ToString()); + } + + //Event log fixup + await util.EventLog(util.AyaType.HeadOffice, RavenId, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified); + + } + } + #endregion ho + #region locales private async System.Threading.Tasks.Task ExportLocales(ProgressForm progress) @@ -1758,20 +1828,6 @@ and this one #endregion globalsettings - #region headoffices - private void ExportHeadOffices(ProgressForm progress) - { - - PickListAutoComplete pl = PickListAutoComplete.GetList("**", "headoffice"); - - progress.Append("Dumping " + pl.Count.ToString() + " Head offices"); - foreach (PickListAutoComplete.PickListAutoCompleteInfo i in pl) - { - HeadOffice c = HeadOffice.GetItem(i.ID); - //DumpObjectToFolder(tempArchiveFolder, c, "headoffice." + c.ID.ToString(), excludes, new TypeAndID(RootObjectTypes.HeadOffice, c.ID)); - } - } - #endregion clients #region contract resolver //public class ExcludeNamedPropertiesContractResolver : DefaultContractResolver