Beispiel #1
0
        /// <summary>
        /// Get an specific resource inside a page.
        /// Page is the name of the csv file containing the resources.
        /// </summary>
        /// <param name="key">Key corresponding to a resource.</param>
        /// <returns>Resource corresponding to the "key".</returns>
        public string this[string key]
        {
            get
            {
                string resource;
                try
                {
                    bool keyExist = resources.Keys.Where(x => x == key).FirstOrDefault() != null;

                    // Throw exception if resource for that key does not exist
                    if (!keyExist)
                    {
                        throw new KeyOfResourceDoesNotExist(key);
                    }
                    else
                    {
                        resource = resources[key];
                    }
                }
                catch (KeyOfResourceDoesNotExist ex)
                {
                    // If it does not exist, a "defaultstring-Key" is returned
                    resource = hp.getStringFromAppConfig("ThereIsNoResourceKey", new InvalidDeafultMessageForNotFoundResourceKey()) + "-" + key;

                    // Log the exception
                    loggerService.writeLog(ex);
                }

                // Return resource if exist. Otherwise a default string from app.config is returned.
                return(resource);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Check if a whole date, only date, or only time is valid according to the format set in web.config.
        /// </summary>
        /// <param name="dateAsString">Date as string to check.</param>
        /// <param name="date">Date variable to fill with the parsed value if it can be parsed.</param>
        /// <returns>True if it is a valid date. Otherwise false.</returns>
        public bool isValidDate(string dateAsString, string format, out DateTime date)
        {
            bool ret = false;

            date = WholeMinDate;

            // Check for the formats
            if (format == WholeDateFormat)
            {
                ret = DateTime.TryParseExact(dateAsString, hp.getStringFromAppConfig("wholeDateFormat"), CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
            }
            else if (format == OnlyDateFormat)
            {
                ret = DateTime.TryParseExact(dateAsString, hp.getStringFromAppConfig("onlyDateFormat"), CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
            }
            else if (format == OnlyTimeFormat)
            {
                ret = DateTime.TryParseExact(dateAsString, hp.getStringFromAppConfig("onlyTimeFormat"), CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
            }

            // True if it can be parsed with the format
            return(ret);
        }