This commit is contained in:
@@ -179,9 +179,13 @@ namespace AyaNova.PlugIn.V8
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
* Error should post somehow to server so can see at server what went wrong
|
* wiki / attached docs
|
||||||
* custom fields processor for: User, Client, Contract, HeadOffice, LoanItem, part, project, purchaseorder, unit, unitmodel, vendor, workorderitem
|
*
|
||||||
* See util.cs in winformapp for all custom field shit, lines 3114 is a good starting point
|
* locales
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -208,7 +212,7 @@ namespace AyaNova.PlugIn.V8
|
|||||||
|
|
||||||
//BIZ objects
|
//BIZ objects
|
||||||
await ExportUsers(progress);
|
await ExportUsers(progress);
|
||||||
//dumpLocales(tempArchiveFolder, progress);
|
// await ExportLocales(progress);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -277,8 +281,6 @@ namespace AyaNova.PlugIn.V8
|
|||||||
}
|
}
|
||||||
#endregion locales
|
#endregion locales
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region Seeds
|
#region Seeds
|
||||||
private class GZSeeds
|
private class GZSeeds
|
||||||
{
|
{
|
||||||
@@ -348,10 +350,10 @@ namespace AyaNova.PlugIn.V8
|
|||||||
private async System.Threading.Tasks.Task ExportUsers(ProgressForm progress)
|
private async System.Threading.Tasks.Task ExportUsers(ProgressForm progress)
|
||||||
{
|
{
|
||||||
//Step 1: export the CustomFields to FormCustom if applicable so that when doing individual items we can export their custom data too
|
//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("User");
|
var ocf = ObjectHasCustomFieldDataToExport("User");
|
||||||
bool ShouldExportCustom = ocf != null;
|
bool ShouldExportCustom = ocf != null;
|
||||||
|
|
||||||
var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
||||||
//Step 2: export the users
|
//Step 2: export the users
|
||||||
|
|
||||||
|
|
||||||
@@ -410,7 +412,7 @@ var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
|||||||
//Custom fields?
|
//Custom fields?
|
||||||
if (ShouldExportCustom)
|
if (ShouldExportCustom)
|
||||||
{
|
{
|
||||||
d.customFields = CustomFieldData(c,DateCustomFields);
|
d.customFields = CustomFieldData(c, DateCustomFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
var a = await util.PostAsync("User", d.ToString());
|
var a = await util.PostAsync("User", d.ToString());
|
||||||
@@ -554,64 +556,123 @@ var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
|||||||
|
|
||||||
#endregion TAG ITEMS
|
#endregion TAG ITEMS
|
||||||
//--------------------------------------------
|
//--------------------------------------------
|
||||||
#endregion object dump methods
|
#endregion object export
|
||||||
|
|
||||||
|
|
||||||
#region Dump
|
#region Custom fields exporter
|
||||||
|
|
||||||
// /// <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 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)
|
//export objects custom field data into jobject string
|
||||||
// serializer.Formatting = Formatting.Indented;
|
private string CustomFieldData(object biz, List<int> dateFields)
|
||||||
//#endif
|
{
|
||||||
// // serializer.Converters.Add(new JavaScriptDateTimeConverter());
|
dynamic d = new JObject();
|
||||||
// // serializer.NullValueHandling = NullValueHandling.Ignore;
|
|
||||||
|
|
||||||
// //generate file name, should be ID of object plus .json
|
for (int x = 0; x < 10; x++)
|
||||||
|
{
|
||||||
|
object o = (object)biz.GetType().GetProperty("Custom" + x.ToString()).GetValue(biz, null);
|
||||||
|
string s = o.ToString();
|
||||||
|
if (string.IsNullOrWhiteSpace(s))
|
||||||
|
{
|
||||||
|
s = null;
|
||||||
|
}
|
||||||
|
if (s != null && dateFields.Contains(x))
|
||||||
|
{
|
||||||
|
//parse out to UTC date
|
||||||
|
DateTime dt = new DateTime();
|
||||||
|
if (DateTime.TryParse(s, out dt))
|
||||||
|
{
|
||||||
|
s = dt.ToUniversalTime().ToString("s");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(s))
|
||||||
|
d["c" + (x + 1).ToString()] = s;
|
||||||
|
|
||||||
// JObject jo = JObject.FromObject(o, serializer);
|
}
|
||||||
// if (jExtra != null)
|
return d.ToString();
|
||||||
// {
|
}
|
||||||
// jo.Add("jextra", jExtra);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
static public ObjectCustomFields ObjectHasCustomFieldDataToExport(string sObject)
|
||||||
|
{
|
||||||
|
ObjectCustomFields ocf = ObjectCustomFields.GetItems(sObject);
|
||||||
|
if (ocf.Count == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// using (StreamWriter sw = new StreamWriter(outputFileName))
|
foreach (ObjectCustomField f in ocf)
|
||||||
// using (JsonWriter writer = new JsonTextWriter(sw))
|
{
|
||||||
// {
|
if (f.Visible)
|
||||||
|
return ocf;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// // serializer.Serialize(writer, o);
|
private async System.Threading.Tasks.Task<List<int>> ExportCustomFieldSchema(ObjectCustomFields ocf, string v7CustomFieldObjectName, string RavenCustomTranslationKeyObjectName)
|
||||||
// serializer.Serialize(writer, jo);
|
{
|
||||||
// }
|
var ret = new List<int>();
|
||||||
|
//NOTE: this code inspired by winforApp::Util.cs PrepareCustomFieldsGrid method
|
||||||
|
dynamic d = new JObject();
|
||||||
|
d.formkey = RavenCustomTranslationKeyObjectName;
|
||||||
|
dynamic dtemplate = new JArray();
|
||||||
|
foreach (ObjectCustomField f in ocf)
|
||||||
|
{
|
||||||
|
if (f.Visible)
|
||||||
|
{
|
||||||
|
int n = Convert.ToInt32(f.FieldName.Replace("Custom", "")) + 1;//raven custom fields are 1 based, v7 are zero based
|
||||||
|
CustomFieldLocaleKeys.Add(RavenCustomTranslationKeyObjectName + n.ToString(),
|
||||||
|
util.LocaleText.GetLocalizedText(v7CustomFieldObjectName + ".Label." + f.FieldName));
|
||||||
|
|
||||||
// //WIKI / ATTACHMENTS
|
dynamic dt = new JObject();
|
||||||
// DumpWikiPageAndAttachments(tid, wikiOutputPath);
|
dt.fld = RavenCustomTranslationKeyObjectName + "Custom" + n.ToString();
|
||||||
// }
|
dt.hide = false;
|
||||||
|
dt.required = false;
|
||||||
|
switch (f.FieldType)
|
||||||
|
{
|
||||||
|
case FormFieldDataTypes.Currency:
|
||||||
|
dt.type = util.AyaUiFieldDataType.Currency;
|
||||||
|
break;
|
||||||
|
case FormFieldDataTypes.DateOnly:
|
||||||
|
dt.type = util.AyaUiFieldDataType.Date;
|
||||||
|
ret.Add(n - 1);
|
||||||
|
break;
|
||||||
|
case FormFieldDataTypes.DateTime:
|
||||||
|
dt.type = util.AyaUiFieldDataType.DateTime;
|
||||||
|
ret.Add(n - 1);
|
||||||
|
break;
|
||||||
|
case FormFieldDataTypes.Number:
|
||||||
|
dt.type = util.AyaUiFieldDataType.Decimal;
|
||||||
|
break;
|
||||||
|
case FormFieldDataTypes.Text:
|
||||||
|
dt.type = util.AyaUiFieldDataType.Text;
|
||||||
|
break;
|
||||||
|
case FormFieldDataTypes.TimeOnly:
|
||||||
|
dt.type = util.AyaUiFieldDataType.Time;
|
||||||
|
ret.Add(n - 1);
|
||||||
|
break;
|
||||||
|
case FormFieldDataTypes.TrueFalse:
|
||||||
|
dt.type = util.AyaUiFieldDataType.Bool;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dt.type = util.AyaUiFieldDataType.Text;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dtemplate.Add(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.template = dtemplate.ToString();
|
||||||
|
|
||||||
|
//ok, were here because there *are* custom fields available
|
||||||
|
var a = await util.GetAsync("FormCustom/" + RavenCustomTranslationKeyObjectName);
|
||||||
|
var ctoken = util.CTokenFromResponse(a);
|
||||||
|
d.concurrencyToken = ctoken;
|
||||||
|
await util.PutAsync("FormCustom/" + RavenCustomTranslationKeyObjectName, d.ToString());
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion custom fields
|
||||||
|
|
||||||
|
#region WIKI page exporter
|
||||||
|
|
||||||
|
|
||||||
//WIKI
|
//WIKI
|
||||||
@@ -640,25 +701,23 @@ var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private void ExportWikiPageAndAttachments(TypeAndID tid, string wikiOutputPath)
|
private async System.Threading.Tasks.Task<string> ExportWikiPageAndAttachments(TypeAndID tid)
|
||||||
{
|
{
|
||||||
|
//todo: upload attached files
|
||||||
|
//todo: return wiki as string
|
||||||
|
|
||||||
// //may not exist
|
//may not exist
|
||||||
// if (!WikiPage.HasWiki(tid.ID)) return;
|
if (!WikiPage.HasWiki(tid.ID)) return null;
|
||||||
|
|
||||||
|
WikiPage w = WikiPage.GetItem(tid);
|
||||||
|
var content = w.GetContentAsString;
|
||||||
|
AyaFileList fl = AyaFileList.GetList(w.ID);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(content) && fl.Count < 1) return null;
|
||||||
|
|
||||||
// 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
|
// //files
|
||||||
// foreach (AyaFileList.AyaFileListInfo i in fl)
|
// foreach (AyaFileList.AyaFileListInfo i in fl)
|
||||||
@@ -713,11 +772,19 @@ var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(content))
|
||||||
|
return content;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion dump
|
#endregion wiki
|
||||||
|
|
||||||
#region Utility methods
|
|
||||||
|
#region TAGS
|
||||||
private void Tagit(Guid g, List<string> tags)
|
private void Tagit(Guid g, List<string> tags)
|
||||||
{
|
{
|
||||||
if (g == Guid.Empty) return;
|
if (g == Guid.Empty) return;
|
||||||
@@ -727,10 +794,8 @@ var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
|||||||
{
|
{
|
||||||
tags.Add(t);
|
tags.Add(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void SetTags(dynamic d, List<string> tags)
|
private void SetTags(dynamic d, List<string> tags)
|
||||||
{
|
{
|
||||||
dynamic dtags = new JArray();
|
dynamic dtags = new JArray();
|
||||||
@@ -739,115 +804,38 @@ var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
|||||||
d.tags = dtags;
|
d.tags = dtags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion tags
|
||||||
|
|
||||||
|
|
||||||
//export objects custom field data into jobject string
|
|
||||||
private string CustomFieldData(object biz, List<int> dateFields)
|
|
||||||
{
|
|
||||||
dynamic d=new JObject();
|
|
||||||
|
|
||||||
for (int x = 0; x < 10; x++)
|
|
||||||
{
|
|
||||||
object o = (object)biz.GetType().GetProperty("Custom"+x.ToString()).GetValue(biz, null);
|
|
||||||
string s = o.ToString();
|
|
||||||
if (string.IsNullOrWhiteSpace(s))
|
|
||||||
{
|
|
||||||
s = null;
|
|
||||||
}
|
|
||||||
if (s!=null && dateFields.Contains(x))
|
|
||||||
{
|
|
||||||
//parse out to UTC date
|
|
||||||
DateTime dt=new DateTime();
|
|
||||||
if (DateTime.TryParse(s, out dt))
|
|
||||||
{
|
|
||||||
s = dt.ToUniversalTime().ToString("s");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!string.IsNullOrWhiteSpace(s))
|
|
||||||
d["c"+(x+1).ToString()] = s;
|
|
||||||
|
|
||||||
}
|
|
||||||
return d.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static public ObjectCustomFields ObjectHasCustomFieldDataToExport(string sObject)
|
|
||||||
{
|
|
||||||
ObjectCustomFields ocf = ObjectCustomFields.GetItems(sObject);
|
|
||||||
if (ocf.Count == 0)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (ObjectCustomField f in ocf)
|
#region OLD JSON EXPORT STUFF
|
||||||
{
|
|
||||||
if (f.Visible)
|
|
||||||
return ocf;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async System.Threading.Tasks.Task<List<int>> ExportCustomFieldSchema(ObjectCustomFields ocf, string v7CustomFieldObjectName, string RavenCustomTranslationKeyObjectName)
|
|
||||||
{
|
|
||||||
var ret = new List<int>();
|
|
||||||
//NOTE: this code inspired by winforApp::Util.cs PrepareCustomFieldsGrid method
|
|
||||||
dynamic d = new JObject();
|
|
||||||
d.formkey = RavenCustomTranslationKeyObjectName;
|
|
||||||
dynamic dtemplate = new JArray();
|
|
||||||
foreach (ObjectCustomField f in ocf)
|
|
||||||
{
|
|
||||||
if (f.Visible)
|
|
||||||
{
|
|
||||||
int n = Convert.ToInt32(f.FieldName.Replace("Custom", "")) + 1;//raven custom fields are 1 based, v7 are zero based
|
|
||||||
CustomFieldLocaleKeys.Add(RavenCustomTranslationKeyObjectName + n.ToString(),
|
|
||||||
util.LocaleText.GetLocalizedText(v7CustomFieldObjectName + ".Label." + f.FieldName));
|
|
||||||
|
|
||||||
dynamic dt = new JObject();
|
#region contract resolver
|
||||||
dt.fld = RavenCustomTranslationKeyObjectName + "Custom" + n.ToString();
|
//public class ExcludeNamedPropertiesContractResolver : DefaultContractResolver
|
||||||
dt.hide = false;
|
//{
|
||||||
dt.required = false;
|
// private readonly List<string> _excludeProperties;
|
||||||
switch (f.FieldType)
|
|
||||||
{
|
|
||||||
case FormFieldDataTypes.Currency:
|
|
||||||
dt.type = util.AyaUiFieldDataType.Currency;
|
|
||||||
break;
|
|
||||||
case FormFieldDataTypes.DateOnly:
|
|
||||||
dt.type = util.AyaUiFieldDataType.Date;
|
|
||||||
ret.Add(n-1);
|
|
||||||
break;
|
|
||||||
case FormFieldDataTypes.DateTime:
|
|
||||||
dt.type = util.AyaUiFieldDataType.DateTime;
|
|
||||||
ret.Add(n - 1);
|
|
||||||
break;
|
|
||||||
case FormFieldDataTypes.Number:
|
|
||||||
dt.type = util.AyaUiFieldDataType.Decimal;
|
|
||||||
break;
|
|
||||||
case FormFieldDataTypes.Text:
|
|
||||||
dt.type = util.AyaUiFieldDataType.Text;
|
|
||||||
break;
|
|
||||||
case FormFieldDataTypes.TimeOnly:
|
|
||||||
dt.type = util.AyaUiFieldDataType.Time;
|
|
||||||
ret.Add(n - 1);
|
|
||||||
break;
|
|
||||||
case FormFieldDataTypes.TrueFalse:
|
|
||||||
dt.type = util.AyaUiFieldDataType.Bool;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dt.type = util.AyaUiFieldDataType.Text;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
dtemplate.Add(dt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
d.template = dtemplate.ToString();
|
|
||||||
|
|
||||||
//ok, were here because there *are* custom fields available
|
// public ExcludeNamedPropertiesContractResolver(List<string> excludeProperties)
|
||||||
var a = await util.GetAsync("FormCustom/" + RavenCustomTranslationKeyObjectName);
|
// {
|
||||||
var ctoken = util.CTokenFromResponse(a);
|
// _excludeProperties = excludeProperties;
|
||||||
d.concurrencyToken = ctoken;
|
// }
|
||||||
await util.PutAsync("FormCustom/" + RavenCustomTranslationKeyObjectName, d.ToString());
|
|
||||||
|
|
||||||
return ret;
|
// 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
|
||||||
|
|
||||||
|
|
||||||
//private static string EnsureValidFileName(string fileName)
|
//private static string EnsureValidFileName(string fileName)
|
||||||
@@ -911,36 +899,9 @@ var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
|||||||
|
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
#endregion
|
#endregion old
|
||||||
|
|
||||||
#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
|
//eoc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//eons
|
//eons
|
||||||
|
|||||||
Reference in New Issue
Block a user