public void SaveDelta(Delta delta)
        {
            if (delta.DeltaOrigin == DeltaOriginType.ArtificialDelta)
            {
                Logger.LogInformation($"{baseLogString} SaveDelta => delta.DeltaOrigin: {delta.DeltaOrigin}, delta.Id: {delta.Id}");
                return;
            }

            long latestVersion = GetLatestVersion();

            if (delta.Id <= latestVersion)
            {
                string warnMessage = $"{baseLogString} SaveDelta => Delta version is lower then the latest version. NetworkModel version: {delta.Id}, LatestVersion: {latestVersion}";
                Logger.LogWarning(warnMessage);

                delta.Id = latestVersion + 1;

                warnMessage = $"{baseLogString} SaveDelta => Delta version is set to a new value: {delta.Id}";
                Logger.LogWarning(warnMessage);
            }

            var newLatestDeltaVersionDocument = new LatestVersionsDocument()
            {
                Id      = MongoStrings.LatestVersions_DeltaVersion,
                Version = delta.Id,
            };

            try
            {
                var latestVersionsCollection = db.GetCollection <LatestVersionsDocument>(MongoStrings.LatestVersionsCollection);
                latestVersionsCollection.ReplaceOne(new BsonDocument("_id", MongoStrings.LatestVersions_DeltaVersion), newLatestDeltaVersionDocument, new ReplaceOptions {
                    IsUpsert = true
                });

                delta.DeltaOrigin = DeltaOriginType.DatabaseDelta;
                var deltasCollection = db.GetCollection <Delta>(MongoStrings.DeltasCollection);
                deltasCollection.InsertOne(delta);
            }
            catch (MongoWriteException e)
            {
                string warnMessage = $"{baseLogString} SaveDelta => Warn: {e.Message}.";
                Logger.LogWarning(warnMessage, e);
            }
            catch (Exception e)
            {
                string errorMessage = $"{baseLogString} SaveDelta => Error: {e.Message}.";
                Logger.LogError(errorMessage, e);
            }
        }
        public void SaveNetworkModel(Dictionary <DMSType, Container> networkModel, long version)
        {
            long latestVersion = GetLatestVersion();

            if (version <= latestVersion)
            {
                string warnMessage = $"{baseLogString} SaveNetworkModel => NetworkModel version is lower then the latest version. NetworkModel version: {version}, LatestVersion: {latestVersion}";
                Logger.LogWarning(warnMessage);

                version = latestVersion + 1;

                warnMessage = $"{baseLogString} SaveNetworkModel => NetworkModel version is set to a new value: {version}";
                Logger.LogWarning(warnMessage);
            }

            var latestNetworkModelVersionDocument = new LatestVersionsDocument
            {
                Id      = MongoStrings.LatestVersions_NetworkModelVersion,
                Version = version,
            };

            try
            {
                var latestVersionsCollection = db.GetCollection <LatestVersionsDocument>(MongoStrings.LatestVersionsCollection);
                latestVersionsCollection.ReplaceOne(new BsonDocument("_id", MongoStrings.LatestVersions_NetworkModelVersion), latestNetworkModelVersionDocument, new ReplaceOptions {
                    IsUpsert = true
                });

                var networkModelDocument = new NetworkModelsDocument()
                {
                    Id           = version,
                    NetworkModel = networkModel,
                };

                var networkModelsCollection = db.GetCollection <NetworkModelsDocument>(MongoStrings.NetworkModelsCollection);
                networkModelsCollection.InsertOne(networkModelDocument);
            }
            catch (MongoWriteException e)
            {
                string errorMessage = $"{baseLogString} SaveNetworkModel => Warn: {e.Message}.";
                Logger.LogWarning(errorMessage, e);
            }
            catch (Exception e)
            {
                string errorMessage = $"{baseLogString} SaveNetworkModel => Error: {e.Message}.";
                Logger.LogError(errorMessage, e);
            }
        }