Exemplo n.º 1
0
        private static void WriteZAxis(IniSection sectionData, XmlWriter xdfFile, string elemFlag, string elemSize)
        {
            xdfFile.WriteStartElement("XDFAXIS");
            xdfFile.WriteAttributeString("id", "z");

            xdfFile.WriteStartElement("EMBEDDEDDATA");
            xdfFile.WriteAttributeString("mmedtypeflags", elemFlag);
            xdfFile.WriteAttributeString("mmedelementsizebits", elemSize);
            xdfFile.WriteAttributeString("mmedaddress", sectionData.GetValue("Addr"));
            xdfFile.WriteEndElement();

            if (sectionData.Contains("Lim1"))
            {
                xdfFile.WriteElementString("min", sectionData.GetValue("Lim1").Replace("\"", ""));
            }

            if (sectionData.Contains("Lim2"))
            {
                xdfFile.WriteElementString("max", sectionData.GetValue("Lim2").Replace("\"", ""));
            }

            xdfFile.WriteElementString("decimalpl", "2");
            xdfFile.WriteElementString("outputtype", "1");

            WriteValueEquation(sectionData, xdfFile);

            xdfFile.WriteEndElement();
        }
Exemplo n.º 2
0
        private static void WriteTableBegin(IniSection sectionData, XmlWriter xdfFile)
        {
            xdfFile.WriteStartElement("XDFTABLE");
            var flags = 0 | (sectionData.Contains("Lim1") ? 0x10 : 0) | (sectionData.Contains("Lim2") ? 0x20 : 0);

            xdfFile.WriteAttributeString("flags", flags.ToString("X2"));
            xdfFile.WriteElementString("title", sectionData.GetValue("Name").Replace("\"", String.Empty));
            WriteCurrentCategory(xdfFile);
        }
Exemplo n.º 3
0
        public void GetKey()
        {
            StringWriter writer = new StringWriter();

            writer.WriteLine("[Nini]");
            writer.WriteLine(" my key = something");
            IniDocument doc = new IniDocument(new StringReader(writer.ToString()));

            IniSection section = doc.Sections["Nini"];

            Assert.IsTrue(section.Contains("my key"));
            Assert.AreEqual("something", section.GetValue("my key"));
            Assert.IsFalse(section.Contains("not here"));
        }
Exemplo n.º 4
0
        private static void WriteXAxis(IniSection sectionData, XmlWriter xdfFile)
        {
            xdfFile.WriteStartElement("XDFAXIS");
            xdfFile.WriteAttributeString("id", "x");
            xdfFile.WriteElementString("units", sectionData.GetValue("NameX"));
            xdfFile.WriteElementString("outputtype", "4");
            xdfFile.WriteElementString("datatype", "0");
            xdfFile.WriteElementString("unittype", "0");

            int count = Convert.ToInt32(sectionData.GetValue("PixelX"));

            xdfFile.WriteElementString("indexcount", count.ToString());

            if (sectionData.Contains("ReferX"))
            {
                WriteReferAxis(xdfFile, sectionData, count, ReadStr(sectionData, "ReferX", String.Empty));
            }
            else
            {
                double firstX = ReadDouble(sectionData, "FirstX", 0);
                double lastX  = ReadDouble(sectionData, "LastX", 255);
                var    delta  = Math.Round((lastX - firstX) / count, 3, MidpointRounding.AwayFromZero);

                WriteAxisLabels(xdfFile, count, firstX, (float)delta);
            }

            xdfFile.WriteEndElement();
        }
Exemplo n.º 5
0
        private static void WriteYAxis(IniSection sectionData, XmlWriter xdfFile)
        {
            xdfFile.WriteStartElement("XDFAXIS");
            xdfFile.WriteAttributeString("id", "y");
            xdfFile.WriteElementString("units", sectionData.GetValue("NameY"));
            xdfFile.WriteElementString("outputtype", "4");
            xdfFile.WriteElementString("datatype", "0");
            xdfFile.WriteElementString("unittype", "0");

            int count = Convert.ToInt32(sectionData.GetValue("PixelY"));

            xdfFile.WriteElementString("indexcount", count.ToString());

            if (sectionData.Contains("ReferY"))
            {
                WriteReferAxis(xdfFile, sectionData, count, ReadStr(sectionData, "ReferY", String.Empty));
            }
            else
            {
                double firstX = ReadDouble(sectionData, "FirstY", 0);
                double lastX  = ReadDouble(sectionData, "LastY", 255);
                int    delta  = (int)Math.Ceiling((lastX - firstX) / count);

                WriteAxisLabels(xdfFile, count, firstX, delta);
            }

            xdfFile.WriteEndElement();
        }
Exemplo n.º 6
0
        protected object Get(string key, object defaultvalue)
        {
            Trace.Call(key, defaultvalue);

#if CONFIG_GCONF
            try {
                return(_GConf.Get(_GConfPrefix + key));
            } catch (GConf.NoSuchKeyException) {
                if (defaultvalue != null)
                {
                    _Set(key, defaultvalue);
                }
                return(defaultvalue);
            }
#elif CONFIG_NINI
            string     inisection = _IniGetSection(key);
            string     inikey     = _IniGetKey(key);
            IniSection section    = m_IniDocument.Sections[inisection];
            if ((section == null) ||
                (!section.Contains(inikey)))
            {
                if (defaultvalue != null)
                {
                    _Set(key, defaultvalue);
                }
                return(defaultvalue);
            }
            else
            {
                // the section and key exist
                return(_Parse(section.GetValue(inikey)));
            }
#endif
        }
Exemplo n.º 7
0
        /// <summary>
        /// Determine if the specified key exists in the section.
        /// </summary>
        public Boolean KeyExist(String aSection, String aKey)
        {
            IniSection section = mDoc.Sections[aSection];

            if (section != null)
            {
                return(section.Contains(aKey));
            }

            return(false);
        }
Exemplo n.º 8
0
        public void SetKey()
        {
            var doc = new IniDocument();

            var section = new IniSection("new section");

            doc.Sections.Add(section);

            section.Set("new key", "some value");

            Assert.IsTrue(section.Contains("new key"));
            Assert.AreEqual("some value", section.GetValue("new key"));
        }
Exemplo n.º 9
0
        static void WriteSectionBit(XmlWriter xdfFile, IniSection sectionData)
        {
            for (int i = 0; i < 8; i++)
            {
                var addrName = String.Format("Addr{0}", i);
                if (!sectionData.Contains(addrName))
                {
                    continue;
                }
                var addr = sectionData.GetValue(addrName);
                for (int j = 0; j < 8; j++)
                {
                    var bitName = String.Format("Bit{0}{1}", i, j);
                    if (!sectionData.Contains(bitName))
                    {
                        continue;
                    }
                    var bit = sectionData.GetValue(bitName);

                    xdfFile.WriteStartElement("XDFFLAG");
                    //xdfFile.WriteAttributeString("uniqueid", addr);
                    xdfFile.WriteElementString("title", bit);

                    WriteCurrentCategory(xdfFile);

                    xdfFile.WriteStartElement("EMBEDDEDDATA");
                    xdfFile.WriteAttributeString("mmedaddress", addr);
                    xdfFile.WriteAttributeString("mmedelementsizebits", "8");
                    xdfFile.WriteEndElement();

                    xdfFile.WriteElementString("mask", ((int)Math.Pow(2, j)).ToString("X2"));

                    xdfFile.WriteEndElement();
                }
            }
        }
Exemplo n.º 10
0
        protected T Get <T>(string key, T defaultvalue)
        {
#if CONFIG_DEBUG
            Trace.Call(key, defaultvalue);
#endif

            string     inisection = _IniGetSection(key);
            string     inikey     = _IniGetKey(key);
            IniSection section    = m_IniDocument.Sections[inisection];
            if ((section == null) ||
                (!section.Contains(inikey)))
            {
                if (defaultvalue != null)
                {
                    _Set(key, defaultvalue);
                }
                return(defaultvalue);
            }
            else
            {
                // the section and key exist
                string strValue   = section.GetValue(inikey);
                Type   targetType = typeof(T);
                if (targetType == typeof(string))
                {
                    return((T)(object)strValue);
                }
                if (targetType == typeof(string[]))
                {
                    return((T)(object)GetList(key));
                }
                if (targetType == typeof(MessageBufferPersistencyType))
                {
                    return((T)Enum.Parse(typeof(MessageBufferPersistencyType), strValue, true));
                }
                // handle empty booleans and integers
                if (targetType.IsValueType && String.IsNullOrEmpty(strValue))
                {
                    return(default(T));
                }

                return((T)Convert.ChangeType(strValue, targetType));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Removes all INI keys that were removed as config keys.
        /// </summary>
        private void RemoveConfigKeys(IConfig config)
        {
            IniSection section = iniDocument.Sections[config.Name];

            // Remove old keys
            string[] configKeys = config.GetKeys();
            foreach (string configKey in configKeys)
            {
                if (!section.Contains(configKey))
                {
                    // Key doesn't exist, remove
                    config.Remove(configKey);
                }
            }

            // Add or set all new keys
            string[] keys = section.GetKeys();
            for (int i = 0; i < keys.Length; i++)
            {
                string key = keys[i];
                config.Set(key, section.GetItem(i).Value);
            }
        }
Exemplo n.º 12
0
 static string ReadStr(IniSection section, string name, string def)
 {
     return(section.Contains(name) ? section.GetValue(name).Replace("\"", "") : def);
 }
Exemplo n.º 13
0
 static int ReadInt(IniSection section, string name, int def)
 {
     return(section.Contains(name)
                ? Convert.ToInt32(section.GetValue(name).Replace("\"", ""), CultureInfo.InvariantCulture)
                : def);
 }
Exemplo n.º 14
0
 static double ReadDouble(IniSection section, string name, double def)
 {
     return(section.Contains(name)
                ? Convert.ToDouble(section.GetValue(name).Replace("\"", ""), CultureInfo.InvariantCulture)
                : def);
 }