From 8972de71a1a30626cdb970b320ac85f22db1d7c4 Mon Sep 17 00:00:00 2001 From: Torben Nehmer Date: Tue, 22 Nov 2016 23:03:24 +0100 Subject: [PATCH] Added support for code contracts (requires VS support!) Implemented Contracts into existing classes (yet incomplete especially with Interface implementations in NavObject). Otherwise it basically works. --- NAV Source Control Test Host/App.config | 6 +- .../NAV Source Control Test Host.csproj | 47 ++++++++++- NAVSCM Library/App.config | 6 +- NAVSCM Library/NAVSCM Library.csproj | 48 ++++++++++- .../NavInterface/DevEnvInterface.cs | 81 +++++++++++++++++++ NAVSCM Library/NavInterface/NavObject.cs | 18 +++-- 6 files changed, 190 insertions(+), 16 deletions(-) create mode 100644 NAVSCM Library/NavInterface/DevEnvInterface.cs diff --git a/NAV Source Control Test Host/App.config b/NAV Source Control Test Host/App.config index 88fa402..bae5d6d 100644 --- a/NAV Source Control Test Host/App.config +++ b/NAV Source Control Test Host/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/NAV Source Control Test Host/NAV Source Control Test Host.csproj b/NAV Source Control Test Host/NAV Source Control Test Host.csproj index 2f48893..226b651 100644 --- a/NAV Source Control Test Host/NAV Source Control Test Host.csproj +++ b/NAV Source Control Test Host/NAV Source Control Test Host.csproj @@ -9,7 +9,7 @@ Properties NavScm.TestHost NAV Source Control Test Host - v4.5.2 + v4.6.1 512 true publish\ @@ -27,6 +27,8 @@ false false true + + 0 AnyCPU @@ -37,6 +39,49 @@ DEBUG;TRACE prompt 4 + True + False + False + False + False + True + True + True + True + True + True + True + True + True + False + True + False + True + False + False + False + False + True + False + True + True + True + False + False + + + + + + + + True + False + False + True + Full + %28none%29 + 0 AnyCPU diff --git a/NAVSCM Library/App.config b/NAVSCM Library/App.config index b23f3ba..41c512f 100644 --- a/NAVSCM Library/App.config +++ b/NAVSCM Library/App.config @@ -1,7 +1,7 @@ - + - + - \ No newline at end of file + diff --git a/NAVSCM Library/NAVSCM Library.csproj b/NAVSCM Library/NAVSCM Library.csproj index 1bc22d1..58296cb 100644 --- a/NAVSCM Library/NAVSCM Library.csproj +++ b/NAVSCM Library/NAVSCM Library.csproj @@ -9,8 +9,10 @@ Properties NavScm NavScm Library - v4.5.2 + v4.6.1 512 + 1 + true @@ -22,6 +24,49 @@ 4 + True + False + True + False + False + True + True + True + True + True + True + True + True + True + False + True + False + True + False + False + False + False + True + False + True + True + True + False + True + + + + + + + + True + False + False + True + Full + Build + 0 pdbonly @@ -50,6 +95,7 @@ + True True diff --git a/NAVSCM Library/NavInterface/DevEnvInterface.cs b/NAVSCM Library/NavInterface/DevEnvInterface.cs new file mode 100644 index 0000000..1075ee6 --- /dev/null +++ b/NAVSCM Library/NavInterface/DevEnvInterface.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using System.Diagnostics.Contracts; + +namespace NavScm.NavInterface +{ + /// + /// Interfaces to the NAV IDE command line interface to export / import objects. + /// + /// + /// The interface is based on the powershell snippets delivered with NAV. + /// Note, that the devenv does not give any return values. Instead, errors can only + /// be detected by the existance of the log file, which is created only upon errors. + /// Currently, the interface expects to be able to access the database using + /// NTLM Single Sign on. SQL user/pass authentication is not supported. + /// + class DevEnvInterface + { + private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(DevEnvInterface)); + + /// + /// Path to the dev env executable. + /// + protected string DevEnvPath { get; private set; } + + /// + /// Hostname of the database server. + /// + protected string DatabaseServer { get; private set; } + + /// + /// Name of the database itself. + /// + protected string DatabaseName { get; private set; } + + /// + /// Create an interface class to a given NAV developer environment. + /// + /// Full path and name to finsql.exe (or however you call it). + public DevEnvInterface(string devEnvPath, string databaseServer, string databaseName) + { + Contract.Requires(devEnvPath != ""); + Contract.Requires(databaseServer != ""); + Contract.Requires(databaseName != ""); + Contract.Ensures(File.Exists(DevEnvPath)); + Contract.Ensures(databaseName == DatabaseName); + Contract.Ensures(databaseServer == DatabaseServer); + Contract.Ensures(devEnvPath == DevEnvPath); + + DevEnvPath = devEnvPath; + if (!File.Exists(DevEnvPath)) + throw new InvalidOperationException($"The file {DevEnvPath} was not found."); + + DatabaseServer = databaseServer; + DatabaseName = databaseName; + + if (log.IsDebugEnabled) + { + log.Debug($"Constructed and attached to DevEnv {DevEnvPath}"); + log.Debug($"Using database [{DatabaseName}] on server {DatabaseServer}"); + } + } + + /// + /// Exports a given NAV object to disk. + /// + /// The NAV object as taken from the SQL database or from the cache (doesn't matter). + /// The name of the destination file. The system ensures, that the file + /// ends with .txt, as finsql.exe deduces the export format from the destiation files extension (crap). + public void Export(NavObject obj, string destinationFileName) + { + Contract.Requires(obj != null); + Contract.Requires(destinationFileName != ""); + } + + } +} diff --git a/NAVSCM Library/NavInterface/NavObject.cs b/NAVSCM Library/NavInterface/NavObject.cs index f2a0493..9c8c341 100644 --- a/NAVSCM Library/NavInterface/NavObject.cs +++ b/NAVSCM Library/NavInterface/NavObject.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Diagnostics.Contracts; namespace NavScm.NavInterface { @@ -43,15 +44,21 @@ namespace NavScm.NavInterface /// partial class NavObject : IEquatable, IComparable, IComparable { + private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(NavObject)); + /// /// Validate restrictions on supported objects as outlined in the class description. /// partial void OnLoaded() { + Contract.Requires(Company_Name.Length == 0); + Contract.Requires(Type >= 0 && Type <= 9 && Type != 2 && Type != 4 ); + /* if (Company_Name.Length > 0) throw new InvalidOperationException($"The object {CacheKey} holds a variant with the company name {Company_Name}, which is unsupported"); if (Type < 0 || Type == 2 || Type == 4 || Type > 9) throw new InvalidOperationException($"The object type of {CacheKey} is unsupported"); + */ } /// @@ -75,20 +82,15 @@ namespace NavScm.NavInterface /// public string CacheKey { - get { - return $"{Type}.{ID}"; - } + get { return $"{Type}.{ID}"; } } /// /// Converts the Date and Time fields to a combined Date/Time value. /// - public DateTime Modified + public DateTime ModifiedDate { - get - { - return Date.Add(Time.TimeOfDay); - } + get { return Date.Add(Time.TimeOfDay); } } ///