private string AddParameter(TesterParameterCodeType type, string sourceXml, string parameterName, string parameterValue)
        {
            if (string.IsNullOrWhiteSpace(sourceXml))
            {
                sourceXml = $"<ProductCode><{type}></{type}></ProductCode>";
            }

            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(sourceXml);
            var deviceParametersNode = xmlDocument.SelectSingleNode($"//ProductCode/{type}");

            if (deviceParametersNode == null)
            {
                var rootNode = xmlDocument.SelectSingleNode($"//ProductCode");
                deviceParametersNode = xmlDocument.CreateElement(type.ToString());
                rootNode.AppendChild(deviceParametersNode);
            }

            var newParameter = xmlDocument.CreateElement(parameterName);
            newParameter.InnerText = parameterValue;
            deviceParametersNode.AppendChild(newParameter);

            var stringWriter = new StringWriter();
            xmlDocument.Save(stringWriter);
            return stringWriter.ToString();
        }
        private string RemoveParameter(TesterParameterCodeType type, string sourceXml, string parameterName, string parameterValue/*, int index*/)
        {
            XDocument doc = XDocument.Parse(sourceXml); // or XDocument.Parse(string)
            doc.Root.Descendants().Where(e => e.Name == parameterName && e.Value == parameterValue).Remove();

            //var xmlDocument = new XmlDocument();
            //xmlDocument.LoadXml(sourceXml);

            //var output = xmlDocument.GetElementsByTagName(parameterName);
            //var parameterNode = xmlDocument.SelectNodes($"//ProductCode/{type}/{parameterName}");
            //if (parameterNode == null) return sourceXml;

            //foreach (XmlNode node in output)
            //{
            //    if (node.InnerText == parameterValue)
            //    {
            //        //node.RemoveChild();
            //    }
            //}
            //parameterNode[index].ParentNode.RemoveChild(parameterNode[index]);

            var stringWriter = new StringWriter();
            doc.Save(stringWriter);
            return stringWriter.ToString();
        }
        private string EditParameter(TesterParameterCodeType type, string sourceXml,
            string oldParameterName, string oldParameterValue, string newParameterName,
            string parameterValue/*, int index*/)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(sourceXml);

            var parameterNode = xmlDocument.GetElementsByTagName(oldParameterName);
            //var parameterNode = xmlDocument.SelectNodes($"//ProductCode/{type}/{oldParameterName}");
            if (parameterNode == null) return sourceXml;

            foreach (XmlNode node in parameterNode)
            {
                if (string.IsNullOrEmpty(oldParameterValue))
                {
                    node.InnerText = parameterValue;
                }
                else if (node.InnerText == oldParameterValue)
                {
                    node.InnerText = parameterValue;
                }
            }

            var stringWriter = new StringWriter();
            xmlDocument.Save(stringWriter);
            return stringWriter.ToString();
        }
示例#4
0
        private string GetParameter(TesterParameterCodeType type, string sourceXml, string parameterName, int index)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(sourceXml);

            var parameterNode = xmlDocument.SelectNodes($"//ProductCode/{type}/{parameterName}");

            return(parameterNode[index]?.InnerText);
        }
示例#5
0
        public async Task <IActionResult> Delete(int id, TesterParameterCodeType type, string parameterName, int revision, string parameterValue)
        {
            var product = await _context.TesterParameters.FirstOrDefaultAsync(x => x.Id == id);

            if (product == null)
            {
                return(NotFound());
            }

            var model = new EditTesterParameter
            {
                Id             = id,
                Type           = type,
                ParameterName  = parameterName,
                ParameterValue = parameterValue, // GetParameter(type, product.Parameter, parameterName, index),
                Revision       = revision
                                                 //Index = index
            };

            ViewBag.DeviceName = product.DeviceName;
            return(View(model));
        }
示例#6
0
        public IActionResult Edit(int id, TesterParameterCodeType type, string parameterName, string parameterValue, int revision /*int index*/)
        {
            var product = _context.TesterParameters.Where(tp => tp.Id == id && tp.Revision == revision).FirstOrDefault();

            if (product == null)
            {
                return(NotFound());
            }

            var model = new EditTesterParameter
            {
                Id             = id,
                Type           = type,
                ParameterName  = parameterName,
                ParameterValue = parameterValue, // GetParameter(type, product.Parameter, parameterName, index),
                Revision       = revision
                                                 //Index = index
            };

            ViewBag.DeviceName = product.DeviceName;
            return(View(model));
        }
示例#7
0
        public async Task <IActionResult> Add(int id, TesterParameterCodeType type, int revision)
        {
            var product = _context.TesterParameters.Where(tp => tp.Id == id && tp.Revision == revision).FirstOrDefault();

            //var product = await _context.TesterParameters.FindAsync(id);
            if (product == null)
            {
                return(NotFound());
            }

            var model = new EditTesterParameter
            {
                Id       = id,
                Type     = type,
                Revision = revision
            };

            if (type == TesterParameterCodeType.DeviceParameters)
            {
                var dropDownListForDeviceParam = new List <SelectListItem>();
                dropDownListForDeviceParam.Add(new SelectListItem
                {
                    Text  = "Please Select",
                    Value = ""
                });
                foreach (DeviceParametersName paramName in Enum.GetValues(typeof(DeviceParametersName)))
                {
                    dropDownListForDeviceParam.Add(new SelectListItem
                    {
                        Text  = Enum.GetName(typeof(DeviceParametersName), paramName),
                        Value = paramName.ToString()
                    });
                }
                ViewBag.DeviceParameterName = dropDownListForDeviceParam;
            }
            else if (type == TesterParameterCodeType.FirmwareGates)
            {
                var dropDownListForFirmwareGates = new List <SelectListItem>();
                dropDownListForFirmwareGates.Add(new SelectListItem
                {
                    Text  = "Please Select",
                    Value = ""
                });
                foreach (FirmwareGatesName paramName in Enum.GetValues(typeof(FirmwareGatesName)))
                {
                    dropDownListForFirmwareGates.Add(new SelectListItem
                    {
                        Text  = Enum.GetName(typeof(FirmwareGatesName), paramName),
                        Value = paramName.ToString()
                    });
                }
                ViewBag.FirmwareGatesName = dropDownListForFirmwareGates;
            }
            else if (type == TesterParameterCodeType.ModemIncludeList)
            {
                var dropDownListForModemInclude = new List <SelectListItem>();
                dropDownListForModemInclude.Add(new SelectListItem
                {
                    Text  = "Please Select",
                    Value = ""
                });
                foreach (ModemIncludeList paramName in Enum.GetValues(typeof(ModemIncludeList)))
                {
                    dropDownListForModemInclude.Add(new SelectListItem
                    {
                        Text  = Enum.GetName(typeof(ModemIncludeList), paramName),
                        Value = paramName.ToString()
                    });
                }
                ViewBag.ModemIncludeList = dropDownListForModemInclude;
            }
            else
            {
                var dropDownListForModemExclude = new List <SelectListItem>();
                dropDownListForModemExclude.Add(new SelectListItem
                {
                    Text  = "Please Select",
                    Value = ""
                });
                foreach (ModemExcludeList paramName in Enum.GetValues(typeof(ModemExcludeList)))
                {
                    dropDownListForModemExclude.Add(new SelectListItem
                    {
                        Text  = Enum.GetName(typeof(ModemExcludeList), paramName),
                        Value = paramName.ToString()
                    });
                }
                ViewBag.ModemExcludeList = dropDownListForModemExclude;
            }
            ViewBag.DeviceName = product.DeviceName;
            return(View(model));
        }