public static string GetName(this Type objType, ChoTypeNameSpecifier typeName) { ChoGuard.ArgumentNotNull(objType, "Type"); switch (typeName) { case ChoTypeNameSpecifier.FullName: return(objType.FullName); case ChoTypeNameSpecifier.AssemblyQualifiedName: return(objType.AssemblyQualifiedName); case ChoTypeNameSpecifier.SimpleQualifiedName: return(objType.SimpleQualifiedName()); default: return(objType.Name); } }
public void SetConfigurationChangedEventHandler(object key, ChoConfigurationChangedEventHandler configurationChanged) { ChoGuard.ArgumentNotNull(key, "key"); ChoGuard.ArgumentNotNull(configurationChanged, "configurationChanged"); lock (_padLock) { List <IChoConfigurationChangeWatcher> configurationChangeWatchers = _configurationChangeWatchers; if (configurationChangeWatchers == null || configurationChangeWatchers.Count == 0) { return; } foreach (IChoConfigurationChangeWatcher configurationChangeWatcher in configurationChangeWatchers) { configurationChangeWatcher.SetConfigurationChangedEventHandler(key, configurationChanged); } } }
public ChoDictionary <string, ChoLogListener[]> Find(ICollection <string> categories) { ChoGuard.ArgumentNotNull(categories, "Categories"); ChoDictionary <string, ChoLogListener[]> logListeners = new ChoDictionary <string, ChoLogListener[]>(); foreach (string category in categories) { foreach (string key in _logSources.Keys) { if (key == category && _logSources.ContainsKey(key)) { logListeners.Add(key, _logSources[key]); } } } return(logListeners); }
public ChoDynamicBindingProxy(T instance) { ChoGuard.ArgumentNotNull(instance, "Instance"); _instance = instance; _type = instance.GetType(); if (_instance is INotifyPropertyChanged) { ((INotifyPropertyChanged)_instance).PropertyChanged += ((sender, e) => { PropertyChangedEventHandler propertyChanged = PropertyChanged; if (propertyChanged != null) { propertyChanged(this, e); } }); } }
public static void PerformAction(IChoDoubleCheckLockObject <T> target, T key, params object[] states) { ChoGuard.ArgumentNotNull(target, "target"); if (target.CanActionBePerformed(key)) { return; } lock (target.DoublCheckLockObject) { if (target.CanActionBePerformed(key)) { return; } target.DoAction(key, states); } }
private static Assembly GetWebApplicationAssembly(HttpContext context) { ChoGuard.ArgumentNotNull(context, "context"); IHttpHandler handler = context.CurrentHandler; if (handler == null) { return(null); } Type type = handler.GetType(); while (type != null && type != typeof(object) && type.Namespace == AspNetNamespace) { type = type.BaseType; } return(type.Assembly); }
public virtual object Load(ChoBaseConfigurationElement configElement, XmlNode node) { ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); ConfigElement = configElement; //ConfigElement.LastLoadedTimeStamp = DateTime.Now; ConfigObjectType = ConfigElement.ConfigbObjectType; ConfigSectionName = configElement.ConfigSectionName; RootConfigNode = ConfigNode = node; //ChoMetaDataManager.SetWatcher(this); if (ConfigObjectType == null) { throw new ChoConfigurationException("Missing configuration object type."); } return(null); }
public override ChoBaseConfigurationElement GetMe(Type type) { ChoGuard.ArgumentNotNull(type, "Type"); if (_xmlConfigurationElement == null) { lock (_padLock) { if (_xmlConfigurationElement == null) { _xmlConfigurationElement = new ChoXmlConfigurationElement(ConfigElementPath, BindingMode, TraceOutputDirectory, TraceOutputFileName.IsNullOrEmpty() ? ChoPath.AddExtension(type.FullName, ChoReservedFileExt.Log) : TraceOutputFileName); _xmlConfigurationElement.DefaultConfigSectionHandlerType = ConfigSectionHandlerType; _xmlConfigurationElement.LogCondition = LogCondition; _xmlConfigurationElement.LogTimeStampFormat = LogTimeStampFormat; } } } return(_xmlConfigurationElement); }
public ChoNACHAWriter(Stream inStream, ChoNACHAConfiguration configuration = null) { ChoGuard.ArgumentNotNull(inStream, "Stream"); Configuration = configuration; if (Configuration == null) { Configuration = new ChoNACHAConfiguration(); } if (inStream is MemoryStream) { _textWriter = new StreamWriter(inStream); } else { _textWriter = new StreamWriter(inStream, Configuration.Encoding, Configuration.BufferSize); } Init(); }
public override IChoAsyncResult EnqueueMethod(Delegate func, object[] parameters, ChoAsyncCallback callback, object state, int timeout, int maxNoOfRetry, int sleepBetweenRetry) { ChoGuard.ArgumentNotNull(func, "Function"); CheckTimeoutArg(timeout); if (ChoGuard.IsDisposed(this)) { return(null); } timeout = timeout > _timeout ? _timeout : timeout; maxNoOfRetry = maxNoOfRetry > _maxNoOfRetry ? _maxNoOfRetry : maxNoOfRetry; sleepBetweenRetry = sleepBetweenRetry > _sleepBetweenRetry ? _sleepBetweenRetry : sleepBetweenRetry; ChoExecutionServiceData data = new ChoExecutionServiceData(func, parameters, timeout, new ChoAsyncResult(callback, state), maxNoOfRetry, sleepBetweenRetry); _queuedMsgService.Enqueue(ChoStandardQueuedMsgObject <ChoExecutionServiceData> .New(data)); return(data.Result); }
public static string GetConfigSectionName(Type type) { ChoGuard.ArgumentNotNull(type, "Type"); string sectionName = type.Name; XmlRootAttribute attribute = ChoType.GetAttribute(type, typeof(XmlRootAttribute)) as XmlRootAttribute; if (attribute != null && !String.IsNullOrEmpty(attribute.ElementName)) { sectionName = attribute.ElementName; } ChoConfigurationSectionAttribute configAttribute = ChoType.GetAttribute(type, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute; if (configAttribute != null && !String.IsNullOrEmpty(configAttribute.ConfigElementPath)) { sectionName = configAttribute.ConfigElementPath; } return(sectionName); }
public static void Register(string name, Action timerServiceCallback, long period) { ChoGuard.ArgumentNotNullOrEmpty(name, "Name"); ChoGuard.ArgumentNotNull(timerServiceCallback, "TimerServiceCallback"); if (period != Timeout.Infinite && period <= 0) { throw new ChoTimerServiceException("Period should be > 0"); } lock (_padLock) { if (_callbacks.ContainsKey(name)) { //TODO: log the duplicate entries return; } _callbacks.Add(name, new ChoGlobalTimerServiceData(name, timerServiceCallback, period)); } }
public static void Load <T>(string logFileName, string[] typeNames, ChoDictionary <string, T> objDictionary, ChoObjConfigurable[] objTypeConfigurables, ChoTypeNameSpecifier defaultObjectKey) where T : class { ChoGuard.ArgumentNotNull(logFileName, "LogFileName"); ChoGuard.ArgumentNotNull(objDictionary, "ObjectDictionary"); if (typeNames == null || typeNames.Length == 0) { return; } foreach (string typeName in typeNames) { if (String.IsNullOrEmpty(typeName)) { continue; } Add <T>(logFileName, objDictionary, defaultObjectKey, typeName); } Adjust <T>(logFileName, objDictionary, objTypeConfigurables, defaultObjectKey); }
//public bool Remove(ChoIniNode iniNode) //{ // if (iniNode == null) // return false; // if (_iniNodes.Contains(iniNode)) // { // _iniNodes.Remove(iniNode); // return true; // } // else // return false; //} public bool Remove(ChoIniNode iniNode) { ChoGuard.ArgumentNotNull(iniNode, "Node"); int index = _iniNodes.FindIndex((node) => node == iniNode); if (index < 0) { throw new ChoIniDocumentException(String.Format("Can't find node. [Node: {0}]", iniNode, iniNode.ToString())); } if (!OwnerDocument.OnNodeRemoving(this, iniNode)) { _iniNodes.RemoveAt(index); OwnerDocument.Dirty = true; OwnerDocument.OnNodeRemoved(this, iniNode); return(true); } return(false); }
public static string SetNamespaceAwareOuterXml(XmlNode xmlNode, string outerXml, string namespaceURI) { ChoGuard.ArgumentNotNull(xmlNode, "XmlNode"); XmlDocument doc = xmlNode.OwnerDocument; if (doc == null) { throw new NullReferenceException("Missing Owner document."); } //Remove all attributes and elements xmlNode.RemoveAll(); XmlDocument newDoc = new XmlDocument(); using (XmlTextReader reader = new XmlTextReader(new StringReader(outerXml))) newDoc.Load(reader); foreach (XmlAttribute attribute in newDoc.DocumentElement.Attributes) { if (attribute.Name.StartsWith("xmlns:")) { continue; } if (namespaceURI.IsNullOrWhiteSpace()) { xmlNode.Attributes.Append(doc.CreateAttribute(attribute.Name)).Value = attribute.Value; } else { xmlNode.Attributes.Append(doc.CreateAttribute(attribute.Name, ChoXmlDocument.CinchooNSURI)).Value = attribute.Value; } } xmlNode.InnerXml = newDoc.DocumentElement.InnerXml; return(doc.OuterXml.IndentXml()); }
public static void Save(XmlNode xmlNode, string xmlFilePath, XmlWriterSettings xws) { ChoGuard.ArgumentNotNull(xmlNode, "XmlDocument"); ChoGuard.ArgumentNotNullOrEmpty(xmlFilePath, "XmlFilePath"); if (xmlNode is XmlDocumentFragment) { xws.OmitXmlDeclaration = true; xws.ConformanceLevel = ConformanceLevel.Auto; xws.Indent = false; } try { //using (FileStream fs = File.Create(xmlFilePath)) //using (FileStream fs = new FileStream(xmlFilePath, FileMode.Open, FileAccess.Write, FileShare.ReadWrite)) //{ using (StreamWriter sw = new StreamWriter(xmlFilePath, false)) { // Create a XMLTextWriter that will send its output to a memory stream (file) using (XmlWriter xtw = XmlTextWriter.Create(sw, xws)) { // Set the formatting property of the XML Text Writer to indented // the text writer is where the indenting will be performed //if (indentOutput) // xtw.Formatting = Formatting.Indented; // write dom xml to the xmltextwriter xmlNode.WriteContentTo(xtw); // Flush the contents of the text writer // to the memory stream, which is simply a memory file xtw.Flush(); } } } catch (Exception ex) { ChoTrace.Error(ex); } }
public static void MoveToPrevious <T>(this IList <T> list, T item) { ChoGuard.ArgumentNotNull(list, "List"); ChoGuard.ArgumentNotNull(item, "Item"); int index = list.IndexOf(item); if (index == -1) { return; } if (index == 0) { return; } else { list.RemoveAt(index); list.Insert(index - 1, item); } }
public static string SetNamespaceAwareOuterXml(XmlNode xmlNode, string xpath, string outerXml, string namespaceURI, XmlNamespaceManager nsmgr = null) { ChoGuard.ArgumentNotNull(xmlNode, "XmlNode"); //Select the cd node with the matching title XmlNode configNode = null; if (nsmgr == null) { configNode = xmlNode.SelectSingleNode(xpath); } else { configNode = xmlNode.SelectSingleNode(xpath, nsmgr); } if (configNode == null) { throw new NullReferenceException(String.Format("Can't find {0} xpath in the XmlNode.", xpath)); } return(SetNamespaceAwareOuterXml(configNode, outerXml, namespaceURI)); }
/// <summary> /// Event raised when the underlying persistence mechanism for configuration notices that /// the persistent representation of configuration information has changed. /// </summary> //public event ChoConfigurationChangedEventHandler ConfigurationChanged; public void SetConfigurationChangedEventHandler(object key, ChoConfigurationChangedEventHandler configurationChanged) { ChoGuard.ArgumentNotNull(key, "key"); ChoGuard.ArgumentNotNull(configurationChanged, "configurationChanged"); OrderedDictionary eventHandlerList = _eventHandlerList; if (eventHandlerList != null) { lock (_eventHandlerListLock) { if (eventHandlerList.Contains(key)) { eventHandlerList[key] = configurationChanged; } else { eventHandlerList.Add(key, configurationChanged); } } } }
public ChoSteppedListEnumerator(IList <T> list, int startIndex, int count, int step, Predicate <T> match) { ChoGuard.ArgumentNotNull(list, "list"); ChoGuard.ArgumentNotNull(match, "match"); if (step <= 0) { throw new ArgumentException("step must be positive."); } _baseList = list; _match = match; _listCount = _baseList.Count; _startIndex = startIndex == ChoListEnumeratorConst.DefaultStartIndex ? 0 : startIndex; _count = count == ChoListEnumeratorConst.DefaultCount ? _listCount : _count; _step = step; list.CheckIndex <T>(_startIndex); list.CheckRange <T>(_startIndex, _count); Reset(); }
public static bool Install(Type[] types, bool forceCreate) { ChoGuard.ArgumentNotNull(types, "types"); ChoPerformanceCounterInstallerBuilder builder = new ChoPerformanceCounterInstallerBuilder(types); PerformanceCounterInstaller installer = builder.CreateInstaller(); if (PerformanceCounterCategory.Exists(installer.CategoryName)) { if (forceCreate) { PerformanceCounterCategory.Delete(installer.CategoryName); } else { return(false); } } PerformanceCounterCategory.Create(installer.CategoryName, installer.CategoryHelp, installer.CategoryType, installer.Counters); return(true); }
public static NameValueCollection GetNameValuesFromAttributes(NameValueCollection prev, XmlNode region) { ChoGuard.ArgumentNotNull(region, "region"); NameValueCollection coll = new NameValueCollection(); if (prev != null) { coll.Add(prev); } ChoCollectionWrapper result = new ChoCollectionWrapper(coll); result = ReadAttributes(result, region); if (result == null) { return(null); } return(result.UnWrap() as NameValueCollection); }
public static void Dispose(IDisposable target, bool finalize) { ChoGuard.ArgumentNotNull(target, "Target"); if (target is IChoDisposable) { IChoDisposable disposableObj = target as IChoDisposable; if (disposableObj is IChoSyncDisposable && ((IChoSyncDisposable)disposableObj).DisposableLockObj != null) { lock (((IChoSyncDisposable)disposableObj).DisposableLockObj) { Dispose(finalize, disposableObj); } } else { Dispose(finalize, disposableObj); } } else { target.Dispose(); } }
internal static Type GetSourceType(ChoBaseConfigurationElement configElement, string propName, ChoPropertyInfoAttribute memberInfoAttribute) { ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); ChoGuard.ArgumentNotNull(propName, "PropertyName"); ChoPropertyInfos propertyInfo = GetPropertyInfos(configElement); if (propertyInfo != null) { ChoPropertyInfo propInfo = propertyInfo[propName]; if (propInfo != null && propInfo.SourceType != null) { return(propInfo.SourceType); } } if (memberInfoAttribute != null && memberInfoAttribute.SourceType != null) { return(memberInfoAttribute.SourceType); } return(null); }
public override void Persist(object data, ChoDictionaryService <string, object> stateInfo) { ChoGuard.ArgumentNotNull(data, "Config Data Object"); string configXml = ToXml(data); if (configXml.IsNullOrEmpty()) { return; } lock (_padLock) { ConfigurationChangeWatcher.StopWatching(); //Save the data if (_odbcSectionInfo != null) { _odbcSectionInfo.SaveData(configXml); } ConfigurationChangeWatcher.StartWatching(); } }
internal static bool IsExpressionProperty(ChoBaseConfigurationElement configElement, string propName, ChoPropertyInfoAttribute memberInfoAttribute) { ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); ChoGuard.ArgumentNotNull(propName, "PropertyName"); ChoPropertyInfos propertyInfo = GetPropertyInfos(configElement); if (propertyInfo != null) { ChoPropertyInfoMetaData propInfo = propertyInfo[propName]; if (propInfo != null) { return(propInfo.IsExpression); } } if (memberInfoAttribute != null) { return(memberInfoAttribute.IsExpression); } return(false); }
/// <summary> /// Initialize a new instance of the <see cref="ChoCustomConfigurationSectionAttribute"/> class with the configuration element name. /// </summary> /// <param name="configElementPath">The <see cref="string"/>configuration element path.</param> public ChoCustomConfigurationSectionAttribute(Type configurationSectionHandlerType, string parameters) { ChoGuard.ArgumentNotNull(configurationSectionHandlerType, "configurationSectionHandlerType"); _configurationSectionHandlerType = configurationSectionHandlerType; _parameters = parameters; }
public static void Initialize(object target, bool beforeFieldInit, object state) { ChoGuard.ArgumentNotNull(target, "Target"); DoInitialize(target, beforeFieldInit, state); }
public static void Initialize(object target) { ChoGuard.ArgumentNotNull(target, "Target"); Initialize(target, false, null); }
bool ICollection <KeyValuePair <TKey1, TValue1> > .Remove(KeyValuePair <TKey1, TValue1> item) { ChoGuard.ArgumentNotNull(item, "Item"); return(Remove(item.Key)); }