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.
This commit is contained in:
parent
28dbc5c7fa
commit
8972de71a1
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
|
||||
</startup>
|
||||
</configuration>
|
@ -9,7 +9,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NavScm.TestHost</RootNamespace>
|
||||
<AssemblyName>NAV Source Control Test Host</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
@ -27,6 +27,8 @@
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile />
|
||||
<CodeContractsAssemblyMode>0</CodeContractsAssemblyMode>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@ -37,6 +39,49 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking>
|
||||
<CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface>
|
||||
<CodeContractsRuntimeThrowOnFailure>False</CodeContractsRuntimeThrowOnFailure>
|
||||
<CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
|
||||
<CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
|
||||
<CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
|
||||
<CodeContractsNonNullObligations>True</CodeContractsNonNullObligations>
|
||||
<CodeContractsBoundsObligations>True</CodeContractsBoundsObligations>
|
||||
<CodeContractsArithmeticObligations>True</CodeContractsArithmeticObligations>
|
||||
<CodeContractsEnumObligations>True</CodeContractsEnumObligations>
|
||||
<CodeContractsRedundantAssumptions>True</CodeContractsRedundantAssumptions>
|
||||
<CodeContractsAssertsToContractsCheckBox>True</CodeContractsAssertsToContractsCheckBox>
|
||||
<CodeContractsRedundantTests>True</CodeContractsRedundantTests>
|
||||
<CodeContractsMissingPublicRequiresAsWarnings>True</CodeContractsMissingPublicRequiresAsWarnings>
|
||||
<CodeContractsMissingPublicEnsuresAsWarnings>False</CodeContractsMissingPublicEnsuresAsWarnings>
|
||||
<CodeContractsInferRequires>True</CodeContractsInferRequires>
|
||||
<CodeContractsInferEnsures>False</CodeContractsInferEnsures>
|
||||
<CodeContractsInferEnsuresAutoProperties>True</CodeContractsInferEnsuresAutoProperties>
|
||||
<CodeContractsInferObjectInvariants>False</CodeContractsInferObjectInvariants>
|
||||
<CodeContractsSuggestAssumptions>False</CodeContractsSuggestAssumptions>
|
||||
<CodeContractsSuggestAssumptionsForCallees>False</CodeContractsSuggestAssumptionsForCallees>
|
||||
<CodeContractsSuggestRequires>False</CodeContractsSuggestRequires>
|
||||
<CodeContractsNecessaryEnsures>True</CodeContractsNecessaryEnsures>
|
||||
<CodeContractsSuggestObjectInvariants>False</CodeContractsSuggestObjectInvariants>
|
||||
<CodeContractsSuggestReadonly>True</CodeContractsSuggestReadonly>
|
||||
<CodeContractsRunInBackground>True</CodeContractsRunInBackground>
|
||||
<CodeContractsShowSquigglies>True</CodeContractsShowSquigglies>
|
||||
<CodeContractsUseBaseLine>False</CodeContractsUseBaseLine>
|
||||
<CodeContractsEmitXMLDocs>False</CodeContractsEmitXMLDocs>
|
||||
<CodeContractsCustomRewriterAssembly />
|
||||
<CodeContractsCustomRewriterClass />
|
||||
<CodeContractsLibPaths />
|
||||
<CodeContractsExtraRewriteOptions />
|
||||
<CodeContractsExtraAnalysisOptions />
|
||||
<CodeContractsSQLServerOption />
|
||||
<CodeContractsBaseLineFile />
|
||||
<CodeContractsCacheAnalysisResults>True</CodeContractsCacheAnalysisResults>
|
||||
<CodeContractsSkipAnalysisIfCannotConnectToCache>False</CodeContractsSkipAnalysisIfCannotConnectToCache>
|
||||
<CodeContractsFailBuildOnWarnings>False</CodeContractsFailBuildOnWarnings>
|
||||
<CodeContractsBeingOptimisticOnExternal>True</CodeContractsBeingOptimisticOnExternal>
|
||||
<CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel>
|
||||
<CodeContractsReferenceAssembly>%28none%29</CodeContractsReferenceAssembly>
|
||||
<CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
|
||||
<connectionStrings>
|
||||
<add name="TERRABIT_2015_DEVEntities" connectionString="metadata=res://*/NavScm.NavInterface.SQL.Model1.csdl|res://*/NavScm.NavInterface.SQL.Model1.ssdl|res://*/NavScm.NavInterface.SQL.Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=tbrt-sql-erp-01;initial catalog="TERRABIT 2015 DEV";integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
|
||||
<add name="TERRABIT_2015_DEVEntities" connectionString="metadata=res://*/NavScm.NavInterface.SQL.Model1.csdl|res://*/NavScm.NavInterface.SQL.Model1.ssdl|res://*/NavScm.NavInterface.SQL.Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=tbrt-sql-erp-01;initial catalog="TERRABIT 2015 DEV";integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient"/>
|
||||
</connectionStrings>
|
||||
</configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
|
||||
|
@ -9,8 +9,10 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NavScm</RootNamespace>
|
||||
<AssemblyName>NavScm Library</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<CodeContractsAssemblyMode>1</CodeContractsAssemblyMode>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -22,6 +24,49 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking>
|
||||
<CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface>
|
||||
<CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure>
|
||||
<CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
|
||||
<CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
|
||||
<CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
|
||||
<CodeContractsNonNullObligations>True</CodeContractsNonNullObligations>
|
||||
<CodeContractsBoundsObligations>True</CodeContractsBoundsObligations>
|
||||
<CodeContractsArithmeticObligations>True</CodeContractsArithmeticObligations>
|
||||
<CodeContractsEnumObligations>True</CodeContractsEnumObligations>
|
||||
<CodeContractsRedundantAssumptions>True</CodeContractsRedundantAssumptions>
|
||||
<CodeContractsAssertsToContractsCheckBox>True</CodeContractsAssertsToContractsCheckBox>
|
||||
<CodeContractsRedundantTests>True</CodeContractsRedundantTests>
|
||||
<CodeContractsMissingPublicRequiresAsWarnings>True</CodeContractsMissingPublicRequiresAsWarnings>
|
||||
<CodeContractsMissingPublicEnsuresAsWarnings>False</CodeContractsMissingPublicEnsuresAsWarnings>
|
||||
<CodeContractsInferRequires>True</CodeContractsInferRequires>
|
||||
<CodeContractsInferEnsures>False</CodeContractsInferEnsures>
|
||||
<CodeContractsInferEnsuresAutoProperties>True</CodeContractsInferEnsuresAutoProperties>
|
||||
<CodeContractsInferObjectInvariants>False</CodeContractsInferObjectInvariants>
|
||||
<CodeContractsSuggestAssumptions>False</CodeContractsSuggestAssumptions>
|
||||
<CodeContractsSuggestAssumptionsForCallees>False</CodeContractsSuggestAssumptionsForCallees>
|
||||
<CodeContractsSuggestRequires>False</CodeContractsSuggestRequires>
|
||||
<CodeContractsNecessaryEnsures>True</CodeContractsNecessaryEnsures>
|
||||
<CodeContractsSuggestObjectInvariants>False</CodeContractsSuggestObjectInvariants>
|
||||
<CodeContractsSuggestReadonly>True</CodeContractsSuggestReadonly>
|
||||
<CodeContractsRunInBackground>True</CodeContractsRunInBackground>
|
||||
<CodeContractsShowSquigglies>True</CodeContractsShowSquigglies>
|
||||
<CodeContractsUseBaseLine>False</CodeContractsUseBaseLine>
|
||||
<CodeContractsEmitXMLDocs>True</CodeContractsEmitXMLDocs>
|
||||
<CodeContractsCustomRewriterAssembly />
|
||||
<CodeContractsCustomRewriterClass />
|
||||
<CodeContractsLibPaths />
|
||||
<CodeContractsExtraRewriteOptions />
|
||||
<CodeContractsExtraAnalysisOptions />
|
||||
<CodeContractsSQLServerOption />
|
||||
<CodeContractsBaseLineFile />
|
||||
<CodeContractsCacheAnalysisResults>True</CodeContractsCacheAnalysisResults>
|
||||
<CodeContractsSkipAnalysisIfCannotConnectToCache>False</CodeContractsSkipAnalysisIfCannotConnectToCache>
|
||||
<CodeContractsFailBuildOnWarnings>False</CodeContractsFailBuildOnWarnings>
|
||||
<CodeContractsBeingOptimisticOnExternal>True</CodeContractsBeingOptimisticOnExternal>
|
||||
<CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel>
|
||||
<CodeContractsReferenceAssembly>Build</CodeContractsReferenceAssembly>
|
||||
<CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@ -50,6 +95,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="NavInterface\DevEnvInterface.cs" />
|
||||
<Compile Include="NavInterface\NavSQL.designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
|
81
NAVSCM Library/NavInterface/DevEnvInterface.cs
Normal file
81
NAVSCM Library/NavInterface/DevEnvInterface.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Interfaces to the NAV IDE command line interface to export / import objects.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>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.</para>
|
||||
/// <para>Currently, the interface expects to be able to access the database using
|
||||
/// NTLM Single Sign on. SQL user/pass authentication is not supported.</para>
|
||||
/// </remarks>
|
||||
class DevEnvInterface
|
||||
{
|
||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(DevEnvInterface));
|
||||
|
||||
/// <summary>
|
||||
/// Path to the dev env executable.
|
||||
/// </summary>
|
||||
protected string DevEnvPath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Hostname of the database server.
|
||||
/// </summary>
|
||||
protected string DatabaseServer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the database itself.
|
||||
/// </summary>
|
||||
protected string DatabaseName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Create an interface class to a given NAV developer environment.
|
||||
/// </summary>
|
||||
/// <param name="devEnvPath">Full path and name to finsql.exe (or however you call it).</param>
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports a given NAV object to disk.
|
||||
/// </summary>
|
||||
/// <param name="obj">The NAV object as taken from the SQL database or from the cache (doesn't matter).</param>
|
||||
/// <param name="destinationFileName">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).</param>
|
||||
public void Export(NavObject obj, string destinationFileName)
|
||||
{
|
||||
Contract.Requires(obj != null);
|
||||
Contract.Requires(destinationFileName != "");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
/// <seealso cref="NavObjectType"/>
|
||||
partial class NavObject : IEquatable<NavObject>, IComparable, IComparable<NavObject>
|
||||
{
|
||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(NavObject));
|
||||
|
||||
/// <summary>
|
||||
/// Validate restrictions on supported objects as outlined in the class description.
|
||||
/// </summary>
|
||||
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");
|
||||
*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -75,20 +82,15 @@ namespace NavScm.NavInterface
|
||||
/// </summary>
|
||||
public string CacheKey
|
||||
{
|
||||
get {
|
||||
return $"{Type}.{ID}";
|
||||
}
|
||||
get { return $"{Type}.{ID}"; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the Date and Time fields to a combined Date/Time value.
|
||||
/// </summary>
|
||||
public DateTime Modified
|
||||
public DateTime ModifiedDate
|
||||
{
|
||||
get
|
||||
{
|
||||
return Date.Add(Time.TimeOfDay);
|
||||
}
|
||||
get { return Date.Add(Time.TimeOfDay); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user