770 lines
32 KiB
C#
770 lines
32 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using System.Reflection;
|
|
using AyaNova.PlugIn;
|
|
using GZTW.AyaNova.BLL;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Serialization;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace AyaNova.PlugIn.V8
|
|
{
|
|
class V8 : IAyaNovaPlugin
|
|
{
|
|
|
|
#region Plugin interface
|
|
System.Resources.ResourceManager resman = null;
|
|
private static List<RootObjectTypes> ObjectsWeCanDealWith = null;
|
|
|
|
|
|
public string PluginName
|
|
{
|
|
get { return "Export to V8"; }
|
|
}
|
|
|
|
public string PluginVersion
|
|
{
|
|
get { return "7.6 (patch 3)"; }
|
|
}
|
|
|
|
public string About
|
|
{
|
|
get
|
|
{
|
|
return "AyaNova V8 export plugin\r\n" +
|
|
"Built " + AyaNova.PlugIn.V8.Timestamp.BuildAt.ToString() + "\r\n" +
|
|
"Copyright 2020 Ground Zero Tech-Works Inc.";
|
|
}
|
|
}
|
|
|
|
public Guid PluginID
|
|
{
|
|
get { return new Guid("{73D7B77F-C96A-4198-9449-6529AFB6AA5B}"); }
|
|
}
|
|
|
|
public System.Drawing.Image PluginSmallIcon
|
|
{
|
|
get { return Resource1.Dump16; }
|
|
}
|
|
|
|
public System.Drawing.Image PluginLargeIcon
|
|
{
|
|
get { return Resource1.Dump32; }
|
|
}
|
|
|
|
public System.Resources.ResourceManager AyaNovaResourceManager
|
|
{
|
|
set { resman = value; }
|
|
get { return resman; }
|
|
}
|
|
|
|
public bool Initialize(Version AyaNovaVersion, LocalizedTextTable localizedText)
|
|
{
|
|
if (AyaNovaVersion.Major < 7)
|
|
{
|
|
MessageBox.Show("The V8 export plugin requires AyaNova version 7.6 or newer");
|
|
return false;
|
|
}
|
|
|
|
if (AyaNovaVersion.Minor < 6)
|
|
{
|
|
MessageBox.Show("The V8 export plugin requires AyaNova version 7.6 or newer");
|
|
return false;
|
|
}
|
|
|
|
ObjectsWeCanDealWith = new List<RootObjectTypes>();
|
|
ObjectsWeCanDealWith.Add(RootObjectTypes.Nothing);
|
|
return true;
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
;
|
|
}
|
|
|
|
public bool SingleObjectMenuShow(RootObjectTypes objectType)
|
|
{
|
|
return (ObjectsWeCanDealWith.Contains(objectType));
|
|
}
|
|
|
|
public bool MultipleObjectsMenuShow(RootObjectTypes objectType)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public List<AyaNovaPluginMenuItem> SingleObjectMenuOptions(RootObjectTypes objectType, object ayaNovaObject)
|
|
{
|
|
if (!ObjectsWeCanDealWith.Contains(objectType)) return null;
|
|
List<AyaNovaPluginMenuItem> list = new List<AyaNovaPluginMenuItem>();
|
|
list.Add(new AyaNovaPluginMenuItem("V8 Export", "Export to AyaNova 8 server", null, null));
|
|
return list;
|
|
}
|
|
|
|
public List<AyaNovaPluginMenuItem> MultipleObjectsMenuOptions(RootObjectTypes objectType)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public bool CommandSelectedForList(string commandKey, RootObjectTypes objectType, List<Guid> objectIDList, object listObject)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public void CommandSelectedForSingleObject(string commandKey, RootObjectTypes objectType, object ayaNovaObject)
|
|
{
|
|
|
|
if (!User.CurrentUserIsAnAdministrator)
|
|
{
|
|
MessageBox.Show("This action can only be done by the AyaNova Administrator account");
|
|
return;
|
|
}
|
|
|
|
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. ***");
|
|
}
|
|
|
|
//Only one command
|
|
DumpIt();
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 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
|
|
/// </summary>
|
|
private void DumpIt()
|
|
{
|
|
|
|
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
|
|
|
|
ProgressForm progress = new ProgressForm();
|
|
progress.Show();
|
|
progress.StartedImport();
|
|
progress.Append("Dumping data to " + tempArchiveFolder);
|
|
|
|
|
|
//DUMP IT!
|
|
|
|
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
|
|
|
|
|
|
|
|
//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();
|
|
|
|
//-----------------------------------
|
|
//endof method
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Object dump methods
|
|
|
|
#region Global settings
|
|
private void dumpGlobalSettings(string tempArchiveFolder, 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));
|
|
}
|
|
#endregion globalsettings
|
|
|
|
#region locales
|
|
private void dumpLocales(string tempArchiveFolder, 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 REGIONS
|
|
private void dumpRegions(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
objectExcludeProperties.Add("ContractName");
|
|
objectExcludeProperties.Add("uiHasTechNotes");
|
|
RegionList l = RegionList.GetList(string.Empty);
|
|
progress.Append("Dumping " + l.Count.ToString() + " Regions");
|
|
foreach (RegionList.RegionListInfo i in l)
|
|
{
|
|
|
|
Region o = Region.GetItem(i.LT_Region_Label_Name.Value);
|
|
DumpObjectToFolder(tempArchiveFolder, o, "region." + o.ID.ToString(), objectExcludeProperties, new TypeAndID(RootObjectTypes.Region,o.ID));
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#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 dumpSeedNumbers(string tempArchiveFolder, 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 dumpClients(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
objectExcludeProperties.Add("ContractName");
|
|
objectExcludeProperties.Add("uiHasTechNotes");
|
|
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 dumpHeadOffices(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> excludes = new List<string>(standardExcludePropertiesList);
|
|
//excludes.Add("ContractInEffect");
|
|
//excludes.Add("uiHasTechNotes");
|
|
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 void dumpUsers(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
objectExcludeProperties.Add("LastView");
|
|
objectExcludeProperties.Add("LastSchedGroupID");
|
|
objectExcludeProperties.Add("LastSchedStartDate");
|
|
objectExcludeProperties.Add("LastSchedStopDate");
|
|
objectExcludeProperties.Add("LastSchedView");
|
|
objectExcludeProperties.Add("ScheduleLastGraphicalPrintSettings");
|
|
objectExcludeProperties.Add("MainGridLastRowCount");
|
|
objectExcludeProperties.Add("ScheduleLastViewOpenOnly");
|
|
objectExcludeProperties.Add("IsAdministrator");
|
|
objectExcludeProperties.Add("IsGenerator");
|
|
objectExcludeProperties.Add("IsScheduleable");
|
|
objectExcludeProperties.Add("IsClientOrHeadOfficeAccount");
|
|
objectExcludeProperties.Add("IsClientAccount");
|
|
objectExcludeProperties.Add("IsHeadOfficeAccount");
|
|
objectExcludeProperties.Add("OrganizationTypeAndID");
|
|
|
|
UserPickList pl = UserPickList.GetList(false);
|
|
progress.Append("Dumping " + pl.Count.ToString() + " Users");
|
|
foreach (UserPickList.UserPickListInfo i in pl)
|
|
{
|
|
User c = User.GetItem(i.ID);
|
|
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);
|
|
|
|
}
|
|
}
|
|
#endregion clients
|
|
|
|
#region Unitmodelcategories
|
|
private void dumpUnitModelCategories(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
//objectExcludeProperties.Add("ContractName");
|
|
//objectExcludeProperties.Add("uiHasTechNotes");
|
|
UnitModelCategories l = UnitModelCategories.GetItems();
|
|
progress.Append("Dumping " + l.Count.ToString() + " Unit model categories");
|
|
|
|
foreach (UnitModelCategory i in l)
|
|
{
|
|
|
|
DumpObjectToFolder(tempArchiveFolder, i, "unitmodelcategory." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Unitservicetypes
|
|
private void dumpUnitServiceTypes(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
//objectExcludeProperties.Add("ContractName");
|
|
//objectExcludeProperties.Add("uiHasTechNotes");
|
|
UnitServiceTypes l = UnitServiceTypes.GetItems();
|
|
progress.Append("Dumping " + l.Count.ToString() + " Unit service types");
|
|
|
|
foreach (UnitServiceType i in l)
|
|
{
|
|
|
|
DumpObjectToFolder(tempArchiveFolder, i, "unitservicetype." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region WorkorderItemTypes
|
|
private void dumpWorkorderItemTypes(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
//objectExcludeProperties.Add("ContractName");
|
|
//objectExcludeProperties.Add("uiHasTechNotes");
|
|
WorkorderItemTypes l = WorkorderItemTypes.GetItems();
|
|
progress.Append("Dumping " + l.Count.ToString() + " Workorder item types");
|
|
|
|
foreach (WorkorderItemType i in l)
|
|
{
|
|
|
|
DumpObjectToFolder(tempArchiveFolder, i, "workorderitemtype." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Client groups
|
|
private void dumpClientGroups(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
//objectExcludeProperties.Add("ContractName");
|
|
//objectExcludeProperties.Add("uiHasTechNotes");
|
|
ClientGroups l = ClientGroups.GetItems();
|
|
progress.Append("Dumping " + l.Count.ToString() + " Client groups");
|
|
|
|
foreach (ClientGroup i in l)
|
|
{
|
|
|
|
DumpObjectToFolder(tempArchiveFolder, i, "clientgroup." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Workorder categories
|
|
private void dumpWorkorderCategories(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
//objectExcludeProperties.Add("ContractName");
|
|
//objectExcludeProperties.Add("uiHasTechNotes");
|
|
WorkorderCategories l = WorkorderCategories.GetItems();
|
|
progress.Append("Dumping " + l.Count.ToString() + " Workorder categories");
|
|
|
|
foreach (WorkorderCategory i in l)
|
|
{
|
|
|
|
DumpObjectToFolder(tempArchiveFolder, i, "workordercategory." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Part categories
|
|
private void dumpPartCategories(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
//objectExcludeProperties.Add("ContractName");
|
|
//objectExcludeProperties.Add("uiHasTechNotes");
|
|
PartCategories l = PartCategories.GetItems();
|
|
progress.Append("Dumping " + l.Count.ToString() + " Part categories");
|
|
|
|
foreach (PartCategory i in l)
|
|
{
|
|
|
|
DumpObjectToFolder(tempArchiveFolder, i, "partcategory." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region ScheduleableUserGroups
|
|
private void dumpScheduleableUserGroups(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
objectExcludeProperties.Add("ContractName");
|
|
objectExcludeProperties.Add("uiHasTechNotes");
|
|
ScheduleableUserGroupPickList pl = ScheduleableUserGroupPickList.GetList();
|
|
progress.Append("Dumping " + pl.Count.ToString() + " Scheduleable user groups");
|
|
foreach (ScheduleableUserGroupPickList.ScheduleableUserGroupPickListInfo i in pl)
|
|
{
|
|
ScheduleableUserGroup c = ScheduleableUserGroup.GetItem(i.ID);
|
|
DumpObjectToFolder(tempArchiveFolder, c, "scheduleableusergroup." + c.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
|
|
|
|
}
|
|
}
|
|
#endregion clients
|
|
|
|
#region Dispatch zones
|
|
private void dumpDispatchZones(string tempArchiveFolder, ProgressForm progress)
|
|
{
|
|
List<string> objectExcludeProperties = new List<string>(standardExcludePropertiesList);
|
|
//objectExcludeProperties.Add("ContractName");
|
|
//objectExcludeProperties.Add("uiHasTechNotes");
|
|
DispatchZones l = DispatchZones.GetItems(false);
|
|
progress.Append("Dumping " + l.Count.ToString() + " Dispatch zones");
|
|
|
|
foreach (DispatchZone i in l)
|
|
{
|
|
|
|
DumpObjectToFolder(tempArchiveFolder, i, "dispatchzone." + i.ID.ToString(), objectExcludeProperties, TypeAndID.Empty);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//--------------------------------------------
|
|
#endregion object dump methods
|
|
|
|
|
|
#region Dump
|
|
|
|
/// <summary>
|
|
/// Write out the object properties as JSON
|
|
/// </summary>
|
|
/// <param name="tempArchiveFolder"></param>
|
|
/// <param name="o"></param>
|
|
private void DumpObjectToFolder(string tempArchiveFolder, 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 dumpFolder = tempArchiveFolder + Path.DirectorySeparatorChar + typestring;
|
|
makeFolderIfNotExist(dumpFolder);
|
|
|
|
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;
|
|
|
|
|
|
#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
|
|
|
|
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))
|
|
{
|
|
|
|
// serializer.Serialize(writer, o);
|
|
serializer.Serialize(writer, jo);
|
|
}
|
|
|
|
//WIKI / ATTACHMENTS
|
|
DumpWikiPageAndAttachments(tid, wikiOutputPath);
|
|
}
|
|
|
|
|
|
//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 void DumpWikiPageAndAttachments(TypeAndID tid, string wikiOutputPath)
|
|
{
|
|
|
|
//may not exist
|
|
if (!WikiPage.HasWiki(tid.ID)) return;
|
|
|
|
WikiPage w= WikiPage.GetItem(tid);
|
|
var content= w.GetContentAsString;
|
|
AyaFileList fl = AyaFileList.GetList(w.ID);
|
|
|
|
if (string.IsNullOrWhiteSpace(content) && fl.Count < 1) return;
|
|
|
|
makeFolderIfNotExist(wikiOutputPath);
|
|
|
|
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);
|
|
|
|
|
|
|
|
//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 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;
|
|
|
|
#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))
|
|
{
|
|
|
|
// serializer.Serialize(writer, o);
|
|
serializer.Serialize(writer, jo);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
#endregion dump
|
|
|
|
#region Utility methods
|
|
|
|
private static string EnsureValidFileName(string fileName)
|
|
{
|
|
//make lower and replace spaces with dashes
|
|
fileName = fileName.ToLowerInvariant().Replace(" ", "-");
|
|
|
|
//ensure each character is a valid path character
|
|
foreach (char c in System.IO.Path.GetInvalidFileNameChars())
|
|
{
|
|
fileName = fileName.Replace(c, '_');
|
|
}
|
|
return fileName;
|
|
}
|
|
|
|
|
|
|
|
private static void makeFolderIfNotExist(string fldr, bool shouldNotExist = false)
|
|
{
|
|
if (Directory.Exists(fldr))
|
|
{
|
|
if (shouldNotExist)
|
|
throw new System.Exception("Error: path already exists and shouldn't:\r\n" + fldr);
|
|
return;
|
|
}
|
|
Directory.CreateDirectory(fldr);
|
|
}
|
|
|
|
private List<string> standardExcludePropertiesList
|
|
{
|
|
get
|
|
{
|
|
return new List<string>()
|
|
{
|
|
"CanWiki",
|
|
"CanDuplicate",
|
|
"IsValid",
|
|
"IsDirty",
|
|
"CurrentUserID",
|
|
"IsEditing",
|
|
"IsNew",
|
|
"IsDeleted",
|
|
"IsSavable",
|
|
"Notify",
|
|
"BrokenRulesText",
|
|
"Docs",
|
|
"MapQuestURL",
|
|
"FullAddress"
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX",
|
|
//"XXX"
|
|
};
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contract resolver
|
|
public class ExcludeNamedPropertiesContractResolver : DefaultContractResolver
|
|
{
|
|
private readonly List<string> _excludeProperties;
|
|
|
|
public ExcludeNamedPropertiesContractResolver(List<string> excludeProperties)
|
|
{
|
|
_excludeProperties = excludeProperties;
|
|
}
|
|
|
|
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
|
{
|
|
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
|
|
|
|
// only serializer properties that start with the specified character
|
|
//properties = properties.Where(p => p.PropertyName.StartsWith(_startingWithChar.ToString())).ToList();
|
|
properties = properties.Where(p => !_excludeProperties.Contains(p.PropertyName)).ToList();
|
|
|
|
return properties;
|
|
}
|
|
}
|
|
#endregion contract resolver
|
|
|
|
|
|
//eoc
|
|
|
|
|
|
|
|
}
|
|
|
|
//eons
|
|
}
|