public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (value == null) { return(null); } StringBuilder msg = new StringBuilder(); if (value.GetType().IsArray) { foreach (object item in (Array)value) { if (msg.Length == 0) { msg.Append(ChoString.ToString(item, String.Empty, String.Empty)); } else { msg.AppendFormat(", {0}", ChoString.ToString(item, String.Empty, String.Empty)); } } return(msg.ToString()); } return(base.ConvertFrom(context, culture, value)); }
public static string GetConfigFilePath() { if (!_configFilePath.IsNullOrWhiteSpace()) { return(_configFilePath); } else { string configFilePath; string appFrxFilePath = ChoAppFrxSettings.Me.AppFrxFilePath; if (appFrxFilePath.IsNullOrWhiteSpace()) { configFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, ChoReservedFileName.CoreFrxConfigFileName)); } else { appFrxFilePath = ChoString.ExpandProperties(appFrxFilePath, ChoEnvironmentVariablePropertyReplacer.Instance); if (ChoPath.IsDirectory(appFrxFilePath)) { appFrxFilePath = Path.Combine(appFrxFilePath, ChoReservedFileName.CoreFrxConfigFileName); } configFilePath = appFrxFilePath; } return(configFilePath); } }
private static bool TryConvertToSpecialValues(object value, Type targetType, CultureInfo culture, out object result) { result = null; if (value is string && ((string)value).Length == 0) { result = ChoTypeEx.Default(targetType); return(true); } if (targetType.IsEnum) { if (value is string) { result = Enum.Parse(targetType, value as string); if (Enum.IsDefined(targetType, result)) { return(true); } else { return(false); } } else { result = Enum.ToObject(targetType, value); if (Enum.IsDefined(targetType, result)) { return(true); } else { return(false); } } } else { if (value is string && targetType == typeof(Guid)) { result = (object)new Guid(value as string); return(true); } else if (value is string && targetType == typeof(Version)) { result = (object)new Version(value as string); return(true); } else if (targetType == typeof(string)) { result = value.ToString(); return(true); } else { result = ChoString.ToObjectInternal(value as string, targetType); return(true); } } }
public override string ToString() { StringBuilder msg = new StringBuilder(); msg.Append(base.ToString()); msg.AppendFormat("Callback: {0}{1}", ChoString.ToString(_asyncCallback), Environment.NewLine); return(msg.ToString()); }
public static string ExpandProperties(object target, string inString) { if (String.IsNullOrEmpty(inString)) { return(inString); } return(ChoString.ExpandProperties(target, inString)); }
public static object ConvertToObject(object inObject) { if (inObject == null) { return(null); } object[] objects = ChoString.Split2Objects(inObject.ToString()); return(objects != null && objects.Length > 0 ? objects[0] : DBNull.Value); }
// If the type of the value to convert is string, parses the string // and returns the integer to set the value of the property to. // This example first extends the integer array that supplies the // standard values collection if the user-entered value is not // already in the array. public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value != null && value.GetType() == typeof(string)) { return(ChoString.ExpandProperties(null, value as string)); } //return ChoString.Evaluate(null, value as string); return(value); }
public static string ExpandPropertiesEx(string inString) { string output = ExpandProperties(null, inString); if (ChoString.ContainsException(output)) { throw new ChoExpressionParseException(output); } return(output); }
public string ReplaceProperty(string propertyName, string format) { //try //{ //return ChoString.ToString(ChoString.Evaluate(_target, propertyName)); return(ChoObject.ToString(ChoString.Evaluate(_target, propertyName), format)); //} //catch (Exception ex) //{ // return ChoPropertyManager.FormatException(propertyName, ex); //} }
protected override object Execute(object value, out bool isHandled) { isHandled = false; Init(); if (_cs == null) { return(value); } string arguments = !Arguments.IsNullOrWhiteSpace() ? "{0} {1}".FormatString(value.ToNString(), ResolveText(Arguments)) : value.ToNString(); return(_cs.ExecuteFunc(ChoString.Split2Objects(arguments, ' '))); }
internal static NameValueCollection ToPersistableNameValueCollection(object target) { ChoGuard.ArgumentNotNull(target, "Target"); NameValueCollection nameValues = new NameValueCollection(); //Dictionary<string, MemberInfo> configMemberInfos = ChoType.GetMembersDictionary(target.GetType(), typeof(ChoConfigurationPropertyAttribute)); //MemberInfo[] memberInfos = ChoType.GetMembers(target.GetType(), typeof(ChoConfigurationPropertyAttribute)); MemberInfo[] memberInfos = ChoTypeMembersCache.GetAllMemberInfos(target.GetType()); if (memberInfos == null || memberInfos.Length == 0) { return(nameValues); } ChoPropertyInfoAttribute memberInfoAttribute = null; string name = null; foreach (MemberInfo memberInfo in memberInfos) { if (memberInfo.GetCustomAttribute <ChoIgnorePropertyAttribute>() != null) { continue; } object memberValue = ChoType.GetMemberValue(target, memberInfo.Name); memberInfoAttribute = (ChoPropertyInfoAttribute)ChoType.GetMemberAttribute(memberInfo, typeof(ChoPropertyInfoAttribute)); //if (memberInfoAttribute == null) continue; name = ChoType.GetMemberName(memberInfo, memberInfoAttribute); if (target is ChoConfigurableObject && ((ChoConfigurableObject)target).RaiseBeforeConfigurationObjectMemberPersist(memberInfo.Name, name, ref memberValue)) { nameValues.Add(name, memberValue == null ? null : memberValue.ToString()); } else { if (memberInfoAttribute != null && !memberInfoAttribute.Persistable) { continue; } memberValue = ChoType.GetMemberValue(target, memberInfo.Name); nameValues.Add(name, ChoString.ToString(ChoConvert.ConvertTo(target, memberValue, typeof(string), ChoTypeDescriptor.GetTypeConverters(memberInfo), ChoTypeDescriptor.GetTypeConverterParams(memberInfo), null), String.Empty, String.Empty)); } } return(nameValues); }
public bool ContainsProperty(string propertyName, object context) { //return true; try { ChoString.Evaluate(_target, propertyName); return(true); } catch (ChoFatalApplicationException) { throw; } catch (Exception) { return(false); } }
internal string PostFormat(string name, string value) { if (Name != null && Name.Length > 0) { name = Name; } else if (name != null && name.Length > 0) { } else { name = "key"; } StringBuilder msg = new StringBuilder(); for (int index = 0; index < NoOfNewLinesBefore; index++) { msg.AppendLine(); } if (name == ChoNull.NullString) { msg.AppendFormat("{0}{1}", ChoString.ToString(value), Environment.NewLine); } else { string valueText = ChoString.ToString(value); if (!valueText.ContainsHeader()) { msg.AppendFormat("{0}: {1}{2}", name, valueText, Environment.NewLine); } else { msg.AppendFormat("{0}{1}", valueText, Environment.NewLine); } } for (int index = 0; index < NoOfNewLinesAfter; index++) { msg.AppendLine(); } return(msg.ToString().Indent(NoOfTabs)); }
protected override object Execute(object value, out bool isHandled) { isHandled = false; if (CodeSnippet.IsNullOrWhiteSpace()) { return(value); } string codeSnippet = ResolveText(CodeSnippet); string arguments = !Arguments.IsNullOrWhiteSpace() ? "{0} {1}".FormatString(value.ToNString(), ResolveText(Arguments)) : value.ToNString(); string[] nameSpaces = Namespaces.SplitNTrim(); ChoCodeDomProvider cs = new ChoCodeDomProvider(new string[] { codeSnippet }, nameSpaces, ChoCodeProviderLanguage.VB); return(cs.ExecuteFunc(ChoString.Split2Objects(arguments, ' '))); }
public override string ToString() { StringBuilder msg = new StringBuilder(); msg.AppendFormat("Status: {0}{1}", _exception != null ? "SUCCESS" : "FAILED", Environment.NewLine); msg.AppendFormat("Aborted: {0}{1}", _isAborted, Environment.NewLine); msg.AppendFormat("Timedout: {0}{1}", _isTimedOut, Environment.NewLine); msg.AppendFormat("State: {0}{1}", _completedState, Environment.NewLine); if (_exception == null) { msg.AppendFormat("Result: {0}{1}", ChoString.ToString(_result), Environment.NewLine); } else { msg.AppendFormat("Exception: {0}{1}", ChoString.ToString(_exception), Environment.NewLine); } msg.AppendFormat("AsyncState: {0}{1}", ChoString.ToString(_asyncState), Environment.NewLine); return(msg.ToString()); }
public bool Format(object target, ref string msg) { try { if (msg.IndexOf("{") == -1) { return(true); } msg = ChoString.ExpandProperties(target, msg, '{', '}', '^', new ChoCustomKeyValuePropertyReplacer(target)); return(true); } catch (ChoFatalApplicationException) { throw; } catch (Exception ex) { msg = ChoPropertyManager.FormatException(msg, ex); return(false); } }
public bool Format(object target, ref string msg) { //try //{ if (msg.IndexOf("{") == -1) { return(true); } msg = ChoString.ExpandPropertiesInternal(target, msg, '{', '}', '^', new IChoPropertyReplacer[] { new ChoCustomKeyValuePropertyReplacer(target) }); return(true); //} //catch (ChoFatalApplicationException) //{ // throw; //} //catch (Exception ex) //{ // msg = ChoPropertyManager.FormatException(msg, ex); // return false; //} }
private void LoadXml(XmlDocument doc) { if (doc == null) { return; } XmlNode rootNode = doc.SelectSingleNode("//sharedEnvironment"); if (rootNode != null) { if (rootNode.Attributes["baseAppSharedConfigDirectory"] != null) { BaseAppConfigDirectory = ChoPath.GetFullPath(ChoString.ExpandProperties(rootNode.Attributes["baseAppSharedConfigDirectory"].Value, ChoEnvironmentVariablePropertyReplacer.Instance)); } if (BaseAppConfigDirectory.IsNullOrWhiteSpace()) { BaseAppConfigDirectory = ChoPath.AssemblyBaseDirectory; } if (rootNode.Attributes["defaultEnvironment"] != null) { DefaultEnvironment = rootNode.Attributes["defaultEnvironment"].Value; } XmlNodeList envNodes = rootNode.SelectNodes("environment"); if (envNodes != null) { List <ChoEnvironmentDetails> environmentDetailList = new List <ChoEnvironmentDetails>(); foreach (XmlNode envNode in envNodes) { ChoEnvironmentDetails environmentDetails = new ChoEnvironmentDetails(); if (envNode.Attributes["name"] != null) { environmentDetails.Name = envNode.Attributes["name"].Value; if (!environmentDetails.Name.IsNullOrWhiteSpace()) { if (envNode.Attributes["freeze"] != null) { Boolean.TryParse(envNode.Attributes["freeze"].Value, out environmentDetails.Freeze); } if (envNode.Attributes["appFrxFilePath"] != null) { environmentDetails.AppFrxFilePath = envNode.Attributes["appFrxFilePath"].Value; if (!environmentDetails.AppFrxFilePath.IsNullOrWhiteSpace()) { if (!Path.IsPathRooted(environmentDetails.AppFrxFilePath)) { environmentDetails.AppFrxFilePath = ChoString.ExpandProperties(environmentDetails.AppFrxFilePath, ChoEnvironmentVariablePropertyReplacer.Instance); if (!Path.IsPathRooted(environmentDetails.AppFrxFilePath)) { environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.AppFrxFilePath); } if (ChoPath.IsDirectory(environmentDetails.AppFrxFilePath)) { environmentDetails.AppFrxFilePath = Path.Combine(environmentDetails.AppFrxFilePath, ChoReservedFileName.CoreFrxConfigFileName); } } } else { environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.Name, ChoReservedFileName.CoreFrxConfigFileName); } } else { environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.Name, ChoReservedFileName.CoreFrxConfigFileName); } XmlNodeList machineNodes = envNode.SelectNodes("machine"); if (machineNodes != null) { List <string> machines = new List <string>(); foreach (XmlNode machineNode in machineNodes) { machines.Add(machineNode.InnerText); } environmentDetails.Machines = machines.ToArray(); } environmentDetailList.Add(environmentDetails); } } } EnvironmentDetails = environmentDetailList.ToArray(); foreach (ChoEnvironmentDetails environmentDetail in EnvironmentDetails) { environmentDetail.Parent = this; } } } }
public string GetHelpText() { ChoString x = new ChoString("Test"); return(x.ToFormattedString()); }
private static string ToString(object target, bool collectErrMsgs, ChoMemberFormatterAttribute memberFormaterAttribute1, ChoMemberItemFormatterAttribute memberItemFormaterAttribute1, BindingFlags bindingFlags) { if (target == null) { return(String.Empty); } if (memberFormaterAttribute1 != null && memberFormaterAttribute1.CanFormat()) { if (target.GetType().IsSimple()) { return(memberFormaterAttribute1.FormatObject(target)); } else { ChoStringMsgBuilder msg = new ChoStringMsgBuilder(); //msg.AppendLineIfNoNL(memberFormaterAttribute1.FormatObject(target)); msg.Append(memberFormaterAttribute1.FormatObject(target)); //msg.AppendNewLine(); if (collectErrMsgs) { GetErrorMsgs(target, msg); } return(msg.ToString()); } } else if (target.GetType().IsSimple() || target.GetType().IsMethodImplemented("ToString")) { return(target.ToString()); } else if (target is Delegate) { return(String.Format("{0}.{1}", ((Delegate)target).Target == null ? "[Static]" : ((Delegate)target).Target.GetType().FullName, ((Delegate)target).Method.Name)); } else if (target is IEnumerable) { StringBuilder arrMsg = new StringBuilder(); int count = 0; foreach (object item in (IEnumerable)target) { count++; arrMsg.AppendFormat("{0}{1}", ToString(item, collectErrMsgs, memberItemFormaterAttribute1, null, bindingFlags), Environment.NewLine); } return("[Count: {0}]{1}{2}".FormatString(count, Environment.NewLine, arrMsg.ToString())); } else { bool foundMatchingFormatter = false; string retValue = ChoObject.Format(target, null, out foundMatchingFormatter); if (foundMatchingFormatter) { if (target.GetType().IsSimple()) { return(retValue); } else { ChoStringMsgBuilder msg = new ChoStringMsgBuilder(); msg.AppendFormat(retValue); msg.AppendNewLine(); if (collectErrMsgs) { GetErrorMsgs(target, msg); } return(msg.ToString()); } } else { ChoInterceptableObject interceptableObject = null; try { if (ChoType.IsRealProxyObject(target.GetType())) { interceptableObject = ChoInterceptableObject.Silentable(target as ChoInterceptableObject); } ChoTypeFormatterAttribute objectFormatter = ChoType.GetAttribute(target.GetType(), typeof(ChoTypeFormatterAttribute)) as ChoTypeFormatterAttribute; if (objectFormatter == null) { ChoStringMsgBuilder msg = new ChoStringMsgBuilder(memberFormaterAttribute1 == null ? String.Format("{0} State", target.GetType().FullName) : memberFormaterAttribute1.Name); //MemberInfo[] memberInfos = target.GetType().GetMembers(bindingFlags /*BindingFlags.Public | BindingFlags.Instance /*| BindingFlags.DeclaredOnly*/ /*| BindingFlags.GetField | BindingFlags.GetProperty*/); IEnumerable <MemberInfo> memberInfos = ChoType.GetGetFieldsNProperties(target.GetType(), bindingFlags); if (memberInfos == null || memberInfos.Count() == 0) { msg.AppendFormatLine(ChoStringMsgBuilder.Empty); } else { foreach (MemberInfo memberInfo in memberInfos) { if (!ChoType.IsValidObjectMember(memberInfo)) { continue; } ChoIgnoreMemberFormatterAttribute memberFormatterIgnoreAttribute = ChoType.GetMemberAttribute(memberInfo, typeof(ChoIgnoreMemberFormatterAttribute)) as ChoIgnoreMemberFormatterAttribute; if (memberFormatterIgnoreAttribute != null) { continue; } string memberText = GetNFormatMemberValue(target, memberInfo, collectErrMsgs, null, null, bindingFlags); int count = 0; if (GetCountFromMsg(ref memberText, ref count)) { msg.AppendFormatLine("{0} [Length: {2}]: {1}", memberInfo.Name, memberText, count); } else if (!memberText.ContainsHeader()) { msg.AppendFormatLine("{0}: {1}", memberInfo.Name, memberText); } else { msg.AppendFormatLine("{0}: {1}", memberInfo.Name, memberText); } } } msg.AppendNewLine(); if (collectErrMsgs) { GetErrorMsgs(target, msg); } return(msg.ToString()); } else { ChoStringMsgBuilder msg = new ChoStringMsgBuilder(ChoString.ExpandProperties(target, objectFormatter.Header));; if (objectFormatter.HasFormatSpecified) { msg.AppendFormat(objectFormatter.FormatObject(target)); } else { //MemberInfo[] memberInfos = target.GetType().GetMembers(bindingFlags /*BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance /*| BindingFlags.DeclaredOnly*/ /*| BindingFlags.GetField | BindingFlags.GetProperty*/); IEnumerable <MemberInfo> memberInfos = ChoType.GetGetFieldsNProperties(target.GetType(), bindingFlags); if (memberInfos == null || memberInfos.Count() == 0) { msg.AppendFormatLine(ChoStringMsgBuilder.Empty); } else { bool isPublicMember = true; foreach (MemberInfo memberInfo in memberInfos) { if (!ChoType.IsValidObjectMember(memberInfo)) { continue; } isPublicMember = true; ChoIgnoreMemberFormatterAttribute memberFormatterIgnoreAttribute = ChoType.GetMemberAttribute(memberInfo, typeof(ChoIgnoreMemberFormatterAttribute)) as ChoIgnoreMemberFormatterAttribute; if (memberFormatterIgnoreAttribute != null) { continue; } ChoMemberFormatterAttribute memberFormaterAttribute = ChoType.GetMemberAttribute(memberInfo, typeof(ChoMemberFormatterAttribute)) as ChoMemberFormatterAttribute; ChoMemberItemFormatterAttribute memberItemFormaterAttribute = ChoType.GetMemberAttribute(memberInfo, typeof(ChoMemberItemFormatterAttribute)) as ChoMemberItemFormatterAttribute; if (memberInfo is PropertyInfo) { MethodInfo getMethod = ((PropertyInfo)memberInfo).GetGetMethod(true); isPublicMember = getMethod != null && getMethod.IsPublic; } else if (memberInfo is FieldInfo) { isPublicMember = ((FieldInfo)memberInfo).IsPublic; } else { continue; } if (isPublicMember || (!isPublicMember && memberFormaterAttribute != null)) { object memberValue = ChoType.GetMemberValue(target, memberInfo); if (memberValue == target) { return(null); } string memberText = GetNFormatMemberValue(target, memberInfo, collectErrMsgs, memberFormaterAttribute, memberItemFormaterAttribute, bindingFlags); string memberName = memberFormaterAttribute == null || memberFormaterAttribute.Name.IsNullOrEmpty() ? memberInfo.Name : ChoPropertyManager.ExpandProperties(target, memberFormaterAttribute.Name); if (memberFormaterAttribute == null || !memberFormaterAttribute.CanFormat()) { int count = 0; if (GetCountFromMsg(ref memberText, ref count)) { msg.AppendFormatLine("{0} [Length: {2}]: {1}", memberName, memberText, count); } else if (memberText.ContainsHeader()) { msg.AppendFormatLine("{0}: {1}", memberName, memberText); } else { msg.AppendFormatLine("{0}: {1}", memberName, memberText); } } else if (memberFormaterAttribute.Name == ChoNull.NullString) { msg.Append(memberFormaterAttribute.PostFormat(memberName, memberText)); } else { msg.AppendFormat(memberFormaterAttribute.PostFormat(memberName, memberText)); } } } } } //msg.AppendNewLine(); if (collectErrMsgs) { GetErrorMsgs(target, msg); } return(msg.ToString()); } } finally { if (interceptableObject != null) { interceptableObject.Dispose(); } } } } }
internal void PostInitialize() { if (ApplicationName.IsNullOrEmpty()) { ChoEnvironment.Exit(101, "Missing ApplicationName."); } if (EventLogSourceName.IsNullOrWhiteSpace()) { EventLogSourceName = System.IO.Path.GetFileName(ChoAssembly.GetEntryAssemblyLocation()); } if (LogSettings.LogTimeStampFormat.IsNullOrWhiteSpace()) { LogSettings.LogTimeStampFormat = "yyyy-MM-dd hh:mm:ss.fffffff"; } if (LogSettings.LogFileName.IsNullOrWhiteSpace()) { LogSettings.LogFileName = ChoPath.ChangeExtension(ApplicationName, ChoReservedFileExt.Log); } LogSettings.LogFileName = ChoPath.CleanFileName(LogSettings.LogFileName); if (Path.IsPathRooted(LogSettings.LogFileName)) { LogSettings.LogFileName = Path.GetFileName(LogSettings.LogFileName); } try { DateTime.Now.ToString(LogSettings.LogTimeStampFormat); } catch (Exception ex) { ChoApplication.Trace(ChoTraceSwitch.Switch.TraceError, "Invalid LogTimeStampFormat '{0}' configured.".FormatString(LogSettings.LogTimeStampFormat)); ChoApplication.Trace(ChoTraceSwitch.Switch.TraceError, ex.ToString()); LogSettings.LogTimeStampFormat = "yyyy-MM-dd hh:mm:ss.fffffff"; } try { string sharedEnvConfigDir = null; if (!AppFrxConfigFilePath.IsNullOrEmpty()) { sharedEnvConfigDir = Path.GetDirectoryName(ChoPath.GetFullPath(AppFrxConfigFilePath)); } if (AppConfigFilePath.IsNullOrWhiteSpace()) { if (sharedEnvConfigDir.IsNullOrWhiteSpace()) { ApplicationConfigFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, ChoPath.AddExtension(ChoPath.CleanFileName(ApplicationName), ChoReservedFileExt.Xml))); } else { ApplicationConfigFilePath = Path.Combine(sharedEnvConfigDir, ChoPath.AddExtension(ChoPath.CleanFileName(ApplicationName), ChoReservedFileExt.Xml)); } } else { if (!Path.IsPathRooted(AppConfigFilePath)) { if (sharedEnvConfigDir.IsNullOrWhiteSpace()) { ApplicationConfigFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, AppConfigFilePath)); } else { ApplicationConfigFilePath = Path.Combine(sharedEnvConfigDir, AppConfigFilePath); } } else { ApplicationConfigFilePath = AppConfigFilePath; } } ApplicationConfigDirectory = Path.GetDirectoryName(ChoPath.GetFullPath(ApplicationConfigFilePath)); AppFrxConfigFilePath = Path.Combine(ApplicationConfigDirectory, ChoReservedFileName.CoreFrxConfigFileName); } catch (System.Security.SecurityException ex) { // This security exception will occur if the caller does not have // some undefined set of SecurityPermission flags. ChoApplication.Trace(ChoTraceSwitch.Switch.TraceError, ex.ToString()); } if (!LogSettings.LogFolder.IsNullOrWhiteSpace()) { ApplicationLogDirectory = ChoString.ExpandProperties(LogSettings.LogFolder, ChoEnvironmentVariablePropertyReplacer.Instance); } if (ApplicationLogDirectory.IsNullOrWhiteSpace()) { if (ChoApplication.AppEnvironment.IsNullOrWhiteSpace()) { ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ChoReservedDirectoryName.Logs); } else { ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ChoReservedDirectoryName.Logs, ChoApplication.AppEnvironment); } } if (!Path.IsPathRooted(ApplicationLogDirectory)) { ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ApplicationLogDirectory); } if (ChoApplication.ApplicationMode == ChoApplicationMode.Service) { TrayApplicationBehaviourSettings.TurnOn = false; } }
public void Initialize() { if (ApplicationBehaviourSettings == null) { ApplicationBehaviourSettings = new ChoApplicationBehaviourSettings(); } if (TrayApplicationBehaviourSettings == null) { TrayApplicationBehaviourSettings = new ChoTrayApplicationBehaviourSettings(); } if (LogSettings == null) { LogSettings = new ChoLogSettings(); } if (ApplicationName.IsNullOrWhiteSpace()) { try { ApplicationName = System.IO.Path.GetFileName(ChoAssembly.GetEntryAssemblyLocation()); } catch (System.Security.SecurityException ex) { ChoApplication.Trace(ChoTrace.ChoSwitch.TraceError, ex.ToString()); } } if (ApplicationName.IsNullOrEmpty()) { ChoApplication.OnFatalApplicationException(101, "Missing ApplicationName."); } ApplicationNameWithoutExtension = Path.GetFileNameWithoutExtension(ApplicationName); if (EventLogSourceName.IsNullOrWhiteSpace()) { EventLogSourceName = System.IO.Path.GetFileName(ChoAssembly.GetEntryAssemblyLocation()); } if (LogSettings.LogTimeStampFormat.IsNullOrWhiteSpace()) { LogSettings.LogTimeStampFormat = "yyyy-MM-dd hh:mm:ss.fffffff"; } if (LogSettings.LogFileName.IsNullOrWhiteSpace()) { LogSettings.LogFileName = ChoPath.ChangeExtension(ApplicationName, ChoReservedFileExt.Log); } LogSettings.LogFileName = ChoPath.CleanFileName(LogSettings.LogFileName); if (Path.IsPathRooted(LogSettings.LogFileName)) { LogSettings.LogFileName = Path.GetFileName(LogSettings.LogFileName); } try { DateTime.Now.ToString(LogSettings.LogTimeStampFormat); } catch (Exception ex) { ChoApplication.Trace(ChoTrace.ChoSwitch.TraceError, "Invalid LogTimeStampFormat '{0}' configured.".FormatString(LogSettings.LogTimeStampFormat)); ChoApplication.Trace(ChoTrace.ChoSwitch.TraceError, ex.ToString()); LogSettings.LogTimeStampFormat = "yyyy-MM-dd hh:mm:ss.fffffff"; } try { string sharedEnvConfigDir = null; if (!AppFrxConfigFilePath.IsNullOrEmpty()) { sharedEnvConfigDir = Path.GetDirectoryName(AppFrxConfigFilePath); } if (AppConfigFilePath.IsNullOrWhiteSpace()) { if (sharedEnvConfigDir.IsNullOrWhiteSpace()) { ApplicationConfigFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, ChoPath.AddExtension(ChoPath.CleanFileName(ApplicationName), ChoReservedFileExt.Xml))); } else { ApplicationConfigFilePath = Path.Combine(sharedEnvConfigDir, ChoPath.AddExtension(ChoPath.CleanFileName(ApplicationName), ChoReservedFileExt.Xml)); } } else { if (!Path.IsPathRooted(AppConfigFilePath)) { if (sharedEnvConfigDir.IsNullOrWhiteSpace()) { ApplicationConfigFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, AppConfigFilePath)); } else { ApplicationConfigFilePath = Path.Combine(sharedEnvConfigDir, AppConfigFilePath); } } else { ApplicationConfigFilePath = AppFrxConfigFilePath; } } ApplicationConfigDirectory = Path.GetDirectoryName(ApplicationConfigFilePath); } catch (System.Security.SecurityException ex) { // This security exception will occur if the caller does not have // some undefined set of SecurityPermission flags. ChoApplication.Trace(ChoTrace.ChoSwitch.TraceError, ex.ToString()); } #region Get HostName // Get the DNS host name of the current machine try { // Lookup the host name if (HostName.IsNullOrWhiteSpace()) { HostName = System.Net.Dns.GetHostName(); } } catch (System.Net.Sockets.SocketException) { } catch (System.Security.SecurityException) { // We may get a security exception looking up the hostname // You must have Unrestricted DnsPermission to access resource } // Get the NETBIOS machine name of the current machine if (HostName.IsNullOrWhiteSpace()) { try { HostName = Environment.MachineName; } catch (InvalidOperationException) { } catch (System.Security.SecurityException) { // We may get a security exception looking up the machine name // You must have Unrestricted EnvironmentPermission to access resource } } #endregion Get HostName #region Get IpAddresses try { IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); for (int i = 0; i < localIPs.Length; i++) { IPAddresses.Add(localIPs[i].ToString()); } } catch (System.Net.Sockets.SocketException) { } catch (System.Security.SecurityException) { // We may get a security exception looking up the hostname // You must have Unrestricted DnsPermission to access resource } #endregion Get IpAddresses if (LogSettings.TraceLevel < 0) { LogSettings.TraceLevel = 4; } if (!LogSettings.LogFolder.IsNullOrWhiteSpace()) { ApplicationLogDirectory = ChoString.ExpandProperties(LogSettings.LogFolder, ChoEnvironmentVariablePropertyReplacer.Instance); } //else // ApplicationLogDirectory = Path.Combine(Path.GetDirectoryName(ChoGlobalApplicationSettings.SharedEnvConfigPath), ChoReservedDirectoryName.Logs); if (ApplicationLogDirectory.IsNullOrWhiteSpace()) { if (ChoApplication.AppEnvironment.IsNullOrWhiteSpace()) { ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ChoReservedDirectoryName.Logs); } else { ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ChoReservedDirectoryName.Logs, ChoApplication.AppEnvironment); } } if (!Path.IsPathRooted(ApplicationLogDirectory)) { ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ApplicationLogDirectory); } if (ChoApplication.ApplicationMode == ChoApplicationMode.Service) { TrayApplicationBehaviourSettings.TurnOn = false; } }
public static object Evaluate(object target, string msg) { //return ChoString.Evaluate(target, msg); return(ChoString.ExpandProperties(target, msg)); }