Beispiel #1
0
        private async Task HandleUpdateOperation(IScadaModelPointItem incomingPointItem, long gid)
        {
            var pointItemResult = await IncomingGidToPointItemMap.TryGetValueAsync(gid);

            if (!pointItemResult.HasValue)
            {
                string errorMessage = $"{baseLogString} HandleUpdateOperation => Model update data in fault state. Updating entity with gid: {gid:X16}, that does not exists in IncomingGidToPointItemMap.";
                Logger.LogError(errorMessage);
                throw new ArgumentException(errorMessage);
            }

            IScadaModelPointItem oldPointItem = pointItemResult.Value;

            var addressToGidMapResult = await IncomingAddressToGidMap.TryGetValueAsync((short)oldPointItem.RegisterType);

            if (!addressToGidMapResult.HasValue)
            {
                string errorMessage = $"{baseLogString} HandleUpdateOperation => Model update data in fault state. Updating entity with gid: {gid:X16}, {oldPointItem.RegisterType} registry type does not exist in incoming IncomingAddressToGidMap.";
                Logger.LogError(errorMessage);
                throw new ArgumentException(errorMessage);
            }

            var incomingAddressToGidMapDictionary = addressToGidMapResult.Value;

            if (!incomingAddressToGidMapDictionary.ContainsKey(oldPointItem.Address))
            {
                string message = $"{baseLogString} HandleUpdateOperation => Model update data in fault state. Updating point with address: {oldPointItem.Address}, that does not exists in IncomingAddressToGidMap.";
                Logger.LogError(message);
                throw new ArgumentException(message);
            }

            if (oldPointItem.Address != incomingPointItem.Address && incomingAddressToGidMapDictionary.ContainsKey(incomingPointItem.Address))
            {
                string message = $"{baseLogString} HandleUpdateOperation => Model update data in fault state. Trying to add point with address: {incomingPointItem.Address}, that already exists in IncomingAddressToGidMap.";
                Logger.LogError(message);
                throw new ArgumentException(message);
            }

            string appendMessage = ""; string oldAddressText = "";

            //LOGIC
            await IncomingGidToPointItemMap.SetAsync(gid, incomingPointItem);

            if (oldPointItem.Address != incomingPointItem.Address)
            {
                incomingAddressToGidMapDictionary.Remove(oldPointItem.Address);
                incomingAddressToGidMapDictionary.Add(incomingPointItem.Address, gid);

                await IncomingAddressToGidMap.SetAsync((short)oldPointItem.RegisterType, incomingAddressToGidMapDictionary);

                appendMessage  = " and IncomingAddressToGidMap";
                oldAddressText = $", Old address: {oldPointItem.Address}";
            }

            string debugMessage = $"{baseLogString} HandleUpdateOperation => SUCCESSFULLY updated point from IncomingGidToPointItemMap{appendMessage}. Gid: 0x{incomingPointItem.Gid:X16}, Address: {incomingPointItem.Address}{oldAddressText}";

            Logger.LogDebug(debugMessage);
        }
Beispiel #2
0
        private async Task HandleDeleteOperation(long gid)
        {
            var pointItemResult = await IncomingGidToPointItemMap.TryGetValueAsync(gid);

            if (!pointItemResult.HasValue)
            {
                string errorMessage = $"{baseLogString} HandleDeleteOperation => Model update data in fault state. Deleting entity with gid: {gid:X16}, that does not exists in IncomingGidToPointItemMap.";
                Logger.LogError(errorMessage);
                throw new ArgumentException(errorMessage);
            }

            IScadaModelPointItem oldPointItem = pointItemResult.Value;

            Dictionary <ushort, long> incomingAddressToGidMapDictionary;
            var type = (short)oldPointItem.RegisterType;

            var addressToGidMapResult = await IncomingAddressToGidMap.TryGetValueAsync(type);

            if (!addressToGidMapResult.HasValue)
            {
                incomingAddressToGidMapDictionary = new Dictionary <ushort, long>();
            }
            else
            {
                incomingAddressToGidMapDictionary = addressToGidMapResult.Value;
            }

            if (!incomingAddressToGidMapDictionary.ContainsKey(oldPointItem.Address))
            {
                string message = $"{baseLogString} HandleDeleteOperation => Model update data in fault state. Deleting point with address: {oldPointItem.Address}, that does not exists in IncomingAddressToGidMap.";
                Logger.LogError(message);
                throw new ArgumentException(message);
            }

            //LOGIC
            await IncomingGidToPointItemMap.TryRemoveAsync(gid);

            incomingAddressToGidMapDictionary.Remove(oldPointItem.Address);
            await IncomingAddressToGidMap.SetAsync(type, incomingAddressToGidMapDictionary);

            string debugMessage = $"{baseLogString} HandleDeleteOperation => SUCCESSFULLY deleted point from IncomingGidToPointItemMap and IncomingAddressToGidMap. Gid: 0x{oldPointItem.Gid:X16}, Address: {oldPointItem.Address}";

            Logger.LogDebug(debugMessage);
        }
Beispiel #3
0
        private async Task HandleInsertOperation(IScadaModelPointItem incomingPointItem, long gid)
        {
            var pointItemResult = await IncomingGidToPointItemMap.TryGetValueAsync(gid);

            if (pointItemResult.HasValue)
            {
                string errorMessage = $"{baseLogString} HandleInsertOperation => Model update data in fault state. Inserting entity with gid: {gid:X16}, that already exists in IncomingGidToPointItemMap.";
                Logger.LogError(errorMessage);
                throw new ArgumentException(errorMessage);
            }

            Dictionary <ushort, long> incomingAddressToGidMapDictionary;
            var type = (short)incomingPointItem.RegisterType;
            var addressToGidMapResult = await IncomingAddressToGidMap.TryGetValueAsync(type);

            if (!addressToGidMapResult.HasValue)
            {
                incomingAddressToGidMapDictionary = new Dictionary <ushort, long>();
            }
            else
            {
                incomingAddressToGidMapDictionary = addressToGidMapResult.Value;
            }

            if (incomingAddressToGidMapDictionary.ContainsKey(incomingPointItem.Address))
            {
                string message = $"{baseLogString} HandleInsertOperation => Model update data in fault state. Inserting entity with address: {incomingPointItem.Address}, that already exists in IncomingAddressToGidMap.";
                Logger.LogError(message);
                throw new ArgumentException(message);
            }

            //LOGIC
            await IncomingGidToPointItemMap.SetAsync(gid, incomingPointItem);

            incomingAddressToGidMapDictionary.Add(incomingPointItem.Address, gid);
            await IncomingAddressToGidMap.SetAsync(type, incomingAddressToGidMapDictionary);

            string debugMessage = $"{baseLogString} HandleInsertOperation => SUCCESSFULLY inserted point into IncomingGidToPointItemMap and IncomingAddressToGidMap. Gid: 0x{incomingPointItem.Gid:X16}, Address: {incomingPointItem.Address}";

            Logger.LogDebug(debugMessage);
        }