public static ICollection <TargetRecord> FindTargetRecords(XDocument document) { ICollection <TargetRecord> targetRecordsList = new List <TargetRecord>(); var targetRecords = from target in document.Root .Elements() .Where(x => x.Name.LocalName == "FieldBook") .Elements() .Where(x => x.Name.LocalName == "TargetRecord") select target; foreach (var targetRecord in targetRecords) { if (targetRecord.Element("TargetHeight").Value != string.Empty) { string targetIndex = targetRecord.Attribute("ID").Value; double targetHeight = double.Parse(targetRecord.Element("TargetHeight").Value); TargetRecord currentTargetRecord = new TargetRecord(targetIndex, targetHeight); targetRecordsList.Add(currentTargetRecord); } } return(targetRecordsList); }
/// <summary> /// Takes raw source records (likely via a <see cref="IRecordReader" />) serially and builds <see cref="TargetRecord" />s based on the /// <see cref="RecordConfiguration" /> and <see cref="IFieldFilterService" /> /// </summary> /// <param name="sourceRecords">Raw field name/value map of source records</param> /// <param name="recordConfiguration">Configuration (<see cref="RecordConfiguration" />) for use with generating the resulting emumerable of <see cref="TargetRecord" /></param> /// <returns>Enumerable of <see cref="TargetRecord" /></returns> public IEnumerable <TargetRecord> Build(IEnumerable <IReadOnlyDictionary <string, string> > sourceRecords, RecordConfiguration recordConfiguration) { var recordNumber = 1; foreach (var sourceRecord in sourceRecords) { TargetRecord targetRecord = null; try { targetRecord = new TargetRecord(recordConfiguration.Fields .Select(fc => new TargetField(fc.Name, fc.Sources? .Select(sourceFieldConfig => { if (!sourceRecord.TryGetValue(sourceFieldConfig.Name, out var sourceFieldValue)) { throw new TextWranglerRecordFieldConfigInvalidException(recordConfiguration.RecordTypeName, fc.Name, $"Source field [{sourceFieldConfig.Name}] does not exist in source record"); } var filteredSourceValue = _fieldFilterService.Filter(sourceFieldValue, sourceFieldConfig.Filters); return(Name: sourceFieldConfig.Name, Value: filteredSourceValue); })) { Value = fc.Format, Type = fc.Type })); }
/// <summary> /// Formats the given records for the given configuration. /// </summary> /// <param name="targetRecords">Lazily evaluated enumerable of populated <see cref="TargetRecord" /> records</param> /// <param name="recordConfiguration">The <see cref="RecordConfiguration" /> being used to transform these source/target records</param> /// <returns>Enumerable of <see cref="TargetRecord" /></returns> public IEnumerable <TargetRecord> Format(IEnumerable <TargetRecord> targetRecords, RecordConfiguration recordConfiguration) { var recordNumber = 1; foreach (var targetRecord in targetRecords) { TargetRecord yieldRecord = null; try { yieldRecord = FormatRecord(targetRecord, recordConfiguration); } catch (Exception x) when(!TextWranglerConfig.OnException(x, $"Could not format target record in [{_formatterName}] from built record [{recordNumber}]")) { // OnException handler says not to rethrow, so keep on going, skipping this record } if (yieldRecord != null) { yield return(yieldRecord); } recordNumber++; } }
private void CreateTargetTemplate(int index, string file) { var record = new TargetRecord { Id = $"Target_{index}", Description = $"Target_{index} description", ReadyUrl = $"http://localhost:{index + 5000}/ping/ready", RunningUrl = $"http://localhost:{index + 5000}/ping/running", StatusCodeMaps = new StatusCodeMap[] { new StatusCodeMap { HttpStatusCode = HttpStatusCode.OK, State = TargetState.Ok }, new StatusCodeMap { HttpStatusCode = HttpStatusCode.NotFound, State = TargetState.Error }, }, BodyElementMaps = new BodyElementMap[] { new BodyElementMap { State = TargetState.Ok, Path = "/state", CompareTo = "success" }, new BodyElementMap { State = TargetState.Error, Path = "/state", CompareTo = "error" }, }, TargetType = "REST", Enabled = true, FrequencyInSeconds = (int)TimeSpan.FromMinutes(5).TotalSeconds, }; File.WriteAllText(file, _json.Serialize(record)); _logger.LogInformation($"Create json template {file} for Agent Assignment"); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnConfirm_Click(object sender, EventArgs e) { var input = CheckInput(); if (!input.Item1) { MessageUtil.ShowError(input.Item2); return; } TargetRecord entity = BusinessFactory <TargetRecordBusiness> .Instance.FindById(this.currentRecord.Id); SetEntity(entity); try { var result = BusinessFactory <TargetRecordBusiness> .Instance.Update(entity, this.currentUser); if (result) { MessageUtil.ShowInfo("保存成功"); this.Close(); } else { MessageUtil.ShowInfo("保存失败"); } } catch (PoseidonException pe) { MessageUtil.ShowError(string.Format("保存失败,错误消息:{0}", pe.Message)); } }
/// <summary> /// 设置实体 /// </summary> /// <param name="entity"></param> private void SetEntity(TargetRecord entity) { entity.Type = Convert.ToInt32(this.cmbType.EditValue); entity.Finance = this.txtFinance.Text; entity.SchoolTake = this.spSchoolTake.Value; entity.SelfTake = this.spSelfTake.Value; entity.Remark = this.txtRemark.Text; }
/// <summary> /// /// This method will apply the arithmetic rule to either the transaction record or the current (i.e., database) record, /// using the other record as a reference. /// /// <param name="poTransactionRecord">The incoming record</param> /// <param name="poCurrentRecord">The current record (i.e., in the database)</param> /// <param name="poErrorMessage">The buffer that will contain an error message if the rule fails</param> /// <returns>Indicates whether or not the target product passed the rule successfully</returns> /// </summary> public override bool Execute(WonkaProduct poTransactionRecord, WonkaProduct poCurrentRecord, StringBuilder poErrorMessage) { bool bResult = false; WonkaProduct TargetRecord = null; WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.GetInstance(); int nAttrId = TargetAttribute.AttrId; int nGroupId = TargetAttribute.GroupId; if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD) { TargetRecord = poTransactionRecord; } else if (RecordOfInterest == TARGET_RECORD.TRID_OLD_RECORD) { TargetRecord = poCurrentRecord; } else { throw new Exception("ERROR! The target record is none!"); } string sTargetData = TargetRecord.GetPrimaryAttributeData(TargetAttribute.GroupId, TargetAttribute.AttrId); if (sTargetData == null) { sTargetData = string.Empty; } RefreshCache(poTransactionRecord, poCurrentRecord); WonkaPrdGroup TempProductGroup = null; if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } TempProductGroup[0][nAttrId] = Convert.ToString(CalculateValue()); if (poErrorMessage != null) { poErrorMessage.Clear(); poErrorMessage.Append(GetVerboseError(TargetRecord)); } return(bResult); }
public static async Task <TargetRecord> CreateTestTarget(this IRecordContainer <TargetRecord> container, int index) { var target = new TargetRecord { Id = $"Target.{index}", Description = "test target", Enabled = true, }; await container.Set(target); return(target); }
public MonitoringJob(TargetRecord targetRecord, IProbe probe, ILogger <MonitoringJob> logger) { targetRecord.VerifyNotNull(nameof(targetRecord)) .VerifyAssert(x => !x.ReadyUrl.IsEmpty(), x => nameof(x.ReadyUrl)) .VerifyAssert(x => x.FrequencyInSeconds != null, x => nameof(x.FrequencyInSeconds)); probe.VerifyNotNull(nameof(probe)); logger.VerifyNotNull(nameof(logger)); _targetRecord = targetRecord; _probe = probe; _logger = logger; }
public RestProbe(string agentId, TargetRecord targetRecord, HttpClient httpClient, IRecordContainer <TraceRecord> traceContainer, ILogger <RestProbe> logger) { agentId.VerifyNotNull(nameof(agentId)); targetRecord.VerifyNotNull(nameof(targetRecord)); httpClient.VerifyNotNull(nameof(httpClient)); traceContainer.VerifyNotNull(nameof(traceContainer)); logger.VerifyNotNull(nameof(logger)); _agentId = agentId; _targetRecord = targetRecord; _traceContainer = traceContainer; _logger = logger; _httpClient = httpClient; }
/// <summary> /// /// This method will apply the domain rule to either the transaction record or the current (i.e., database) record, /// using the other record as a reference. /// /// <param name="poTransactionRecord">The incoming record</param> /// <param name="poCurrentRecord">The current record (i.e., in the database)</param> /// <param name="poErrorMessage">The buffer that will contain an error message if the rule fails</param> /// <returns>Indicates whether or not the target product passed the rule successfully</returns> /// </summary> public override bool Execute(WonkaProduct poTransactionRecord, WonkaProduct poCurrentRecord, StringBuilder poErrorMessage) { bool bResult = false; WonkaProduct TargetRecord = null; WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.GetInstance(); if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD) { TargetRecord = poTransactionRecord; } else if (RecordOfInterest == TARGET_RECORD.TRID_OLD_RECORD) { TargetRecord = poCurrentRecord; } else { throw new Exception("ERROR! The target record is none!"); } string sTargetData = TargetRecord.GetPrimaryAttributeData(TargetAttribute.GroupId, TargetAttribute.AttrId); if (sTargetData == null) { sTargetData = ""; } RefreshCache(poTransactionRecord, poCurrentRecord); if (DomainCache.Contains(sTargetData)) { bResult = true; } else { bResult = false; } if (poErrorMessage != null) { poErrorMessage.Clear(); poErrorMessage.Append(GetVerboseError(TargetRecord)); } return(bResult); }
// used if distance is small private void ResetRecordArray() { _i = 0; _j = 1; _t = 0f; _records = new TargetRecord[_arraySize]; for (int i = 0; i < _records.Length; i++) { _records[i] = new TargetRecord(transform.position); } _record = _records[_j]; }
/// <summary> /// Performs a string.format on the target field values in each of the records, passing the source field values /// from the RecordConfiguration source configuration as the format args. /// </summary> protected override TargetRecord FormatRecord(TargetRecord targetRecord, RecordConfiguration recordConfiguration) { foreach (var targetField in targetRecord.Fields) { if (targetField.Value.IndexOf('{') < 0) { continue; } try { targetField.Value = string.Format(targetField.Value, targetField.Sources .Select(s => { if (!recordConfiguration.TryGetFieldByName(targetField.Name, out var targetConfig)) { throw new TextWranglerInvalidTargetStateException(recordConfiguration.RecordTypeName, targetField.Name, $"Target field has target name [{targetField.Name}] that does not exist in configuration"); } if (!targetConfig.TryGetSourceByName(s.Name, out var sourceConfig)) { throw new TextWranglerInvalidTargetStateException(recordConfiguration.RecordTypeName, targetField.Name, $"Target field [{targetField.Name}] has source name [{s.Name}] that does not exist in configuration"); } if (sourceConfig.Type.IsNullOrEmpty()) { return(s.Value); } var typedValue = s.Value.ConvertToType(sourceConfig.GetSystemType()); return(typedValue); }) .ToArray()); } catch (FormatException fx) when(fx.Message.IndexOf("Input string was not in", StringComparison.OrdinalIgnoreCase) >= 0) { throw new TextWranglerRecordFieldConfigInvalidException(recordConfiguration.RecordTypeName, targetField.Name, $"Target field [{targetField.Name}] has invalid format string [{targetField.Value}]", fx); } } return(targetRecord); }
public IProbe Create(TargetRecord targetRecord, string agentId, IRecordContainer <TraceRecord>?traceContainer) { targetRecord.VerifyNotNull(nameof(targetRecord)); agentId.VerifyNotEmpty(nameof(agentId)); traceContainer.VerifyNotNull(nameof(traceContainer)); if (!Enum.TryParse(typeof(ProbeType), targetRecord.TargetType, true, out object probeTypeObj)) { throw new InvalidExpressionException($"Unknown target type {targetRecord.TargetType}"); } return((ProbeType)probeTypeObj switch { ProbeType.REST => new RestProbe(agentId !, targetRecord, _httpClientFactory.CreateClient(), traceContainer, _loggerFactory.CreateLogger <RestProbe>()), _ => throw new InvalidOperationException($"Unsupported target type, probeType={probeTypeObj}"), });
private void RecordData(float deltaTime) { if (!_recording) { return; } // check intervals if (_t < _interval) { _t += deltaTime; } // record this frame else { // record target data _records[_i] = new TargetRecord(target.position); // set next record index if (_i < _records.Length - 1) { _i++; } else { _i = 0; } // set next follow index if (_j < _records.Length - 1) { _j++; } else { _j = 0; } // handle current record _record = _records[_j]; _t = 0f; } }
/// <summary> /// 显示信息 /// </summary> /// <param name="entity"></param> private void DisplayInfo(TargetRecord entity) { this.txtDepartmentName.Text = BusinessFactory <DepartmentBusiness> .Instance.FindById(entity.DepartmentId).Name; this.txtType.Text = Poseidon.Core.Utility.DictUtility.GetDictValue(entity, "Type", entity.Type); this.txtFinance.Text = entity.Finance; this.spSchoolTake.Value = entity.SchoolTake; this.spSelfTake.Value = entity.SelfTake; this.txtRemark.Text = entity.Remark; this.txtPlanQuantum.Text = entity.PlanQuantum.ToString(); this.txtPlanAmount.Text = entity.PlanAmount.ToString(); this.txtCreateUser.Text = entity.CreateBy.Name; this.txtCreateTime.Text = entity.CreateBy.Time.ToDateTimeString(); this.txtEditUser.Text = entity.UpdateBy.Name; this.txtEditTime.Text = entity.UpdateBy.Time.ToDateTimeString(); this.stGrid.DataSource = entity.StaffTarget; this.atGrid.DataSource = entity.AllowanceTarget; }
private async Task WriteRecord(string recordType, string json, CancellationToken token) { switch (recordType) { case nameof(AgentRecord): AgentRecord agentRecord = _json.Deserialize <AgentRecord>(json); await _agentContainer.Set(agentRecord, token); break; case nameof(TargetRecord): TargetRecord targetRecord = _json.Deserialize <TargetRecord>(json); await _targetContainer.Set(targetRecord, token); break; default: throw new ArgumentException($"Unknown record type for importing, recordType={recordType}"); } }
private void InitData(string id) { this.currentRecord = BusinessFactory <TargetRecordBusiness> .Instance.FindById(id); this.currentTarget = BusinessFactory <TargetBusiness> .Instance.FindById(this.currentRecord.TargetId); }
/// <summary> /// 能源结算记录转报表模型 /// </summary> /// <param name="departmentName">部门名称</param> /// <param name="settlement">能源结算</param> /// <param name="entity">能源结算记录</param> /// <param name="targetRecord">指标记录</param> /// <returns></returns> public static SettlementReportModel SettlementReportTranslate(string departmentName, Settlement settlement, SettlementRecord entity, TargetRecord targetRecord) { SettlementReportModel model = new SettlementReportModel(); model.DepartmentName = departmentName; model.Term = settlement.BelongTime; if (entity.EnergyType == (int)EnergyType.Electric) { model.EnergyType = "电"; model.Unit = "度"; model.UnitPrice = string.Format("{0} 元/度", entity.UnitPrice); } else if (entity.EnergyType == (int)EnergyType.Water) { model.EnergyType = "水"; model.Unit = "吨"; model.UnitPrice = string.Format("{0} 元/吨", entity.UnitPrice); } if (targetRecord == null) { model.PlanQuantum = 0; model.PlanAmount = 0; } else { model.PlanQuantum = targetRecord.PlanQuantum; model.PlanAmount = targetRecord.PlanAmount; } model.LastQuantum = model.PlanQuantum - entity.BeginQuantum; model.LastAmount = model.PlanAmount - entity.BeginAmount; model.Quantum = entity.Quantum; model.Amount = entity.Amount; model.EndQuantum = entity.BeginQuantum - entity.Quantum; model.EndAmount = entity.BeginAmount - entity.Amount; return(model); }
protected abstract TargetRecord FormatRecord(TargetRecord record, RecordConfiguration recordConfiguration);
/// <summary> /// /// This method will apply the assignment rule to either the transaction record or the current (i.e., database) /// record, using the other record as a reference. /// /// <param name="poTransactionRecord">The incoming record</param> /// <param name="poCurrentRecord">The current record (i.e., in the database)</param> /// <param name="poErrorMessage">The buffer that will contain an error message if the rule fails</param> /// <returns>Indicates whether or not the target product passed the rule successfully</returns> /// </summary> public override bool Execute(WonkaProduct poTransactionRecord, WonkaProduct poCurrentRecord, StringBuilder poErrorMessage) { bool bResult = false; WonkaProduct TargetRecord = null; WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.GetInstance(); int nAttrId = TargetAttribute.AttrId; int nGroupId = TargetAttribute.GroupId; if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD) { TargetRecord = poTransactionRecord; } else if (RecordOfInterest == TARGET_RECORD.TRID_OLD_RECORD) { TargetRecord = poCurrentRecord; } else { throw new Exception("ERROR! The target record is none!"); } string sTargetData = TargetRecord.GetPrimaryAttributeData(TargetAttribute.GroupId, TargetAttribute.AttrId); if (sTargetData == null) { sTargetData = string.Empty; } RefreshCache(poTransactionRecord, poCurrentRecord); WonkaPrdGroup TempProductGroup = null; if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } if ((CustomOpDelegate == null) && (CustomOpSource.CustomOpDelegate != null)) { CustomOpDelegate = CustomOpSource.CustomOpDelegate; } if (CustomOpDelegate != null) { string[] CustomOpArgs = new string[4]; for (int idx = 0; idx < 4; ++idx) { if (idx < DomainCache.Count()) { CustomOpArgs[idx] = DomainCache.ElementAt(idx); } else { CustomOpArgs[idx] = string.Empty; } } string sCustomOpResult = CustomOpDelegate(CustomOpArgs[0], CustomOpArgs[1], CustomOpArgs[2], CustomOpArgs[3]); // NOTE: If the result is empty, we consider the rule's invocation as a failure if (!String.IsNullOrEmpty(sCustomOpResult)) { TempProductGroup[0][nAttrId] = sCustomOpResult; bResult = true; } if (poErrorMessage != null) { poErrorMessage.Clear(); poErrorMessage.Append(GetVerboseError(TargetRecord)); } } return(bResult); }
private void ProcessFiles(string File1, string File2) { const string CrLf = "\r\n"; List <string> SL1 = new List <string>(); List <string> SL2 = new List <string>(); List <TargetRecord> Tbl = new List <TargetRecord>(); TargetRecord LocalRecord; string StrLine = ""; string TargetCSV = ""; SL1 = ReadTextFile(File1); SL2 = ReadTextFile(File2); for (var I = 1; I <= SL1.Count - 1; I++) { LocalRecord = new TargetRecord(); StrLine = SL1[I].Trim(); if (StrLine != "") { LocalRecord.AccountCode = ParseStr(ParseStr(StrLine, 1), 2, "|"); LocalRecord.Name = ParseStr(StrLine, 2); LocalRecord.OpenDate = ParseStr(StrLine, 4); LocalRecord.Currency = ParseStr(StrLine, 5); LocalRecord.Type = FindInStringList(SL2, LocalRecord.Name, 1, 2); Tbl.Add(LocalRecord); } LocalRecord = default(TargetRecord); } SL1 = null; SL2 = null; LocalRecord = new TargetRecord(); FieldInfo[] FieldNames = LocalRecord.GetType().GetFields(); LocalRecord = default(TargetRecord); foreach (FieldInfo field in FieldNames) { TargetCSV = TargetCSV + field.Name + ";"; } TargetCSV = TargetCSV + CrLf; for (var I = 0; I <= Tbl.Count - 1; I++) { TargetCSV = TargetCSV + Tbl[I].AccountCode + ";" + Tbl[I].Name + ";" + Tbl[I].Type + ";" + Tbl[I].OpenDate + ";" + Tbl[I].Currency + CrLf; } try { System.IO.StreamWriter objWriter = new System.IO.StreamWriter(Application.StartupPath + @"\Target.csv"); objWriter.Write(TargetCSV); objWriter.Close(); objWriter = null; MessageBox.Show("Target.csv file created!"); } catch (Exception ex) { MessageBox.Show("ERROR! : Target.csv file couldn't created!"); } Tbl = null; }
/// <summary> /// /// This method will apply the arithmetic limit rule to either the incoming record or the current (i.e., database) /// record, using the other record as a reference. /// /// <param name="poTransactionRecord">The incoming record</param> /// <param name="poCurrentRecord">The current record (i.e., the already existing record)</param> /// <param name="poErrorMessage">The buffer that will contain an error message if the rule fails</param> /// <returns>Indicates whether or not the target product passed the rule successfully</returns> /// </summary> public override bool Execute(WonkaProduct poTransactionRecord, WonkaProduct poCurrentRecord, StringBuilder poErrorMessage) { bool bResult = false; WonkaProduct TargetRecord = null; WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.GetInstance(); if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD) { TargetRecord = poTransactionRecord; } else if (RecordOfInterest == TARGET_RECORD.TRID_OLD_RECORD) { TargetRecord = poCurrentRecord; } else { throw new Exception("ERROR! The target record is none!"); } string sTargetData = TargetRecord.GetPrimaryAttributeData(TargetAttribute.GroupId, TargetAttribute.AttrId); if (!String.IsNullOrEmpty(sTargetData)) { RefreshMinAndMax(poTransactionRecord, poCurrentRecord); try { double dTargetValue = Convert.ToDouble(sTargetData); if ((this.MaxValue >= dTargetValue) && (dTargetValue >= this.MinValue)) { bResult = true; } else { bResult = false; } if (poErrorMessage != null) { poErrorMessage.Clear(); poErrorMessage.Append(GetVerboseError(TargetRecord)); } } catch (Exception ex) { bResult = false; if (poErrorMessage != null) { poErrorMessage.Clear(); poErrorMessage.Append(ex.ToString()); } } } return(bResult); }
/// <summary> /// 设置指标记录 /// </summary> /// <param name="id">指标记录ID</param> public void SetTargetRecord(string id) { this.currentRecord = BusinessFactory <TargetRecordBusiness> .Instance.FindById(id); DisplayInfo(this.currentRecord); }