Пример #1
0
        /// <summary>
        /// Parses the input string assuming it represents an organisation number or PEPPOL participant identifier in one
        /// of these forms:
        /// <ol>
        /// <li>icd +':' + organisation identifier</li>
        /// <li>National organisation number with at least two character prefix.</li>
        /// </ol>
        /// <p>
        /// After parsing, the organisation identifier is validated in accordance with the rules of the scheme a
        /// validator is found.
        /// </p>
        /// </summary>
        /// <param name="participantId">the string representing the participant identifier or organisation identifier</param>
        /// <returns>a string on the form [ISO6523 ICD]:[participantId];</returns>
        static string Parse(string participantId)                            // throws InvalidPeppolParticipantException
        {
            string organisationId = participantId.Trim().Replace("\\s", ""); // Squeezes out any white spaces
            IIcd   schemeId       = null;

            MatchCollection matches = Iso6523Pattern.Matches(organisationId);

            if (matches.Count == 0)
            {
                throw new InvalidPeppolParticipantException(string.Format("ICD not found in '{0}'.", participantId));
            }

            // If the representation is in the form xxxx:yyyyyyyyy, we are good
            string icd = matches[0].Groups[1].Value;

            organisationId = matches[0].Groups[2].Value;

            try
            {
                schemeId = SchemeId.FromIso6523(icd); // Locates the associated scheme
            }
            catch (ArgumentException)
            {
                // No action.
            }

            if (schemeId == null)
            {
                throw new InvalidPeppolParticipantException("ICD " + icd + " is unknown");
            }

            // Constructs the textual representation of the PEPPOL participant identifier
            return($"{schemeId.Code}:{organisationId}");
        }
Пример #2
0
        /// <summary>
        /// Uses combination of SchemeId and Organisation identifier to create new instance.
        /// The Organisation identifier is validated in accordance with the rules of the scheme.
        /// </summary>
        /// <param name="schemeId"></param>
        /// <param name="organisationId"></param>
        public ParticipantId(IIcd schemeId, string organisationId)
        {
            if (schemeId == null)
            {
                throw new ArgumentException("SchemeId must be specified with a a valid ISO6523 code.");
            }

            if (organisationId == null)
            {
                throw new ArgumentException("The organisation id must be specified.");
            }

            if (organisationId.Length > InternationOrgIdMaxLength)
            {
                throw new ArgumentException(
                          string.Format(
                              "Invalid organisation id. '{0}' is longer than {1} characters",
                              organisationId,
                              InternationOrgIdMaxLength));
            }

            // Formats the organisation identifier in accordance with what PEPPOL expects.
            this.peppolParticipantIdValue = string.Format("{0}:{1}", schemeId.Code, organisationId);
        }
Пример #3
0
 public static IcdIdentifier Of(IIcd icd, string identifier)
 {
     return(new IcdIdentifier(icd, identifier));
 }
Пример #4
0
 private IcdIdentifier(IIcd icd, string identifier)
 {
     this.Icd        = icd;
     this.Identifier = identifier;
 }