Exemplo n.º 1
0
        // Note: The following is needed to satisfy pattern matching delegates! Do not refactor it!

        /// <summary>
        /// Try to parse the given JSON representation of a charge detail record location.
        /// </summary>
        /// <param name="JSON">The JSON to parse.</param>
        /// <param name="CDRLocation">The parsed location.</param>
        /// <param name="ErrorResponse">An optional error response.</param>
        public static Boolean TryParse(JObject JSON,
                                       out CDRLocation CDRLocation,
                                       out String ErrorResponse)

        => TryParse(JSON,
                    out CDRLocation,
                    out ErrorResponse,
                    null);
Exemplo n.º 2
0
 /// <summary>
 /// Try to parse the given text representation of a charge detail record location.
 /// </summary>
 /// <param name="Text">The text to parse.</param>
 /// <param name="CDRLocation">The parsed location.</param>
 /// <param name="ErrorResponse">An optional error response.</param>
 /// <param name="CustomCDRLocationParser">A delegate to parse custom location JSON objects.</param>
 public static Boolean TryParse(String Text,
                                out CDRLocation CDRLocation,
                                out String ErrorResponse,
                                CustomJObjectParserDelegate <CDRLocation> CustomCDRLocationParser = null)
 {
     try
     {
         return(TryParse(JObject.Parse(Text),
                         out CDRLocation,
                         out ErrorResponse,
                         CustomCDRLocationParser));
     }
     catch (Exception e)
     {
         CDRLocation   = null;
         ErrorResponse = "The given text representation of a location is invalid: " + e.Message;
         return(false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Try to parse the given JSON representation of a charge detail record location.
        /// </summary>
        /// <param name="JSON">The JSON to parse.</param>
        /// <param name="CDRLocation">The parsed location.</param>
        /// <param name="ErrorResponse">An optional error response.</param>
        /// <param name="CustomCDRLocationParser">A delegate to parse custom location JSON objects.</param>
        public static Boolean TryParse(JObject JSON,
                                       out CDRLocation CDRLocation,
                                       out String ErrorResponse,
                                       CustomJObjectParserDelegate <CDRLocation> CustomCDRLocationParser = null)
        {
            try
            {
                CDRLocation = default;

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

                #region Parse Id                        [mandatory]

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

                #endregion

                #region Parse Name                      [optional]

                var Name = JSON.GetString("name");

                #endregion

                #region Parse Address                   [mandatory]

                if (!JSON.ParseMandatoryText("address",
                                             "address",
                                             out String Address,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse City                      [mandatory]

                if (!JSON.ParseMandatoryText("city",
                                             "city",
                                             out String City,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse PostalCode                [optional]

                var PostalCode = JSON.GetString("postal_code");

                #endregion

                #region Parse Country                   [mandatory]

                if (!JSON.ParseMandatoryText("country",
                                             "country",
                                             out String Country,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse Coordinates               [mandatory]

                if (!JSON.ParseMandatoryJSON("coordinates",
                                             "geo coordinates",
                                             GeoCoordinate.TryParse,
                                             out GeoCoordinate Coordinates,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse EVSEUId                   [mandatory]

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

                #endregion

                #region Parse EVSEId                    [mandatory]

                if (!JSON.ParseMandatory("evse_id",
                                         "EVSE identification",
                                         EVSE_Id.TryParse,
                                         out EVSE_Id EVSEId,
                                         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 ConnectorStandard         [mandatory]

                if (!JSON.ParseMandatoryEnum("connector_standard",
                                             "connector standard/type",
                                             out ConnectorTypes ConnectorStandard,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse ConnectorFormat           [mandatory]

                if (!JSON.ParseMandatoryEnum("connector_format",
                                             "connector format",
                                             out ConnectorFormats ConnectorFormat,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse ConnectorPowerType        [mandatory]

                if (!JSON.ParseMandatoryEnum("connector_power_type",
                                             "connector power type",
                                             out PowerTypes ConnectorPowerType,
                                             out ErrorResponse))
                {
                    return(false);
                }

                #endregion


                CDRLocation = new CDRLocation(Id,
                                              Address,
                                              City,
                                              Country,
                                              Coordinates,
                                              EVSEUId,
                                              EVSEId,
                                              ConnectorId,
                                              ConnectorStandard,
                                              ConnectorFormat,
                                              ConnectorPowerType,
                                              Name,
                                              PostalCode);


                if (CustomCDRLocationParser != null)
                {
                    CDRLocation = CustomCDRLocationParser(JSON,
                                                          CDRLocation);
                }

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