Example #1
0
            /// <summary>
            /// Create a new message builder.
            /// </summary>
            public Builder(Message_Id Id,
                           User_Id Sender,
                           IEnumerable <User_Id> Receivers,
                           I18NString Subject,
                           I18NString Text,
                           Message_Id?InReplyTo = null,

                           JObject CustomData = default,
                           IEnumerable <AttachedFile> AttachedFiles = default,
                           JSONLDContext?JSONLDContext = default,
                           String DataSource           = default,
                           DateTime?LastChange         = default)

                : base(Id,
                       JSONLDContext ?? DefaultJSONLDContext,
                       CustomData,
                       DataSource,
                       LastChange)

            {
                this.Sender        = Sender;
                this.Receivers     = AttachedFiles != null ?  new HashSet <User_Id>     (Receivers)     : new HashSet <User_Id>();
                this.Subject       = Subject ?? new I18NString();
                this.Text          = Text ?? new I18NString();
                this.InReplyTo     = InReplyTo;
                this.AttachedFiles = AttachedFiles != null ?  new HashSet <AttachedFile>(AttachedFiles) : new HashSet <AttachedFile>();
            }
Example #2
0
 public SecurityToken(User_Id UserId,
                      DateTime Expires,
                      User_Id?Astronaut = null)
 {
     this.UserId    = UserId;
     this.Expires   = Expires;
     this.Astronaut = Astronaut;
 }
Example #3
0
        /// <summary>
        /// Create a new message.
        /// </summary>
        /// <param name="Id">The unique identification of the message.</param>
        /// <param name="Sender">The sender of the message.</param>
        /// <param name="Receivers">The receivers of the message.</param>
        /// <param name="Subject">The (multi-language) subject of the message.</param>
        /// <param name="Text">An optional (multi-language) text of the message.</param>
        /// <param name="InReplyTo">The message is a reply to another message.</param>
        /// <param name="DataSource">The source of all this data, e.g. an automatic importer.</param>
        public Message(Message_Id Id,
                       User_Id Sender,
                       IEnumerable <User_Id> Receivers,
                       I18NString Subject,
                       I18NString Text,
                       Message_Id?InReplyTo = null,

                       JObject CustomData = default,
                       IEnumerable <AttachedFile> AttachedFiles = default,
                       JSONLDContext?JSONLDContext = default,
                       String DataSource           = default,
                       DateTime?LastChange         = default)

            : base(Id,
                   JSONLDContext ?? DefaultJSONLDContext,
                   CustomData,
                   DataSource,
                   LastChange)

        {
            #region Initial checks

            if (Receivers == null || !Receivers.Any())
            {
                throw new ArgumentNullException(nameof(Receivers), "The enumeration of message receivers must not be null or empty!");
            }

            #endregion

            this.Sender        = Sender;
            this.Receivers     = Receivers;
            this.Subject       = Subject ?? new I18NString();
            this.Text          = Text ?? new I18NString();
            this.InReplyTo     = InReplyTo;
            this.AttachedFiles = AttachedFiles ?? new AttachedFile[0];
        }
Example #4
0
 /// <summary>
 /// Create a new user identification and password combination.
 /// </summary>
 /// <param name="Login">The unique user identification.</param>
 /// <param name="Password">The password of the user.</param>
 public LoginPassword(User_Id Login,
                      Password Password)
 {
     this.Login    = Login;
     this.Password = Password;
 }
Example #5
0
        public static Boolean TryParseJSON(JObject JSONObject,
                                           UserProviderDelegate UserProvider,
                                           out PasswordReset PasswordReset,
                                           out String ErrorResponse,
                                           Boolean IgnoreContextMismatches = true)

        {
            try
            {
                PasswordReset = null;

                if (JSONObject == null)
                {
                    ErrorResponse = "The given JSON object must not be null!";
                    return(false);
                }

                #region Parse Context            [mandatory]

                if (!IgnoreContextMismatches)
                {
                    if (!JSONObject.ParseMandatoryText("@context",
                                                       "JSON-LD context",
                                                       out String Context,
                                                       out ErrorResponse))
                    {
                        ErrorResponse = @"The JSON-LD ""@context"" information is missing!";
                        return(false);
                    }

                    if (Context != JSONLDContext)
                    {
                        ErrorResponse = @"The given JSON-LD ""@context"" information '" + Context + "' is not supported!";
                        return(false);
                    }
                }

                #endregion

                #region Parse Timestamp          [mandatory]

                if (!JSONObject.ParseMandatory("timestamp",
                                               "timestamp",
                                               out DateTime Timestamp,
                                               out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse Users              [mandatory]

                if (!JSONObject.ParseMandatory("userIds",
                                               "user identifications",
                                               out JArray UserIdArray,
                                               out ErrorResponse))
                {
                    return(false);
                }

                HashSet <User_Id> userIds = null;

                try
                {
                    userIds = UserIdArray.
                              Where(jsonvalue => jsonvalue != null).
                              Select(jsonvalue => User_Id.Parse(jsonvalue.Value <String>())).
                              ToHashSet();
                }
                catch
                {
                    ErrorResponse = "The given array of users '" + UserIdArray + "' is invalid!";
                    return(false);
                }

                if (!userIds.Any())
                {
                    ErrorResponse = "The given array of users '" + UserIdArray + "' must not be empty!";
                    return(false);
                }

                HashSet <User> Users = new HashSet <User>();

                foreach (var userId in userIds)
                {
                    if (!UserProvider(userId, out User user))
                    {
                        ErrorResponse = "The given user '" + userId + "' is unknown or invalid!";
                        return(false);
                    }

                    Users.Add(user);
                }

                #endregion

                #region Parse SecurityToken1     [mandatory]

                if (!JSONObject.ParseMandatory("securityToken1",
                                               "security token #1",
                                               SecurityToken_Id.TryParse,
                                               out SecurityToken_Id SecurityToken1,
                                               out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse SecurityToken2     [optional]

                if (JSONObject.ParseOptionalStruct("securityToken2",
                                                   "security token #2",
                                                   SecurityToken_Id.TryParse,
                                                   out SecurityToken_Id? SecurityToken2,
                                                   out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse EventTrackingId    [optional]

                if (JSONObject.ParseOptional("eventTrackingId",
                                             "event tracking identification",
                                             EventTracking_Id.TryParse,
                                             out EventTracking_Id EventTrackingId,
                                             out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion


                PasswordReset = new PasswordReset(Timestamp,
                                                  Users,
                                                  SecurityToken1,
                                                  SecurityToken2,
                                                  EventTrackingId);

                return(true);
            }
            catch (Exception e)
            {
                ErrorResponse = e.Message;
                PasswordReset = null;
                return(false);
            }
        }