Click here to Skip to main content
15,886,258 members
Articles / Security / Encryption

Enhanced String Handling II

Rate me:
Please Sign up or sign in to vote.
3.76/5 (11 votes)
16 Dec 2010CPOL2 min read 36K   213   15  
Overcoming limitations of: Enhanced String Handling
using System;
using System.Collections.Generic;
using EnhancedStringEvaluate;
using System.Configuration;
using TestEvaluation.ProcessEvaluate;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

namespace TestEvaluation
{
	class Program
	{
		static void Main(string[] args)
		{
			var config = new Dictionary<string,string>();
			foreach (var name in ConfigurationManager.AppSettings.AllKeys)
				config.Add(name, ConfigurationManager.AppSettings[name]);

			// handling
			var context = new List<IProcessEvaluate>();
			context.Add(new ProcessDate());
			context.Add(new ProcessKey(config));
			context.Add(new ProcessForeignKey());
			context.Add(new ProcessIf());
			context.Add(new ProcessLiteral());
			IProcessEvaluate evalCurrentDir = new ProcessCurrentDir();
			context.Add(evalCurrentDir);
			context.Add(new ProcessCurrentTime());

			EnhancedStringEval eval = new EnhancedStringEval(context);

			try
			{
				ProcessCurrentDir currDir = (ProcessCurrentDir)evalCurrentDir;
				currDir.CurrentDir = @"C:\Directory 1";
				string key = "Flat";
				string test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);

				key = "Static flat";
				test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);

				key = "Static date";
				test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);

				key = "Dynamic current directory";
				test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);

				key = "temp";
				test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);

				key = "Dynamic current path";
				test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);

				key = "Stamp";
				test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);

				key = "Stamp2";
				test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);

				key = "Stamp3";
				test = eval.EvaluateString(config[key]);
				Console.WriteLine("{0} (orig: {1}): {2}", key, ConfigurationManager.AppSettings[key], test);
			}
			catch (EnhancedStringException ex1)
			{
				string msg = ex1.Message;
				int counter = 1;
				for (Exception iEx = ex1.InnerException; iEx != null; iEx = iEx.InnerException)
					msg += string.Format("{0}\t{1}.\t{2}", Environment.NewLine, counter++, iEx.Message);
				Console.WriteLine("ID: \"{0}\", {1}, {2}", ex1.Identifier, ex1.Element, msg);
			}

			Console.ReadKey();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
avifarah@gmail.com

Comments and Discussions