Ejemplo n.º 1
0
        public static Boolean TryParseJSON(JObject JSONObject,
                                           out Dashboard Dashboard,
                                           out String ErrorResponse,
                                           Dashboard_Id?DashboardIdURL = null)
        {
            try
            {
                Dashboard = null;

                #region Parse DashboardId      [optional]

                // Verify that a given Dashboard identification
                //   is at least valid.
                if (JSONObject.ParseOptionalStruct("@id",
                                                   "dashboard identification",
                                                   Dashboard_Id.TryParse,
                                                   out Dashboard_Id? DashboardIdBody,
                                                   out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                if (!DashboardIdURL.HasValue && !DashboardIdBody.HasValue)
                {
                    ErrorResponse = "The Dashboard identification is missing!";
                    return(false);
                }

                if (DashboardIdURL.HasValue && DashboardIdBody.HasValue && DashboardIdURL.Value != DashboardIdBody.Value)
                {
                    ErrorResponse = "The optional Dashboard 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-LinkedData context information",
                                               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 Name             [mandatory]

                if (!JSONObject.ParseMandatory("name",
                                               "dashboard name",
                                               out I18NString Name,
                                               out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse Description      [optional]

                if (!JSONObject.ParseOptional("description",
                                              "dashboard description",
                                              out I18NString Description,
                                              out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse Creation date    [optional]

                if (!JSONObject.ParseOptional("creationDate",
                                              "creation date",
                                              out DateTime? CreationDate,
                                              out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                var Tags = new TagRelevance[0];

                var IsDisabled = JSONObject["isDisabled"]?.Value <Boolean>();

                #region Get   DataSource       [optional]

                var DataSource = JSONObject.GetOptional("dataSource");

                #endregion

                #region Parse CryptoHash       [optional]

                var CryptoHash = JSONObject.GetOptional("cryptoHash");

                #endregion


                Dashboard = new Dashboard(DashboardIdBody ?? DashboardIdURL.Value,
                                          Name,
                                          Description,
                                          CreationDate,
                                          Tags,
                                          IsDisabled,
                                          DataSource);

                ErrorResponse = null;
                return(true);
            }
            catch (Exception e)
            {
                ErrorResponse = e.Message;
                Dashboard     = null;
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static Boolean TryParseJSON(JObject JSONObject,
                                           UserProviderDelegate UserProvider,
                                           out NewsPosting NewsPosting,
                                           out String ErrorResponse,
                                           NewsPosting_Id?NewsIdURL = null)
        {
            try
            {
                NewsPosting = null;

                #region Parse NewsId            [optional]

                // Verify that a given News identification
                //   is at least valid.
                if (JSONObject.ParseOptionalStruct("@id",
                                                   "News identification",
                                                   NewsPosting_Id.TryParse,
                                                   out NewsPosting_Id? NewsIdBody,
                                                   out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                if (!NewsIdURL.HasValue && !NewsIdBody.HasValue)
                {
                    ErrorResponse = "The News identification is missing!";
                    return(false);
                }

                if (NewsIdURL.HasValue && NewsIdBody.HasValue && NewsIdURL.Value != NewsIdBody.Value)
                {
                    ErrorResponse = "The optional News 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-LinkedData context information",
                                               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 Headline          [mandatory]

                if (!JSONObject.ParseMandatory("headline",
                                               "news headline",
                                               out I18NString Headline,
                                               out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse Text              [mandatory]

                if (!JSONObject.ParseMandatory("text",
                                               "news text",
                                               out I18NString Text,
                                               out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse Author            [mandatory]

                User Author = null;

                if (JSONObject["author"] is JObject authorJSON &&
                    authorJSON.ParseMandatory("@id",
                                              "author identification",
                                              User_Id.TryParse,
                                              out User_Id AuthorId,
                                              out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }

                    if (!UserProvider(AuthorId, out Author))
                    {
                        ErrorResponse = "The given author '" + AuthorId + "' is unknown!";
                        return(false);
                    }
                }

                else
                {
                    return(false);
                }

                #endregion

                #region Parse PublicationDate   [mandatory]

                if (!JSONObject.ParseMandatory("publicationDate",
                                               "publication date",
                                               out DateTime PublicationDate,
                                               out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                var Tags = new TagRelevance[0];

                #region Parse IsHidden          [optional]

                if (JSONObject.ParseOptional("isHidden",
                                             "is hidden",
                                             out Boolean? IsHidden,
                                             out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                var Signatures = new Signature[0];

                var CustomData = JSONObject["CustomData"] as JObject;

                #region Get   DataSource        [optional]

                var DataSource = JSONObject.GetOptional("dataSource");

                #endregion

                #region Get   LastChange        [optional]

                if (JSONObject.ParseOptional("lastChange",
                                             "last change",
                                             out DateTime? LastChange,
                                             out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse CryptoHash        [optional]

                var CryptoHash = JSONObject.GetOptional("cryptoHash");

                #endregion


                NewsPosting = new NewsPosting(NewsIdBody ?? NewsIdURL.Value,
                                              Headline,
                                              Text,
                                              Author,
                                              PublicationDate,
                                              Tags,
                                              IsHidden ?? false,
                                              Signatures,

                                              CustomData,
                                              DataSource,
                                              LastChange);

                ErrorResponse = null;
                return(true);
            }