Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic IntializeDataRepository #133

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<ImageData Id="1016">424de6000000000000007600000028000000100000000e000000010004000000000070000000c30e0000c30e000010000000100000000000ff00ff00ff00ff000000ffff000000ff000000ffff0000008000800080008000000080800000008000000080800080808000c0c0c000ffffff0000000000111111111111111100ffffffffffffff00fffffffffff00ffffffffffffff00ffff00fff00fffffffff00fff00fffffffffffffffffff44f00fffffffffff44f00ffffffffffffffdddddd1111111111dddddd1111111111dddddd1111111111dddddd1111111111dddddd1111111111</ImageData>
<ImageData Id="1017">424de6000000000000007600000028000000100000000e000000010004000000000070000000c30e0000c30e000010000000100000000000ff00ff00ff00ff000000ffff000000ff000000ffff0000008000800080008000000080800000008000000080800080808000c0c0c000ffffff00000000001111111111111111fffffffffffffffffcfcfcfcfffff00ff4f4f4f4fffff00ffffffffffffffffffffffffffffffffffcfcfcfcfffff00ff4f4f4f4fffff00fffffffffffffffff55555511111111115555551111111111555555111111111155555511111111115555551111111111</ImageData>
</ImageDatas>
<Project ProjectGUID="{81535540-06FC-4400-AD30-5DF785BB9A0E}" Target64Bit="true" ShowHideConfigurations="#x106">
<Project ProjectGUID="{81535540-06FC-4400-AD30-5DF785BB9A0E}" ShowHideConfigurations="#x106">
<System>
<Settings MaxCpus="24" NonWinCpus="1"/>
<Tasks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
<DUT Name="ProcessData" Id="{113396d1-0fe0-4862-b140-87fe92cd116d}">
<Declaration><![CDATA[{attribute clr [Container(Layout.Tabs)]}
TYPE
ProcessData EXTENDS TcoData.TcoEntity :
ProcessData EXTENDS TcoEntityBase :
STRUCT
{attribute clr [RenderIgnore("Control", "ShadowControl")]}
{attribute addProperty Name "<#Created#>"}
_Created : DT;
{attribute clr [RenderIgnore("Control", "ShadowControl")]}
{attribute addProperty Name "<#Modified#>"}
_Modified : DT;
{attribute addProperty Name "<#Entity header#>"}
EntityHeader : EntityHeader := (Parent := THISSTRUCT);
{attribute addProperty Name "<#CU00x#>"}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
<DUT Name="TcoEntityBase" Id="{c8c4cc6f-61a4-4ead-b300-8aa0513c06f9}">
<Declaration><![CDATA[TYPE TcoEntityBase EXTENDS TcoData.TcoEntity :
STRUCT
{attribute clr [RenderIgnore("Control", "ShadowControl")]}
{attribute addProperty Name "<#Created#>"}
_Created : DT;
{attribute clr [RenderIgnore("Control", "ShadowControl")]}
{attribute addProperty Name "<#Modified#>"}
_Modified : DT;

END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
<DUT Name="TechnologyData" Id="{117cc65d-87e4-0834-348f-298728a9d5a3}">
<Declaration><![CDATA[{attribute clr [Container(Layout.Tabs)]}
TYPE
TechnologyData EXTENDS TcoData.TcoEntity :
TechnologyData EXTENDS TcoEntityBase :
STRUCT
{attribute clr [RenderIgnore("Control", "ShadowControl")]}
{attribute addProperty Name "<#Created#>"}
_Created : DT;
{attribute clr [RenderIgnore("Control", "ShadowControl")]}
{attribute addProperty Name "<#Modified#>"}
_Modified : DT;
CU00x : CU00xTechnologicalData := (Parent := THISSTRUCT);
END_STRUCT
END_TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@
<Compile Include="Technology\CU00x\Data\CU00xProcessData.TcDUT">
<SubType>Code</SubType>
</Compile>
<Compile Include="Technology\Data\TcoEntityBase.TcDUT">
<SubType>Code</SubType>
</Compile>
<Compile Include="Technology\Data\TechnologicalDataManager.TcPOU">
<SubType>Code</SubType>
</Compile>
Expand Down
67 changes: 32 additions & 35 deletions templates/mts-s-template/t/src/x_template_xOp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ namespace x_template_xOp
/// </summary>
public partial class App : Application
{

/// <summary>
/// Set this to false to consume the database without writing
/// </summary>
private bool IsDataServer { get; set; } = true;

protected override void OnStartup(StartupEventArgs e)
{

Expand Down Expand Up @@ -296,7 +302,6 @@ private static void StartRavenDBEmbeddedServer()
}
private IAuthenticationService CreateSecurityManageUsingRavenDb()
{

var users = new RavenDbRepository<UserData>(new RavenDbRepositorySettings<UserData>(new string[] { Entry.Settings.GetConnectionString() }, "Users", "", ""));
var groups = new RavenDbRepository<GroupData>(new RavenDbRepositorySettings<GroupData>(new string[] { Entry.Settings.GetConnectionString() }, "Groups", "", ""));
var roleGroupManager = new RoleGroupManager(groups);
Expand All @@ -307,13 +312,13 @@ private IAuthenticationService CreateSecurityManageUsingRavenDb()
private void SetUpRepositoriesUsingRavenDb()
{
var ProcessDataRepoSettings = new RavenDbRepositorySettings<PlainProcessData>(new string[] { Entry.Settings.GetConnectionString() }, "ProcessSettings", "", "");
InitializeProcessDataRepositoryWithDataExchange(x_template_xPlc.MAIN._technology._processSettings, new RavenDbRepository<PlainProcessData>(ProcessDataRepoSettings));
IntializeDataRepository(x_template_xPlc.MAIN._technology._processSettings, new RavenDbRepository<PlainProcessData>(ProcessDataRepoSettings),IsDataServer);

var TechnologicalDataRepoSettings = new RavenDbRepositorySettings<PlainTechnologyData>(new string[] { Entry.Settings.GetConnectionString() }, "TechnologySettings", "", "");
IntializeTechnologyDataRepositoryWithDataExchange(x_template_xPlc.MAIN._technology._technologySettings, new RavenDbRepository<PlainTechnologyData>(TechnologicalDataRepoSettings));
IntializeDataRepository(x_template_xPlc.MAIN._technology._technologySettings, new RavenDbRepository<PlainTechnologyData>(TechnologicalDataRepoSettings),IsDataServer);

var ReworklDataRepoSettings = new RavenDbRepositorySettings<PlainProcessData>(new string[] { Entry.Settings.GetConnectionString() }, "ReworkSettings", "", "");
InitializeProcessDataRepositoryWithDataExchange(x_template_xPlc.MAIN._technology._reworkSettings, new RavenDbRepository<PlainProcessData>(ReworklDataRepoSettings));
IntializeDataRepository(x_template_xPlc.MAIN._technology._reworkSettings, new RavenDbRepository<PlainProcessData>(ReworklDataRepoSettings),IsDataServer);

//Statistics
var _statisticsDataHandler = RepositoryDataSetHandler<StatisticsDataItem>.CreateSet(new RavenDbRepository<EntitySet<StatisticsDataItem>>(new RavenDbRepositorySettings<EntitySet<StatisticsDataItem>>(new string[] { Entry.Settings.GetConnectionString() }, "Statistics", "", "")));
Expand All @@ -325,8 +330,8 @@ private void SetUpRepositoriesUsingRavenDb()


var Traceability = new RavenDbRepositorySettings<PlainProcessData>(new string[] { Entry.Settings.GetConnectionString() }, "Traceability", "", "");
InitializeProcessDataRepositoryWithDataExchange(x_template_xPlc.MAIN._technology._processTraceability, new RavenDbRepository<PlainProcessData>(Traceability));
InitializeProcessDataRepositoryWithDataExchangeWithStatistic(x_template_xPlc.MAIN._technology._cu00x._processData, new RavenDbRepository<PlainProcessData>(Traceability), CuxStatistic);
IntializeDataRepository(x_template_xPlc.MAIN._technology._processTraceability, new RavenDbRepository<PlainProcessData>(Traceability),IsDataServer);
InitializeProcessDataRepositoryWithStatistics(x_template_xPlc.MAIN._technology._cu00x._processData, new RavenDbRepository<PlainProcessData>(Traceability), CuxStatistic, IsDataServer);

Rework = new ReworkModel(new RavenDbRepository<PlainProcessData>(ReworklDataRepoSettings), new RavenDbRepository<PlainProcessData>(Traceability));

Expand Down Expand Up @@ -357,18 +362,17 @@ private IAuthenticationService CreateSecurityManageUsingMongoDb()

}


private void SetUpRepositoriesUsingMongoDb()
{
var ProcessDataRepoSettings = new MongoDbRepositorySettings<PlainProcessData>(Entry.Settings.GetConnectionString(), Entry.Settings.DbName, "ProcessSettings");
InitializeProcessDataRepositoryWithDataExchange(x_template_xPlc.MAIN._technology._processSettings, new MongoDbRepository<PlainProcessData>(ProcessDataRepoSettings));
IntializeDataRepository(x_template_xPlc.MAIN._technology._processSettings, new MongoDbRepository<PlainProcessData>(ProcessDataRepoSettings), IsDataServer);
InitializeIndexProcessDataRepositoryMongoDb(ProcessDataRepoSettings);

var TechnologicalDataRepoSettings = new MongoDbRepositorySettings<PlainTechnologyData>(Entry.Settings.GetConnectionString(), Entry.Settings.DbName, "TechnologySettings");
IntializeTechnologyDataRepositoryWithDataExchange(x_template_xPlc.MAIN._technology._technologySettings, new MongoDbRepository<PlainTechnologyData>(TechnologicalDataRepoSettings));
IntializeDataRepository(x_template_xPlc.MAIN._technology._technologySettings, new MongoDbRepository<PlainTechnologyData>(TechnologicalDataRepoSettings), IsDataServer);

var ReworklDataRepoSettings = new MongoDbRepositorySettings<PlainProcessData>(Entry.Settings.GetConnectionString(), Entry.Settings.DbName, "ReworkSettings");
InitializeProcessDataRepositoryWithDataExchange(x_template_xPlc.MAIN._technology._reworkSettings, new MongoDbRepository<PlainProcessData>(ReworklDataRepoSettings));
IntializeDataRepository(x_template_xPlc.MAIN._technology._reworkSettings, new MongoDbRepository<PlainProcessData>(ReworklDataRepoSettings),IsDataServer);

//Statistics
var _statisticsDataHandler = RepositoryDataSetHandler<StatisticsDataItem>.CreateSet(new MongoDbRepository<EntitySet<StatisticsDataItem>>(new MongoDbRepositorySettings<EntitySet<StatisticsDataItem>>(Entry.Settings.GetConnectionString(), Entry.Settings.DbName, "Statistics")));
Expand All @@ -380,8 +384,8 @@ private void SetUpRepositoriesUsingMongoDb()


var Traceability = new MongoDbRepositorySettings<PlainProcessData>(Entry.Settings.GetConnectionString(), Entry.Settings.DbName, "Traceability");
InitializeProcessDataRepositoryWithDataExchange(x_template_xPlc.MAIN._technology._processTraceability, new MongoDbRepository<PlainProcessData>(Traceability));
InitializeProcessDataRepositoryWithDataExchangeWithStatistic(x_template_xPlc.MAIN._technology._cu00x._processData, new MongoDbRepository<PlainProcessData>(Traceability), CuxStatistic);
IntializeDataRepository(x_template_xPlc.MAIN._technology._processTraceability, new MongoDbRepository<PlainProcessData>(Traceability), IsDataServer);
InitializeProcessDataRepositoryWithStatistics(x_template_xPlc.MAIN._technology._cu00x._processData, new MongoDbRepository<PlainProcessData>(Traceability), CuxStatistic, IsDataServer);
InitializeIndexProcessDataRepositoryMongoDb(Traceability);

Rework = new ReworkModel(new MongoDbRepository<PlainProcessData>(ReworklDataRepoSettings), new MongoDbRepository<PlainProcessData>(Traceability));
Expand Down Expand Up @@ -429,7 +433,6 @@ public void InitializeIndexProcessDataRepositoryMongoDb(MongoDbRepositorySetting
indexOptions.Name = name;
var indexKey = Builders<PlainProcessData>.IndexKeys.Descending(p => p._EntityId);
mongoDbRepositorySettings.Collection.Indexes.CreateOne(new CreateIndexModel<PlainProcessData>(indexKey, indexOptions));

}

name = "_Created";
Expand All @@ -439,59 +442,53 @@ public void InitializeIndexProcessDataRepositoryMongoDb(MongoDbRepositorySetting
indexOptions.Name = name;
var indexKey = Builders<PlainProcessData>.IndexKeys.Descending(p => p._Created);
mongoDbRepositorySettings.Collection.Indexes.CreateOne(new CreateIndexModel<PlainProcessData>(indexKey, indexOptions));

}

name = "_Modified";
if (!indexes.Exists(i => i.GetElement("name").ToString().Contains(name)))
{
var indexOptions = new CreateIndexOptions();
indexOptions.Name = name;
var indexKey = Builders<PlainProcessData>.IndexKeys.Descending(p => p._Modified);
mongoDbRepositorySettings.Collection.Indexes.CreateOne(new CreateIndexModel<PlainProcessData>(indexKey, indexOptions));

}

}

/// <summary>
/// Initializes <see cref="ProcessDataManager"/>s repository for data exchange between PLC and storage (database).
/// </summary>
/// <param name="manager">Data manager</param>
/// <param name="repository">Repository</param>
private static void InitializeProcessDataRepositoryWithDataExchange(ProcessDataManager processData, IRepository<PlainProcessData> repository)
{
repository.OnCreate = (id, data) => { data._Created = DateTime.Now; data._Modified = DateTime.Now; };
repository.OnUpdate = (id, data) => { data._Modified = DateTime.Now; };
processData.InitializeRepository(repository);
processData.InitializeRemoteDataExchange(repository);

}

/// Initializes <see cref="ProcessDataManager"/>s repository for data exchange between PLC and storage (database).
/// </summary>
/// <param name="manager">Data manager</param>
/// <param name="repository">Repository</param>
private static void InitializeProcessDataRepositoryWithDataExchangeWithStatistic(ProcessDataManager processData, IRepository<PlainProcessData> repository, StatisticsDataController cuxStatistic)
private static void InitializeProcessDataRepositoryWithStatistics(ProcessDataManager processData, IRepository<PlainProcessData> repository, StatisticsDataController cuSytatistics, bool withDataExchange)
{
repository.OnCreate = (id, data) => { data._Created = DateTime.Now; data._Modified = DateTime.Now; };
repository.OnUpdate = (id, data) => { data._Modified = DateTime.Now; cuxStatistic.Count(data); };
repository.OnUpdate = (id, data) => { data._Modified = DateTime.Now; cuSytatistics.Count(data); };
processData.InitializeRepository(repository);
processData.InitializeRemoteDataExchange(repository);
if (withDataExchange)
{
processData.InitializeRemoteDataExchange(repository);
}
}


/// <summary>
/// Initializes <see cref="TechnologicalDataManager"/>s repository for data exchange between PLC and storage (database).
/// Initializes <see cref="TechnologicalDataManager"/>s or <see cref="ProcessDataManager"/>s repository for data exchange between PLC and storage (database).
/// </summary>
/// <param name="manager">Data manager</param>
/// <param name="repository">Repository</param>
private static void IntializeTechnologyDataRepositoryWithDataExchange(TechnologicalDataManager manager, IRepository<PlainTechnologyData> repository)
private static void IntializeDataRepository<T1, T2>(T1 manager, IRepository<T2> repository, bool withDataExchange) where T1 : TcoData.TcoDataExchange
where T2 : PlainTcoEntityBase
{
repository.OnCreate = (id, data) => { data._Created = DateTime.Now; data._Modified = DateTime.Now; };
repository.OnUpdate = (id, data) => { data._Modified = DateTime.Now; };
manager.InitializeRepository(repository);
manager.InitializeRemoteDataExchange(repository);
if (withDataExchange)
{
manager.InitializeRemoteDataExchange(repository);
}
}


/// <summary>
/// Gets the twin connector for this application.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,20 @@
<data name="___Average_cycle_time_filter_constant__" xml:space="preserve">
<value>Average cycle time filter constant</value>
</data>
<data name="___CU00x__" xml:space="preserve">
<value>CU00x</value>
</data>
<data name="___Created__" xml:space="preserve">
<value>Created</value>
</data>
<data name="___Modified__" xml:space="preserve">
<value>Modified</value>
</data>
<data name="___Presure_OK___" xml:space="preserve">
<value>Presure OK </value>
</data>
<data name="___Emergency_Stop___" xml:space="preserve">
<value>Emergency Stop </value>
<data name="___CU00x__" xml:space="preserve">
<value>CU00x</value>
</data>
Expand Down