From ffde0a011071b10f335ac511e28fc41d7d8f02f8 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Sat, 2 May 2020 21:25:30 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 137 +++++++++++++++---------- 1 file changed, 85 insertions(+), 52 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 036b1f0..faca659 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -165,6 +165,13 @@ namespace AyaNova.PlugIn.V8 #endregion private Dictionary Map = new Dictionary(); + private long SafeGetUserMap(Guid id) + { + if (!Map.ContainsKey(id)) return 1;//1=raven administrator account + return Map[id]; + + } + private Dictionary TagMap = new Dictionary(); private Dictionary LocaleMap = new Dictionary(); @@ -253,16 +260,10 @@ namespace AyaNova.PlugIn.V8 await ExportUsers(progress); - + if (progress.KeepGoing) + await ExportClients(progress); - //dumpGlobalSettings(tempArchiveFolder, progress); - - //dumpSeedNumbers(tempArchiveFolder, progress); - //dumpClients(tempArchiveFolder, progress); - //dumpHeadOffices(tempArchiveFolder, progress); - // - //NOTE: when get to PRIORITY, or WORKORDER STATUS be sure to add color code as per already done in USER export @@ -311,8 +312,8 @@ namespace AyaNova.PlugIn.V8 bool ShouldExportCustom = ocf != null; var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User"); - //Step 2: export the users - + + //Step 2: export the objects UserPickList pl = UserPickList.GetList(false); progress.Append("Exporting " + pl.Count.ToString() + " Users"); @@ -369,7 +370,7 @@ namespace AyaNova.PlugIn.V8 User c = User.GetItem(i.ID); - var UserTID = new TypeAndID(RootObjectTypes.User, c.ID); + var ObjectTID = new TypeAndID(RootObjectTypes.User, c.ID); dynamic d = new JObject(); d.name = c.FirstName + " " + c.LastName; @@ -416,8 +417,8 @@ namespace AyaNova.PlugIn.V8 var hasWiki = WikiPage.HasWiki(c.ID); if (hasWiki) { - await ExportAttachments(UserTID, progress); - d.wiki = GetWikiContent(UserTID); + await ExportAttachments(ObjectTID, progress); + d.wiki = GetWikiContent(ObjectTID); } //Custom fields? @@ -444,10 +445,10 @@ namespace AyaNova.PlugIn.V8 } //Attachments / FILES - await ExportAttachments(UserTID, progress); + await ExportAttachments(ObjectTID, progress); //docs - string NonFileUrls = await ExportDocs(UserTID, c.Docs, progress); + string NonFileUrls = await ExportDocs(ObjectTID, c.Docs, progress); if (!string.IsNullOrEmpty(NonFileUrls)) { //need to repost the user with the notes modified @@ -477,6 +478,75 @@ namespace AyaNova.PlugIn.V8 } #endregion clients + #region clients + private async System.Threading.Tasks.Task ExportClients(ProgressForm progress) + { + var ObjectTypeName = "Client"; + //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, "Customer"); + + //Step 2: export the objects + ClientPickList pl = ClientPickList.GetList(); + progress.Append("Exporting " + pl.Count.ToString() + ObjectTypeName +"s"); + + foreach (ClientPickList.ClientPickListInfo i in pl) + { + if (!progress.KeepGoing) return; + List tags = new List(); + tags.Add(ImportTag); + + Client c = Client.GetItem(i.ID); + var ObjectTID = new TypeAndID(RootObjectTypes.Client, 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.DispatchZoneID, tags); + Tagit(c.ClientGroupID, tags); + SetTags(d, tags); + + //Attachments and wiki + 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("Customer", 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("Customer/" + RavenId.ToString(), d.ToString()); + } + + //Event log fixup + await util.EventLog(8, RavenId, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified); + + } + } + #endregion clients + + #region locales private async System.Threading.Tasks.Task ExportLocales(ProgressForm progress) { @@ -1128,30 +1198,6 @@ namespace AyaNova.PlugIn.V8 //WIKI - #region Wikiable objects reference - /* - Find all "Util.OpenWikiPage", Whole word, Subfolders, Keep modified files open, Find Results 1, Entire Solution, "" - C:\data\ayanova\source\WinFormApp\ClientInfoForm.cs(1579): Util.OpenWikiPage(RootObjectTypes.Client, mClient.ID,false); - C:\data\ayanova\source\WinFormApp\ContractInfoForm.cs(687): Util.OpenWikiPage(RootObjectTypes.Contract, mContract.ID, false); - C:\data\ayanova\source\WinFormApp\Form1.cs(3713): Util.OpenWikiPage(RootObjectTypes.Global, Address.GlobalAddressID, false); - C:\data\ayanova\source\WinFormApp\Form1.cs(3856): Util.OpenWikiPage(RootObjectTypes.User, User.CurrentThreadUserID, false); - C:\data\ayanova\source\WinFormApp\Form1.cs(3867): // Util.OpenWikiPage(RootObjectTypes.User,User.CurrentThreadUserID,false); - C:\data\ayanova\source\WinFormApp\HeadOfficeInfoForm.cs(1402): Util.OpenWikiPage(RootObjectTypes.HeadOffice, mHeadOffice.ID,false); - C:\data\ayanova\source\WinFormApp\LoanItemInfoForm.cs(860): Util.OpenWikiPage(RootObjectTypes.LoanItem, mLoanItem.ID, false); - C:\data\ayanova\source\WinFormApp\PartInfoForm.cs(1111): Util.OpenWikiPage(RootObjectTypes.Part, mPart.ID, false); - C:\data\ayanova\source\WinFormApp\ProjectInfoForm.cs(712): Util.OpenWikiPage(RootObjectTypes.Project, mProject.ID, false); - C:\data\ayanova\source\WinFormApp\PurchaseOrderInfoForm.cs(1010): Util.OpenWikiPage(RootObjectTypes.PurchaseOrder, mPurchaseOrder.ID, false); - C:\data\ayanova\source\WinFormApp\RegionInfoForm.cs(1186): Util.OpenWikiPage(RootObjectTypes.Region, mRegion.ID, false); - C:\data\ayanova\source\WinFormApp\UnitInfoForm.cs(1280): Util.OpenWikiPage(RootObjectTypes.Unit, mUnit.ID, false); - C:\data\ayanova\source\WinFormApp\UnitModelInfoForm.cs(926): Util.OpenWikiPage(RootObjectTypes.UnitModel, mUnitModel.ID, false); - C:\data\ayanova\source\WinFormApp\UserInfoForm.cs(1395): Util.OpenWikiPage(RootObjectTypes.User, mUser.ID, false); - C:\data\ayanova\source\WinFormApp\VendorInfoForm.cs(1193): Util.OpenWikiPage(RootObjectTypes.Vendor, mVendor.ID, false); - C:\data\ayanova\source\WinFormApp\WorkorderForm.cs(10332): Util.OpenWikiPage(mWorkorder.RootObjectType, mWorkorder.ID, false);//case 1584 was RootObjectTypes.Workorder - C:\data\ayanova\source\WBI\maingrid.aspx.cs(1277): Util.OpenWikiPage(this.Page, new TypeAndID(RootObjectTypes.Global, Address.GlobalAddressID)); - C:\data\ayanova\source\WBI\schedule.aspx.cs(187): Util.OpenWikiPage(this.Page, new TypeAndID(RootObjectTypes.Global, Address.GlobalAddressID)); - Matching lines: 18 Matching files: 16 Total files searched: 1769 - */ - #endregion private string GetWikiContent(TypeAndID tid) { @@ -1718,19 +1764,6 @@ and this one } #endregion globalsettings - #region clients - private void ExportClients(ProgressForm progress) - { - ClientPickList pl = ClientPickList.GetList(); - progress.Append("Dumping " + pl.Count.ToString() + " Clients"); - foreach (ClientPickList.ClientPickListInfo i in pl) - { - Client c = Client.GetItem(i.ID); - //DumpObjectToFolder(tempArchiveFolder, c, "client." + c.ID.ToString(), objectExcludeProperties, new TypeAndID(RootObjectTypes.Client, c.ID)); - - } - } - #endregion clients #region headoffices private void ExportHeadOffices(ProgressForm progress)