aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.CodeGeneration
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.CodeGeneration')
-rw-r--r--Software/Visual_Studio/Tango.CodeGeneration/EntityCodeFile.cs6
-rw-r--r--Software/Visual_Studio/Tango.CodeGeneration/ObservablesContextCodeFile.cs12
-rw-r--r--Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj2
-rw-r--r--Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml37
-rw-r--r--Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml60
5 files changed, 91 insertions, 26 deletions
diff --git a/Software/Visual_Studio/Tango.CodeGeneration/EntityCodeFile.cs b/Software/Visual_Studio/Tango.CodeGeneration/EntityCodeFile.cs
index bc0f37929..ad91e8117 100644
--- a/Software/Visual_Studio/Tango.CodeGeneration/EntityCodeFile.cs
+++ b/Software/Visual_Studio/Tango.CodeGeneration/EntityCodeFile.cs
@@ -62,6 +62,12 @@ namespace Tango.CodeGeneration
/// </summary>
public String Description { get; set; }
+ public bool IsForeignKey { get; set; }
+
+ public String ForeignKeyName { get; set; }
+
+ public bool Complex { get; set; }
+
/// <summary>
/// Gets or sets a value indicating whether to initialize this field in the constructor.
/// </summary>
diff --git a/Software/Visual_Studio/Tango.CodeGeneration/ObservablesContextCodeFile.cs b/Software/Visual_Studio/Tango.CodeGeneration/ObservablesContextCodeFile.cs
new file mode 100644
index 000000000..618af0916
--- /dev/null
+++ b/Software/Visual_Studio/Tango.CodeGeneration/ObservablesContextCodeFile.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.CodeGeneration
+{
+ public class ObservablesContextCodeFile : Class
+ {
+ }
+}
diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj b/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj
index 1c491813a..ff9072a1a 100644
--- a/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj
+++ b/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj
@@ -67,6 +67,7 @@
<Compile Include="EntityCodeFileJava.cs" />
<Compile Include="EntityCodeFile.cs" />
<Compile Include="EnumerationField.cs" />
+ <Compile Include="ObservablesContextCodeFile.cs" />
<Compile Include="TangoDAOJavaFile.cs" />
<Compile Include="EnumerationFileJava.cs" />
<Compile Include="EnumerationFile.cs" />
@@ -104,6 +105,7 @@
<EmbeddedResource Include="Templates\EntityCodeFileJava.cshtml" />
<EmbeddedResource Include="Templates\EnumerationFileJava.cshtml" />
<EmbeddedResource Include="Templates\TangoDAOJavaFile.cshtml" />
+ <EmbeddedResource Include="Templates\ObservablesContextCodeFile.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml
index 709da7dda..001a2bb3f 100644
--- a/Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml
+++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml
@@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Tango.DAL.Remote.DB;
namespace Tango.DAL.Observables
{
- [EntityFieldName("@(Model.TableName)")]
- public partial class @(Model.Name) : ObservableEntity<@(Model.EntityName)>
+ [Table("@(Model.TableName)")]
+ public partial class @(Model.Name) : ObservableEntity
{
@foreach (var prop in Model.Fields)
{
@@ -16,8 +18,9 @@ namespace Tango.DAL.Observables
/// <summary>
/// Gets or sets the @(Model.Name.ToLower()) @(prop.Description).
/// </summary>
- [EntityFieldName("@(prop.FieldName)")]
- public @(prop.Type) @(prop.Name)
+ @(!prop.Construct && !prop.Complex ? "[Column(\"" + prop.FieldName + "\")]" : "")
+ @(prop.IsForeignKey ? "[ForeignKey(\"" + prop.ForeignKeyName + "\")]" : "")
+ public @(prop.Construct || prop.Complex ? "virtual" : "") @(prop.Type) @(prop.Name)
{
get { return _@(prop.Name.ToLower()); }
set { _@(prop.Name.ToLower()) = value; RaisePropertyChanged(nameof(@(prop.Name))); }
@@ -30,31 +33,13 @@ namespace Tango.DAL.Observables
/// </summary>
public @(Model.Name)() : base()
{
- Init();
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="@(Model.Name)" /> class.
- /// </summary>
- /// <param name="entity">The entity.</param>
- public @(Model.Name)(@(Model.EntityName) entity) : base(entity)
- {
- Init();
- MapEntityToObservable(entity, this);
- }
-
- /// <summary>
- /// Initialize complex types.
- /// </summary>
- private void Init()
- {
@foreach (var prop in Model.Fields)
{
if (prop.Construct)
- {
- <div>
- @(prop.Name) = new @(prop.Type)();
- </div>
+ {
+ <div>
+ @(prop.Name) = new @(prop.Type)();
+ </div>
}
}
}
diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml
new file mode 100644
index 000000000..43330235c
--- /dev/null
+++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Data.Entity;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Settings;
+
+namespace Tango.DAL.Observables
+{
+ public class ObservablesContext : DbContext
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ObservablesContext" /> class.
+ /// </summary>
+ /// <param name="path">The server file path.</param>
+ /// <param name="isFile">if set to <c>true</c> will try to connect to an .mdf file.</param>
+ public ObservablesContext(String path, bool isFile) : base(ComposeConnectionString(path, isFile))
+ {
+
+ }
+
+ /// <summary>
+ /// Composes the connection string.
+ ///</summary>
+ /// <param name="source">The source.</param>
+ /// <param name="isFile">if set to <c>true</c> [is file].</param>
+ /// <returns></returns>
+ private static String ComposeConnectionString(String source, bool isFile)
+ {
+ if (!isFile)
+ {
+ return String.Format("Data Source={0};Initial Catalog=Tango;Integrated Security=true", source);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /// <summary>
+ /// Creates a default remote database context by the address specified in <see cref="SettingsManager.Default.DataBase.SQLServerAddress" />.
+ /// </summary>
+ /// <returns></returns>
+ public static ObservablesContext CreateDefault()
+ {
+ return new ObservablesContext(SettingsManager.Default.DataBase.SQLServerAddress, false);
+ }
+
+ @foreach (var prop in Model.Properties)
+ {
+ <div>
+ /// <summary>
+ /// Gets or sets the @(prop.Name).
+ /// </summary>
+ public @(prop.Type) @(prop.Name) { get; set; }
+ </div>
+ }
+ }
+}