Esempio n. 1
0
        public WWCPImporter <T> AddOrUpdateForwardingInfos(IEnumerable <ImporterForwardingInfo> ForwardingInfos,
                                                           Boolean MarkAllOutOfService = true)
        {
            lock (_AllForwardingInfos)
            {
                // Mark ForwardingInfos as 'OutOfService', to detect which are no longer within the XML...
                if (MarkAllOutOfService)
                {
                    _AllForwardingInfos.Values.ForEach(FwdInfo => FwdInfo.OutOfService = true);
                }

                ImporterForwardingInfo ExistingForwardingInfo;
                Boolean ForwardingInformationChanged = false;

                foreach (var ForwardingInfo in ForwardingInfos)
                {
                    #region An existing forwarding information was found: Look for changes...

                    if (_AllForwardingInfos.TryGetValue(ForwardingInfo.StationId, out ExistingForwardingInfo))
                    {
                        ForwardingInformationChanged = false;

                        #region StationNameChanged...

                        if (ExistingForwardingInfo.StationName != ForwardingInfo.StationName)
                        {
                            ExistingForwardingInfo.StationName = ForwardingInfo.StationName;
                            ForwardingInformationChanged       = true;
                        }

                        #endregion

                        #region StationServiceTag changed...

                        if (ExistingForwardingInfo.StationServiceTag != ForwardingInfo.StationServiceTag)
                        {
                            ExistingForwardingInfo.StationServiceTag = ForwardingInfo.StationServiceTag;
                            ForwardingInformationChanged             = true;
                        }

                        #endregion

                        #region StationAddress changed...

                        if (ExistingForwardingInfo.StationAddress != ForwardingInfo.StationAddress)
                        {
                            ExistingForwardingInfo.StationAddress = ForwardingInfo.StationAddress;
                            ForwardingInformationChanged          = true;
                        }

                        #endregion

                        #region StationGeoCoordinate changed...

                        if (ExistingForwardingInfo.StationGeoCoordinate != ForwardingInfo.StationGeoCoordinate)
                        {
                            ExistingForwardingInfo.StationGeoCoordinate = ForwardingInfo.StationGeoCoordinate;
                            ForwardingInformationChanged = true;
                        }

                        #endregion

                        ExistingForwardingInfo.UpdateTimestamp();

                        if (ForwardingInformationChanged)
                        {
                            OnForwardingInformationChanged?.Invoke(DateTime.UtcNow,
                                                                   this,
                                                                   ExistingForwardingInfo, //ToDo: Send a clone of the previous forwarding info!
                                                                   ExistingForwardingInfo);
                        }
                    }

                    #endregion

                    #region ...or a new one was created!

                    else
                    {
                        _AllForwardingInfos.Add(ForwardingInfo.StationId, ForwardingInfo);

                        OnNewForwardingInformation?.Invoke(DateTime.UtcNow,
                                                           this,
                                                           ForwardingInfo);
                    }

                    #endregion
                }
            }

            return(this);
        }
Esempio n. 2
0
        public WWCPImporter <T> AddOrUpdateForwardingInfos(IEnumerable <ImporterForwardingInfo> GivenForwardingInfos)
        {
            lock (_AllForwardingInfos)
            {
                var NewForwardingInfos = new List <ImporterForwardingInfo>();

                GivenForwardingInfos.ForEach(GivenForwardingInfo => {
                    #region An existing forwarding information was found... search for changes...

                    ImporterForwardingInfo ExistingForwardingInfo;

                    if (_AllForwardingInfos.TryGetValue(GivenForwardingInfo.StationId, out ExistingForwardingInfo))
                    {
                        #region StationNameChanged...

                        if (ExistingForwardingInfo.StationName != GivenForwardingInfo.StationName)
                        {
                            _HTTPImportEvents.SubmitSubEvent("StationNameChanged",
                                                             new JObject(
                                                                 new JProperty("Timestamp", DateTime.Now.ToIso8601()),
                                                                 new JProperty("ChargingStationId", ExistingForwardingInfo.StationId.ToString()),
                                                                 new JProperty("OldValue", ExistingForwardingInfo.StationName),
                                                                 new JProperty("NewValue", GivenForwardingInfo.StationName)
                                                                 ).ToString().
                                                             Replace(Environment.NewLine, ""));

                            ExistingForwardingInfo.StationName = GivenForwardingInfo.StationName;
                        }

                        #endregion

                        #region StationServiceTag changed...

                        if (ExistingForwardingInfo.StationServiceTag != GivenForwardingInfo.StationServiceTag)
                        {
                            _HTTPImportEvents.SubmitSubEvent("StationServiceTagChanged",
                                                             new JObject(
                                                                 new JProperty("Timestamp", DateTime.Now.ToIso8601()),
                                                                 new JProperty("ChargingStationId", ExistingForwardingInfo.StationId.ToString()),
                                                                 new JProperty("OldValue", ExistingForwardingInfo.StationServiceTag),
                                                                 new JProperty("NewValue", GivenForwardingInfo.StationServiceTag)
                                                                 ).ToString().
                                                             Replace(Environment.NewLine, ""));

                            ExistingForwardingInfo.StationServiceTag = GivenForwardingInfo.StationServiceTag;
                        }

                        #endregion

                        #region StationAddress changed...

                        if (ExistingForwardingInfo.StationAddress != GivenForwardingInfo.StationAddress)
                        {
                            _HTTPImportEvents.SubmitSubEvent("StationAddressChanged",
                                                             new JObject(
                                                                 new JProperty("Timestamp", DateTime.Now.ToIso8601()),
                                                                 new JProperty("ChargingStationId", ExistingForwardingInfo.StationId.ToString()),
                                                                 new JProperty("OldValue", ExistingForwardingInfo.StationAddress.ToString()),
                                                                 new JProperty("NewValue", GivenForwardingInfo.StationAddress.ToString())
                                                                 ).ToString().
                                                             Replace(Environment.NewLine, ""));

                            ExistingForwardingInfo.StationAddress = GivenForwardingInfo.StationAddress;
                        }

                        #endregion

                        #region StationGeoCoordinate changed...

                        if (ExistingForwardingInfo.StationGeoCoordinate != GivenForwardingInfo.StationGeoCoordinate)
                        {
                            _HTTPImportEvents.SubmitSubEvent("StationGeoCoordinateChanged",
                                                             new JObject(
                                                                 new JProperty("Timestamp", DateTime.Now.ToIso8601()),
                                                                 new JProperty("ChargingStationId", ExistingForwardingInfo.StationId.ToString()),
                                                                 new JProperty("OldValue", ExistingForwardingInfo.StationGeoCoordinate.ToString()),
                                                                 new JProperty("NewValue", GivenForwardingInfo.StationGeoCoordinate.ToString())
                                                                 ).ToString().
                                                             Replace(Environment.NewLine, ""));

                            ExistingForwardingInfo.StationGeoCoordinate = GivenForwardingInfo.StationGeoCoordinate;
                        }

                        #endregion

                        ExistingForwardingInfo.UpdateTimestamp();
                    }

                    #endregion

                    #region ...or a new one was created.

                    else
                    {
                        NewForwardingInfos.Add(GivenForwardingInfo);

                        _AllForwardingInfos.Add(GivenForwardingInfo.StationId, GivenForwardingInfo);
                    }

                    #endregion
                });

                if (NewForwardingInfos.Any())
                {
                    //ToDo: Implement me!
                    _HTTPImportEvents.SubmitSubEvent("NewForwardingInfos",
                                                     new JObject(
                                                         new JProperty("Timestamp", DateTime.Now.ToIso8601()),
                                                         new JProperty("ForwardingInfos", new JArray())
                                                         ).ToString().
                                                     Replace(Environment.NewLine, ""));

                    var OnForwardingInformationAddedLocal = OnForwardingInformationAdded;
                    if (OnForwardingInformationAddedLocal != null)
                    {
                        OnForwardingInformationAddedLocal(DateTime.Now, this, NewForwardingInfos);
                    }
                }
            }

            return(this);
        }