Exemple #1
0
        /// <summary>
        /// Create a new CardiCloudAffected builder.
        /// </summary>
        public static Affected.Builder ToBuilder(this Affected Affected)

        => Affected == null
                   ? new Affected.Builder()
                   : new Affected.Builder(ServiceTicketLinks:  Affected.ServiceTickets,
                                          UserLinks:           Affected.Users,
                                          OrganizationLinks:   Affected.Organizations);
Exemple #2
0
        /// <summary>
        /// Whether the list of affected things is empty.
        /// </summary>
        public static Boolean IsEmpty(this Affected Affected)

        => Affected == null ||
        !(Affected.ServiceTickets.SafeAny() ||
          Affected.Users.SafeAny() ||
          Affected.Organizations.SafeAny());
Exemple #3
0
        /// <summary>
        /// Try to parse the given service ticket JSON.
        /// </summary>
        /// <param name="JSONObject">A JSON object.</param>
        /// <param name="ServiceTicketProvider">A delegate resolving service tickets.</param>
        /// <param name="UserProvider">A delegate resolving users.</param>
        /// <param name="OrganizationProvider">A delegate resolving organizations.</param>
        /// <param name="Affected">The parsed list of affected things.</param>
        /// <param name="ErrorResponse">An error message.</param>
        public static Boolean TryParseJSON(JObject JSONObject,
                                           ServiceTicketProviderDelegate ServiceTicketProvider,
                                           UserProviderDelegate UserProvider,
                                           OrganizationProviderDelegate OrganizationProvider,
                                           out Affected Affected,
                                           out String ErrorResponse)
        {
            try
            {
                Affected = null;

                #region Parse ServiceTickets   [optional]

                var RelatedServiceTickets = new HashSet <MessageHolder <ServiceTicket_Id, ServiceTicket> >();

                if (JSONObject.ParseOptionalHashSet("serviceTicketIds",
                                                    "related service tickets",
                                                    ServiceTicket_Id.TryParse,
                                                    out HashSet <ServiceTicket_Id> RelatedServiceTicketIds,
                                                    out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }

                    if (ServiceTicketProvider != null)
                    {
                        foreach (var relatedServiceTicketId in RelatedServiceTicketIds)
                        {
                            if (ServiceTicketProvider(relatedServiceTicketId, out ServiceTicket relatedServiceTicket))
                            {
                                RelatedServiceTickets.Add(new MessageHolder <ServiceTicket_Id, ServiceTicket>(relatedServiceTicketId, relatedServiceTicket));
                            }
                        }
                    }
                }

                #endregion

                #region Parse Users            [optional]

                var RelatedUsers = new HashSet <MessageHolder <User_Id, User> >();

                if (JSONObject.ParseOptionalHashSet("userIds",
                                                    "related users",
                                                    User_Id.TryParse,
                                                    out HashSet <User_Id> RelatedUserIds,
                                                    out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }

                    if (UserProvider != null)
                    {
                        foreach (var relatedUserId in RelatedUserIds)
                        {
                            if (UserProvider(relatedUserId, out User relatedUser))
                            {
                                RelatedUsers.Add(new MessageHolder <User_Id, User>(relatedUserId, relatedUser));
                            }
                        }
                    }
                }

                #endregion

                #region Parse Organizations    [optional]

                var RelatedOrganizations = new HashSet <MessageHolder <Organization_Id, Organization> >();

                if (JSONObject.ParseOptionalHashSet("organizationIds",
                                                    "related organizations",
                                                    Organization_Id.TryParse,
                                                    out HashSet <Organization_Id> RelatedOrganizationIds,
                                                    out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }

                    if (OrganizationProvider != null)
                    {
                        foreach (var relatedOrganizationId in RelatedOrganizationIds)
                        {
                            if (OrganizationProvider(relatedOrganizationId, out Organization relatedOrganization))
                            {
                                RelatedOrganizations.Add(new MessageHolder <Organization_Id, Organization>(relatedOrganizationId, relatedOrganization));
                            }
                        }
                    }
                }

                #endregion


                Affected = new Affected(ServiceTicketLinks:  RelatedServiceTickets,
                                        UserLinks:           RelatedUsers,
                                        OrganizationLinks:   RelatedOrganizations);

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