2016-11-19 21:00:13 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-11-19 21:35:33 +00:00
|
|
|
|
using log4net;
|
2016-11-20 20:34:21 +00:00
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Data.Linq;
|
|
|
|
|
using NavScm;
|
|
|
|
|
using NavScm.NavInterface;
|
|
|
|
|
using System.IO;
|
2016-11-19 21:00:13 +00:00
|
|
|
|
|
2016-11-20 15:24:39 +00:00
|
|
|
|
namespace NavScm.TestHost
|
2016-11-19 21:00:13 +00:00
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2016-11-19 21:35:33 +00:00
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(Program));
|
|
|
|
|
|
2016-11-19 21:00:13 +00:00
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2016-11-19 21:35:33 +00:00
|
|
|
|
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("Config Files\\log4net.config"));
|
|
|
|
|
|
|
|
|
|
log.Info("Starting up...");
|
|
|
|
|
|
2016-11-20 20:34:21 +00:00
|
|
|
|
var context = new NavSQLDataContext("Data Source=tbrt-sql-erp-01;Initial Catalog=\"TERRABIT 2015 DEV\";Integrated Security=True");
|
|
|
|
|
var NavSqlObjects = context.NavObject;
|
|
|
|
|
|
|
|
|
|
log.InfoFormat("{0} total entries in NavSqlObjects", NavSqlObjects.Count());
|
|
|
|
|
|
|
|
|
|
var query = from sql in NavSqlObjects
|
2016-11-25 21:32:34 +00:00
|
|
|
|
where sql.Modified == 1 && sql.Type > 0
|
2016-11-20 20:34:21 +00:00
|
|
|
|
select sql;
|
|
|
|
|
|
|
|
|
|
int count = query.Count();
|
|
|
|
|
|
2016-11-25 21:32:34 +00:00
|
|
|
|
log.InfoFormat("{0} modified objects detected, reading them into the cache...", count);
|
2016-11-20 20:34:21 +00:00
|
|
|
|
|
|
|
|
|
var foundObjects = new Dictionary<string, NavObject>(count);
|
|
|
|
|
|
2016-11-25 21:32:34 +00:00
|
|
|
|
// int i = 1;
|
2016-11-20 20:34:21 +00:00
|
|
|
|
foreach (NavObject o in query)
|
|
|
|
|
{
|
2016-11-25 21:32:34 +00:00
|
|
|
|
//log.DebugFormat("Row {6}/{7}: Type {0}, ID {1}, Name {2}, Modified {3} {4}, Version {5}",
|
|
|
|
|
// o.Type, o.ID, o.Name, o.Date.ToShortDateString(), o.Time.ToShortTimeString(), o.Version_List, i++, count);
|
2016-11-20 20:34:21 +00:00
|
|
|
|
|
2016-11-22 20:50:01 +00:00
|
|
|
|
foundObjects.Add(o.CacheKey, o);
|
2016-11-20 20:34:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.InfoFormat("Collection has {0} entries, writing to cache.xml", foundObjects.Count);
|
|
|
|
|
|
|
|
|
|
FileStream writer = new FileStream("cache.xml", FileMode.Create);
|
|
|
|
|
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, NavObject>));
|
|
|
|
|
serializer.WriteObject(writer, foundObjects);
|
|
|
|
|
writer.Close();
|
|
|
|
|
|
|
|
|
|
log.Info("Reloading these entries");
|
|
|
|
|
FileStream reader = new FileStream("cache.xml", FileMode.Open);
|
|
|
|
|
XmlDictionaryReader xmlReader = XmlDictionaryReader.CreateTextReader(reader, new XmlDictionaryReaderQuotas());
|
|
|
|
|
var loadedObjects = (Dictionary<string, NavObject>)serializer.ReadObject(xmlReader, true);
|
|
|
|
|
|
2016-11-25 21:32:34 +00:00
|
|
|
|
// 5.99997 => CU TN_Test
|
2016-11-20 20:34:21 +00:00
|
|
|
|
|
2016-11-25 21:32:34 +00:00
|
|
|
|
log.Debug("Dumping sample object descriptor for 5.99997 ");
|
|
|
|
|
|
|
|
|
|
NavObject o2 = loadedObjects["5.99997"];
|
2016-11-20 20:34:21 +00:00
|
|
|
|
log.DebugFormat("Type {0}, ID {1}, Name {2}, Modified {3} {4}, Version {5}",
|
|
|
|
|
o2.Type, o2.ID, o2.Name, o2.Date.ToShortDateString(), o2.Time.ToShortTimeString(), o2.Version_List);
|
2016-11-19 21:35:33 +00:00
|
|
|
|
|
2016-11-26 21:11:35 +00:00
|
|
|
|
log.Debug("=== Exporting sample objects ===");
|
|
|
|
|
|
2016-11-25 21:32:34 +00:00
|
|
|
|
DevEnvInterface devenv = new DevEnvInterface("C:\\Program Files (x86)\\Microsoft Dynamics NAV\\tbrt-nav-erp-02\\RoleTailored Client\\finsql.exe",
|
|
|
|
|
"tbrt-sql-erp-01", "TERRABIT 2015 DEV");
|
|
|
|
|
|
|
|
|
|
devenv.Export(loadedObjects["5.80"], $"{Directory.GetCurrentDirectory()}\\CU80.txt");
|
2016-11-26 21:11:35 +00:00
|
|
|
|
devenv.Export(loadedObjects["5.99996"], $"{Directory.GetCurrentDirectory()}\\CU99996.txt");
|
2016-11-25 21:32:34 +00:00
|
|
|
|
devenv.Export(loadedObjects["5.99997"], $"{Directory.GetCurrentDirectory()}\\CU99997.txt");
|
2016-11-26 21:11:35 +00:00
|
|
|
|
devenv.Export(loadedObjects["5.99998"], $"{Directory.GetCurrentDirectory()}\\CU99998.txt");
|
2016-11-25 21:32:34 +00:00
|
|
|
|
devenv.Export(loadedObjects["1.13"], $"{Directory.GetCurrentDirectory()}\\TAB13.txt");
|
|
|
|
|
|
2016-11-26 21:11:35 +00:00
|
|
|
|
//log.Debug("=== Importing TN_WORK ===");
|
|
|
|
|
|
|
|
|
|
//o2 = devenv.Import(loadedObjects["5.99997"], $"{Directory.GetCurrentDirectory()}\\CU99997.txt");
|
|
|
|
|
//log.DebugFormat("Object after import: Type {0}, ID {1}, Name {2}, Modified {3} {4}, Version {5}",
|
|
|
|
|
// o2.Type, o2.ID, o2.Name, o2.Date.ToShortDateString(), o2.Time.ToShortTimeString(), o2.Version_List);
|
|
|
|
|
|
|
|
|
|
//log.Debug("=== Compiling TN_WORK ===");
|
|
|
|
|
|
|
|
|
|
//o2 = devenv.Compile(loadedObjects["5.99997"]);
|
|
|
|
|
//log.DebugFormat("Object after compilation: Type {0}, ID {1}, Name {2}, Modified {3} {4}, Version {5}",
|
|
|
|
|
// o2.Type, o2.ID, o2.Name, o2.Date.ToShortDateString(), o2.Time.ToShortTimeString(), o2.Version_List);
|
|
|
|
|
|
2016-11-19 21:35:33 +00:00
|
|
|
|
log.Info("Shutting down...");
|
|
|
|
|
|
|
|
|
|
Console.ReadLine();
|
2016-11-19 21:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|