Example #1
0
		public static String FindAndExecuteMethod(String name, ValuesBase valuesBase, String param)
		{
			var normilized = ValuesBase.NormalizeKey(name);
			if (methods != null && methods.ContainsKey(normilized))
			{
				List<String> paramS = new List<String>();
				if (!String.IsNullOrEmpty(param))
				{
					String[] splits = param.Split(',');
					foreach (var p in splits)
					{
						paramS.Add(Uri.UnescapeDataString(p));
					}
				}

				MethodInfo mi = methods[normilized];
				var results = mi.Invoke(null, new object[]
				{
					valuesBase,
					paramS.ToArray()
				}) as String;

				return results;
			}

			return null;
		}
Example #2
0
		public static String FixFileName(ValuesBase valuesBase, params String[] arguments)
		{
			if (valuesBase == null)
			{
				throw new ArgumentNullException("track");
			}

			if (arguments == null || arguments.Length == 0)
			{
				if (log.IsErrorEnabled)
				{
					log.Error("No arguments passed to Method FixFileName.");
				}

				return "";
			}

			if (arguments.Length > 1)
			{
				if (log.IsWarnEnabled)
				{
					log.WarnFormat("{0} arguments passed to FixFileName only '{1}' will be used", arguments.Length, arguments[0]);
				}
			}

			String name = arguments[0];
			String value = valuesBase[name];

			if (value == null)
			{
				if (log.IsDebugEnabled)
				{
					log.DebugFormat("No value was returned for key {0}", name);
				}

				return "";
			}

			StringBuilder fixedName = new StringBuilder();

			var invalidChars = Path.GetInvalidFileNameChars();
			char c;
			for (int i = 0; i < value.Length; i++)
			{
				c = value[i];
				if (!invalidChars.Contains(c))
				{
					fixedName.Append(c);
				}
				else
				{
					fixedName.Append('_');
				}
			}

			return fixedName.ToString();
		}