示例#1
0
        public string ReplaceProperty(string propertyName, string format, object context)
        {
            if (String.IsNullOrEmpty(propertyName))
            {
                return(propertyName);
            }

            switch (propertyName)
            {
            case "APPLICATION_NAME":
                return(ChoObject.Format(ChoGlobalApplicationSettings.Me.ApplicationName, format));

            case "PROCESS_ID":
                return(ChoObject.Format(ChoApplication.ProcessId, format));

            case "THREAD_ID":
                return(ChoObject.Format(ChoApplication.GetThreadId(), format));

            case "THREAD_NAME":
                return(ChoObject.Format(ChoApplication.GetThreadName(), format));

            case "RANDOM_NO":
                return(ChoObject.Format(ChoRandom.NextRandom(), format));

            case "TODAY":
                if (String.IsNullOrEmpty(format))
                {
                    return(System.DateTime.Today.ToShortDateString());
                }
                else
                {
                    return(ChoObject.Format(System.DateTime.Today, format));
                }

            case "NOW":
                if (String.IsNullOrEmpty(format))
                {
                    return(System.DateTime.Now.ToShortTimeString());
                }
                else
                {
                    return(ChoObject.Format(System.DateTime.Now, format));
                }

            case "SEQ_NO":
                return(ChoObject.Format(_sequenceGeneratorSettings.Value.Next(), format));

            default:
                return(ChoObject.Format(propertyName, format));
            }
        }
            public string ReplaceProperty(string propertyName, string format)
            {
                //try
                //{
                object output    = null;
                string className = "ChoClass_{0}".FormatString(ChoRandom.NextRandom(0, Int32.MaxValue));
                string statement = String.Format("public class {0} {{ public object Execute() {{ return {1}; }} }}", className, propertyName);

                using (Microsoft.CSharp.CSharpCodeProvider foo =
                           new Microsoft.CSharp.CSharpCodeProvider())
                {
                    var res = foo.CompileAssemblyFromSource(_compilerParameters, statement);

                    if (res.Errors.Count > 0)
                    {
                        StringBuilder errors = new StringBuilder();
                        foreach (CompilerError CompErr in res.Errors)
                        {
                            errors.AppendFormat("Line number {0}, Error Number: {1}, {2}{3}", CompErr.Line, CompErr.ErrorNumber, CompErr.ErrorText, Environment.NewLine);
                        }

                        throw new ChoApplicationException("Exception compiling dynamic statement {1}{1}{0}{1}{1}{2}".FormatString(
                                                              propertyName, Environment.NewLine, errors.ToString()));
                    }

                    var type = res.CompiledAssembly.GetType(className);
                    var obj  = Activator.CreateInstance(type);

                    output = type.GetMethod("Execute").Invoke(obj, new object[] { });
                }

                return(ChoObject.ToString(output, format));
                //}
                //catch (Exception ex)
                //{
                //    return ChoPropertyManager.FormatException(propertyName, ex);
                //}
            }
 internal ChoDictionaryPropertyReplacer(IDictionary <string, object> properties)
     : this(String.Format("DictionaryPropertyReplacer_{0}", ChoRandom.NextRandom().ToString()), properties)
 {
 }
示例#4
0
 public ChoNameableObject() : this(String.Format("ChoNamedObject_{0}", ChoRandom.NextRandom()))
 {
 }
示例#5
0
 static ChoRandom()
 {
     _random = new ChoRandom((int)DateTime.Now.Ticks);
 }
示例#6
0
 public ChoCustomKeyValuePropertyReplacer(IChoKeyValuePropertyReplacer keyValuePropertyReplacer)
     : this(String.Format("CustomKeyValuePropertyReplacer_{0}", ChoRandom.NextRandom().ToString()), keyValuePropertyReplacer)
 {
 }