コード例 #1
0
        /// <summary>
        /// Checks that a JournalEntry personae entry is in the correct format
        /// </summary>
        /// <returns>bool indicating whether the personae entry is valid</returns>
        /// <param name="personae">The personae entry to be validated</param>
        public static bool ValidateJentryPersonae(string personae)
        {
            bool isValid = true;

            // split using'|'
            string[] persSplit = personae.Split('|');
            if (persSplit.Length != 2)
            {
                isValid = false;
            }

            // 1st section must be valid character ID or 'all'
            else if ((!persSplit[0].Equals("all")) && (!Utility_Methods.ValidateCharacterID(persSplit[0])))
            {
                isValid = false;
            }

            // 2nd section must be all letters
            else if (!Utility_Methods.CheckStringValid("letters", persSplit[1]))
            {
                isValid = false;
            }

            return(isValid);
        }
コード例 #2
0
        /// <summary>
        /// Constructor for Place_Serialised taking seperate values.
        /// For creating Place_Serialised from CSV file.
        /// </summary>
        /// <param name="id">String holding place ID</param>
        /// <param name="nam">String holding place name</param>
        /// <param name="own">String holding Place owner (ID)</param>
        /// <param name="tiHo">String holding place title holder (charID)</param>
        /// <param name="rnk">String holding Place rank (ID)</param>
        public Place_Serialised(String id, String nam, byte r, String tiHo = null, string own = null)
        {
            // VALIDATION

            // ID
            // trim and ensure is uppercase
            id = id.Trim().ToUpper();

            if (!Utility_Methods.ValidatePlaceID(id))
            {
                throw new InvalidDataException("Place_Serialised id must be 5 characters long, start with a letter, and end in at least 2 numbers");
            }

            // NAM
            // trim and ensure 1st is uppercase
            nam = Utility_Methods.FirstCharToUpper(nam.Trim());

            if (!Utility_Methods.ValidateName(nam))
            {
                throw new InvalidDataException("Place_Serialised name must be 1-40 characters long and contain only valid characters (a-z and ') or spaces");
            }

            // TIHO
            if (!String.IsNullOrWhiteSpace(tiHo))
            {
                // trim and ensure 1st is uppercase
                tiHo = Utility_Methods.FirstCharToUpper(tiHo.Trim());

                if (!Utility_Methods.ValidateCharacterID(tiHo))
                {
                    throw new InvalidDataException("Place_Serialised titleHolder must have the format 'Char_' followed by some numbers");
                }
            }

            // OWNER
            if (!String.IsNullOrWhiteSpace(owner))
            {
                // trim and ensure 1st is uppercase
                owner = Utility_Methods.FirstCharToUpper(owner.Trim());

                if (!Utility_Methods.ValidateCharacterID(owner))
                {
                    throw new InvalidDataException("Place_Serialised owner must have the format 'Char_' followed by some numbers");
                }
            }

            this.id          = id;
            this.name        = nam;
            this.owner       = own;
            this.titleHolder = tiHo;
            this.rank        = r;
        }
コード例 #3
0
ファイル: Rank.cs プロジェクト: FraserSimpson241/JominiEngine
        /// <summary>
        /// Constructor for Position
        /// </summary>
        /// <param name="holder">string holding ID of the office holder</param>
        /// <param name="nat">Nationality associated with the position</param>
        public Position(byte id, TitleName[] ti, byte stat, string holder, Nationality nat)
            : base(id, ti, stat)
        {
            // VALIDATION

            // HOLDER
            if (!String.IsNullOrWhiteSpace(holder))
            {
                // trim and ensure 1st is uppercase
                holder = Utility_Methods.FirstCharToUpper(holder.Trim());

                if (!Utility_Methods.ValidateCharacterID(holder))
                {
                    throw new InvalidDataException("Position officeHolder id must have the format 'Char_' followed by some numbers");
                }
            }

            this.officeHolder = holder;
            this.nationality  = nat;
        }
コード例 #4
0
ファイル: Rank.cs プロジェクト: FraserSimpson241/JominiEngine
        /// <summary>
        /// Constructor for Position_Serialised taking seperate values.
        /// For creating Position_Serialised from CSV file.
        /// </summary>
        /// <param name="id">byte holding Position ID</param>
        /// <param name="ti">title name in various languages</param>
        /// <param name="stat">byte holding stature for this position</param>
        /// <param name="holder">string ID of the office holder</param>
        /// <param name="nat">string holding ID of Nationality associated with the position</param>
        public Position_Serialised(byte id, TitleName[] ti, byte stat, string holder, string nat)
        {
            // VALIDATION

            // STAT
            if (stat < 1)
            {
                stat = 1;
            }
            else if (stat > 3)
            {
                stat = 3;
            }

            // HOLDER
            if (!String.IsNullOrWhiteSpace(holder))
            {
                // trim and ensure 1st is uppercase
                holder = Utility_Methods.FirstCharToUpper(holder.Trim());

                if (!Utility_Methods.ValidateCharacterID(holder))
                {
                    throw new InvalidDataException("Position_Serialised officeHolder id must have the format 'Char_' followed by some numbers");
                }
            }

            // NAT
            // trim and ensure 1st is uppercase
            nat = Utility_Methods.FirstCharToUpper(nat.Trim());

            if (!Utility_Methods.ValidateNationalityID(nat))
            {
                throw new InvalidDataException("Position_Serialised nationality ID must be 1-3 characters long, and consist entirely of letters");
            }

            this.id           = id;
            this.title        = ti;
            this.stature      = stat;
            this.officeHolder = holder;
            this.nationality  = nat;
        }