/// <summary> /// Try to parse the given communicator group JSON. /// </summary> /// <param name="JSONObject">A JSON object.</param> /// <param name="AttachedFile">The parsed attached file.</param> /// <param name="ErrorResponse">An error message.</param> public static Boolean TryParseJSON(JObject JSONObject, out AttachedFile AttachedFile, out String ErrorResponse) => TryParseJSON(JSONObject, out AttachedFile, out ErrorResponse, null);
/// <summary> /// Try to parse the given communicator group JSON. /// </summary> /// <param name="JSONObject">A JSON object.</param> /// <param name="AttachedFile">The parsed attached file.</param> /// <param name="ErrorResponse">An error message.</param> public static Boolean TryParseJSON(JObject JSONObject, out AttachedFile AttachedFile, out String ErrorResponse, AttachedFile_Id?AttachedFileIdURL) { try { AttachedFile = null; if (JSONObject?.HasValues != true) { ErrorResponse = "The given JSON object must not be null or empty!"; return(false); } #region Parse AttachedFileId [optional] // Verify that a given AttachedFile identification // is at least valid. if (JSONObject.ParseOptionalStruct("@id", "attached file identification", AttachedFile_Id.TryParse, out AttachedFile_Id? AttachedFileIdBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!AttachedFileIdURL.HasValue && !AttachedFileIdBody.HasValue) { ErrorResponse = "The AttachedFile identification is missing!"; return(false); } if (AttachedFileIdURL.HasValue && AttachedFileIdBody.HasValue && AttachedFileIdURL.Value != AttachedFileIdBody.Value) { ErrorResponse = "The optional AttachedFile identification given within the JSON body does not match the one given in the URI!"; return(false); } #endregion #region Parse Context [mandatory] if (!JSONObject.ParseMandatory("@context", "JSON-LD context", JSONLDContext.TryParse, out JSONLDContext Context, out ErrorResponse)) { ErrorResponse = @"The JSON-LD ""@context"" information is missing!"; return(false); } if (Context != DefaultJSONLDContext) { ErrorResponse = @"The given JSON-LD ""@context"" information '" + Context + "' is not supported!"; return(false); } #endregion #region Parse Description [optional] if (JSONObject.ParseOptional("description", "description", out I18NString Description, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion var Locations = new List <HTTPPath>(); var ContentType = HTTPContentType.JSONLD_UTF8; var Size = 0UL; var Icon = new HTTPPath?(); var Created = Timestamp.Now; var LastModified = Timestamp.Now; #region Get DataSource [optional] var DataSource = JSONObject.GetOptional("dataSource"); #endregion #region Parse CryptoHash [optional] var CryptoHash = JSONObject.GetOptional("cryptoHash"); #endregion AttachedFile = new AttachedFile(Id: AttachedFileIdBody ?? AttachedFileIdURL.Value, Description: Description, Locations: Locations, ContentType: ContentType, Size: Size, Icon: Icon, Created: Created, LastModifed: LastModified, DataSource: DataSource); ErrorResponse = null; return(true); } catch (Exception e) { ErrorResponse = e.Message; AttachedFile = null; return(false); } }