public void LoadConfig(TargetConfig config) { if (config == null) { throw new ArgumentNullException("config"); } Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) { throw new ConfigurationErrorsException("EventLogTarget子元素 " + node.Name + "只能为单值元素"); } switch (node.Name) { case "maxSize": MaxSize = Util.ToInt64(node.FirstChild.Value, 1024); break; case "eventLogName": EventLogName = node.FirstChild.Value; break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析EventLogTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
public override void Install() { try { if (string.IsNullOrEmpty(_FileName)) { Util.BackupFile(TargetFile, PhysicalSitePath, Log); _TargetConfig = new XmlDocument(); TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); XmlMerge merge = new XmlMerge(new StringReader(InstallConfig), this.Package.Version.ToString(), this.Package.Name); merge.UpdateConfig(TargetConfig); Completed = true; Log.AddInfo(Util.CONFIG_Updated + " - " + TargetFile.Name); } else { string strConfigFile = Path.Combine(this.Package.InstallerInfo.TempInstallFolder, _FileName); if (File.Exists(strConfigFile)) { StreamReader stream = File.OpenText(strConfigFile); XmlMerge merge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " Install"); merge.UpdateConfigs(); stream.Close(); Completed = true; Log.AddInfo(Util.CONFIG_Updated); } } } catch (Exception ex) { Log.AddFailure(Util.EXCEPTION + " - " + ex.Message); } }
public void LoadConfig(TargetConfig config) { CheckUtil.ArgumentNotNull(config, "config"); Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) throw new ConfigurationErrorsException("DbTarget子元素 " + node.Name + "只能为单值元素"); switch (node.Name) { case "connectionStringName": ConnectionStringName = node.FirstChild.Value; break; case "commandText": CommandText = node.FirstChild.Value; break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析DbTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
/// <summary> /// 加载配置 /// </summary> /// <param name="config"></param> /// <exception cref="InvalidOperationException">配置已经被加载</exception> /// <exception cref="ArgumentNullException">参数<c>config</c> 不能为空</exception> /// <exception cref="ConfigurationErrorsException">配置无法正确加载</exception> public void LoadConfig(TargetConfig config) { CheckUtil.ArgumentNotNull(config, "config"); this.Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) throw new ConfigurationErrorsException("RemotingTarget子元素 " + node.Name + "只能为单值元素"); switch (node.Name) { case "clientName": ClientName = node.FirstChild.Value; break; case "appName": AppName = node.FirstChild.Value; break; default: break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析RemotingTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
public void LoadConfig(TargetConfig config) { if (config == null) throw new ArgumentNullException("config"); Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) throw new ConfigurationErrorsException("EventLogTarget子元素 " + node.Name + "只能为单值元素"); switch (node.Name) { case "maxSize": MaxSize = ConvertUtil.ToInt64(node.FirstChild.Value, 1024); break; case "eventLogName": EventLogName = node.FirstChild.Value; break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析EventLogTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
/// <summary> /// 属性事件处理 /// </summary> /// <param name="property"></param> protected override void OnPropertyChangedInner(string property) { if (TargetConfig?.Parent == null) { return; } switch (property) { case nameof(TargetConfig.Name): case nameof(TargetConfig.ColumnName): SyncLinkField(field => field.LinkField = TargetConfig.ColumnName); break; case nameof(TargetConfig.CanEmpty): if (!TargetConfig.CanEmpty) { TargetConfig.IsRequired = true; } break; case nameof(TargetConfig.Nullable): TargetConfig.RaisePropertyChanged(nameof(TargetConfig.DbNullable)); break; } }
private bool InsertNode(XmlNode childRootNode, XmlNode actionNode, NodeInsertType mode) { XmlNode rootNode = childRootNode.ParentNode; Debug.Assert(rootNode != null); var changedNode = false; foreach (XmlNode child in actionNode.ChildNodes) { if (child.NodeType == XmlNodeType.Element || child.NodeType == XmlNodeType.Comment) { DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "InsertNode:" + child.InnerXml.ToString()); switch (mode) { case NodeInsertType.Before: rootNode.InsertBefore(TargetConfig.ImportNode(child, true), childRootNode); changedNode = true; break; case NodeInsertType.After: rootNode.InsertAfter(TargetConfig.ImportNode(child, true), childRootNode); changedNode = true; break; } } } return(changedNode); }
/// <summary> /// 加载配置 /// </summary> /// <param name="config"></param> /// <exception cref="InvalidOperationException">配置已经被加载</exception> /// <exception cref="ArgumentNullException">参数<c>config</c> 不能为空</exception> /// <exception cref="ConfigurationErrorsException">配置无法正确加载</exception> public void LoadConfig(TargetConfig config) { Util.ArgumentNotNull(config, "config"); this.Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) { throw new ConfigurationErrorsException("RemotingTarget子元素 " + node.Name + "只能为单值元素"); } switch (node.Name) { case "clientName": ClientName = node.FirstChild.Value; break; case "appName": AppName = node.FirstChild.Value; break; default: break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析RemotingTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
public void LoadConfig(TargetConfig config) { CheckUtil.ArgumentNotNull(config, "config"); Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) { throw new ConfigurationErrorsException("DbTarget子元素 " + node.Name + "只能为单值元素"); } switch (node.Name) { case "connectionStringName": ConnectionStringName = node.FirstChild.Value; break; case "commandText": CommandText = node.FirstChild.Value; break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析DbTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
private bool UpdateAttribute(XmlNode rootNode, XmlNode actionNode) { Debug.Assert(actionNode.Attributes != null, "actionNode.Attributes != null"); Debug.Assert(rootNode.Attributes != null, "rootNode.Attributes != null"); var changedNode = false; if (actionNode.Attributes["name"] != null && actionNode.Attributes["value"] != null) { string attributeName = actionNode.Attributes["name"].Value; string attributeValue = actionNode.Attributes["value"].Value; if (!string.IsNullOrEmpty(attributeName)) { DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "UpdateAttribute:attributeName=" + attributeName.ToString()); if (rootNode.Attributes[attributeName] == null) { rootNode.Attributes.Append(TargetConfig.CreateAttribute(attributeName)); changedNode = true; } var oldAttributeValue = rootNode.Attributes[attributeName].Value; rootNode.Attributes[attributeName].Value = attributeValue; if (!string.Equals(oldAttributeValue, attributeValue, StringComparison.Ordinal)) { changedNode = true; } } } return(changedNode); }
/// <summary> /// 属性事件处理 /// </summary> /// <param name="property"></param> protected override void OnPropertyChangedInner(string property) { switch (property) { case nameof(TargetConfig.Name): TargetConfig.RaisePropertyChanged(nameof(TargetConfig.DisplayName)); break; case nameof(TargetConfig.SaveTableName): TargetConfig.RaisePropertyChanged(nameof(TargetConfig.ReadTableName)); TargetConfig.RaisePropertyChanged(nameof(TargetConfig.DisplayName)); TargetConfig.RaisePropertyChanged(nameof(TargetConfig.SaveTable)); break; case nameof(TargetConfig.ReadTableName): TargetConfig.RaisePropertyChanged(nameof(TargetConfig.SaveTableName)); TargetConfig.RaisePropertyChanged(nameof(TargetConfig.DisplayName)); TargetConfig.RaisePropertyChanged(nameof(TargetConfig.SaveTable)); break; case nameof(TargetConfig.Classify): OnClassifyChanged(); break; case nameof(TargetConfig.Project): CheckEntityProject(); break; } }
/// ----------------------------------------------------------------------------- /// <summary> /// The UnInstall method uninstalls the config component /// </summary> /// <history> /// [cnurse] 08/04/2007 created /// </history> /// ----------------------------------------------------------------------------- public override void UnInstall() { if (string.IsNullOrEmpty(_UninstallFileName)) { //Create an XmlDocument for the config file _TargetConfig = new XmlDocument(); TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); //Create XmlMerge instance from UnInstallConfig source var merge = new XmlMerge(new StringReader(UnInstallConfig), Package.Version.ToString(), Package.Name); //Update the Config file - Note that this method does save the file merge.UpdateConfig(TargetConfig, TargetFile.FullName); } else { //Process external file string strConfigFile = Path.Combine(Package.InstallerInfo.TempInstallFolder, _UninstallFileName); if (File.Exists(strConfigFile)) { //Create XmlMerge instance from config file source StreamReader stream = File.OpenText(strConfigFile); var merge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " UnInstall"); //Process merge merge.UpdateConfigs(); //Close stream stream.Close(); } } }
/// <summary> /// 加载配置 /// </summary> /// <param name="config"></param> /// <exception cref="InvalidOperationException">配置已经被加载</exception> /// <exception cref="ArgumentNullException">参数<c>config</c> 不能为空</exception> /// <exception cref="ConfigurationErrorsException">配置无法正确加载</exception> public void LoadConfig(TargetConfig config) { if (config == null) { throw new ArgumentNullException("config"); } Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) { throw new ConfigurationErrorsException("ConsoleTarget子元素 " + node.Name + "只能为单值元素"); } object value = Enum.Parse(typeof(ConsoleColor), node.FirstChild.Value, true); string fc = node.Name.Substring(0, 1).ToUpper(); GetType().GetProperty(Util.InitialToUpper(node.Name)).SetValue(this, value, null); } catch (Exception ex) { throw new ConfigurationErrorsException("解析ConsoleTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
/// <summary> /// 属性事件处理 /// </summary> /// <param name="property"></param> protected override void OnPropertyChangedInner(string property) { switch (property) { case nameof(TargetConfig.IdDataType): TargetConfig.Foreach <PropertyConfig>(p => p.IsPrimaryKey || p.IsRelationField, p => p.DataType = TargetConfig.IdDataType); break; case nameof(TargetConfig.UserIdDataType): TargetConfig.Foreach <PropertyConfig>(p => p.IsUserId, p => p.DataType = TargetConfig.UserIdDataType); break; case nameof(TargetConfig.Entities): TargetConfig.EntityList.CollectionChanged += EntitiesCollectionChanged; break; case nameof(TargetConfig.Projects): TargetConfig.ProjectList.CollectionChanged += ConfigCollectionChanged; break; case nameof(TargetConfig.ApiItems): TargetConfig.ApiList.CollectionChanged += ConfigCollectionChanged; break; case nameof(TargetConfig.Enums): TargetConfig.EnumList.CollectionChanged += ConfigCollectionChanged; break; } }
public void CreateTarget(Vector3 worldPosition, TargetTypes targetType) { TargetConfig config = ConfigDatabase.Instance.GetTargetConfig(targetType); RefreshTarget(new IngamePanel.IndicatorDisplaySettings(config.circleSizeValue, Camera.main.WorldToScreenPoint(worldPosition), config.circleColor)); currentTargetConfig = config; currentTargetWorldPosition = worldPosition; }
private void AddNode(XmlNode rootNode, XmlNode actionNode) { foreach (XmlNode child in actionNode.ChildNodes) { if (child.NodeType == XmlNodeType.Element || child.NodeType == XmlNodeType.Comment) { rootNode.AppendChild(TargetConfig.ImportNode(child, true)); } } }
public ConfigBuilderTests() { _target = new TargetConfig(); _settings = new Dictionary <string, string>(); _options = new StronkConfig() .From.Source(new DictionarySource(_settings)); _builder = new ConfigBuilder(_options); }
private void AddNode(XmlNode rootNode, XmlNode actionNode) { foreach (XmlNode child in actionNode.ChildNodes) { if (child.NodeType == XmlNodeType.Element || child.NodeType == XmlNodeType.Comment) { rootNode.AppendChild(TargetConfig.ImportNode(child, true)); DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "AddNode:" + child.InnerXml.ToString()); } } }
private void ProcessNode(XmlNode node) { string rootNodePath = node.Attributes["path"].Value; XmlNode rootNode; if (node.Attributes["nameSpace"] == null) { rootNode = TargetConfig.SelectSingleNode(rootNodePath); } else { string xmlNameSpace = node.Attributes["nameSpace"].Value; string xmlNameSpacePrefix = node.Attributes["nameSpacePrefix"].Value; XmlNamespaceManager nsmgr = new XmlNamespaceManager(TargetConfig.NameTable); nsmgr.AddNamespace(xmlNameSpacePrefix, xmlNameSpace); rootNode = TargetConfig.SelectSingleNode(rootNodePath, nsmgr); } if (rootNode == null) { } string nodeAction = node.Attributes["action"].Value; switch (nodeAction.ToLowerInvariant()) { case "add": AddNode(rootNode, node); break; case "insertbefore": InsertNode(rootNode, node, NodeInsertType.Before); break; case "insertafter": InsertNode(rootNode, node, NodeInsertType.After); break; case "remove": RemoveNode(rootNode); break; case "removeattribute": RemoveAttribute(rootNode, node); break; case "update": UpdateNode(rootNode, node); break; case "updateattribute": UpdateAttribute(rootNode, node); break; } }
private IEnumerable <XmlNode> GetTargetRoots() { yield return(TargetConfig.DocumentElement); var locations = TargetConfig.SelectNodes("/configuration/location"); if (locations != null) { foreach (XmlNode node in locations) { yield return(node); } } }
/// ----------------------------------------------------------------------------- /// <summary> /// The Install method installs the config component /// </summary> /// ----------------------------------------------------------------------------- public override void Install() { try { if (string.IsNullOrEmpty(_FileName)) { //First backup the config file Util.BackupFile(TargetFile, PhysicalSitePath, Log); //Create an XmlDocument for the config file _TargetConfig = new XmlDocument { XmlResolver = null }; TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); //Create XmlMerge instance from InstallConfig source _xmlMerge = new XmlMerge(new StringReader(InstallConfig), Package.Version.ToString(), Package.Name); //Update the Config file - Note that this method does not save the file - we will save it in Commit _xmlMerge.UpdateConfig(TargetConfig); Completed = true; Log.AddInfo(Util.CONFIG_Updated + " - " + TargetFile.Name); } else { //Process external file string strConfigFile = Path.Combine(Package.InstallerInfo.TempInstallFolder, _FileName); if (File.Exists(strConfigFile)) { //Create XmlMerge instance from config file source using (var stream = File.OpenText(strConfigFile)) { _xmlMerge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " Install"); //Process merge _xmlMerge.UpdateConfigs(false); } Completed = true; Log.AddInfo(Util.CONFIG_Updated); } } } catch (Exception ex) { Log.AddFailure(Util.EXCEPTION + " - " + ex.Message); } }
private bool PrependNode(XmlNode rootNode, XmlNode actionNode) { var changedNode = false; foreach (XmlNode child in actionNode.ChildNodes) { if (child.NodeType == XmlNodeType.Element || child.NodeType == XmlNodeType.Comment) { rootNode.PrependChild(TargetConfig.ImportNode(child, true)); DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "PrependNode:" + child.InnerXml.ToString()); changedNode = true; } } return(changedNode); }
static void Main(string[] args) { System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileMajorPart.ToString() + "." + fvi.FileMinorPart.ToString() + "." + fvi.FileBuildPart.ToString(); Console.WriteLine(fvi.FileDescription + " " + version); Console.WriteLine(fvi.LegalCopyright + " - " + fvi.CompanyName); Console.WriteLine(); var options = new Options(); #if DEBUG if (args.Length == 0) { args = new string[] { "--File", @"c:\temp\sample.json" } } ; #endif if (!CommandLine.Parser.Default.ParseArguments(args, options)) { return; } logger.Info(String.Format("Reading configuration from '{0}'", options.ConfigurationFile)); if (!File.Exists(options.ConfigurationFile)) { logger.Error(String.Format("File not found: '{0}'", options.ConfigurationFile)); Console.WriteLine("Run XESmartTarget -? for help."); return; } TargetConfig config = TargetConfig.LoadFromFile(options.ConfigurationFile); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; logger.Info("Received shutdown signal..."); config.Target.Stop(); source.CancelAfter(TimeSpan.FromSeconds(10)); // give a 10 seconds cancellation grace period }; logger.Info("Starting Target"); Task t = processTargetAsync(config.Target); t.Wait(); logger.Info("Target process ended"); }
/// <summary> /// 发出属性修改前事件 /// </summary> /// <param name="property">属性</param> /// <param name="oldValue">旧值</param> /// <param name="newValue">新值</param> protected override void BeforePropertyChangedInner(string property, object oldValue, object newValue) { switch (property) { case nameof(TargetConfig.Key): GlobalConfig.ConfigDictionary.Remove((Guid)oldValue); break; case nameof(TargetConfig.Name): var now = (string)newValue; if (!string.IsNullOrWhiteSpace(now) && !TargetConfig.OldNames.Contains(now) && now != "NewField") { TargetConfig.OldNames.Add(now); } TargetConfig.RaisePropertyChanged(nameof(TargetConfig.NameHistory)); break; } }
public GitlabRepositoryTarget( TargetConfig mirrorToConfig) { _mirrorToConfig = mirrorToConfig; var match = _userRegex.Match(_mirrorToConfig.Target); if (!match.Success) { throw new ArgumentException("Expected a valid gitlab username url but got: " + _mirrorToConfig.Target); } UserName = match.Groups[1].Value; _httpClient = new HttpClient { BaseAddress = new Uri("https://gitlab.com/api/v4/") }; }
private void UpdateAttribute(XmlNode rootNode, XmlNode actionNode) { string AttributeName = Null.NullString; string AttributeValue = Null.NullString; if (actionNode.Attributes["name"] != null && actionNode.Attributes["value"] != null) { AttributeName = actionNode.Attributes["name"].Value; AttributeValue = actionNode.Attributes["value"].Value; if (!string.IsNullOrEmpty(AttributeName)) { if (rootNode.Attributes[AttributeName] == null) { rootNode.Attributes.Append(TargetConfig.CreateAttribute(AttributeName)); } rootNode.Attributes[AttributeName].Value = AttributeValue; } } }
/// <summary> /// 发出属性修改前事件 /// </summary> /// <param name="property">属性</param> /// <param name="oldValue">旧值</param> /// <param name="newValue">新值</param> protected override void BeforePropertyChanged(string property, object oldValue, object newValue) { if (TargetConfig.IsPredefined) { return; } switch (property) { case nameof(TargetConfig.Name): var now = (string)newValue; if (!string.IsNullOrWhiteSpace(now) && !TargetConfig.OldNames.Contains(now) && now != "NewField") { TargetConfig.OldNames.Add(now); } TargetConfig.RaisePropertyChanged(nameof(TargetConfig.NameHistory)); break; } BeforePropertyChangedInner(property, oldValue, newValue); }
private void UpdateAttribute(XmlNode rootNode, XmlNode actionNode) { Debug.Assert(actionNode.Attributes != null, "actionNode.Attributes != null"); Debug.Assert(rootNode.Attributes != null, "rootNode.Attributes != null"); if (actionNode.Attributes["name"] != null && actionNode.Attributes["value"] != null) { string attributeName = actionNode.Attributes["name"].Value; string attributeValue = actionNode.Attributes["value"].Value; if (!string.IsNullOrEmpty(attributeName)) { if (rootNode.Attributes[attributeName] == null) { rootNode.Attributes.Append(TargetConfig.CreateAttribute(attributeName)); } rootNode.Attributes[attributeName].Value = attributeValue; } } }
private void UpdateAttribute(XmlNode rootNode, XmlNode actionNode) { Debug.Assert(actionNode.Attributes != null, "actionNode.Attributes != null"); Debug.Assert(rootNode.Attributes != null, "rootNode.Attributes != null"); if (actionNode.Attributes["name"] != null && actionNode.Attributes["value"] != null) { string attributeName = actionNode.Attributes["name"].Value; string attributeValue = actionNode.Attributes["value"].Value; if (!string.IsNullOrEmpty(attributeName)) { DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "UpdateAttribute:attributeName=" + attributeName.ToString()); if (rootNode.Attributes[attributeName] == null) { rootNode.Attributes.Append(TargetConfig.CreateAttribute(attributeName)); } rootNode.Attributes[attributeName].Value = attributeValue; } } }
private void InsertNode(XmlNode childRootNode, XmlNode actionNode, NodeInsertType mode) { XmlNode rootNode = childRootNode.ParentNode; foreach (XmlNode child in actionNode.ChildNodes) { if (child.NodeType == XmlNodeType.Element || child.NodeType == XmlNodeType.Comment) { switch (mode) { case NodeInsertType.Before: rootNode.InsertBefore(TargetConfig.ImportNode(child, true), childRootNode); break; case NodeInsertType.After: rootNode.InsertAfter(TargetConfig.ImportNode(child, true), childRootNode); break; } } } }
public override void UnInstall() { if (string.IsNullOrEmpty(_UninstallFileName)) { _TargetConfig = new XmlDocument(); TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); XmlMerge merge = new XmlMerge(new StringReader(UnInstallConfig), this.Package.Version.ToString(), this.Package.Name); merge.UpdateConfig(TargetConfig, TargetFile.FullName); } else { string strConfigFile = Path.Combine(this.Package.InstallerInfo.TempInstallFolder, _UninstallFileName); if (File.Exists(strConfigFile)) { StreamReader stream = File.OpenText(strConfigFile); XmlMerge merge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " UnInstall"); merge.UpdateConfigs(); stream.Close(); } } }
private async Task <InteractionResult> ExecuteTargetAsync(TargetConfig target, InterationContext context, TargetConfig[] allTargets) { var actions = target.Actions.Select(x => x.GetAction()); var lastResult = default(InteractionResult); foreach (var action in actions) { var result = lastResult = await action.ExecuteAsync(context); if (!result.Ok) { break; } if (string.IsNullOrEmpty(result.Target)) { continue; } var callTarget = allTargets.FirstOrDefault(t => t.Name.Equals(result.Target, StringComparison.OrdinalIgnoreCase)); if (callTarget == null) { throw new Exception("callTarget cannot be found:" + result.Target); } result = lastResult = await ExecuteTargetAsync(callTarget, context, allTargets); if (!result.Ok) { break; } } lastResult.Outputs = context.Outputs; return(lastResult); }
/// <summary> /// 加载配置 /// </summary> /// <param name="config"></param> /// <exception cref="InvalidOperationException">配置已经被加载</exception> /// <exception cref="ArgumentNullException">参数<c>config</c> 不能为空</exception> /// <exception cref="ConfigurationErrorsException">配置无法正确加载</exception> public void LoadConfig(TargetConfig config) { if (config == null) throw new ArgumentNullException("config"); Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) throw new ConfigurationErrorsException("ConsoleTarget子元素 " + node.Name + "只能为单值元素"); object value = Enum.Parse(typeof(ConsoleColor), node.FirstChild.Value, true); string fc = node.Name.Substring(0, 1).ToUpper(); GetType().GetProperty(StringUtil.InitialToUpper(node.Name)).SetValue(this, value, null); } catch (Exception ex) { throw new ConfigurationErrorsException("解析ConsoleTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
static void Main(string[] args) { System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileMajorPart.ToString() + "." + fvi.FileMinorPart.ToString() + "." + fvi.FileBuildPart.ToString(); string name = assembly.FullName; logger.Info(name + " " + version); var options = new Options(); #if DEBUG options.ConfigurationFile = @"c:\temp\sample.json"; #else if (!CommandLine.Parser.Default.ParseArguments(args, options)) { return; } #endif logger.Info(String.Format("Reading configuration from '{0}'", options.ConfigurationFile)); TargetConfig config = TargetConfig.LoadFromFile(options.ConfigurationFile); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; logger.Info("Received shutdown signal..."); config.Target.Stop(); source.CancelAfter(TimeSpan.FromSeconds(10)); // give a 10 seconds cancellation grace period }; logger.Info("Starting Target"); Task t = processTargetAsync(config.Target); t.Wait(); logger.Info("Target process ended"); }
/// <summary> /// 加载配置 /// </summary> /// <param name="config"></param> /// <exception cref="InvalidOperationException">配置已经被加载</exception> /// <exception cref="ArgumentNullException">参数<c>config</c> 不能为空</exception> /// <exception cref="ConfigurationErrorsException">配置无法正确加载</exception> public void LoadConfig(TargetConfig config) { CheckUtil.ArgumentNotNull(config,"config"); _Config = config; Name = _Config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) throw new ConfigurationErrorsException("FileTarget子元素 " + node.Name + "只能为单值元素"); switch (node.Name) { case "daysToKeepLogs": DaysToKeepLogs = int.Parse(node.FirstChild.Value); break; case "writeDirectly": WriteDirectly = node.FirstChild.Value.ToLower() == "true"; break; case "baseDirectory": _BaseDirectory = node.FirstChild.Value; break; case "yearInPath": YearInPath = node.FirstChild.Value.ToLower() == "true"; break; case "monthInPath": MonthInPath = node.FirstChild.Value.ToLower() == "true"; break; case "dayInPath": DayInPath = node.FirstChild.Value.ToLower() == "true"; break; case "loggerNameInPath": LoggerNameInPath = node.FirstChild.Value.ToLower() == "true"; break; case "logLevelInPath": LogLevelInPath = node.FirstChild.Value.ToLower() == "true"; break; case "fileName": FileName = node.FirstChild.Value; break; case "writePerYear": WritePerYear = node.FirstChild.Value.ToLower() == "true"; break; case "writePerMonth": WritePerMonth = node.FirstChild.Value.ToLower() == "true"; break; case "writePerDay": WritePerDay = node.FirstChild.Value.ToLower() == "true"; break; case "writePerHour": WritePerHour = node.FirstChild.Value.ToLower() == "true"; break; case "loggerNameInFilename": LoggerNameInFilename = node.FirstChild.Value.ToLower() == "true"; break; case "logLevelInFilename": LogLevelInFilename = node.FirstChild.Value.ToLower() == "true"; break; default: break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析FileTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } try { if (string.IsNullOrEmpty(_BaseDirectory) == false && Directory.Exists(_BaseDirectory) == false) { Directory.CreateDirectory(_BaseDirectory); } } catch (Exception ex) { LogManager.TriggerEvent(this, ex); } }