Skip to content

Commit

Permalink
if persistent data not exist on Read in DB -> create it
Browse files Browse the repository at this point in the history
  • Loading branch information
blazej.kuhajda committed Sep 18, 2024
1 parent 23e6aa4 commit 39dc647
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ private void AddTagsFromRecordToWrittenList(List<ITwinPrimitive> tagsToWrite, Pe
}
}


/// <summary>
/// Updates a persistent group of tags to the repository after reading from the PLC.
/// </summary>
Expand All @@ -155,7 +154,6 @@ public async Task<bool> UpdatePersistentGroupFromPlcToRepository(string persiste

private bool UpdateReadedTagsToRepository(string persistentGroupName)
{

var primitivesTagsInGroup = tagsInGroups[persistentGroupName];

if (primitivesTagsInGroup == null)
Expand Down Expand Up @@ -223,7 +221,6 @@ private bool UpdateReadedTagsToRepository(string persistentGroupName)
return true;
}


/// <summary>
/// Updates a persistent group of tags to the repository after reading from the PLC.
/// </summary>
Expand All @@ -241,7 +238,6 @@ public async Task<bool> UpdateAllPersistentGroupsToRepository()
return true;
}


#endregion Main Handling Method - Read Write

#region Data Exchange Implementation
Expand Down Expand Up @@ -292,6 +288,13 @@ private async Task Handle()
switch (operation)
{
case ePersistentOperation.Read:

// if not exist => create it
if (!Repository.Exists(identifier))
{
await UpdatePersistentGroupFromPlcToRepository(identifier);
}

await this.WritePersistentGroupFromRepository(identifier);
break;

Expand All @@ -301,9 +304,13 @@ private async Task Handle()

case ePersistentOperation.ReadAll:

if (!Repository.Exists(DEFAULT_IDENTIFIER)) // repo is empty
// if any group not exist => create it
foreach (var persitGroupName in this.CollectedGroups)
{
await this.UpdateAllPersistentGroupsToRepository(); // create records from online
if (!Repository.Exists(persitGroupName))
{
await UpdatePersistentGroupFromPlcToRepository(persitGroupName);
}
}

await this.WriteAllPersistentGroupsFromRepositoryToPlc();
Expand Down

0 comments on commit 39dc647

Please sign in to comment.