This commit is contained in:
2020-04-27 23:28:36 +00:00
parent 0fcc7772f3
commit f4922b8a92
2 changed files with 143 additions and 119 deletions

View File

@@ -141,66 +141,54 @@ namespace AyaNova.PlugIn.V8
MessageBox.Show("Login successful! JWT is " + util.JWT); MessageBox.Show("Login successful! JWT is " + util.JWT);
//Only one command //Only one command
// DumpIt(); DoExport();
} }
#endregion #endregion
private Dictionary<Guid, long> Map = new Dictionary<Guid, long>();
private Dictionary<Guid, string> TagMap = new Dictionary<Guid, string>();
/// <summary> /// <summary>
/// Dump the objects into a temporary directory as a series of JSON files /// Dump the objects into a temporary directory as a series of JSON files
/// then zip it all up into a single archive file and then erase the temporary folder /// then zip it all up into a single archive file and then erase the temporary folder
/// </summary> /// </summary>
private void DumpIt() private void DoExport()
{ {
Map.Clear();
string dumpname = "ayanova.data.dump." + DateTime.Now.ToString("yyyy-MM-d--HH-mm-ss");
string dumpfolder = string.Empty;
#if(DEBUG)
dumpfolder = @"c:\temp";
#else
MessageBox.Show("Select a location to dump AyaNova data");
using (var folderDialog = new FolderBrowserDialog())
{
if (folderDialog.ShowDialog() == DialogResult.OK)
{
dumpfolder = folderDialog.SelectedPath;
}
else
{
return;
}
}
#endif
//create a temporary folder to generate JSON in
string tempArchiveFolder = dumpfolder + Path.DirectorySeparatorChar + dumpname;
string zipName = dumpfolder + Path.DirectorySeparatorChar + dumpname + ".zip";
makeFolderIfNotExist(tempArchiveFolder, true);
//Show progress form //Show progress form
ProgressForm progress = new ProgressForm(); ProgressForm progress = new ProgressForm();
progress.Show(); progress.Show();
progress.StartedImport(); progress.StartedImport();
progress.Append("Dumping data to " + tempArchiveFolder); progress.Append("Exporting data to AyaNova server @ " + util.ApiBaseUrl);
//DUMP IT! //Export in correct order:
//TAGS
ExportUnitModelCategories(progress);
ExportUnitServiceTypes(progress);
ExportWorkorderItemTypes(progress);
ExportRegions(progress);
ExportClientGroups(progress);
ExportWorkorderCategories(progress);
ExportPartCategories(progress);
ExportScheduleableUserGroups(progress);
ExportDispatchZones(progress);
//dumpUsers(tempArchiveFolder, progress);
//dumpGlobalSettings(tempArchiveFolder, progress);
//dumpLocales(tempArchiveFolder, progress);
//dumpSeedNumbers(tempArchiveFolder, progress);
//dumpClients(tempArchiveFolder, progress);
//dumpHeadOffices(tempArchiveFolder, progress);
//
dumpUsers(tempArchiveFolder, progress);
dumpGlobalSettings(tempArchiveFolder, progress);
dumpLocales(tempArchiveFolder, progress);
dumpRegions(tempArchiveFolder, progress);
dumpSeedNumbers(tempArchiveFolder, progress);
dumpClients(tempArchiveFolder, progress);
dumpHeadOffices(tempArchiveFolder, progress);
dumpUnitModelCategories(tempArchiveFolder, progress);
dumpUnitServiceTypes(tempArchiveFolder, progress);
dumpWorkorderItemTypes(tempArchiveFolder, progress);
dumpClientGroups(tempArchiveFolder, progress);
dumpWorkorderCategories(tempArchiveFolder, progress);
dumpPartCategories(tempArchiveFolder, progress);
dumpScheduleableUserGroups(tempArchiveFolder, progress);
dumpDispatchZones(tempArchiveFolder, progress);
//NOTE: when get to PRIORITY, or WORKORDER STATUS be sure to add color code as per already done in USER export //NOTE: when get to PRIORITY, or WORKORDER STATUS be sure to add color code as per already done in USER export
@@ -223,10 +211,10 @@ namespace AyaNova.PlugIn.V8
#region Object dump methods #region Object Export methods
#region Global settings #region Global settings
private void dumpGlobalSettings(string tempArchiveFolder, ProgressForm progress) private void ExportGlobalSettings(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
progress.Append("Dumping Global Settings"); progress.Append("Dumping Global Settings");
@@ -235,7 +223,7 @@ namespace AyaNova.PlugIn.V8
#endregion globalsettings #endregion globalsettings
#region locales #region locales
private void dumpLocales(string tempArchiveFolder, ProgressForm progress) private void ExportLocales(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
@@ -260,7 +248,7 @@ namespace AyaNova.PlugIn.V8
#endregion locales #endregion locales
#region REGIONS #region REGIONS
private void dumpRegions(string tempArchiveFolder, ProgressForm progress) private void ExportRegions(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
objectExcludeProperties.Add("ContractName"); objectExcludeProperties.Add("ContractName");
@@ -286,7 +274,7 @@ namespace AyaNova.PlugIn.V8
public int WorkorderNumberStartSeed = 1; public int WorkorderNumberStartSeed = 1;
public int PreventiveMaintenanceNumberStartSeed = 1; public int PreventiveMaintenanceNumberStartSeed = 1;
} }
private void dumpSeedNumbers(string tempArchiveFolder, ProgressForm progress) private void ExportSeedNumbers(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
progress.Append("Dumping seeds"); progress.Append("Dumping seeds");
@@ -314,7 +302,7 @@ namespace AyaNova.PlugIn.V8
#endregion globalsettings #endregion globalsettings
#region clients #region clients
private void dumpClients(string tempArchiveFolder, ProgressForm progress) private void ExportClients(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
objectExcludeProperties.Add("ContractName"); objectExcludeProperties.Add("ContractName");
@@ -331,7 +319,7 @@ namespace AyaNova.PlugIn.V8
#endregion clients #endregion clients
#region headoffices #region headoffices
private void dumpHeadOffices(string tempArchiveFolder, ProgressForm progress) private void ExportHeadOffices(ProgressForm progress)
{ {
List<string> excludes = new List<string>(standardExcludePropertiesList); List<string> excludes = new List<string>(standardExcludePropertiesList);
//excludes.Add("ContractInEffect"); //excludes.Add("ContractInEffect");
@@ -348,7 +336,7 @@ namespace AyaNova.PlugIn.V8
#endregion clients #endregion clients
#region users #region users
private void dumpUsers(string tempArchiveFolder, ProgressForm progress) private void ExportUsers(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
@@ -383,43 +371,37 @@ namespace AyaNova.PlugIn.V8
#endregion clients #endregion clients
#region Unitmodelcategories #region Unitmodelcategories
private void dumpUnitModelCategories(string tempArchiveFolder, ProgressForm progress) private void ExportUnitModelCategories(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//objectExcludeProperties.Add("ContractName");
//objectExcludeProperties.Add("uiHasTechNotes");
UnitModelCategories l = UnitModelCategories.GetItems(); UnitModelCategories l = UnitModelCategories.GetItems();
progress.Append("Dumping " + l.Count.ToString() + " Unit model categories"); progress.Append("Exporting " + l.Count.ToString() + " Unit model categories");
foreach (UnitModelCategory i in l) foreach (UnitModelCategory i in l)
{ {
TagMap.Add(i.ID, util.NormalizeTag(i.Name + "." + "unitmodelcategory"));
DumpObjectToFolder(tempArchiveFolder, i, "unitmodelcategory." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
} }
} }
#endregion #endregion
#region Unitservicetypes #region Unitservicetypes
private void dumpUnitServiceTypes(string tempArchiveFolder, ProgressForm progress) private void ExportUnitServiceTypes(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//objectExcludeProperties.Add("ContractName");
//objectExcludeProperties.Add("uiHasTechNotes");
UnitServiceTypes l = UnitServiceTypes.GetItems(); UnitServiceTypes l = UnitServiceTypes.GetItems();
progress.Append("Dumping " + l.Count.ToString() + " Unit service types"); progress.Append("Dumping " + l.Count.ToString() + " Unit service types");
foreach (UnitServiceType i in l) foreach (UnitServiceType i in l)
{ {
DumpObjectToFolder(tempArchiveFolder, i, "unitservicetype." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty); TagMap.Add(i.ID, util.NormalizeTag(i.Name + "." + "unitservicetype"));
} }
} }
#endregion #endregion
#region WorkorderItemTypes #region WorkorderItemTypes
private void dumpWorkorderItemTypes(string tempArchiveFolder, ProgressForm progress) private void ExportWorkorderItemTypes(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//objectExcludeProperties.Add("ContractName"); //objectExcludeProperties.Add("ContractName");
@@ -437,7 +419,7 @@ namespace AyaNova.PlugIn.V8
#endregion #endregion
#region Client groups #region Client groups
private void dumpClientGroups(string tempArchiveFolder, ProgressForm progress) private void ExportClientGroups(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//objectExcludeProperties.Add("ContractName"); //objectExcludeProperties.Add("ContractName");
@@ -455,7 +437,7 @@ namespace AyaNova.PlugIn.V8
#endregion #endregion
#region Workorder categories #region Workorder categories
private void dumpWorkorderCategories(string tempArchiveFolder, ProgressForm progress) private void ExportWorkorderCategories(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//objectExcludeProperties.Add("ContractName"); //objectExcludeProperties.Add("ContractName");
@@ -473,7 +455,7 @@ namespace AyaNova.PlugIn.V8
#endregion #endregion
#region Part categories #region Part categories
private void dumpPartCategories(string tempArchiveFolder, ProgressForm progress) private void ExportPartCategories(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//objectExcludeProperties.Add("ContractName"); //objectExcludeProperties.Add("ContractName");
@@ -491,7 +473,7 @@ namespace AyaNova.PlugIn.V8
#endregion #endregion
#region ScheduleableUserGroups #region ScheduleableUserGroups
private void dumpScheduleableUserGroups(string tempArchiveFolder, ProgressForm progress) private void ExportScheduleableUserGroups(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
objectExcludeProperties.Add("ContractName"); objectExcludeProperties.Add("ContractName");
@@ -508,7 +490,7 @@ namespace AyaNova.PlugIn.V8
#endregion clients #endregion clients
#region Dispatch zones #region Dispatch zones
private void dumpDispatchZones(string tempArchiveFolder, ProgressForm progress) private void ExportDispatchZones(ProgressForm progress)
{ {
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList); List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
//objectExcludeProperties.Add("ContractName"); //objectExcludeProperties.Add("ContractName");
@@ -536,7 +518,7 @@ namespace AyaNova.PlugIn.V8
/// </summary> /// </summary>
/// <param name="tempArchiveFolder"></param> /// <param name="tempArchiveFolder"></param>
/// <param name="o"></param> /// <param name="o"></param>
private void DumpObjectToFolder(string tempArchiveFolder, object o, string objectFileName, List<string> excludeProperties, private void ExportObjectToFolder(object o, string objectFileName, List<string> excludeProperties,
TypeAndID tid, string forceTypeString = "", JObject jExtra = null) TypeAndID tid, string forceTypeString = "", JObject jExtra = null)
{ {
@@ -612,7 +594,7 @@ namespace AyaNova.PlugIn.V8
*/ */
#endregion #endregion
private void DumpWikiPageAndAttachments(TypeAndID tid, string wikiOutputPath) private void ExportWikiPageAndAttachments(TypeAndID tid, string wikiOutputPath)
{ {
//may not exist //may not exist
@@ -653,8 +635,18 @@ namespace AyaNova.PlugIn.V8
if (af == null) continue; if (af == null) continue;
af.WriteToDisk(filePath, af.Name); 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, var fileInfo = new
mimetype = af.mimeType, id = af.ID, size = af.FileSize, ayafiletype = af.FileType, rootobjectid = af.RootObjectID, rootobjecttype = af.RootObjectType }; {
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(); JsonSerializer serializer = new JsonSerializer();
serializer.NullValueHandling = NullValueHandling.Include; serializer.NullValueHandling = NullValueHandling.Include;

View File

@@ -17,7 +17,7 @@ namespace AyaNova.PlugIn.V8
const string API_BASE_ROUTE = "api/v8/"; const string API_BASE_ROUTE = "api/v8/";
static HttpClient client = new HttpClient(); static HttpClient client = new HttpClient();
//url once known to be good //url once known to be good
static string ApiBaseUrl { get; set; } internal static string ApiBaseUrl { get; set; }
internal static string JWT { get; set; } internal static string JWT { get; set; }
static bool Initialized { get; set; } static bool Initialized { get; set; }
@@ -183,6 +183,38 @@ namespace AyaNova.PlugIn.V8
} }
#endregion #endregion
#region Misc utils
public static string NormalizeTag(string inObj)
{
//Must be lowercase per rules
//This may be naive when we get international customers but for now supporting utf-8 and it appears it's safe to do this with unicode
inObj = inObj.ToLowerInvariant();
//No spaces in tags, replace with dashes
inObj = inObj.Replace(" ", "-");
//Remove multiple dash sequences
inObj = System.Text.RegularExpressions.Regex.Replace(inObj, "-+", "-");
//Ensure doesn't start or end with a dash
inObj = inObj.Trim('-');
//No longer than 255 characters
inObj = MaxLength(inObj, 255);
return inObj;
}
/// <summary>
/// Trim a string if necessary
/// </summary>
/// <param name="s"></param>
/// <param name="maxLength"></param>
/// <returns></returns>
public static string MaxLength(string s, int maxLength)
{
if (s.Length > maxLength)
s = s.Substring(0, maxLength);
return s;
}
#endregion
}//eoc }//eoc