public void Initialize(bool beforeFieldInit) { if (_initialized) { return; } _initialized = true; ChoProfile.WriteLine("Missing Name"); if (String.IsNullOrEmpty(Name)) { ChoProfile.WriteLine("Missing Name"); return; } using (ChoBufferProfile profile = ChoBufferProfile.DelayedAutoStart(new ChoBufferProfile(true, Name, "Loading property handler..."))) { try { _propertyReplaceHandler = new ChoCallbackObj(Type, Method).CreateDelegate <ChoPropertyReplaceHandler>() as ChoPropertyReplaceHandler; } catch (Exception ex) { profile.AppendLine(String.Format("{0}: {1}", Name, ex.ToString())); } } }
/// <summary> /// Removes a watcher for the configuration source. /// </summary> /// <param name="configSource"> /// The source to remove the watcher. /// </param> public static void RemoveWatcherForConfigSource(IChoConfigurationChangeWatcher configSourceWatcher) { if (_configSourceWatcherMapping.Contains(configSourceWatcher)) { _configSourceWatcherMapping.Remove(configSourceWatcher); configSourceWatcher.Dispose(); ChoProfile.WriteLine(String.Format("Removing Watcher: [{0}]", configSourceWatcher.EventData.ToString())); } }
/// <summary> /// Sets a watcher for a configuration source. /// </summary> /// <param name="configSource"> /// The configuration source to watch. /// </param> public static void SetWatcherForConfigSource(IChoConfigurationChangeWatcher configSourceWatcher) { if (!IsWatchingConfigSource(configSourceWatcher)) { ////configSourceWatcher.ConfigurationChanged += OnConfigurationChanged; _configSourceWatcherMapping.Add(configSourceWatcher); ChoProfile.WriteLine(String.Format("Setting Watcher: [{0}]", configSourceWatcher.EventData.ToString())); } }
public void Initialize(bool beforeFieldInit) { if (ConfigNameValues == null || ConfigNameValues.Length == 0) { return; } if (String.IsNullOrEmpty(Name)) { ChoProfile.WriteLine("Missing Name"); return; } using (ChoBufferProfile profile = ChoBufferProfile.DelayedAutoStart(new ChoBufferProfile(true, Name, "Loading property dictionary..."))) { foreach (ChoPropertyNameValue configNameValue in ConfigNameValues) { if (configNameValue == null) { continue; } if (String.IsNullOrEmpty(configNameValue.Name)) { continue; } try { _properties.Add(configNameValue.Name, ChoString.ToObject(configNameValue.Value)); } catch (Exception ex) { profile.AppendLine(String.Format("{0}: {1}", configNameValue.Name, ex.ToString())); } } } ConfigNameValues = null; }
public void Initialize() { if (_propertyReplacers == null) { _propertyReplacers = new ChoDictionary <string, IChoPropertyReplacer>(DefaultPropertyReplacers); } if (_propertyReplacers.Count == DefaultPropertyReplacers.Count) { if (PropertyDictionaryReplacers != null) { foreach (ChoObjConfigurable objConfigurable in PropertyDictionaryReplacers) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (!(objConfigurable is IChoKeyValuePropertyReplacer)) { continue; } if (_propertyReplacers.ContainsKey(objConfigurable.Name)) { ChoProfile.WriteLine(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _propertyReplacers.Add(objConfigurable.Name, objConfigurable as IChoPropertyReplacer); } } if (CustomPropertyReplacers != null) { foreach (ChoObjConfigurable objConfigurable in CustomPropertyReplacers) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (!(objConfigurable is IChoCustomPropertyReplacer)) { continue; } if (_propertyReplacers.ContainsKey(objConfigurable.Name)) { ChoProfile.WriteLine(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _propertyReplacers.Add(objConfigurable.Name, objConfigurable as IChoPropertyReplacer); } } } }
private void WaitFor(Delegate func, object[] parameters, int timeout, int maxNoOfRetry, int sleepBetweenRetry, ChoExecutionServiceData data) { ChoGuard.ArgumentNotNull(func, "Function"); ChoAbortableAsyncResult asyncResult = data.Result as ChoAbortableAsyncResult; ChoWaitFor.CheckParams(timeout, maxNoOfRetry, sleepBetweenRetry); int noOfRetry = 0; object retValue = null; ChoList <Exception> aggExceptions = new ChoList <Exception>(); Func <object> wrappedFunc = delegate { if (asyncResult.AbortRequested) { asyncResult.SetAsAborted(true); } asyncResult.ThreadToKill = Thread.CurrentThread; return(func.DynamicInvoke(parameters)); }; while (true) { if (asyncResult.AbortRequested) { asyncResult.SetAsAborted(true); } try { if (timeout == Timeout.Infinite) { retValue = wrappedFunc.Invoke(); } else { IAsyncResult result = wrappedFunc.BeginInvoke(null, null); Thread.Sleep(1000); using (result.AsyncWaitHandle) { if (!result.AsyncWaitHandle.WaitOne(timeout, true)) { if (asyncResult.ThreadToKill != null && asyncResult.ThreadToKill.IsAlive) { asyncResult.ThreadToKill.AbortThread(); } ChoWaitFor.RaiseTimeoutException(func, timeout); } else { try { retValue = wrappedFunc.EndInvoke(result); } catch (ThreadAbortException) { //Thread.ResetAbort(); asyncResult.SetAsAborted(true); return; } } } } asyncResult.SetAsSuccess(retValue, true); return; } catch (ThreadAbortException) { Thread.ResetAbort(); ChoProfile.WriteLine("Thread Aborted."); ChoProfile.WriteLine(data.ToString()); asyncResult.SetAsAborted(true); break; } catch (ChoFatalApplicationException) { throw; } catch (Exception ex) { if (maxNoOfRetry != 0) { if (noOfRetry == maxNoOfRetry) { asyncResult.SetAsFailed(new ChoAggregateException(String.Format("The method failed to execute after {0} retries.", maxNoOfRetry), aggExceptions), true); return; } noOfRetry++; aggExceptions.Add(ex); Thread.Sleep((int)sleepBetweenRetry); } else { ChoProfile.WriteLine(ex.ToString()); ChoProfile.WriteLine(data.ToString()); asyncResult.SetAsFailed(ex.InnerException != null ? ex.InnerException : ex, true); return; } } } //if (asyncResult.AbortRequested) // asyncResult.SetAsAborted(true); //Action wrappedFunc1 = delegate //{ // asyncResult.ThreadToKill = Thread.CurrentThread; // while (true) // { // if (asyncResult.AbortRequested) // { // asyncResult.SetAsAborted(true); // break; // } // try // { // if (timeout == Timeout.Infinite) // retValue = func.DynamicInvoke(parameters); // else // { // IAsyncResult result = wrappedFunc.BeginInvoke(null, null); // Thread.Sleep(1000); // using (result.AsyncWaitHandle) // { // if (!result.AsyncWaitHandle.WaitOne(timeout, true)) // { // try // { // if (asyncResult.ThreadToKill != null && asyncResult.ThreadToKill.IsAlive) // asyncResult.ThreadToKill.Abort(); // } // catch (ThreadAbortException) // { // Thread.ResetAbort(); // } // ChoWaitFor.RaiseTimeoutException(func, timeout); // } // else // retValue = wrappedFunc.EndInvoke(result); // } // } // asyncResult.SetAsSuccess(retValue, true); // return; // } // catch (ThreadAbortException) // { // Thread.ResetAbort(); // ChoProfile.WriteLine("Thread Aborted."); // ChoProfile.WriteLine(data.ToString()); // asyncResult.SetAsAborted(true); // break; // } // catch (Exception ex) // { // if (maxNoOfRetry != 0) // { // if (noOfRetry == maxNoOfRetry) // { // asyncResult.SetAsFailed(new ChoAggregateException(String.Format("The method failed to execute after {0} retries.", maxNoOfRetry), aggExceptions), true); // return; // } // noOfRetry++; // aggExceptions.Add(ex); // Thread.Sleep((int)sleepBetweenRetry); // } // else // { // ChoProfile.WriteLine(ex.ToString()); // ChoProfile.WriteLine(data.ToString()); // asyncResult.SetAsFailed(ex.InnerException != null ? ex.InnerException : ex, true); // return; // } // } // } //}; //IAsyncResult r = wrappedFunc1.BeginInvoke(null, null); //wrappedFunc1.EndInvoke(r); }
public bool Initialize(bool beforeFieldInit, object state) { if (_propertyReplacers == null) { //ChoStreamProfile.Clean(ChoReservedDirectoryName.Settings, ChoType.GetLogFileName(typeof(ChoPropertyManagerSettings), ChoReservedFileExt.Err)); _propertyReplacers = new ChoDictionary <string, IChoPropertyReplacer>(DefaultPropertyReplacers); } if (!beforeFieldInit) { if (_propertyReplacers.Count == DefaultPropertyReplacers.Count) { if (PropertyDictionaryReplacers != null) { foreach (ChoObjConfigurable objConfigurable in PropertyDictionaryReplacers) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (!(objConfigurable is IChoKeyValuePropertyReplacer)) { continue; } if (_propertyReplacers.ContainsKey(objConfigurable.Name)) { ChoProfile.WriteLine(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _propertyReplacers.Add(objConfigurable.Name, objConfigurable as IChoPropertyReplacer); } } if (CustomPropertyReplacers != null) { foreach (ChoObjConfigurable objConfigurable in CustomPropertyReplacers) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (!(objConfigurable is IChoCustomPropertyReplacer)) { continue; } if (_propertyReplacers.ContainsKey(objConfigurable.Name)) { ChoProfile.WriteLine(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _propertyReplacers.Add(objConfigurable.Name, objConfigurable as IChoPropertyReplacer); } } } } return(false); }
internal static string FormatException(string expr, Exception ex) { ChoProfile.WriteLine("Expression: {1}{0}Error: {2}", Environment.NewLine, expr, ex.ToString()); return(String.Format("{2} Error while evaluating `{0}' expression. {1}]", expr, ex.Message, ChoString.ExceptionStringToken)); }