private void AddPropertyForMapperAndDevice(sconnConfigMapper maper, Device edited, int DevNo) { try { iotRepository <DeviceProperty> proprepo = new iotRepository <DeviceProperty>(); DeviceProperty prop = new DeviceProperty(); prop.PropertyName = "Input" + maper.SeqNumber; //TODO read from name cfg prop.Device = edited; prop.LastUpdateTime = DateTime.Now; proprepo.Add(prop); List <DeviceProperty> storeprops = proprepo.GetAll().ToList(); DeviceProperty storedProp = (from s in storeprops where s.PropertyName == prop.PropertyName select s).First(); //create parameter and bind mapper to it iotRepository <DeviceParameter> paramrepo = new iotRepository <DeviceParameter>(); DeviceParameter param = new DeviceParameter(); param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[DevNo]); param.Type = ParamTypeForSconnMapper(maper); param.Property = storedProp; paramrepo.Add(param); List <DeviceParameter> storeparams = paramrepo.GetAll().ToList(); DeviceParameter storedParam = (from p in storeparams where p.Property == param.Property select p).First(); maper.Parameter = storedParam; iotRepository <sconnConfigMapper> mapperRepo = new iotRepository <sconnConfigMapper>(); mapperRepo.Add(maper); } catch (Exception e) { } }
/// <summary> /// Helper method for whether the given value for the <see cref="DeviceParameter"/> is equal with given <see cref="QualityqualityData"/>'s <see cref="TwoFoldValue.FirstValue"/> /// </summary> /// <param name="value">Value to check for.</param> /// <param name="deviceParameter">Which <see cref="DeviceParameter"/> should be checked?</param> /// <param name="qualityData">Which <see cref="QualityqualityData"/> should be checked?</param> /// <returns></returns> private bool IsEqual(string value, DeviceParameter deviceParameter, QualityData qualityData, bool runWithContains = false) { for (int i = 0; i < qualityData.QualityProperties.Count; i++) { if (qualityData.QualityProperties[i].DeviceParameter == deviceParameter) { for (int j = 0; j < qualityData.QualityProperties[i].Argument.Count; j++) { string expectedValue = qualityData.QualityProperties[i].Argument[j].FirstValue; if (runWithContains) { if (value.Contains(expectedValue, StringComparison.OrdinalIgnoreCase)) { return(true); } } if (value == expectedValue) { return(true); } } return(false); } } return(false); }
public async Task <IActionResult> Edit(int id, [Bind("Id,DeviceTypeId,Name")] DeviceParameter deviceParameter) { if (id != deviceParameter.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(deviceParameter); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeviceParameterExists(deviceParameter.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DeviceTypeId"] = new SelectList(_context.DeviceType, "Id", "Id", deviceParameter.DeviceTypeId); return(View(deviceParameter)); }
/// <summary> /// Fetching and writing all device params to JSON (around 319 params are available on the FLIR A65). /// </summary> /// <param name="sourceFile"></param> private void CreateDeviceParamsFiles(string sourceFile) { List <GenICamParameter> deviceParams; try { deviceParams = _camera.DeviceControl.GetDeviceParameters(); } catch (CommandFailedException ex) { Log.Error("Could not load device parameters from camera. Always fails if using emulator.", ex); return; } var mappedValues = from param in deviceParams where DeviceParameter.HasValue(param) select new DeviceParameter(param); var json = JsonConvert.SerializeObject(new DeviceParameters.DeviceParameters { Parameters = mappedValues }, Formatting.Indented); var deviceParamFile = $@"{sourceFile}-DeviceParams.json"; File.WriteAllText(deviceParamFile, json); Publish(Commands.Upload, deviceParamFile); }
/// <summary> /// Helper method for whether the given value for the <see cref="DeviceParameter"/> is within the range of given <see cref="QualityqualityData"/>'s <see cref="TwoFoldValue"/> /// </summary> /// <param name="value">Value to check for.</param> /// <param name="deviceParameter">Which <see cref="DeviceParameter"/> should be checked?</param> /// <param name="qualityData">Which <see cref="QualityqualityData"/> should be checked?</param> /// <returns></returns> private bool IsWithinRange(int value, DeviceParameter deviceParameter, QualityData qualityData) { for (int i = 0; i < qualityData.QualityProperties.Count; i++) { if (qualityData.QualityProperties[i].DeviceParameter == deviceParameter) { for (int j = 0; j < qualityData.QualityProperties[i].Argument.Count; j++) { int expectedMiValue; int expectedMaxValue; string trimmedFirstValue = qualityData.QualityProperties[i].Argument[j].FirstValue.Trim(); string trimmedSecondValue = qualityData.QualityProperties[i].Argument[j].SecondValue.Trim(); if (!int.TryParse(trimmedFirstValue, out expectedMiValue)) { Debug.LogError("[" + qualityData.QualityProperties[i].DeviceParameter + "] first value for [" + qualityData.Quality + "] setting can not be converted to integer. Please check the value given! Value : " + trimmedFirstValue); return(false); } if (!int.TryParse(trimmedSecondValue, out expectedMaxValue)) { Debug.LogError("[" + qualityData.QualityProperties[i].DeviceParameter + "] second value for [" + qualityData.Quality + "] setting can not be converted to integer. Please check the value given! Value : " + trimmedSecondValue); return(false); } if (value >= expectedMiValue && value <= expectedMaxValue) { return(true); } } return(false); } } return(false); }
/// <summary> /// 设备参数采集修改功能 /// </summary> /// <param name="model"></param> /// <returns></returns> public CommonResult <DeviceParameter> UpdatDevParameter(DeviceParameter model) { var result = new CommonResult <DeviceParameter>(); try { // CheckDeviceClass(model, result); if (result.IsSuccess) { var dbSession = new DBService <DeviceParameter>().DbSession; if (dbSession.GetQueryable(t => t.DevpCode == model.DevpCode).FirstOrDefault() == null) { result.IsSuccess = false; result.Message = "不存在该设备参数"; } else { result.Data = dbSession.Update(model); } } } catch (Exception ex) { Utils.Logger.Error(ex.Message); throw ex; } return(result); }
private void AddPropertyForMapperAndDevice(sconnPropertyMapper maper, Device edited, int DevNo) { try { iotContext cont = new iotContext(); DeviceProperty prop = new DeviceProperty(); prop.PropertyName = "Input" + maper.SeqNumber; //TODO read from name cfg Device storedDevice = cont.Devices.Where(d => d.Id == edited.Id).First(); //devRepo.GetById(edited.Id); prop.Device = storedDevice; prop.LastUpdateTime = DateTime.Now; cont.Properties.Add(prop); cont.SaveChanges(); DeviceParameter param = new DeviceParameter(); param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[DevNo]); ParameterType extType = ParamTypeForSconnMapper(maper); ParameterType inType = cont.ParamTypes.Where(p => p.Id == extType.Id).First(); param.Type = inType; param.Property = prop; cont.Parameters.Add(param); cont.SaveChanges(); maper.Parameter = param; cont.PropertyResultMappers.Add(maper); cont.SaveChanges(); } catch (Exception e) { nlogger.ErrorException(e.Message, e); } }
public List <DeviceParameter> SelectAllParameters(int deviceID) { DataBaseContext oDbContext = null; oDbContext = new DataBaseContext(); DeviceParameter oParameter = new DeviceParameter(); var Parameters = oDbContext.deviceParameters.Where(E => E.Device_ID == deviceID).ToList(); return(Parameters); }
public async Task <IActionResult> Create([Bind("Id,DeviceTypeId,Name")] DeviceParameter deviceParameter) { if (ModelState.IsValid) { _context.Add(deviceParameter); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DeviceTypeId"] = new SelectList(_context.DeviceType, "Id", "Name", deviceParameter.DeviceTypeId); return(View(deviceParameter)); }
private bool IsTwoFold(DeviceParameter deviceParameter) { switch (deviceParameter) { case DeviceParameter.RAM: case DeviceParameter.CPUCOUNT: case DeviceParameter.DPI: return(true); default: return(false); } }
public bool ResParamUpdate(DeviceParameter param) { try { iotSharedEntityContext <DeviceParameter> propCont = new iotSharedEntityContext <DeviceParameter>(); propCont.UpdateWithHistory(param); return(true); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(false); } }
public bool PropertyResultParamAdd(DeviceParameter param) { try { iotSharedEntityContext <DeviceParameter> cont = new iotSharedEntityContext <DeviceParameter>(); cont.Add(param); return(true); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(false); } }
public bool ResParamRemove(DeviceParameter domain) { try { iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>(); repo.Delete(domain); return(true); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(false); } }
public bool ResParamAdd(DeviceParameter param) { try { iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>(); repo.Add(param); return(true); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(false); } }
public static bool TryConvert <T, TValue>(DeviceParameter inputParameter, out T outputParameter) where T : IDeviceValueTypedDeviceParameter <TValue>, new() where TValue : struct { if (inputParameter == null) { throw new NullReferenceException($"DeviceValueTypedDeviceParameter:'{typeof(T)}' must be initialized first"); } bool result = false; outputParameter = default; var tempOut = new T(); // create object to get around lack of abstract static methods if (tempOut.IsPossibleValue(inputParameter)) { tempOut.DeviceId = inputParameter.DeviceId; switch (tempOut.ParseType) { case ValueParseTypes.Enum: if (Enum.TryParse(inputParameter.Value, out TValue typedValue)) { tempOut.Value = typedValue; outputParameter = tempOut; result = true; } break; case ValueParseTypes.DateTime: if (DateTime.TryParse(inputParameter.Value, out var dtValue)) { tempOut.Value = (TValue)Convert.ChangeType(dtValue, typeof(TValue)); outputParameter = tempOut; result = true; } break; case ValueParseTypes.Int: if (Int32.TryParse(inputParameter.Value, out var intValue)) { tempOut.Value = (TValue)Convert.ChangeType(intValue, typeof(TValue)); outputParameter = tempOut; result = true; } break; } } return(result); }
public bool InsertParameter(int divice_id, string name, string unit, string parameterDesc) { DataBaseContext oDbContext = null; oDbContext = new DataBaseContext(); DeviceParameter oParameter = new DeviceParameter(); oParameter.Device_ID = divice_id; oParameter.Name = name; oParameter.Unit = unit; oParameter.ParameterDesc = parameterDesc; oDbContext.deviceParameters.Add(oParameter); oDbContext.SaveChanges(); return(true); }
/// <summary> /// 测试设备参数增加功能 /// </summary> /// <param name="model"></param> /// <returns></returns> public CommonResult <DeviceParameter> AddDevParameter(DeviceParameter model) { var result = new CommonResult <DeviceParameter>(); try { var dbSession = new DBService <DeviceParameter>().DbSession; result.Data = dbSession.Insert(model); } catch (Exception ex) { Utils.Logger.Error(ex.Message); throw ex; } return(result); }
public static bool TryConvert <TValue>(DeviceParameter inputParameter, IDeviceValueTypedDeviceParameter <TValue> outputParameter) where TValue : struct { if (inputParameter == null) { throw new ArgumentNullException(nameof(inputParameter)); } else if (outputParameter == null) { throw new ArgumentNullException(nameof(outputParameter)); } bool result = false; if (outputParameter.IsPossibleValue(inputParameter)) { outputParameter.DeviceId = inputParameter.DeviceId; switch (outputParameter.ParseType) { case ValueParseTypes.Enum: if (Enum.TryParse(inputParameter.Value, out TValue typedValue)) { outputParameter.Value = typedValue; result = true; } break; case ValueParseTypes.DateTime: if (DateTime.TryParse(inputParameter.Value, out var dtValue)) { outputParameter.Value = (TValue)Convert.ChangeType(dtValue, typeof(TValue)); result = true; } break; case ValueParseTypes.Int: if (Int32.TryParse(inputParameter.Value, out var intValue)) { outputParameter.Value = (TValue)Convert.ChangeType(intValue, typeof(TValue)); result = true; } break; } } return(result); }
public DeviceParameter DeviceParameterWithId(int ParamId) { try { iotSharedEntityContext <DeviceParameter> devCont = new iotSharedEntityContext <DeviceParameter>(); DeviceParameter dev = devCont.GetById(ParamId); if (dev != null) { return(dev); } return(null); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(new DeviceParameter()); } }
public void PublishParamUpdate(DeviceParameter param) { IIotContextBase cont = new iotContext(); DeviceParameter toUpdate = cont.Parameters.Include("Property").FirstOrDefault(e => e.Id == param.Id); //unbind after parent if (toUpdate.Property != null) { toUpdate.Property.Device = null; toUpdate.Property.ResultParameters = null; } string jsonParam = JsonConvert.SerializeObject(toUpdate); Clients.All.updateParam(jsonParam); }
public void TestDeviceParamQueryTime() { int ReadTestInterations = 50; int maxQueryTimeMs = 25; Stopwatch watch = new Stopwatch(); DeviceProperty prop = context.Properties.FirstOrDefault(); //load initialy watch.Start(); for (int i = 0; i < ReadTestInterations; i++) { DeviceParameter param = context.Parameters .Include(p => p.sconnMappers) .FirstOrDefault(); } watch.Stop(); double TimePerQueryMs = watch.ElapsedMilliseconds / ReadTestInterations; Assert.IsTrue(TimePerQueryMs < maxQueryTimeMs); }
private void AddActionForMapperAndDevice(sconnConfigMapper maper, Device edited, int DevNo) { try { DeviceAction action = new DeviceAction(); action.ActionName = "Output" + maper.SeqNumber; //TODO read from name cfg action.Device = edited; action.LastActivationTime = DateTime.Now; var qry = connector.ActionAdd(action); //copy maper for action sconnConfigMapper actionMaper = new sconnConfigMapper(); actionMaper.ConfigType = maper.ConfigType; actionMaper.SeqNumber = maper.SeqNumber; ParameterType paramtype = ParamTypeForSconnMapper(actionMaper); ActionParameter inparam = new ActionParameter(); inparam.Value = sconnConfigToStringVal(actionMaper, site.siteCfg.deviceConfigs[DevNo]); inparam.Type = paramtype; inparam.Action = action; actionMaper.ActionParam = inparam; qry = connector.ActionParamAdd(inparam); //create parameter and bind mapper to it DeviceParameter param = new DeviceParameter(); param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[DevNo]); param.Type = paramtype; param.Action = action; qry = connector.ParameterAdd(param); maper.Parameter = param; qry = connector.MapperAdd(maper); } catch (Exception e) { } }
static public void StoreParamChange(DeviceParameter param) { try { //add history only if param already in DB iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>(); DeviceParameter stparam = repo.GetById(param.Id); if (stparam != null) { ParameterChangeHistory hist = new ParameterChangeHistory(); hist.Date = DateTime.Now; hist.Property = param; hist.Value = param.Value; iotRepository <ParameterChangeHistory> histrepo = new iotRepository <ParameterChangeHistory>(); histrepo.Add(hist); } } catch (Exception e) { } }
public bool OnParameterChanged(DeviceParameter p) #endif { if (State != DeviceState.Connected) { throw new NotConnectedException(); } var id = p.Identifier.ToR7().FromR7().EnumToInt(); var parameter = Parameters.SingleOrDefault(x => (int)x.Id == (int)id); if (parameter == null) { Debugger.Break(); return(false); } try { bool changed = ((BaseDeviceParameter)parameter).UpdateCachedValue(new int[] { (int)p.CachedValue }); if (changed) { ParameterChanged(this, new ParameterChangedEventArgs() { Parameter = parameter }); } return(changed); } catch (DeviceIsLockedException e) { SetLockStatus(LockState.Locked); return(false); } }
/// <summary> /// Get all the parameters /// </summary> /// <param name="definition">The parameter definition</param> /// <returns></returns> private void StoreParameters(string definition, Dictionary <string, DeviceParameter> parameters) { // Remove all comments definition = Code.RemoveComments(definition); // Extract the part that lists the parameters int s = definition.IndexOf('{'); int e = Code.GetMatchingParenthesis(definition, s); definition = definition.Substring(s + 1, e - s - 1); // Find each parameter Regex param = new Regex(@"(?<flags>\w+)\s*\(\s*""(?<name>[^""]+)""\s*,\s*(?<id>\w+)\s*,\s*(?<type>\w+)\s*,\s*""(?<description>[^""]*)""\s*\)"); var ms = param.Matches(definition); foreach (Match m in ms) { // Get the values var id = m.Groups["id"].Value; var flags = m.Groups["flags"].Value; var name = m.Groups["name"].Value; var type = m.Groups["type"].Value; var description = m.Groups["description"].Value; // Store the parameter if (parameters.ContainsKey(id)) { parameters[id].Names.Add(name); } else { // Add a new parameter to the list var dp = new DeviceParameter(flags, name, description, type); parameters.Add(id, dp); } } }
public override bool IsPossibleValue(DeviceParameter aValue) => Int32.TryParse(aValue.Value, out _);
public override bool IsPossibleValue(DeviceParameter aValue) => ArmingStatusesNames.Contains(aValue.Value);
public virtual bool IsPossibleValue(DeviceParameter aValue) => false;
void iotContext_ParamUpdateEvent(DeviceParameter param) { PublishParamUpdate(param); }
public void UpdateParameter(string paramData) { DeviceParameter param = (DeviceParameter)JsonConvert.DeserializeObject(paramData); //DeviceRestfulService cl = new DeviceRestfulService(); //cl.ResParamUpdate(param); }