2012-04-24 18:16:33 -03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Xml.Linq;
|
2012-04-25 15:39:03 -03:00
|
|
|
|
using System.Linq;
|
2012-11-25 01:42:46 -04:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2012-04-24 18:16:33 -03:00
|
|
|
|
|
|
|
|
|
namespace ArdupilotMega.Utilities
|
|
|
|
|
{
|
|
|
|
|
public class ParameterMetaDataRepository
|
|
|
|
|
{
|
|
|
|
|
private static XDocument _parameterMetaDataXML;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="ParameterMetaDataRepository"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ParameterMetaDataRepository()
|
|
|
|
|
{
|
2012-07-12 11:06:22 -03:00
|
|
|
|
Reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reload()
|
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
string paramMetaDataXMLFileName = String.Format("{0}{1}{2}", Application.StartupPath, Path.DirectorySeparatorChar, ConfigurationManager.AppSettings["ParameterMetaDataXMLFileName"]);
|
2012-07-12 11:06:22 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(paramMetaDataXMLFileName))
|
|
|
|
|
_parameterMetaDataXML = XDocument.Load(paramMetaDataXMLFileName);
|
2012-05-07 11:25:56 -03:00
|
|
|
|
|
2012-07-12 11:06:22 -03:00
|
|
|
|
}
|
|
|
|
|
catch { } // Exception System.Xml.XmlException: Root element is missing.
|
2012-04-24 18:16:33 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the parameter meta data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="nodeKey">The node key.</param>
|
|
|
|
|
/// <param name="metaKey">The meta key.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetParameterMetaData(string nodeKey, string metaKey)
|
|
|
|
|
{
|
|
|
|
|
if(_parameterMetaDataXML != null)
|
|
|
|
|
{
|
|
|
|
|
// Use this to find the endpoint node we are looking for
|
|
|
|
|
// Either it will be pulled from a file in the ArduPlane hierarchy or the ArduCopter hierarchy
|
2012-05-07 11:25:56 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var element = _parameterMetaDataXML.Element("Params").Element(MainV2.cs.firmware.ToString());
|
|
|
|
|
if (element != null && element.HasElements)
|
|
|
|
|
{
|
|
|
|
|
var node = element.Element(nodeKey);
|
|
|
|
|
if (node != null && node.HasElements)
|
|
|
|
|
{
|
|
|
|
|
var metaValue = node.Element(metaKey);
|
|
|
|
|
if (metaValue != null)
|
|
|
|
|
{
|
|
|
|
|
return metaValue.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { } // Exception System.ArgumentException: '' is an invalid expanded name.
|
2012-04-24 18:16:33 -03:00
|
|
|
|
}
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|