Ejemplo n.º 1
0
 public Parameter GetParameter(ParameterTagId tagId)
 {
     return this.Parameters.Single(p => p.TagId == tagId);
 }
Ejemplo n.º 2
0
 public Parameter GetParameter(ParameterTagId tagId)
 {
     return this.ParameterList.First(p => p.TagId == tagId);
 }
Ejemplo n.º 3
0
 public string GetParameterScanValue(ParameterTagId tagId)
 {
     return this.ParameterList.First(p => p.TagId == tagId).ScannedValue ?? string.Empty;
 }
        public static void UpdateParamTargetValue(string parameterInfoSetName, ParameterTagId tagId, string newValue, bool isActive, bool isAutoincrement)
        {
            using (var context = ApplicationDbContext.Create())
            {
                var ps =
                    context.ParameterInfoSets.Include(s => s.ParameterInfos)
                        .FirstOrDefault(s => s.Name == parameterInfoSetName);

                if (ps == null)
                {
                    throw new NullReferenceException("No parameterInfoSet found with name: " + parameterInfoSetName);
                }

                var param = ps.ParameterInfos.FirstOrDefault(p => p.TagId == tagId);
                if (param == null)
                {
                    throw new NullReferenceException("No paramter found with tagId: " + tagId);
                }

                // update settings
                param.InitialValue = newValue;
                param.IsActive = isActive;
                param.IsAutoIncrement = isAutoincrement;

                if (tagId == ParameterTagId.ManufacturerSerialNumber)
                {
                    // update serverid when serialnumber is changed
                    var serverIdParam = ps.ParameterInfos.First(p => p.TagId == ParameterTagId.ServerId);
                    var bytesStr = serverIdParam.InitialValue.Split('-');
                    var bytes = BitConverter.GetBytes(int.Parse(param.InitialValue)).Reverse().ToArray();

                    bytesStr[bytesStr.Length - 1] = string.Format("{0:X2}", bytes[3]);
                    bytesStr[bytesStr.Length - 2] = string.Format("{0:X2}", bytes[2]);
                    bytesStr[bytesStr.Length - 3] = string.Format("{0:X2}", bytes[1]);
                    bytesStr[bytesStr.Length - 4] = string.Format("{0:X2}", bytes[0]);

                    serverIdParam.InitialValue = string.Join("-", bytesStr);
                }

                context.ParameterInfos.AddOrUpdate(param);
                context.SaveChanges();
            }
        }