/// <summary> /// Loads the file. /// </summary> /// <param name="node">The node.</param> protected void LoadFile(ConfigNode node = null) { lock (this) { _configNode = node ?? new ConfigNode(LoadSection(FileName, SectionName)); RefreshBaseSections(); var fileOnly = Path.GetFileName(FileName); var pathOnly = FileName.Replace(fileOnly, string.Empty); if (_fileWatcher != null) { _fileWatcher.Dispose(); } _fileWatcher = new FileSystemWatcher() { Path = pathOnly, Filter = fileOnly, NotifyFilter = NotifyFilters.LastWrite, EnableRaisingEvents = true }; _fileWatcher.Changed += OnConfigFileChanged; _fileWatcher.Created += OnConfigFileChanged; _fileWatcher.Deleted += OnConfigFileChanged; } }
private void SaveSettings() { ConfigNode CN = new ConfigNode(); FieldInfo[] FI = this.GetType().GetFields(); for (int indexFields = 0; indexFields < FI.Length; indexFields++) { FieldInfo currentFI = FI[indexFields]; if (currentFI.IsPublic && currentFI.IsStatic) { IConfigNode tempCN = currentFI.GetValue(this) as IConfigNode; if (null != tempCN) { tempCN.Save(CN.AddNode(currentFI.Name)); } else { CN.AddValue(currentFI.Name, Convert.ToString(currentFI.GetValue(this))); } } } string filePath = Path.ChangeExtension(typeof(StockBugFixPlusController).Assembly.Location, ".cfg"); Debug.Log("Saving StockBugFix and StockPlus Settings: " + filePath); CN.Save(filePath, "StockBugFix and StockPlus Settings"); }
public override void Initialize(IConfigNode config) { this.PopServerPort = 110; this.SmtpServerPort = 25; base.Initialize(config); }
/// <summary> /// The update event tree head node. /// </summary> private void UpdateEventTreeHeadNode() { if (null != this.currentEventTreeHeadNode) { this.currentEventTreeHeadNode.Dispose(); } IEventConfiguration eventConfiguration = ConfigurationManager.Singleton.GetEventConfiguration(this.version); IConfigNode eventConfigHeadNode = eventConfiguration.EventHeadNode; if (eventConfigHeadNode == null) { return; } this.currentEventTreeHeadNode = new EventTreeRootNode { ConfigurationNode = eventConfigHeadNode }; foreach (var child in eventConfigHeadNode.Children) { this.currentEventTreeHeadNode.Children.Add( new ConfigNodeWrapper { ConfigurationNode = child, Parent = this.currentEventTreeHeadNode }); } }
/// <summary> /// Gets the node child attributes. /// </summary> /// <param name="node">The node.</param> /// <param name="parentXPath">The parent x path.</param> /// <returns></returns> public static NodeChildAttributes GetNodeChildAttributes(IConfigNode node, string parentXPath) { var nca = new NodeChildAttributes(); var pnode = node.GetConfigNode(parentXPath); if (pnode != null) { nca.ParentAttributes.NodeName = pnode.Name; nca.ParentAttributes.Attributes.Add(pnode.GetAttributes()); var children = pnode.GetConfigNodes("./*"); foreach (var cnode in children) { var na = new NodeAttributes() { NodeName = cnode.Name }; na.Attributes.Add(cnode.GetAttributes()); nca.ChildAttributes.Add(na); } } return(nca); }
/// <summary> /// Initializes a new instance of the <see cref="RMQConfigurationManager"/> class. /// </summary> /// <param name="configPath">The configuration path.</param> public RMQConfigurationManager(string configPath = null) { if (configPath == null) { try { var xmlConfigSection = (XmlNode)ConfigurationManager.GetSection("rmqSettings"); if (xmlConfigSection != null) { _configNode = new ConfigNode(xmlConfigSection); _nodeAttributes = ConfigHelper.GetNodeChildAttributes(_configNode, "."); } } catch (ConfigurationErrorsException) { _nodeAttributes = new NodeChildAttributes(); } } else { using (var configContainer = new ConfigContainer(configPath, "./rmqSettings")) { _configNode = configContainer.Node; _nodeAttributes = ConfigHelper.GetNodeChildAttributes(_configNode, "."); } } }
/// <summary> /// /// </summary> /// <param name="config"></param> public override void Initialize(IConfigNode config) { base.Initialize(config); if (null == this.PayRoutes || this.PayRoutes.Count < 1) { return; } var providerValues = this.GetPropertyValues(); var routeProperties = typeof(PayRouteConfig).GetPersistProperties(); foreach (var routeItem in this.PayRoutes) { var payRoute = routeItem.Value; var propValues = payRoute.GetPropertyValues(); var appendPropValues = new Dictionary <string, object>(); foreach (var propItem in providerValues) { if (routeProperties.ContainsKey(propItem.Key) && (false == propValues.ContainsKey(propItem.Key) || null == propValues[propItem.Key])) { appendPropValues.Add(propItem.Key, propItem.Value); } } if (appendPropValues.Count > 0) { payRoute.SetPropertyValues(appendPropValues); } } }
/// <summary> /// /// </summary> /// <param name="config"></param> public virtual void Initialize(IConfigNode config) { if (null != config) { this.DeserializeObject(config); } }
/// <summary> /// 获取配置信息 /// </summary> /// <param name="configSectionName"></param> /// <param name="nodePath"></param> /// <returns></returns> public static IConfigNode GetConfigNode(string configSectionName, string nodePath) { IConfigNode config = null; var configFile = GetConfigPath(configSectionName); if (File.Exists(configFile) == false) { throw new ConfigException(string.Format("cannot find the config : {0}", configFile)); } var xml = new XmlDocument(); xml.Load(configFile); string xpath = null; if (string.IsNullOrEmpty(nodePath)) { xpath = string.Format(@"/configuration/{0}", configSectionName); } else { xpath = string.Format(@"/configuration/{0}{1}", configSectionName, nodePath); } var targetNode = xml.SelectSingleNode(xpath); if (null != targetNode) { config = new ConfigNode(targetNode); } return(config); }
/// <summary> /// Verifies that <paramref name="parent"/> can be used as parameter of /// <see cref="IConfigNode.Clone"/> method of <paramref name="thisInstance"/>. If the method throws /// an exception, it means that <paramref name="parent"/> cannot be used. Otherwise it can. /// </summary> internal static void VerifyParent([NotNull] this IConfigNode thisInstance, IConfigNode parent) { if (parent == null) { if (thisInstance.Parent == null) { return; } throw new ArgumentException( $"{nameof(parent)} cannot be null when {nameof(IConfigNode.Parent)} property of this instance isn't null.", nameof(parent)); } if (thisInstance.Parent == null) { throw new ArgumentException( $"{nameof(parent)} has to be null when {nameof(IConfigNode.Parent)} property of this instance is null.", nameof(parent)); } if (!string.Equals(parent.Name, thisInstance.Parent.Name, StringComparison.Ordinal)) { throw new ArgumentException( $"{nameof(IConfigNode.Name)} of {nameof(parent)} instance ({parent.Name}) isn't equal to {nameof(IConfigNode.Name)} of the parent of this instance ({thisInstance.Parent.Name}).", nameof(parent)); } if (parent.IndentLevel != thisInstance.Parent.IndentLevel) { throw new ArgumentException( $"{nameof(IConfigNode.IndentLevel)} of {nameof(parent)} instance ({parent.IndentLevel}) isn't equal to {nameof(IConfigNode.IndentLevel)} of the parent of this instance ({thisInstance.Parent.IndentLevel}).", nameof(parent)); } }
/// <summary> /// The parse. /// </summary> /// <param name="e"> /// The e. /// </param> /// <returns> /// The <see cref="IConfigNodeWrapper"/>. /// </returns> public IConfigNodeWrapper Parse(IEvent e) { try { if (e.RawData == null) { return(null); } var stream = new MemoryStream(e.RawData); //IEventConfiguration eventConfiguration = new ConfigurationManager().GetEventConfiguration(e.Version); IEventConfiguration eventConfiguration = ConfigurationManager.Singleton.GetEventConfiguration(e.Version); IConfigNode eventConfigHeadNode = eventConfiguration.EventHeadNode; if (eventConfigHeadNode == null) { return(null); } var rootNode = new EventTreeRootNode { ConfigurationNode = eventConfigHeadNode, EventIndex = e.DisplayIndex }; foreach (var child in eventConfigHeadNode.Children) { rootNode.Children.Add(new ConfigNodeWrapper { ConfigurationNode = child, Parent = rootNode }); } rootNode.InitializeValue(stream, e.Version); int eventId; if (Int32.TryParse(rootNode.GetChildNodeById("EventType").Value.ToString(), out eventId) == true) { IConfigNode eventConfigBodyNode = eventConfiguration.GetEventBodyNodeById( Convert.ToInt32(eventId)); if (eventConfigBodyNode != null) { // wrong "EventType" cause null var eventTreeBodyNode = new EventTreeBodyNode { ConfigurationNode = eventConfigBodyNode, Parent = rootNode }; this.GenerateEventTreeChildrenNode(eventTreeBodyNode); rootNode.Children.Add(eventTreeBodyNode); eventTreeBodyNode.InitializeValue(stream, e.Version); } return(rootNode); } } catch (Exception ex) { Log.Error(string.Format("二次解析出错,event id = {0},error message = {1}", e.EventIdentifier, ex.Message)); return(null); } return(null); }
/// <summary> /// /// </summary> /// <param name="config"></param> public override void Initialize(IConfigNode config) { base.Initialize(config); if (null == this.SqlProcessor) { this.SqlProcessor = new SqlProcessor(); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public override void Initialize(IConfigNode config) { base.Initialize(config); if (this.Formatter == null) { this.Formatter = new TextFormatter(); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public void Initialize(IConfigNode config) { this.minLevel = LogLevel.Info; this.maxLevel = LogLevel.Off; if (AppInstance.Config.Debug) { this.minLevel = LogLevel.All; } }
/// <summary> /// The dispose. /// </summary> public void Dispose() { this.Parent = null; foreach (var child in this.Children) { child.Dispose(); } this.Children.Clear(); }
/// <summary> /// Inserts <paramref name="node"/> at specified <paramref name="index"/> in <see cref="Children"/> list. /// </summary> /// <param name="index">Index at which <paramref name="node"/> should be inserted.</param> /// <param name="node">Node to insert.</param> internal void InsertChild(int index, IConfigNode node) { if (!ValidChild(node)) { throw new ArgumentException( $"Array item nodes and regular nodes cannot be mixed in the same {nameof(ConfigurationNode)} instance."); } _children.Insert(index, node); }
private static object ResolveObject(Type sourceType, string alias, IConfigNode resolveInfo) { var obj = sourceType.BuildObject(alias); if (obj is IResolveObject) { (obj as IResolveObject).Initialize(resolveInfo); } return(obj); }
static StringBuilder ToText(IConfigNode val, int level, StringBuilder output) { var map = val.GetProperties(); foreach (var item in map) { ToText(item.Value, item.Key, level + 1, output); } return(output); }
public static string ToConfigString(this IConfigNode inode) { if (inode == null) { return(""); } var node = new ConfigNode(inode.GetID()); inode.Save(node); return(node.ToString()); }
public object Clone() { IConfigNode obj = (IConfigNode)Activator.CreateInstance(this.GetType()); ConfigNode node = new ConfigNode(); SerializeToNode(node); obj.Load(node); return(obj); }
private static object getVal(IConfigNode node, Type type, string tname, string mname) { try { return(node.ValueAsType(type)); } catch (Exception error) { throw new ConfigException(string.Format(StringConsts.CONFIGURATION_ATTR_APPLY_VALUE_ERROR, mname, tname, error.Message)); } }
private static object getVal(IConfigNode node, Type type, string tname, string mname, bool verbatim) { try { return(node.ValueAsType(type, verbatim, strict: false)); } catch (Exception error) { throw new ConfigException(StringConsts.CONFIGURATION_ATTR_APPLY_VALUE_ERROR.Args(mname, tname, error.Message), error); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public override void Initialize(IConfigNode config) { this.WorkQueues = new List <IMessageQueue>(2); base.Initialize(config); if (this.LoadStrategy == null) { throw new ConfigException(string.Format("not find LoadStrategy for Queues[{0}]", this.Name)); } this.LoadStrategy.Initialize(this.Name, this.WorkQueues); }
public RDBMSEntity(RDBMSEntity parentEntity, IConfigNode sourceNode, RDBMSEntityType entityType, string originalName, string originalShortName = null, string transformedName = null, string transformedShortName = null) { if (parentEntity!=null) parentEntity.Children.Add(this); ParentEntity = parentEntity; SourceNode = sourceNode; EntityType = entityType; OriginalName = originalName; OriginalShortName = originalShortName; TransformedName = transformedName; TransformedShortName = transformedShortName; }
/// <summary> /// Builds the string based on the configured state supplied as a config vector, or /// passes the supplied string through if it is not a laconic vector with CONFIG_BUILDER_ROOT /// </summary> /// <param name="level">The configuration section level</param> /// <param name="sectionOrAttributeName">The name of section or attribute at the specified level</param> /// <returns>The original attribute string value or the string returned by IConfigStringBuilder.BuildString() method if IConfigStringBuilder was specified</returns> public static string Build(IConfigSectionNode level, string sectionOrAttributeName) { if (level == null || !level.Exists) { return(string.Empty); } IConfigNode source = level[sectionOrAttributeName]; if (!source.Exists) { source = level.AttrByName(sectionOrAttributeName); } return(Build(source)); }
public RDBMSEntity(RDBMSEntity parentEntity, IConfigNode sourceNode, RDBMSEntityType entityType, string originalName, string originalShortName = null, string transformedName = null, string transformedShortName = null) { if (parentEntity != null) { parentEntity.Children.Add(this); } ParentEntity = parentEntity; SourceNode = sourceNode; EntityType = entityType; OriginalName = originalName; OriginalShortName = originalShortName; TransformedName = transformedName; TransformedShortName = transformedShortName; }
/// <summary> /// Allows the on change. /// </summary> /// <param name="cNode">The c node.</param> /// <returns></returns> protected bool AllowOnChange(IConfigNode cNode) { var rValue = true; foreach (var cAttr in _allowOnChangeAttribute) { if (cNode.GetAttribute(cAttr.XPath, cAttr.AttrName, cAttr.Value) != cAttr.Value) { rValue = false; break; } } return(rValue); }
/// <summary> /// /// </summary> /// <param name="config"></param> public override void Initialize(IConfigNode config) { base.Initialize(config); foreach (var key in this.ListenerIndexes.Keys) { var proxy = this.ListenerIndexes[key]; if (proxy.Enabled) { var listener = LogFactory.Instance.ListenerRespository.GetListener(proxy.Name); this.Listeners.Add(listener); } } this.InitializeAsyncProcessor(); }
void AddChildNodeToProperty(IConfigNode node, string propName) { IList <IConfigNode> list = null; if (this.propertyMap.ContainsKey(propName) == false) { list = new List <IConfigNode>(4); this.propertyMap.Add(propName, list); } else { list = (IList <IConfigNode>) this.propertyMap[propName]; } list.Add(node); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="alias"></param> /// <returns></returns> public static T GetSingleton <T>(string alias) { Type sourceType = typeof(T); IConfigNode resolveInfo = null; if (sourceType.GetInterface(typeof(IResolveObject).Name) != null) { resolveInfo = LoadResolveConfig <T>(alias); } var instance = (T)GetSingleton(sourceType, alias, resolveInfo); return(instance); }
/// <summary> /// Builds the string based on the configured state supplied as a config vector, or /// passes the supplied string through if it is not a loaconic vector with CONFIG_BUILDER_ROOT /// </summary> /// <param name="source">The original source which may be IConfigStringBuilder injector or attribute value</param> /// <returns>The original attribute string value or the string returnd by IConfigStringBuilder.BuildString() method if IConfigStringBuilder was specified</returns> public static string Build(IConfigNode source) { if (source == null || !source.Exists) { return(string.Empty); } if (source is IConfigAttrNode) { return(source.Value); } var root = (IConfigSectionNode)source; var builder = FactoryUtils.MakeAndConfigure <IConfigStringBuilder>(root); return(builder.BuildString()); }
/// <summary> /// Turns domain name into domain instance /// </summary> protected virtual RDBMSDomain CreateDomain(string sourcePath, string name, IConfigNode node) { try { string argsLine = null; var iop = name.LastIndexOf('('); var icp = name.LastIndexOf(')'); if (iop>0 && icp>iop) { argsLine = name.Substring(iop+1, icp-iop-1); name = name.Substring(0, iop); } Type dtype = Type.GetType(name, false, true); if (dtype==null) { var paths = DomainSearchPaths.Split('|', ';'); foreach(var path in paths) { var fullName = path.Replace(".*", "." + name); dtype = Type.GetType(fullName, false, true); if (dtype!=null) break; } } if (dtype==null) { m_CompileErrors.Add(new SchemaCompilationException(sourcePath, "Domain type not found in any paths: " + name)); return null; } object[] args = null; var ctor = dtype.GetConstructor(Type.EmptyTypes); if (argsLine!=null) { var argsStrings = argsLine.Split(','); ctor = dtype.GetConstructors().Where(ci => ci.GetParameters().Length==argsStrings.Length).FirstOrDefault(); if (ctor==null) { m_CompileErrors.Add(new SchemaCompilationException(sourcePath, "Domain .ctor '{0}' argument mismatch '{1}'".Args(dtype.FullName, argsLine))); return null; } args = new object[ctor.GetParameters().Length]; var i = 0; foreach(var pi in ctor.GetParameters()) { args[i] = argsStrings[i].Trim().AsType(pi.ParameterType); i++; } } var result = Activator.CreateInstance(dtype, args) as RDBMSDomain; if (node is IConfigSectionNode) result.Configure((IConfigSectionNode)node); return result; } catch(Exception error) { m_CompileErrors.Add(new SchemaCompilationException(sourcePath, "Domain '{0}' creation error: {1} ".Args(name, error.ToMessageWithType()))); return null; } }
private static object getVal(IConfigNode node, Type type, string tname, string mname) { try { return node.ValueAsType(type); } catch(Exception error) { throw new ConfigException(string.Format(StringConsts.CONFIGURATION_ATTR_APPLY_VALUE_ERROR, mname, tname, error.Message)); } }