Skip to content

Commit

Permalink
[ENHANCEMENT]Rework Offline_Online (#52)
Browse files Browse the repository at this point in the history
* Create draft PR for #51

* + fix  merger tests

* +rework settings
+rework model

* +add resources
*fix merger TcoDataMerge tests

* +OfflineReworkView in Template app
+ReworkSettingView in Template app
+completed tests

Co-authored-by: peterbarancek <[email protected]>
Co-authored-by: Peter Barancek <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2022
1 parent 387964a commit c25ab08
Show file tree
Hide file tree
Showing 35 changed files with 2,427 additions and 0 deletions.
195 changes: 195 additions & 0 deletions templates/mts-s-template/t/src/TcoDataMerge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# TcoDataMerge #

## Introduction ##

`TcoDataMerge` is a package to provide merging identical objects (entities).There are two way how to merging data, first is one to one entity and second is
one to many entities.

## MergeEntitiesData class ###
Data for merging are stored in any repository that implements `TcOpen.Inxton.Data.IRepository` interface `MergeEntitiesData<T>` is generic class where T is type of data in collection stored in repository. T object must implemented `TcOpen.Inxton.Data.IBrowsableDataObject`, `Vortex.Connector.IPlain`

## Implemnetation Example 1 ##
First you must declare an instance of the class

```csharp
var merge = new MergeEntitiesData<TestData>(
repositorySource
, repositoryTarget
, reqTypes
, reqProperties
, Exclusion
, Inclusion
);
```
where
- repositorySource and repositoryTarget `IRepository<T>` - here is defined repository where eitities are stored.

```csharp
private IRepository<TestData> repositorySource;
private IRepository<TestData> repositoryTarget;
```


```csharp
repositorySource = new MongoDbRepository<TestData>(new MongoDbRepositorySettings<TestData>(connectionString, databaseName, "SourceData"));
repositoryTarget = new MongoDbRepository<TestData>(new MongoDbRepositorySettings<TestData>(connectionString, databaseName, "TargetData"));
```
or for RavenDbRepository
```csharp
repositorySource = new RavenDbRepository<TestData>(new RavenDbRepositorySettings<TestData>(new string[] { @"http://localhost:8080" }, "SourceData", "", ""));
```
- reqTypes - here you can define list of types witch you want to change in `T` object
```csharp
List<Type> reqTypes = new List<Type>();

reqTypes.Add(typeof(PlainTcoAnalogueInspectorData));
reqTypes.Add(typeof(PlainTcodigitalInspectorData));
```
- reqProperties - here you can define list of properties witch you want to change in types defined above
ReqProperties is a colection of string and can be populated like a string items or we can use a static method `PropertyHelper.GetPropertiesNames()`. This method help populate collection without mistakes, We are sure about this required properties are in required type
```csharp
List<string> reqProperties = new List<string>();

reqProperties = PropertyHelper.GetPropertiesNames(new PlainTcoAnalogueInspectorData(), p => p.IsByPassed, p => p.IsExcluded, p => p.Minimum, p => p.Maximum, p => p.NumberOfAllowedRetries);
```
*You can use a method PropertyHelper.GetPropertiesNames to search properties of object includet to merging*

- Exclusion - here you can define special conditions for exlude from merge operations.
**Can be also null ,then is irelevant.**
```csharp
private bool Exclusion(object obj)
{
switch (obj)
{
// here is definitions of all types and condition witch are relevat not to merge
case TcoInspectors.PlainTcoInspectorData c:
return c is TcoInspectors.PlainTcoAnalogueInspectorData;

default:
break;
}

return false;
}
```

- Inclusion - define aditional special rules for object to change in merge operations.**Can be also null ,then is irelevant.**
```csharp
private bool Inclusion(object obj)
{
switch (obj)
{
case TcoInspectors.PlainTcoInspectorData c:
return c.Result != (short)TcoInspectors.eOverallResult.NoAction;
case PlainCuHeader c:
return c is PlainCuHeader;
}

return false;
}
```





### Merge method call ###
```csharp
merge.Merge(testDataSourceId, testDataTargetId);
```
By calling a method Merge , where SourceId and TargetId are inputs parameters of method. This parameters are identifiers of entities ( entities implemented `Vortex.Connector.IPlain`).
Merge operation consist of:

- read entities from specified repositiories defined in constructor
- search whole entity object and find all required type and appropriate properties of this types and change values from source to target (also is checked conditions from Exclude and Include methods)
- update entity in target repository

## Implemnetation Example 2 ##
First you must declare an instance of the class

```csharp
var merge = new MergeEntitiesData<TestData>(
repositorySource
, repositoryTarget
);
```
where
- repositorySource and repositoryTarget `IRepository<T>` - here is defined repository where eitities are stored.

```csharp
private IRepository<TestData> repositorySource;
private IRepository<TestData> repositoryTarget;
```


```csharp
repositorySource = new MongoDbRepository<TestData>(new MongoDbRepositorySettings<TestData>(connectionString, databaseName, "SourceData"));
repositoryTarget = new MongoDbRepository<TestData>(new MongoDbRepositorySettings<TestData>(connectionString, databaseName, "TargetData"));
```


### Merge method call ###

```csharp
merger.Merge(sourceId, targetId, Exclude,Include, ReqProperty);
```
Call a method with this parameters , all rules for merging are defined below (see examples).
```csharp
private IEnumerable<string> ReqProperty(object obj)
{
var retVal = new List<string>();
switch (obj)
{
// here you define properties witch are relevant for reqired types to change by rework
case TcoInspectors.PlainTcoDigitalInspectorData c:
return PropertyHelper.GetPropertiesNames(c, p => p.RetryAttemptsCount ,p =>p.IsByPassed,p => p.IsExcluded);
case TcoInspectors.PlainTcoAnalogueInspectorData c:
return PropertyHelper.GetPropertiesNames(c, p => p.RetryAttemptsCount, p => p.IsByPassed, p => p.IsExcluded);
case TcoInspectors.PlainTcoDataInspectorData c:
return PropertyHelper.GetPropertiesNames(c, p => p.RetryAttemptsCount, p => p.IsByPassed, p => p.IsExcluded);
case PlainCuHeader c:
return PropertyHelper.GetPropertiesNames(c, p => p.NextOnPassed, p => p.NextOnFailed);

default:
break;
}

return new List<string>();

return new List<string>();
}
```
```csharp
private bool Exclude(object obj)
{
// some special con
return false;
}
```
```csharp
private bool Include(object obj)
{
switch (obj)
{
// here is definitions of all types and condition witch are relevat to change by rework
case IPlainstCheckerData c:
return c is IPlainstCheckerData; //c.Result != (short)enumCheckResult.NoAction;
//case PlainstAnalogueCheckerData c:
// return c is PlainstAnalogueCheckerData;
default:
break;
}

return false;
}
```
By calling a method Merge , where SourceId and TargetId are inputs parameters of method. This parameters are identifiers of entities ( entities implemented `Vortex.Connector.IPlain`).
Merge operation consist of:

- read entities from specified repositiories defined in constructor
- search whole entity object and find all required type and appropriate properties of this types and change values from source to target (also is checked conditions from Exclude and Include methods)
- update entity in target repository



44 changes: 44 additions & 0 deletions templates/mts-s-template/t/src/TcoDataMerge/TcoDataMerge.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30611.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scr", "scr", "{47F786CF-EAA9-4328-A8D8-CDE8BCFEC3F8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F6E00004-CD76-4B6D-AA2B-F338BAD29B95}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vortex.Framework.Data.Merge", "scr\Vortex.Framework.DataMerge\Vortex.Framework.Data.Merge.csproj", "{B55E8856-E15E-4ED7-93AF-9034FD752147}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vortex.Framework.Data.Merge.Test", "tests\Vortex.Framework.Data.Merge.Test\Vortex.Framework.Data.Merge.Test.csproj", "{BCD79E88-37FC-4D6C-8054-7F739AC18834}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CF693E01-BF97-4A3A-AD6E-C86707585245}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B55E8856-E15E-4ED7-93AF-9034FD752147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B55E8856-E15E-4ED7-93AF-9034FD752147}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B55E8856-E15E-4ED7-93AF-9034FD752147}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B55E8856-E15E-4ED7-93AF-9034FD752147}.Release|Any CPU.Build.0 = Release|Any CPU
{BCD79E88-37FC-4D6C-8054-7F739AC18834}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCD79E88-37FC-4D6C-8054-7F739AC18834}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCD79E88-37FC-4D6C-8054-7F739AC18834}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCD79E88-37FC-4D6C-8054-7F739AC18834}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B55E8856-E15E-4ED7-93AF-9034FD752147} = {47F786CF-EAA9-4328-A8D8-CDE8BCFEC3F8}
{BCD79E88-37FC-4D6C-8054-7F739AC18834} = {F6E00004-CD76-4B6D-AA2B-F338BAD29B95}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9E7FBB84-E19B-49EB-9B2E-937B47D134E8}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace TcOpen.Inxton.Data.Merge.Base
{
public interface IMergeEntityData<T> where T : IBrowsableDataObject
{


T GetData(string id, IRepository<T> repository);

void UpdateData(T data , IRepository<T> repository);


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Linq;

namespace TcOpen.Inxton.Data.Merge.Base
{
public class MergeEntityData<T> : MergeEntityDataBase<T> where T : IBrowsableDataObject, new()
{
public override T GetEntityData(string id, IRepository<T> repository)
{
return repository.Queryable.FirstOrDefault<T>(p => p._EntityId == id);
}

public IQueryable<T> GetEntities(IRepository<T> repository)
{
return repository.Queryable.Where(p => true);
}


public override void UpdateEntityData(T data, IRepository<T> repository)
{
var browserEntity = new DataBrowser<T>(repository);

browserEntity.UpdateRecord(data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace TcOpen.Inxton.Data.Merge.Base
{
public abstract class MergeEntityDataBase<T> : IMergeEntityData<T> where T : IBrowsableDataObject
{


public abstract T GetEntityData(string id, IRepository<T> repository);
public abstract void UpdateEntityData(T data, IRepository<T> repository);



T IMergeEntityData<T>.GetData(string id, IRepository<T> repository)
{
return GetEntityData(id, repository);
}

void IMergeEntityData<T>.UpdateData(T data, IRepository<T> repository)
{
UpdateEntityData(data, repository);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TcOpen.Inxton.Data.Merge.Base;

namespace TcOpen.Inxton.Data.Merge

{
public interface IMergeEntitiesData<T> : IMergeEntityData<T> where T : IBrowsableDataObject
{


T Source { get; set; }
T Target { get; set; }

IRepository<T> SourceRepository { get; set; }
IRepository<T> TargetRepository { get; set; }

IQueryable<T> GetEntities(IRepository<T> repository);


IEnumerable<Type> RequiredTypes { get; }

IEnumerable<string> RequiredProperties { get; }
Func<object, bool> Exclusion { get; }


}
}

Loading

0 comments on commit c25ab08

Please sign in to comment.