This commit is contained in:
2020-04-28 00:11:47 +00:00
parent 3c4acc3911
commit d536bff961
3 changed files with 117 additions and 115 deletions

View File

@@ -30,6 +30,15 @@ namespace AyaNova.PlugIn.V8
}
private async void btnOk_Click(object sender, EventArgs e)
{
if (!util.Initialized)
{
var result = await util.TestUrlAsync(edServerUrl.Text);
if (result != "OK")
{
MessageBox.Show("Server could not be reached at that URL\n" + result);
return;
}
}
var res = await util.AuthenticateAsync(edUserName.Text,edPassword.Text);
if (!res)
{

View File

@@ -125,11 +125,13 @@ namespace AyaNova.PlugIn.V8
return;
}
#if(!DEBUG)
if (!AyaBizUtils.AyaNovaConnectionSetting.SingleUserConnection)
{
MessageBox.Show("** WARNING: before proceeding ensure no other users are logged into AyaNova to ensure the integrity of your exported data. Failing to do so *will* result in damaged data. ***");
MessageBox.Show("** WARNING: before proceeding make sure your AyaNova Generator service is STOPPED to ensure the integrity of your exported data. Failing to do so *will* result in damaged data. ***");
}
#endif
Auth d = new Auth();
var res = d.ShowDialog(); ;
@@ -139,7 +141,7 @@ namespace AyaNova.PlugIn.V8
}
//here because we logged in fine and can proceed
MessageBox.Show("Login successful! JWT is " + util.JWT);
//MessageBox.Show("Login successful! JWT is " + util.JWT);
//Only one command
DoExport();
}
@@ -188,19 +190,10 @@ namespace AyaNova.PlugIn.V8
//dumpHeadOffices(tempArchiveFolder, progress);
//
//NOTE: when get to PRIORITY, or WORKORDER STATUS be sure to add color code as per already done in USER export
//progress.Append("Zipping up archive");
//FastZip fastZip = new FastZip();
//fastZip.CreateZip(zipName, tempArchiveFolder, true, null);
//progress.Append("Cleaning up temporary folder");
//Directory.Delete(tempArchiveFolder, true);
progress.Append("Export completed");
progress.FinishedImport();
@@ -217,8 +210,8 @@ namespace AyaNova.PlugIn.V8
private void ExportGlobalSettings(ProgressForm progress)
{
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
progress.Append("Dumping Global Settings");
DumpObjectToFolder(tempArchiveFolder, AyaBizUtils.GlobalSettings, "globalsettings", objectExcludeProperties, new TypeAndID(RootObjectTypes.Global, Address.GlobalAddressID));
progress.Append("STUB: Dumping Global Settings");
////DumpObjectToFolder(tempArchiveFolder, AyaBizUtils.GlobalSettings, "globalsettings", objectExcludeProperties, new TypeAndID(RootObjectTypes.Global, Address.GlobalAddressID));
}
#endregion globalsettings
@@ -241,7 +234,7 @@ namespace AyaNova.PlugIn.V8
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");
//DumpObjectToFolder(tempArchiveFolder, lt.LT, "translation." + EnsureValidFileName(i.Locale), objectExcludeProperties, TypeAndID.Empty, "GZTW.AyaNova.BLL.Translation");
}
}
}
@@ -259,7 +252,7 @@ namespace AyaNova.PlugIn.V8
{
Region o = Region.GetItem(i.LT_Region_Label_Name.Value);
DumpObjectToFolder(tempArchiveFolder, o, "region." + o.ID.ToString(), objectExcludeProperties, new TypeAndID(RootObjectTypes.Region, o.ID));
//DumpObjectToFolder(tempArchiveFolder, o, "region." + o.ID.ToString(), objectExcludeProperties, new TypeAndID(RootObjectTypes.Region, o.ID));
}
}
@@ -297,7 +290,7 @@ namespace AyaNova.PlugIn.V8
seeds.WorkorderNumberStartSeed = AyaBizUtils.GlobalSettings.WorkorderNumberStartSeed + 1;
seeds.PreventiveMaintenanceNumberStartSeed = PMStartSeed + 1;
DumpObjectToFolder(tempArchiveFolder, seeds, "seeds", objectExcludeProperties, TypeAndID.Empty, "GZTW.AyaNova.BLL.Seed");
//DumpObjectToFolder(tempArchiveFolder, seeds, "seeds", objectExcludeProperties, TypeAndID.Empty, "GZTW.AyaNova.BLL.Seed");
}
#endregion globalsettings
@@ -312,7 +305,7 @@ namespace AyaNova.PlugIn.V8
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));
//DumpObjectToFolder(tempArchiveFolder, c, "client." + c.ID.ToString(), objectExcludeProperties, new TypeAndID(RootObjectTypes.Client, c.ID));
}
}
@@ -330,7 +323,7 @@ namespace AyaNova.PlugIn.V8
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));
//DumpObjectToFolder(tempArchiveFolder, c, "headoffice." + c.ID.ToString(), excludes, new TypeAndID(RootObjectTypes.HeadOffice, c.ID));
}
}
#endregion clients
@@ -364,7 +357,7 @@ namespace AyaNova.PlugIn.V8
JObject xtra = new JObject();
xtra.Add("hexaScheduleBackColor", System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(c.ScheduleBackColor)));
DumpObjectToFolder(tempArchiveFolder, c, "user." + c.ID.ToString(), objectExcludeProperties, new TypeAndID(RootObjectTypes.User, c.ID), null, xtra);
//DumpObjectToFolder(tempArchiveFolder, c, "user." + c.ID.ToString(), objectExcludeProperties, new TypeAndID(RootObjectTypes.User, c.ID), null, xtra);
}
}
@@ -456,59 +449,59 @@ namespace AyaNova.PlugIn.V8
#region Dump
/// <summary>
/// Write out the object properties as JSON
/// </summary>
/// <param name="tempArchiveFolder"></param>
/// <param name="o"></param>
private void ExportObjectToFolder(object o, string objectFileName, List<string> excludeProperties,
TypeAndID tid, string forceTypeString = "", JObject jExtra = null)
{
// /// <summary>
// /// Write out the object properties as JSON
// /// </summary>
// /// <param name="tempArchiveFolder"></param>
// /// <param name="o"></param>
// private void ExportObjectToFolder(object o, string objectFileName, List<string> excludeProperties,
// TypeAndID tid, string forceTypeString = "", JObject jExtra = null)
// {
var typestring = o.GetType().ToString();
if (!string.IsNullOrWhiteSpace(forceTypeString))
{
typestring = forceTypeString;
}
// var typestring = o.GetType().ToString();
// if (!string.IsNullOrWhiteSpace(forceTypeString))
// {
// typestring = forceTypeString;
// }
var dumpFolder = tempArchiveFolder + Path.DirectorySeparatorChar + typestring;
makeFolderIfNotExist(dumpFolder);
// var dumpFolder = tempArchiveFolder + Path.DirectorySeparatorChar + typestring;
// makeFolderIfNotExist(dumpFolder);
var outputFileName = dumpFolder + Path.DirectorySeparatorChar + objectFileName + ".json";
var wikiOutputPath = dumpFolder + Path.DirectorySeparatorChar + objectFileName + Path.DirectorySeparatorChar + "files";
// var outputFileName = dumpFolder + Path.DirectorySeparatorChar + objectFileName + ".json";
// var wikiOutputPath = dumpFolder + Path.DirectorySeparatorChar + objectFileName + Path.DirectorySeparatorChar + "files";
JsonSerializer serializer = new JsonSerializer();
serializer.NullValueHandling = NullValueHandling.Include;
serializer.ContractResolver = new ExcludeNamedPropertiesContractResolver(excludeProperties);
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
// JsonSerializer serializer = new JsonSerializer();
// serializer.NullValueHandling = NullValueHandling.Include;
// serializer.ContractResolver = new ExcludeNamedPropertiesContractResolver(excludeProperties);
// serializer.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
#if(DEBUG)
serializer.Formatting = Formatting.Indented;
#endif
// serializer.Converters.Add(new JavaScriptDateTimeConverter());
// serializer.NullValueHandling = NullValueHandling.Ignore;
//#if(DEBUG)
// serializer.Formatting = Formatting.Indented;
//#endif
// // serializer.Converters.Add(new JavaScriptDateTimeConverter());
// // serializer.NullValueHandling = NullValueHandling.Ignore;
//generate file name, should be ID of object plus .json
// //generate file name, should be ID of object plus .json
JObject jo = JObject.FromObject(o, serializer);
if (jExtra != null)
{
jo.Add("jextra", jExtra);
}
// JObject jo = JObject.FromObject(o, serializer);
// if (jExtra != null)
// {
// jo.Add("jextra", jExtra);
// }
using (StreamWriter sw = new StreamWriter(outputFileName))
using (JsonWriter writer = new JsonTextWriter(sw))
{
// using (StreamWriter sw = new StreamWriter(outputFileName))
// using (JsonWriter writer = new JsonTextWriter(sw))
// {
// serializer.Serialize(writer, o);
serializer.Serialize(writer, jo);
}
// // serializer.Serialize(writer, o);
// serializer.Serialize(writer, jo);
// }
//WIKI / ATTACHMENTS
DumpWikiPageAndAttachments(tid, wikiOutputPath);
}
// //WIKI / ATTACHMENTS
// DumpWikiPageAndAttachments(tid, wikiOutputPath);
// }
//WIKI
@@ -540,76 +533,76 @@ namespace AyaNova.PlugIn.V8
private void ExportWikiPageAndAttachments(TypeAndID tid, string wikiOutputPath)
{
//may not exist
if (!WikiPage.HasWiki(tid.ID)) return;
// //may not exist
// if (!WikiPage.HasWiki(tid.ID)) return;
WikiPage w = WikiPage.GetItem(tid);
var content = w.GetContentAsString;
AyaFileList fl = AyaFileList.GetList(w.ID);
// WikiPage w = WikiPage.GetItem(tid);
// var content = w.GetContentAsString;
// AyaFileList fl = AyaFileList.GetList(w.ID);
if (string.IsNullOrWhiteSpace(content) && fl.Count < 1) return;
// if (string.IsNullOrWhiteSpace(content) && fl.Count < 1) return;
makeFolderIfNotExist(wikiOutputPath);
// makeFolderIfNotExist(wikiOutputPath);
if (!string.IsNullOrWhiteSpace(content))
{
//write out the html wiki page
File.WriteAllText(wikiOutputPath + Path.DirectorySeparatorChar + "w.html", content);
}
// if (!string.IsNullOrWhiteSpace(content))
// {
// //write out the html wiki page
// File.WriteAllText(wikiOutputPath + Path.DirectorySeparatorChar + "w.html", content);
// }
//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);
// //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);
//save each file plus file info into their own folder by ayafile id this is because ayafiles can be dupe names and we need the wiki info to fixup the last created date etc
var filePath = wikiOutputPath + Path.DirectorySeparatorChar + i.LT_O_AyaFile.Value.ToString();
makeFolderIfNotExist(filePath);//output/objectype/client.f861ec01-8bde-46e1-9849-fcee9b42f05e/files/d5461ec01-8bde-46e1-9849-fcee9b42f0ff34/
// //save each file plus file info into their own folder by ayafile id this is because ayafiles can be dupe names and we need the wiki info to fixup the last created date etc
// var filePath = wikiOutputPath + Path.DirectorySeparatorChar + i.LT_O_AyaFile.Value.ToString();
// makeFolderIfNotExist(filePath);//output/objectype/client.f861ec01-8bde-46e1-9849-fcee9b42f05e/files/d5461ec01-8bde-46e1-9849-fcee9b42f0ff34/
var af = AyaFile.GetItem(i.LT_O_AyaFile.Value);
if (af == null) continue;
af.WriteToDisk(filePath, af.Name);
// var af = AyaFile.GetItem(i.LT_O_AyaFile.Value);
// if (af == null) continue;
// 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
};
// 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
// };
JsonSerializer serializer = new JsonSerializer();
serializer.NullValueHandling = NullValueHandling.Include;
// JsonSerializer serializer = new JsonSerializer();
// serializer.NullValueHandling = NullValueHandling.Include;
#if(DEBUG)
serializer.Formatting = Formatting.Indented;
#endif
JObject jo = JObject.FromObject(fileInfo, serializer);
//#if(DEBUG)
// serializer.Formatting = Formatting.Indented;
//#endif
// JObject jo = JObject.FromObject(fileInfo, serializer);
using (StreamWriter sw = new StreamWriter(filePath + Path.DirectorySeparatorChar + "meta.json"))
using (JsonWriter writer = new JsonTextWriter(sw))
{
// using (StreamWriter sw = new StreamWriter(filePath + Path.DirectorySeparatorChar + "meta.json"))
// using (JsonWriter writer = new JsonTextWriter(sw))
// {
// serializer.Serialize(writer, o);
serializer.Serialize(writer, jo);
}
// // serializer.Serialize(writer, o);
// serializer.Serialize(writer, jo);
// }
}
// }
}
#endregion dump

View File

@@ -19,7 +19,7 @@ namespace AyaNova.PlugIn.V8
//url once known to be good
internal static string ApiBaseUrl { get; set; }
internal static string JWT { get; set; }
static bool Initialized { get; set; }
public static bool Initialized { get; set; }