This commit is contained in:
2020-04-29 18:58:36 +00:00
parent 23d69ae1d0
commit 0abc8de546
4 changed files with 240 additions and 208 deletions

View File

@@ -175,6 +175,7 @@
this.Controls.Add(this.pictureBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Auth";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Erase all data on v8 server and import from v7";
this.Load += new System.EventHandler(this.Auth_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();

View File

@@ -31,6 +31,8 @@
this.edOut = new System.Windows.Forms.TextBox();
this.btnClose = new System.Windows.Forms.Button();
this.lblCurrent = new System.Windows.Forms.Label();
this.edCurrent = new System.Windows.Forms.TextBox();
this.edSubOp = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// edOut
@@ -43,7 +45,7 @@
this.edOut.Name = "edOut";
this.edOut.ReadOnly = true;
this.edOut.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.edOut.Size = new System.Drawing.Size(870, 513);
this.edOut.Size = new System.Drawing.Size(870, 461);
this.edOut.TabIndex = 0;
//
// btnClose
@@ -51,7 +53,7 @@
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnClose.Location = new System.Drawing.Point(777, 577);
this.btnClose.Location = new System.Drawing.Point(777, 603);
this.btnClose.Margin = new System.Windows.Forms.Padding(2);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(82, 32);
@@ -69,13 +71,37 @@
this.lblCurrent.Size = new System.Drawing.Size(846, 23);
this.lblCurrent.TabIndex = 2;
//
// edCurrent
//
this.edCurrent.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.edCurrent.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.edCurrent.Location = new System.Drawing.Point(0, 504);
this.edCurrent.Name = "edCurrent";
this.edCurrent.ReadOnly = true;
this.edCurrent.Size = new System.Drawing.Size(870, 22);
this.edCurrent.TabIndex = 3;
//
// edSubOp
//
this.edSubOp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.edSubOp.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.edSubOp.Location = new System.Drawing.Point(0, 532);
this.edSubOp.Name = "edSubOp";
this.edSubOp.ReadOnly = true;
this.edSubOp.Size = new System.Drawing.Size(870, 22);
this.edSubOp.TabIndex = 4;
//
// ProgressForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnClose;
this.ClientSize = new System.Drawing.Size(870, 620);
this.ClientSize = new System.Drawing.Size(870, 646);
this.ControlBox = false;
this.Controls.Add(this.edSubOp);
this.Controls.Add(this.edCurrent);
this.Controls.Add(this.lblCurrent);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.edOut);
@@ -94,5 +120,7 @@
private System.Windows.Forms.TextBox edOut;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Label lblCurrent;
private System.Windows.Forms.TextBox edCurrent;
private System.Windows.Forms.TextBox edSubOp;
}
}

View File

@@ -34,6 +34,26 @@ namespace AyaNova.PlugIn.V8
edOut.AppendText(txt + "\r\n");
}
public void Op(string txt)
{
edCurrent.Text = txt;
}
public string LastOp
{
get { return edCurrent.Text; }
}
public void SubOp(string txt)
{
edSubOp.Text = txt;
}
public string LastSubOp
{
get { return edSubOp.Text; }
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();

View File

@@ -170,6 +170,7 @@ namespace AyaNova.PlugIn.V8
progress.Append("Exporting data to AyaNova server @ " + util.ApiBaseUrl);
try
{
progress.Op("Preparing to export....");
Map.Clear();
TagMap.Clear();
CustomFieldLocaleKeys.Clear();
@@ -181,6 +182,8 @@ namespace AyaNova.PlugIn.V8
/*
TODO:
* Current operation progress feedback
*
* wiki / attached docs
*
* locales
@@ -196,10 +199,11 @@ namespace AyaNova.PlugIn.V8
//Export in correct order:
//ERASE DB
progress.Op("Erasing AyaNova 8 data");
var a = await util.PostAsync("License/PermanentlyEraseAllData", "\"I understand\"");
if (!a.HttpResponse.IsSuccessStatusCode) { MessageBox.Show("Error erasing database: \n" + a.HttpResponse.ReasonPhrase); return; }
//TAGS
progress.Op("Compiling tags");
ExportUnitModelCategories(progress);
ExportUnitServiceTypes(progress);
ExportWorkorderItemTypes(progress);
@@ -212,6 +216,7 @@ namespace AyaNova.PlugIn.V8
ExportUserSkills(progress);
ExportUserCertifications(progress);
progress.Op("Exporting objects");
//BIZ objects
await ExportUsers(progress);
// await ExportLocales(progress);
@@ -232,13 +237,20 @@ namespace AyaNova.PlugIn.V8
progress.Append("Export completed");
progress.Op("");
}
catch (Exception ex)
{
progress.Append("ERROR, During operation: " + progress.LastOp + "\n"+progress.LastSubOp);
progress.Append("\n************\nExport failed with error:");
progress.Append(ex.Message);
progress.Append("stack:\n" + ex.StackTrace);
}
progress.FinishedImport();
finally {
progress.FinishedImport();
}
//-----------------------------------
//endof method
@@ -249,104 +261,7 @@ namespace AyaNova.PlugIn.V8
#region Object Export methods
#region Global settings
private void ExportGlobalSettings(ProgressForm progress)
{
progress.Append("STUB: Dumping Global Settings");
////DumpObjectToFolder(tempArchiveFolder, AyaBizUtils.GlobalSettings, "globalsettings", objectExcludeProperties, new TypeAndID(RootObjectTypes.Global, Address.GlobalAddressID));
}
#endregion globalsettings
#region locales
private void ExportLocales(ProgressForm progress)
{
// List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//Skip stock locales already handled in Raven
List<string> SkipLocales = new List<string>();
SkipLocales.Add("Deutsch");
SkipLocales.Add("English");
SkipLocales.Add("Español");
SkipLocales.Add("Français");
LocaleList l = LocaleList.GetList();
progress.Append("Dumping " + l.Count.ToString() + " Locales");
foreach (LocaleList.LocaleListInfo i in l)
{
if (!SkipLocales.Contains(i.Locale))
{
LocalizedTextTable lt = LocalizedTextTable.Load(i.Locale);
//DumpObjectToFolder(tempArchiveFolder, lt.LT, "translation." + EnsureValidFileName(i.Locale), objectExcludeProperties, TypeAndID.Empty, "GZTW.AyaNova.BLL.Translation");
}
}
}
#endregion locales
#region Seeds
private class GZSeeds
{
public int InventoryAdjustmentStartSeed = 1;
public int PurchaseOrderStartSeed = 1;
public int QuoteNumberStartSeed = 1;
public int WorkorderNumberStartSeed = 1;
public int PreventiveMaintenanceNumberStartSeed = 1;
}
private void ExportSeedNumbers(ProgressForm progress)
{
// List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
progress.Append("Dumping seeds");
//create a new object with the id numbers in it and then dump it
WorkorderPMList pml = WorkorderPMList.GetList("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?> \r\n" +
"<GRIDCRITERIA> \r\n" +
" <COLUMNITEM CM=\"aWorkorderPreventiveMaintenance.aPreventiveMaintenanceNumber\" UI=\"LT_O_WorkorderPreventiveMaintenance\" PIN=\"0\" WIDTH=\"150\" SORT=\"DESC\" /> \r\n" +
"</GRIDCRITERIA> ");
int PMStartSeed = 0;
if (pml.Count > 0)
{
PMStartSeed = int.Parse(pml[0].LT_O_WorkorderPreventiveMaintenance.Display);
}
var seeds = new GZSeeds();
seeds.InventoryAdjustmentStartSeed = AyaBizUtils.GlobalSettings.InventoryAdjustmentStartSeed + 1;
seeds.PurchaseOrderStartSeed = AyaBizUtils.GlobalSettings.PurchaseOrderStartSeed + 1;
seeds.QuoteNumberStartSeed = AyaBizUtils.GlobalSettings.QuoteNumberStartSeed + 1;
seeds.WorkorderNumberStartSeed = AyaBizUtils.GlobalSettings.WorkorderNumberStartSeed + 1;
seeds.PreventiveMaintenanceNumberStartSeed = PMStartSeed + 1;
//DumpObjectToFolder(tempArchiveFolder, seeds, "seeds", objectExcludeProperties, TypeAndID.Empty, "GZTW.AyaNova.BLL.Seed");
}
#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)
{
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 users
private async System.Threading.Tasks.Task ExportUsers(ProgressForm progress)
@@ -364,6 +279,7 @@ namespace AyaNova.PlugIn.V8
#region Export administrator wiki and attached files if present
User admin = User.GetItem(User.AdministratorID);
progress.Op("Administrator account");
//wiki page
var adminWiki = GetWikiContent(new TypeAndID(RootObjectTypes.User, admin.ID));
@@ -387,7 +303,7 @@ namespace AyaNova.PlugIn.V8
//Attachments
if (adminWiki != null)
await ExportAttachments(new TypeAndID(RootObjectTypes.User, User.AdministratorID));
await ExportAttachments(new TypeAndID(RootObjectTypes.User, User.AdministratorID), progress);
#endregion admin export
@@ -401,9 +317,10 @@ namespace AyaNova.PlugIn.V8
if (i.ID == User.AdministratorID) continue;
User c = User.GetItem(i.ID);
dynamic d = new JObject();
d.name = c.FirstName + " " + c.LastName;
progress.Op("User " + d.name);
d.userType = (int)c.UserType;
//if special 3rd party user type then set their parent object id to -1 to signify will fill in later and satisfy biz rules at server
@@ -455,6 +372,7 @@ namespace AyaNova.PlugIn.V8
d.customFields = CustomFieldData(c, DateCustomFields);
}
var a = await util.PostAsync("User", d.ToString());
long RavenId = util.IdFromResponse(a);
Map.Add(c.ID, RavenId);
@@ -471,7 +389,7 @@ namespace AyaNova.PlugIn.V8
}
//Attachments / FILES
await ExportAttachments(new TypeAndID(RootObjectTypes.User, c.ID));
await ExportAttachments(new TypeAndID(RootObjectTypes.User, c.ID),progress);
}
@@ -599,6 +517,7 @@ namespace AyaNova.PlugIn.V8
}
#endregion TAG ITEMS
//--------------------------------------------
#endregion object export
@@ -715,6 +634,70 @@ namespace AyaNova.PlugIn.V8
}
#endregion custom fields
#region Attachments exporter
private async System.Threading.Tasks.Task ExportAttachments(TypeAndID tid, ProgressForm progress)
{
if (!WikiPage.HasWiki(tid.ID)) return;
WikiPage w = WikiPage.GetItem(tid);
AyaFileList fl = AyaFileList.GetList(w.ID);
if (fl.Count == 0) return;
//iterate the files
foreach (AyaFileList.AyaFileListInfo i in fl)
{
var af = AyaFile.GetItem(i.LT_O_AyaFile.Value);
if (af == null) continue;
progress.SubOp("Wikifile: \"" + af.Name + "\" size:" + af.FileSize);
//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();
}
}
dynamic dFileData = new JArray();
dynamic dFile = new JObject();
dFile.name = af.Name;
dFile.lastModified = dtLastModified.ToUnixTimeMilliseconds();
dFileData.Add(dFile);
//Upload
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
//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(dFileData.ToString()), name: "FileData");
StreamContent AttachmentFile = new StreamContent(af.GetContent());
AttachmentFile.Headers.ContentType = new MediaTypeHeaderValue(af.mimeType);
AttachmentFile.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
AttachmentFile.Headers.ContentDisposition.FileName = af.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);
}
}
#endregion attachments
#region WIKI page exporter
@@ -753,6 +736,9 @@ namespace AyaNova.PlugIn.V8
WikiPage w = WikiPage.GetItem(tid);
var content = w.GetContentAsString;
//TODO: fixup internal urls using MAP of file attachment uploads
//TODO: Convert to Markdown format
if (!string.IsNullOrWhiteSpace(content))
return content;
else
@@ -760,103 +746,7 @@ namespace AyaNova.PlugIn.V8
}
private async System.Threading.Tasks.Task ExportAttachments(TypeAndID tid)
{
if (!WikiPage.HasWiki(tid.ID)) return;
WikiPage w = WikiPage.GetItem(tid);
AyaFileList fl = AyaFileList.GetList(w.ID);
if (fl.Count == 0) return;
//files
foreach (AyaFileList.AyaFileListInfo i in fl)
{
//WikiFileInfo fi = new WikiFileInfo();
// fi.Id = i.LT_O_AyaFile.Value.ToString();
// fi.Name = i.LT_O_AyaFile.Display;
// fi.Size = i.LT_AyaFile_Label_FileSize;
// fi.Creator = i.LT_Common_Label_Creator.Display;
// fi.Created = i.LT_Common_Label_Created.ToString();
// ret.Add(fi);
var af = AyaFile.GetItem(i.LT_O_AyaFile.Value);
if (af == null) continue;
//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();
}
}
dynamic dFileData = new JArray();
dynamic dFile = new JObject();
dFile.name = af.Name;
dFile.lastModified = dtLastModified.ToUnixTimeMilliseconds();
dFileData.Add(dFile);
//Upload
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
//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(dFileData.ToString()), name: "FileData");
//or if testing non-existant this is probably safe: long.MaxValue
StreamContent AttachmentFile = new StreamContent(af.GetContent());
AttachmentFile.Headers.ContentType = new MediaTypeHeaderValue(af.mimeType);
AttachmentFile.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
AttachmentFile.Headers.ContentDisposition.FileName = af.Name;
AttachmentFile.Headers.ContentDisposition.ModificationDate = dtLastModified;
formDataContent.Add(AttachmentFile);
//create via inventory full test user as attachments use the role of the object attaching to
await util.PostFormDataAsync("Attachment", formDataContent);
//af.WriteToDisk(filePath, af.Name);
//var fileInfo = new
//{
// name = i.LT_O_AyaFile.Display,
// created = i.LT_Common_Label_Created,
// creator = i.LT_Common_Label_Creator.Value,
// mimetype = af.mimeType,
// id = af.ID,
// size = af.FileSize,
// ayafiletype = af.FileType,
// rootobjectid = af.RootObjectID,
// rootobjecttype = af.RootObjectType
//};
}
}
#endregion wiki
@@ -884,12 +774,105 @@ namespace AyaNova.PlugIn.V8
#endregion tags
#region OLD JSON EXPORT STUFF
#region Global settings
private void ExportGlobalSettings(ProgressForm progress)
{
progress.Append("STUB: Dumping Global Settings");
////DumpObjectToFolder(tempArchiveFolder, AyaBizUtils.GlobalSettings, "globalsettings", objectExcludeProperties, new TypeAndID(RootObjectTypes.Global, Address.GlobalAddressID));
}
#endregion globalsettings
#region locales
private void ExportLocales(ProgressForm progress)
{
// List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//Skip stock locales already handled in Raven
List<string> SkipLocales = new List<string>();
SkipLocales.Add("Deutsch");
SkipLocales.Add("English");
SkipLocales.Add("Español");
SkipLocales.Add("Français");
LocaleList l = LocaleList.GetList();
progress.Append("Dumping " + l.Count.ToString() + " Locales");
foreach (LocaleList.LocaleListInfo i in l)
{
if (!SkipLocales.Contains(i.Locale))
{
LocalizedTextTable lt = LocalizedTextTable.Load(i.Locale);
//DumpObjectToFolder(tempArchiveFolder, lt.LT, "translation." + EnsureValidFileName(i.Locale), objectExcludeProperties, TypeAndID.Empty, "GZTW.AyaNova.BLL.Translation");
}
}
}
#endregion locales
#region Seeds
private class GZSeeds
{
public int InventoryAdjustmentStartSeed = 1;
public int PurchaseOrderStartSeed = 1;
public int QuoteNumberStartSeed = 1;
public int WorkorderNumberStartSeed = 1;
public int PreventiveMaintenanceNumberStartSeed = 1;
}
private void ExportSeedNumbers(ProgressForm progress)
{
// List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
progress.Append("Dumping seeds");
//create a new object with the id numbers in it and then dump it
WorkorderPMList pml = WorkorderPMList.GetList("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?> \r\n" +
"<GRIDCRITERIA> \r\n" +
" <COLUMNITEM CM=\"aWorkorderPreventiveMaintenance.aPreventiveMaintenanceNumber\" UI=\"LT_O_WorkorderPreventiveMaintenance\" PIN=\"0\" WIDTH=\"150\" SORT=\"DESC\" /> \r\n" +
"</GRIDCRITERIA> ");
int PMStartSeed = 0;
if (pml.Count > 0)
{
PMStartSeed = int.Parse(pml[0].LT_O_WorkorderPreventiveMaintenance.Display);
}
var seeds = new GZSeeds();
seeds.InventoryAdjustmentStartSeed = AyaBizUtils.GlobalSettings.InventoryAdjustmentStartSeed + 1;
seeds.PurchaseOrderStartSeed = AyaBizUtils.GlobalSettings.PurchaseOrderStartSeed + 1;
seeds.QuoteNumberStartSeed = AyaBizUtils.GlobalSettings.QuoteNumberStartSeed + 1;
seeds.WorkorderNumberStartSeed = AyaBizUtils.GlobalSettings.WorkorderNumberStartSeed + 1;
seeds.PreventiveMaintenanceNumberStartSeed = PMStartSeed + 1;
//DumpObjectToFolder(tempArchiveFolder, seeds, "seeds", objectExcludeProperties, TypeAndID.Empty, "GZTW.AyaNova.BLL.Seed");
}
#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)
{
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