Esempio n. 1
0
 public static void CheckForInvalidNullNameReference(string name, string messageName)
 {
     if ((null == name) || (name.Length == 0))
     {
         throw new InvalidOperationException(SafeFormatter.Format(ExceptionInvalidNullNameArgument, messageName));
     }
 }
Esempio n. 2
0
 public static void CheckExpectedType(object variable, Type type)
 {
     CheckForNullReference(variable, "variable");
     CheckForNullReference(type, "type");
     if (!type.IsAssignableFrom(variable.GetType()))
     {
         throw new ArgumentException(SafeFormatter.Format(ExceptionExpectedType, type.FullName));
     }
 }
Esempio n. 3
0
 public static void CheckForEmptyString(string variable, string variableName)
 {
     CheckForNullReference(variable, variableName);
     CheckForNullReference(variableName, "variableName");
     if (variable.Length == 0)
     {
         throw new ArgumentException(SafeFormatter.Format(ExceptionEmptyString, variableName));
     }
 }
Esempio n. 4
0
        public static void CheckEnumeration(Type enumType, object variable, string variableName)
        {
            CheckForNullReference(variable, "variable");
            CheckForNullReference(enumType, "enumType");
            CheckForNullReference(variableName, "variableName");

            if (!Enum.IsDefined(enumType, variable))
            {
                throw new ArgumentException(SafeFormatter.Format(ExceptionEnumerationNotDefined, variable.ToString(), enumType.FullName), variableName);
            }
        }
Esempio n. 5
0
        public static bool AppSettingsBool(string name, bool required, bool defaultVal)
        {
            string configValue = AppSettingsString(name, required, defaultVal.ToString());
            bool   retVal      = defaultVal;

            try {
                retVal = bool.Parse(configValue);
            }
            catch (Exception e) {
                if (!required)
                {
                    retVal = defaultVal;
                }
                else
                {
                    throw new Exception(SafeFormatter.Format(ELEMENT_NOT_FOUND, name), e);
                }
            }
            return(retVal);
        }
Esempio n. 6
0
        public static string Paste2HasteBin(string payload)
        {
            if (payload.Trim() == string.Empty)
            {
                return(string.Empty);
            }

            try
            {
                var            data    = Encoding.ASCII.GetBytes(payload);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(HASTEBIN_POSTURL);
                request.Method        = "POST";
                request.ContentType   = "application/json";
                request.ContentLength = data.Length;
                StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }

                var response       = (HttpWebResponse)request.GetResponse();
                var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

                dynamic stuff = JsonConvert.DeserializeObject(responseString);
                string  key   = stuff["key"];

                if (key != string.Empty)
                {
                    return(SafeFormatter.Format(HASTEBIN_RETURN, key));
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
                return(string.Empty);
            }
        }
Esempio n. 7
0
        public static string AppSettingsString(string name, bool required, string defaultValue)
        {
            ArgumentValidation.CheckForEmptyString(name, "config item name");

            string configValue = ConfigurationManager.AppSettings[name];

            configValue = (null == configValue ? string.Empty : configValue.Trim());

            if (string.Empty == configValue)
            {
                if (!required)
                {
                    return(defaultValue);
                }
                throw new Exception(SafeFormatter.Format(ELEMENT_NOT_FOUND, name));
            }
            else
            {
                return(configValue);
            }
        }