Exemple #1
0
        /// <summary>
        /// Create an OICP AuthorizeStart XML/SOAP request.
        /// </summary>
        /// <param name="OperatorId">The unqiue identification of the charging station operator.</param>
        /// <param name="Identification">An user identification.</param>
        /// <param name="EVSEId">An optional EVSE identification.</param>
        /// <param name="PartnerProductId">An optional partner product identification.</param>
        /// <param name="SessionId">An optional charging session identification.</param>
        /// <param name="CPOPartnerSessionId">An optional CPO partner session identification.</param>
        /// <param name="EMPPartnerSessionId">An optional EMP partner session identification.</param>
        ///
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="CancellationToken">An optional token to cancel this request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="RequestTimeout">An optional timeout for this request.</param>
        public AuthorizeStartRequest(Operator_Id OperatorId,
                                     Identification Identification,
                                     EVSE_Id?EVSEId = null,
                                     PartnerProduct_Id?PartnerProductId = null,
                                     Session_Id?SessionId = null,
                                     CPOPartnerSession_Id?CPOPartnerSessionId = null,
                                     EMPPartnerSession_Id?EMPPartnerSessionId = null,

                                     DateTime?Timestamp = null,
                                     CancellationToken?CancellationToken = null,
                                     EventTracking_Id EventTrackingId    = null,
                                     TimeSpan?RequestTimeout             = null)

            : base(Timestamp,
                   CancellationToken,
                   EventTrackingId,
                   RequestTimeout)

        {
            this.OperatorId          = OperatorId;
            this.Identification      = Identification;
            this.EVSEId              = EVSEId;
            this.PartnerProductId    = PartnerProductId;
            this.SessionId           = SessionId;
            this.CPOPartnerSessionId = CPOPartnerSessionId;
            this.EMPPartnerSessionId = EMPPartnerSessionId;
        }
Exemple #2
0
        AuthorizeRemoteStart(this IEMPClient EMPClient,
                             Provider_Id ProviderId,
                             EVSE_Id EVSEId,
                             Identification Identification,
                             Session_Id?SessionId = null,
                             CPOPartnerSession_Id?CPOPartnerSessionId = null,
                             EMPPartnerSession_Id?EMPPartnerSessionId = null,
                             PartnerProduct_Id?PartnerProductId       = null,
                             JObject CustomData = null,

                             DateTime?Timestamp = null,
                             CancellationToken?CancellationToken = null,
                             EventTracking_Id EventTrackingId    = null,
                             TimeSpan?RequestTimeout             = null)

        => EMPClient.AuthorizeRemoteStart(
            new AuthorizeRemoteStartRequest(
                ProviderId,
                EVSEId,
                Identification,
                SessionId,
                CPOPartnerSessionId,
                EMPPartnerSessionId,
                PartnerProductId,
                CustomData,

                Timestamp,
                CancellationToken,
                EventTrackingId,
                RequestTimeout ?? EMPClient.RequestTimeout));
        /// <summary>
        /// Create an AuthorizeRemoteReservationStart request.
        /// </summary>
        /// <param name="ProviderId">An e-mobility provider identification.</param>
        /// <param name="EVSEId">An EVSE identification.</param>
        /// <param name="Identification">The user or contract identification.</param>
        /// <param name="SessionId">An optional charging session identification.</param>
        /// <param name="CPOPartnerSessionId">An optional CPO partner session identification.</param>
        /// <param name="EMPPartnerSessionId">An optional EMP partner session identification.</param>
        /// <param name="PartnerProductId">An optional partner product identification.</param>
        /// <param name="Duration">The optional duration of reservation.</param>
        /// <param name="CustomData">Optional customer specific data, e.g. in combination with custom parsers and serializers.</param>
        ///
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="CancellationToken">An optional token to cancel this request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="RequestTimeout">The timeout for this request.</param>
        public AuthorizeRemoteReservationStartRequest(Provider_Id ProviderId,
                                                      EVSE_Id EVSEId,
                                                      Identification Identification,
                                                      Session_Id?SessionId = null,
                                                      CPOPartnerSession_Id?CPOPartnerSessionId = null,
                                                      EMPPartnerSession_Id?EMPPartnerSessionId = null,
                                                      PartnerProduct_Id?PartnerProductId       = null,
                                                      TimeSpan?Duration  = null,
                                                      JObject CustomData = null,

                                                      DateTime?Timestamp = null,
                                                      CancellationToken?CancellationToken = null,
                                                      EventTracking_Id EventTrackingId    = null,
                                                      TimeSpan?RequestTimeout             = null)

            : base(CustomData,
                   Timestamp,
                   CancellationToken,
                   EventTrackingId,
                   RequestTimeout)

        {
            this.ProviderId          = ProviderId;
            this.EVSEId              = EVSEId;
            this.Identification      = Identification;
            this.SessionId           = SessionId;
            this.CPOPartnerSessionId = CPOPartnerSessionId;
            this.EMPPartnerSessionId = EMPPartnerSessionId;
            this.PartnerProductId    = PartnerProductId;
            this.Duration            = Duration;
        }
        /// <summary>
        /// Create a new OICP Authorization Start response.
        /// </summary>
        /// <param name="Request">The request leading to this response.</param>
        /// <param name="AuthorizationStatus">The status of the mobile authorization request.</param>
        /// <param name="GeoCoordinates">The geo coordinate of the EVSE.</param>
        /// <param name="ChargingStationName">An optional charging station name of the EVSE.</param>
        /// <param name="Address">An optional address of the EVSE.</param>
        /// <param name="SessionId">An optional session identification of the mobile authorization request.</param>
        /// <param name="StatusCode">An optional status code for the mobile authorization request.</param>
        /// <param name="TermsOfUse">An optional multilingual term-of-use text.</param>
        /// <param name="AdditionalInfo">Optional additional information.</param>
        /// <param name="CustomData">Optional custom data.</param>
        public MobileAuthorizationStart(MobileAuthorizeStartRequest Request,
                                        AuthorizationStatusTypes AuthorizationStatus,
                                        GeoCoordinate GeoCoordinates,
                                        I18NString ChargingStationName = null,
                                        Address Address           = null,
                                        Session_Id?SessionId      = null,
                                        StatusCode?StatusCode     = null,
                                        I18NString TermsOfUse     = null,
                                        I18NString AdditionalInfo = null,
                                        IReadOnlyDictionary <String, Object> CustomData = null)

            : base(Request,
                   CustomData)

        {
            #region Initial checks

            if (GeoCoordinates == null)
            {
                throw new ArgumentNullException(nameof(GeoCoordinates), "The given geo coordinates must not be null!");
            }

            #endregion

            this.AuthorizationStatus = AuthorizationStatus;
            this.GeoCoordinates      = GeoCoordinates;
            this.ChargingStationName = ChargingStationName ?? new I18NString();
            this.Address             = Address;
            this.SessionId           = SessionId;
            this.StatusCode          = StatusCode ?? new StatusCode(StatusCodes.Success);
            this.TermsOfUse          = TermsOfUse ?? new I18NString();
            this.AdditionalInfo      = AdditionalInfo ?? new I18NString();
        }
Exemple #5
0
 /// <summary>
 /// Try to parse the given text representation of a session.
 /// </summary>
 /// <param name="Text">The text to parse.</param>
 /// <param name="Session">The parsed session.</param>
 /// <param name="ErrorResponse">An optional error response.</param>
 /// <param name="SessionIdURL">An optional session identification, e.g. from the HTTP URL.</param>
 /// <param name="CustomSessionParser">A delegate to parse custom session JSON objects.</param>
 public static Boolean TryParse(String Text,
                                out Session Session,
                                out String ErrorResponse,
                                CountryCode?CountryCodeURL = null,
                                Party_Id?PartyIdURL        = null,
                                Session_Id?SessionIdURL    = null,
                                CustomJObjectParserDelegate <Session> CustomSessionParser = null)
 {
     try
     {
         return(TryParse(JObject.Parse(Text),
                         out Session,
                         out ErrorResponse,
                         CountryCodeURL,
                         PartyIdURL,
                         SessionIdURL,
                         CustomSessionParser));
     }
     catch (Exception e)
     {
         Session       = null;
         ErrorResponse = "The given text representation of a session is invalid: " + e.Message;
         return(false);
     }
 }
Exemple #6
0
        AuthorizeRemoteReservationStart(this ICentralClient ICentralClient,
                                        Provider_Id ProviderId,
                                        EVSE_Id EVSEId,
                                        Identification Identification,
                                        Session_Id?SessionId = null,
                                        CPOPartnerSession_Id?CPOPartnerSessionId = null,
                                        EMPPartnerSession_Id?EMPPartnerSessionId = null,
                                        PartnerProduct_Id?PartnerProductId       = null,
                                        TimeSpan?Duration = null,

                                        DateTime?Timestamp = null,
                                        CancellationToken?CancellationToken = null,
                                        EventTracking_Id EventTrackingId    = null,
                                        TimeSpan?RequestTimeout             = null)


        => ICentralClient.AuthorizeRemoteReservationStart(new EMP.AuthorizeRemoteReservationStartRequest(ProviderId,
                                                                                                         EVSEId,
                                                                                                         Identification,
                                                                                                         SessionId,
                                                                                                         CPOPartnerSessionId,
                                                                                                         EMPPartnerSessionId,
                                                                                                         PartnerProductId,
                                                                                                         Duration,

                                                                                                         Timestamp,
                                                                                                         CancellationToken,
                                                                                                         EventTrackingId,
                                                                                                         RequestTimeout ?? ICentralClient.RequestTimeout));
        AuthorizeStart(this ICPOClient ICPOClient,
                       Operator_Id OperatorId,
                       UID UID,
                       EVSE_Id?EVSEId = null,
                       PartnerProduct_Id?PartnerProductId = null,
                       Session_Id?SessionId = null,
                       CPOPartnerSession_Id?CPOPartnerSessionId = null,
                       EMPPartnerSession_Id?EMPPartnerSessionId = null,

                       DateTime?Timestamp = null,
                       CancellationToken?CancellationToken = null,
                       EventTracking_Id EventTrackingId    = null,
                       TimeSpan?RequestTimeout             = null)


        => ICPOClient.AuthorizeStart(new AuthorizeStartRequest(OperatorId,
                                                               Identification.FromUID(UID),
                                                               EVSEId,
                                                               PartnerProductId,
                                                               SessionId,
                                                               CPOPartnerSessionId,
                                                               EMPPartnerSessionId,

                                                               Timestamp,
                                                               CancellationToken,
                                                               EventTrackingId,
                                                               RequestTimeout ?? ICPOClient.RequestTimeout));
Exemple #8
0
        /// <summary>
        /// Parse the given text representation of a session.
        /// </summary>
        /// <param name="Text">The text to parse.</param>
        /// <param name="SessionIdURL">An optional session identification, e.g. from the HTTP URL.</param>
        /// <param name="CustomSessionParser">A delegate to parse custom session JSON objects.</param>
        public static Session Parse(String Text,
                                    CountryCode?CountryCodeURL = null,
                                    Party_Id?PartyIdURL        = null,
                                    Session_Id?SessionIdURL    = null,
                                    CustomJObjectParserDelegate <Session> CustomSessionParser = null)
        {
            if (TryParse(Text,
                         out Session session,
                         out String ErrorResponse,
                         CountryCodeURL,
                         PartyIdURL,
                         SessionIdURL,
                         CustomSessionParser))
            {
                return(session);
            }

            throw new ArgumentException("The given text representation of a session is invalid: " + ErrorResponse, nameof(Text));
        }
Exemple #9
0
        /// <summary>
        /// Try to parse the given JSON representation of a session.
        /// </summary>
        /// <param name="JSON">The JSON to parse.</param>
        /// <param name="Session">The parsed session.</param>
        /// <param name="ErrorResponse">An optional error response.</param>
        /// <param name="CountryCodeURL">An optional country code, e.g. from the HTTP URL.</param>
        /// <param name="PartyIdURL">An optional party identification, e.g. from the HTTP URL.</param>
        /// <param name="SessionIdURL">An optional session identification, e.g. from the HTTP URL.</param>
        /// <param name="CustomSessionParser">A delegate to parse custom session JSON objects.</param>
        public static Boolean TryParse(JObject JSON,
                                       out Session Session,
                                       out String ErrorResponse,
                                       CountryCode?CountryCodeURL = null,
                                       Party_Id?PartyIdURL        = null,
                                       Session_Id?SessionIdURL    = null,
                                       CustomJObjectParserDelegate <Session> CustomSessionParser = null)
        {
            try
            {
                Session = default;

                if (JSON?.HasValues != true)
                {
                    ErrorResponse = "The given JSON object must not be null or empty!";
                    return(false);
                }

                #region Parse CountryCode               [optional]

                if (JSON.ParseOptionalStruct("country_code",
                                             "country code",
                                             CountryCode.TryParse,
                                             out CountryCode? CountryCodeBody,
                                             out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                if (!CountryCodeURL.HasValue && !CountryCodeBody.HasValue)
                {
                    ErrorResponse = "The country code is missing!";
                    return(false);
                }

                if (CountryCodeURL.HasValue && CountryCodeBody.HasValue && CountryCodeURL.Value != CountryCodeBody.Value)
                {
                    ErrorResponse = "The optional country code given within the JSON body does not match the one given in the URL!";
                    return(false);
                }

                #endregion

                #region Parse PartyIdURL                [optional]

                if (JSON.ParseOptionalStruct("party_id",
                                             "party identification",
                                             Party_Id.TryParse,
                                             out Party_Id? PartyIdBody,
                                             out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                if (!PartyIdURL.HasValue && !PartyIdBody.HasValue)
                {
                    ErrorResponse = "The party identification is missing!";
                    return(false);
                }

                if (PartyIdURL.HasValue && PartyIdBody.HasValue && PartyIdURL.Value != PartyIdBody.Value)
                {
                    ErrorResponse = "The optional party identification given within the JSON body does not match the one given in the URL!";
                    return(false);
                }

                #endregion

                #region Parse Id                        [optional]

                if (JSON.ParseOptionalStruct("id",
                                             "session identification",
                                             Session_Id.TryParse,
                                             out Session_Id? SessionIdBody,
                                             out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                if (!SessionIdURL.HasValue && !SessionIdBody.HasValue)
                {
                    ErrorResponse = "The session identification is missing!";
                    return(false);
                }

                if (SessionIdURL.HasValue && SessionIdBody.HasValue && SessionIdURL.Value != SessionIdBody.Value)
                {
                    ErrorResponse = "The optional session identification given within the JSON body does not match the one given in the URL!";
                    return(false);
                }

                #endregion

                #region Parse Start                     [mandatory]

                if (!JSON.ParseMandatory("start_date_time",
                                         "start timestamp",
                                         out DateTime Start,
                                         out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse End                       [optional]

                if (JSON.ParseOptional("end_date_time",
                                       "end timestamp",
                                       out DateTime? End,
                                       out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse KWh                       [mandatory]

                if (!JSON.ParseMandatory("kwh",
                                         "charged kWh",
                                         out Decimal KWh,
                                         out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse CDRToken                  [mandatory]

                if (!JSON.ParseMandatoryJSON("cdr_token",
                                             "charge detail record token",
                                             OCPIv2_1_1.CDRToken.TryParse,
                                             out CDRToken CDRToken,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse AuthMethod                [mandatory]

                if (!JSON.ParseMandatoryEnum("auth_method",
                                             "authentication method",
                                             out AuthMethods AuthMethod,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse AuthorizationReference    [optional]

                if (JSON.ParseOptionalStruct("authorization_reference",
                                             "authorization reference",
                                             OCPIv2_1_1.AuthorizationReference.TryParse,
                                             out AuthorizationReference? AuthorizationReference,
                                             out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse LocationId                [mandatory]

                if (!JSON.ParseMandatory("location_id",
                                         "location identification",
                                         Location_Id.TryParse,
                                         out Location_Id LocationId,
                                         out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse EVSEUId                   [mandatory]

                if (!JSON.ParseMandatory("evse_uid",
                                         "EVSE identification",
                                         EVSE_UId.TryParse,
                                         out EVSE_UId EVSEUId,
                                         out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse ConnectorId               [mandatory]

                if (!JSON.ParseMandatory("connector_id",
                                         "connector identification",
                                         Connector_Id.TryParse,
                                         out Connector_Id ConnectorId,
                                         out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse MeterId                   [optional]

                if (JSON.ParseOptional("meter_id",
                                       "meter identification",
                                       Meter_Id.TryParse,
                                       out Meter_Id? MeterId,
                                       out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse EnergyMeter               [optional]

                if (JSON.ParseOptionalJSON("energy_meter",
                                           "energy meter",
                                           OCPIv2_1_1.EnergyMeter.TryParse,
                                           out EnergyMeter EnergyMeter,
                                           out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse TransparencySoftwares     [optional]

                if (JSON.ParseOptionalJSON("transparency_softwares",
                                           "transparency softwares",
                                           TransparencySoftware.TryParse,
                                           out IEnumerable <TransparencySoftware> TransparencySoftwares,
                                           out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse Currency                  [mandatory]

                if (!JSON.ParseMandatory("currency",
                                         "currency",
                                         OCPIv2_1_1.Currency.TryParse,
                                         out Currency Currency,
                                         out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse ChargingPeriods           [optional]

                if (JSON.ParseOptionalJSON("charging_periods",
                                           "charging periods",
                                           ChargingPeriod.TryParse,
                                           out IEnumerable <ChargingPeriod> ChargingPeriods,
                                           out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse TotalCosts                [optional]

                if (JSON.ParseOptionalJSON("total_cost",
                                           "total costs",
                                           Price.TryParse,
                                           out Price? TotalCosts,
                                           out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse Status                    [mandatory]

                if (!JSON.ParseMandatoryEnum("status",
                                             "session status",
                                             out SessionStatusTypes Status,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse LastUpdated               [mandatory]

                if (!JSON.ParseMandatory("last_updated",
                                         "last updated",
                                         out DateTime LastUpdated,
                                         out ErrorResponse))
                {
                    return(false);
                }

                #endregion


                Session = new Session(CountryCodeBody ?? CountryCodeURL.Value,
                                      PartyIdBody ?? PartyIdURL.Value,
                                      SessionIdBody ?? SessionIdURL.Value,
                                      Start,
                                      KWh,
                                      CDRToken,
                                      AuthMethod,
                                      LocationId,
                                      EVSEUId,
                                      ConnectorId,
                                      Currency,
                                      Status,

                                      End,
                                      AuthorizationReference,
                                      MeterId,
                                      EnergyMeter,
                                      TransparencySoftwares,
                                      ChargingPeriods,
                                      TotalCosts,

                                      LastUpdated);


                if (CustomSessionParser != null)
                {
                    Session = CustomSessionParser(JSON,
                                                  Session);
                }

                return(true);
            }
            catch (Exception e)
            {
                Session       = default;
                ErrorResponse = "The given JSON representation of a session is invalid: " + e.Message;
                return(false);
            }
        }