public IActionResult Put(int id, [FromBody] TagDefViewModel tagdef) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TagDef _tagdefDb = _tagdefRepository.GetSingle(id); if (_tagdefDb == null) { return(NotFound()); } else { _tagdefDb.Source = tagdef.Source; _tagdefDb.Name = tagdef.Name; _tagdefDb.Description = tagdef.Description; _tagdefDb.ExtendedDescription = tagdef.ExtendedDescription; _tagdefRepository.Commit(); } tagdef = Mapper.Map <TagDef, TagDefViewModel>(_tagdefDb); return(new NoContentResult()); }
public IActionResult GetTagDef(int id) { TagDef _tagdef = _tagdefRepository.GetSingle(u => u.Id == id); if (_tagdef != null) { TagDefViewModel _tagdefVM = Mapper.Map <TagDef, TagDefViewModel>(_tagdef); return(new OkObjectResult(_tagdefVM)); } else { return(NotFound()); } }
public IActionResult Get() { if (Request.Query.Count() > 0) { //List<TagDef> result; foreach (var param in Request.Query) { TagDef _tagdef = _tagdefRepository.GetSingle(u => u.Name.Equals(param.Value, StringComparison.CurrentCultureIgnoreCase)); if (_tagdef != null) { TagDefViewModel _tagdefVM = Mapper.Map <TagDef, TagDefViewModel>(_tagdef); return(new OkObjectResult(_tagdefVM)); } else { return(NotFound()); } } } var pagination = Request.Headers["Pagination"]; if (!string.IsNullOrEmpty(pagination)) { string[] vals = pagination.ToString().Split(','); int.TryParse(vals[0], out page); int.TryParse(vals[1], out pageSize); } int currentPage = page; int currentPageSize = pageSize; var totalRecs = _tagdefRepository.Count(); var totalPages = (int)Math.Ceiling((double)totalRecs / pageSize); IEnumerable <TagDef> _tagdefs = _tagdefRepository .GetAll() .OrderBy(u => u.Id) .Skip((currentPage - 1) * currentPageSize) .Take(currentPageSize) .ToList(); IEnumerable <TagDefViewModel> _tagdefsVM = Mapper.Map <IEnumerable <TagDef>, IEnumerable <TagDefViewModel> >(_tagdefs); Response.AddPagination(page, pageSize, totalRecs, totalPages); return(new OkObjectResult(_tagdefsVM)); }
public IActionResult Delete(int id) { TagDef _tagdefDb = _tagdefRepository.GetSingle(id); if (_tagdefDb == null) { return(new NotFoundResult()); } else { _taghistRepository.DeleteWhere(a => a.TagDefId == id); _tagdefRepository.Delete(_tagdefDb); _tagdefRepository.Commit(); return(new NoContentResult()); } }
public IActionResult GetTagsCurrentValue(string TagName) { if (string.IsNullOrEmpty(TagName)) { return(NotFound()); } TagDef _tagdef = _tagdefRepository.GetSingle(u => u.Name.Equals(TagName, StringComparison.CurrentCultureIgnoreCase)); if (_tagdef != null) { TagDefViewModel _userVM = Mapper.Map <TagDef, TagDefViewModel>(_tagdef); return(new OkObjectResult(_userVM)); } else { return(NotFound()); } }
public IActionResult Create([FromBody] TagDefViewModel tagdef) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TagDef _newTag = new TagDef { Name = tagdef.Name, Description = tagdef.Description, ExtendedDescription = tagdef.ExtendedDescription }; _tagdefRepository.Add(_newTag); _tagdefRepository.Commit(); tagdef = Mapper.Map <TagDef, TagDefViewModel>(_newTag); CreatedAtRouteResult result = CreatedAtRoute("GetTagDef", new { controller = "TagDefs", id = tagdef.Id }, tagdef); return(result); }
protected Dictionary <string, TagDef> GetTagDef(XDocument doc) { var nodeName = "TagDef"; var result = new Dictionary <string, TagDef>(); var tagDefs = doc.Descendants(ns + nodeName); if (tagDefs != null) { foreach (var item in tagDefs) { var def = new TagDef(); def.Index = GetAttibuteValue(item, "index"); def.Name = GetAttibuteValue(item, "name"); def.Symbol = GetAttibuteValue(item, "symbol"); def.Type = GetAttibuteValue(item, "type"); result.Add(def.Index, def); } } return(result); }
static Interpreter() { TagFuncs = new Dictionary<string, TagDef>(); TagFuncs["rep"] = TagFuncs["r"] = new TagDef(Repeat, TagArgType.Result); TagFuncs["num"] = TagFuncs["n"] = new TagDef(Number, TagArgType.Result, TagArgType.Result); TagFuncs["sep"] = TagFuncs["s"] = new TagDef(Separator, TagArgType.Tokens); TagFuncs["before"] = new TagDef(Before, TagArgType.Tokens); TagFuncs["after"] = new TagDef(After, TagArgType.Tokens); TagFuncs["chance"] = new TagDef(Chance, TagArgType.Result); TagFuncs["sync"] = new TagDef(Sync, TagArgType.Result, TagArgType.Result); TagFuncs["desync"] = new TagDef(Desync); TagFuncs["pin"] = new TagDef(Pin, TagArgType.Result); TagFuncs["unpin"] = new TagDef(Unpin, TagArgType.Result); TagFuncs["step"] = new TagDef(Step, TagArgType.Result); TagFuncs["reset"] = new TagDef(Reset, TagArgType.Result); TagFuncs["first"] = new TagDef(First, TagArgType.Tokens); TagFuncs["last"] = new TagDef(Last, TagArgType.Tokens); TagFuncs["middle"] = new TagDef(Middle, TagArgType.Tokens); TagFuncs["notfirst"] = new TagDef(NotFirst, TagArgType.Tokens); TagFuncs["notlast"] = new TagDef(NotLast, TagArgType.Tokens); TagFuncs["notmiddle"] = new TagDef(NotMiddle, TagArgType.Tokens); TagFuncs["odd"] = new TagDef(Odd, TagArgType.Tokens); TagFuncs["even"] = new TagDef(Even, TagArgType.Tokens); TagFuncs["nth"] = new TagDef(Nth, TagArgType.Result, TagArgType.Result, TagArgType.Tokens); TagFuncs["repnum"] = TagFuncs["rn"] = new TagDef(RepNum); TagFuncs["repindex"] = TagFuncs["ri"] = new TagDef(RepIndex); TagFuncs["repcount"] = TagFuncs["rc"] = new TagDef(RepCount); TagFuncs["alt"] = new TagDef(Alt, TagArgType.Tokens, TagArgType.Tokens); TagFuncs["match"] = new TagDef(ReplaceMatch); TagFuncs["group"] = new TagDef(ReplaceGroup, TagArgType.Result); TagFuncs["arg"] = new TagDef(Arg, TagArgType.Result); TagFuncs["numfmt"] = new TagDef(NumFmt, TagArgType.Result); TagFuncs["caps"] = new TagDef(Caps, TagArgType.Result); TagFuncs["capsinfer"] = new TagDef(CapsInfer, TagArgType.Result); TagFuncs["out"] = new TagDef(Out, TagArgType.Result, TagArgType.Result); TagFuncs["close"] = new TagDef(Close, TagArgType.Result); TagFuncs["extern"] = new TagDef(Extern, TagArgType.Result); }
public async void EditTag(TagDef item) { await StoreItem(item); }
public void DeleteTag(TagDef item) { DeleteItem(item); }
/// <summary> /// Чтение приращений (показаний) /// </summary> /// <param name="fromTime"></param> /// <param name="typeQuery"></param> /// <param name="typeInc"></param> /// <param name="aplus"></param> /// <param name="aminus"></param> /// <param name="rplus"></param> /// <param name="rminus"></param> /// <param name="depth"></param> /// <param name="deepSyncTime"></param> /// <param name="tariff"> /// Добавлена поддержка чтения тарифов для показаний, т.к. эту величину нельзя расчитать. /// </param> static internal void ReadInc( QueryInfo info, DateTimeZone fromTime, TypeQuery typeQuery, TypeInc typeInc, TagDef aplus, TagDef aminus, TagDef rplus, TagDef rminus, int depth, DateTimeUtc deepSyncTime, ETariff tariff = ETariff.NoTariff) { //Если в гране нет данных то дальше этой даты записываем что нельзя востонавить bool fillBadNoRestore = false; int itemNum = 0; OperationResult oper = new OperationResult(Quality.Bad); var holes = info.GetHoles(typeInc, fromTime, depth, deepSyncTime, new[] { aplus }); var reversedHoles = holes.Reverse(); foreach (var item in reversedHoles) { itemNum++; Energy read = null; OperationResult res = OperationResult.Bad; if (fillBadNoRestore) { read = new Energy(0, 0, 0, 0); oper = new OperationResult(Quality.BadNoRestore); } else if (info.Session.BeginOperation()) { if (DataBusSetting.StubData) //STUBDATA-> { read = new Energy(StubUtil.Int32(500), StubUtil.Int32(600), StubUtil.Int32(700), StubUtil.Int32(800)); oper = new OperationResult(Quality.Good); } else { switch (typeQuery) { #region (case TypeQuery.SlicesEnergy:) case TypeQuery.SlicesEnergy: if (!info.IsHalfHourInterval) { oper = new OperationResult(Quality.Bad, "HalfHour Interval is incorrect!"); } else { // только для версий СЕ102 S7, R8, CE301M S31, R33 // версии CE102 S6, R5 не поддерживают архив получасов oper = info.Request.TryReadSlicesEnergy( info.DataBus, info.Cs.Psw, info.Session.TimeDevice, SlicesQuery.From(item, info.Cs.Address), out read); read.Calc(info.DeviceKoef); } break; #endregion #region (case TypeQuery.Counter:) case TypeQuery.Counter: oper = info.Request.TryReadCounter( info.DataBus, info.Cs.Psw, typeInc, RequestIndex.From(item, typeInc, info.Cs.Address, true), tariff, out read); read.Calc(info.DeviceKoef); break; #endregion /*#region (case TypeQuery.Power3min:) * case TypeQuery.Power3min: * AvPowerIndex pi; * oper = info.Request.TryReadAvPower3min( * info.DataBus, * info.Session.TimeDevice, * info.Session.Zone, * RequestIndex.From(item, typeInc, info.Cs.Address, false), * item, * out pi); * if (oper.IsGood) * read = pi.Power.ToEnergy(20); * break; #endregion*/ } //Может возникать ситуация когда на компе уже наступило время опроса а на счетчике нет и будет возвращен блок поврежден //TODO if ((itemNum < 3) && (oper.Quality == Quality.BadNoRestore)) oper.Quality = Quality.Bad; } /*if ((!oper.IsGood) && (oper.Code == 2)) * { * if (info.Session.OpenData.NewDevice != ChangeDeviceInfo.None) * info.LogWarn(SR.NOT_PARAM, info.DisplayName, aplus.AccountKind, aplus.Discrete, aplus.DiscreteValue); * info.Session.EndOperation(OperationResult.Good); * break; //Неизвестная функция не подерживаемая версией устройства * }*/ info.Session.EndOperation(oper); if (!oper.IsGood) { read = new Energy(0, 0, 0, 0); info.DataBus.DiscardInBuffer(); } if (oper.Quality == Quality.BadNoRestore) { fillBadNoRestore = true; //заполним все полохими не востанавливаемыми } } else { break; } info.Storage.WriteTagsValue( HW(oper.Quality, read.Aplus, item, aplus), HW(Quality.Bad, read.Aminus, item, aminus), HW(Quality.Bad, read.Rplus, item, rplus), HW(Quality.Bad, read.Rminus, item, rminus)); if (info.Log.Trace.IsOn(2)) { var sb = new StringBuilder(); sb.AppendFormat("Read from [{0}] {1} {2}", item, typeInc, oper.Quality); if (typeQuery != TypeQuery.SlicesEnergy) { sb.Append(" " + typeQuery); } if (!oper.IsGood) { sb.AppendFormat(". Error: {0}", oper.ErrorMsg); info.Log.Trace.Error(2, sb.ToString()); } else { sb.AppendFormat(". A+: {0}, A-: {1}, R+: {2}, R-: {3}", read.Aplus, read.Aminus, read.Rplus, read.Rminus); info.Log.Trace.Info(2, sb.ToString()); } } } }
public async Task <long> CreateTag(TagDef item) { var result = await StoreItem(item); return(result); }
private static HistoryData HW(Quality quality, DataDriverEvent @value, DateTimeUtc timeWrite, TagDef tagDef) { return(new HistoryData( tagDef, new TagData(quality, DateTimeUtc.Now, TagValue.FromObject(DataType.Structured, value)), timeWrite, HistoryWriterKind.Insert)); }
private static HistoryData HW(Quality quality, double @value, DateTimeUtc timeWrite, TagDef tagDef) { return(new HistoryData( tagDef, new TagData(quality, DateTimeUtc.Now, value), timeWrite, HistoryWriterKind.InsertUpdate)); }
private static void InitializeTaxonomy() { if (!context.Tags.Any()) { TagDef pt_01 = new TagDef { Source = "eDNA", Name = "PRISMLAKE_01", Description = "Prism Data Lake Point 01", ExtendedDescription = "Prism Data Lake Point 01 Extended Description" }; TagDef pt_02 = new TagDef { Source = "pi", Name = "PRISMLAKE_02", Description = "Prism Data Lake Point 02", ExtendedDescription = "Prism Data Lake Point 02 Extended Description" }; TagDef pt_03 = new TagDef { Source = "ODBC", Name = "PRISMLAKE_03", Description = "Prism Data Lake Point 03", ExtendedDescription = "Prism Data Lake Point 03 Extended Description" }; TagDef pt_04 = new TagDef { Source = "eDNA", Name = "PRISMLAKE_04", Description = "Prism Data Lake Point 04", ExtendedDescription = "Prism Data Lake Point 04 Extended Description" }; TagDef pt_05 = new TagDef { Source = "pi", Name = "PRISMLAKE_05", Description = "Prism Data Lake Point 05", ExtendedDescription = "Prism Data Lake Point 05 Extended Description" }; TagDef pt_06 = new TagDef { Source = "eDNA", Name = "PRISMLAKE_06", Description = "Prism Data Lake Point 06", ExtendedDescription = "Prism Data Lake Point 06 Extended Description" }; context.Tags.Add(pt_01); context.Tags.Add(pt_02); context.Tags.Add(pt_03); context.Tags.Add(pt_04); context.Tags.Add(pt_05); context.Tags.Add(pt_06); context.SaveChanges(); } //if (!context.Historian.Any()) //{ // double startAngle = 0.0; // List<DateTime> times = new List<DateTime>(); // DateTime start = DateTime.UtcNow; // for (int i = 0; i < 10; i++) // times.Add(start.AddHours(-1 * i)); // for (int pointIndex = 1; pointIndex < 7; pointIndex++) // { // startAngle = 0.0; // for (int recIndex = 0; recIndex < 12; recIndex++) // { // TagHist hist_x = new TagHist // { // TagDefId = pointIndex, // TagName = context.Tags.FirstOrDefault(t => t.Id == pointIndex).Name, // TimeStamp = times[recIndex], // Value = GenerateValue(pointIndex, startAngle) // }; // startAngle += 30; // context.Historian.Add(hist_x); // } // } //} //context.SaveChanges(); }
public void Put(TagDef item) { Service.EditTag(item); }
public async Task <HttpResponseMessage> Post(TagDef item) { var id = await Service.CreateTag(item); return(Request.CreateResponse(HttpStatusCode.Accepted, id)); }