Exemplo n.º 1
0
 public void CopyFrom(valueInfo sourceInfo)
 {
     m_infos.Clear();
     if (sourceInfo != null)
     {
         foreach (string key in sourceInfo.m_infos.Keys)
         {
             m_infos.Add(key, sourceInfo.m_infos[key]);
         }
     }
 }
Exemplo n.º 2
0
 public bool CheckLowestByInfo(valueInfo inputInfo)
 {
     foreach (string key in inputInfo.m_infos.Keys)
     {
         int value   = inputInfo.GetValueInt(key);
         int myValue = GetValueInt(key);
         if (value > myValue)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 3
0
        public float GetInfoValueFloat(string id, string key)
        {
            if (m_infoList.Count <= 0)
            {
                return(0);
            }
            valueInfo vi = null;

            if (m_infoList.TryGetValue(id, out vi))
            {
                if (vi != null)
                {
                    float value = vi.GetValueFloat(key);
                    return(value);
                }
            }
            return(0);
        }
Exemplo n.º 4
0
        public string GetInfoValue(string id, string key)
        {
            if (m_infoList.Count <= 0)
            {
                return("");
            }
            valueInfo vi = null;

            if (m_infoList.TryGetValue(id, out vi))
            {
                if (vi != null)
                {
                    string value = vi.GetValue(key);
                    return(value);
                }
            }
            return("");
        }
Exemplo n.º 5
0
        public static string ReadFromCSV(string filename)
        {
            if (false == System.IO.File.Exists(filename))
            {
                return(null);
            }
            Encoding     encoding = Encoding.Default;
            FileStream   fs       = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
            StreamReader sr       = new StreamReader(fs, encoding);
            string       content  = sr.ReadToEnd();

            sr.Close();
            fs.Close();
            if (null == content)
            {
                return(null);
            }
            string[] arrLine = content.Split('\n');
            if (null == arrLine)
            {
                return(null);
            }

            valueInfoList reta = new valueInfoList();

            //第一行中文备注,第二行key
            string[] arrKey = arrLine[1].Remove(arrLine[1].Length - 1).Split(',');
            for (int i = 2; i < arrLine.Length - 1; i++)
            {
                string strLine = arrLine[i];
                //每行末尾有一个‘/r’
                strLine = strLine.Remove(arrLine[i].Length - 1);
                string[] arrWord = strLine.Split(',');

                valueInfo viNode = new valueInfo();
                for (int j = 0; j < arrKey.Length; j++)
                {
                    viNode.SetValue(arrKey[j], arrWord[j]);
                }
                reta.m_infoList.Add(i.ToString(), viNode);
            }
            return(content);
        }
Exemplo n.º 6
0
        public bool SetInfoValueFloat(string id, string key, float value)
        {
            float oldValue = GetInfoValueInt(id, key);

            if (oldValue == value)
            {
                return(false);
            }
            if (m_infoList.ContainsKey(id))
            {
                valueInfo vi = null;
                if (m_infoList.TryGetValue(id, out vi))
                {
                    vi.SetValueFloat(key, value);
                }
            }
            else
            {
                valueInfo vi = new valueInfo();
                vi.SetValueFloat(key, value);
                m_infoList.Add(id, vi);
            }
            return(true);
        }
Exemplo n.º 7
0
        static public valueInfoList ReadFromIni(string filename)
        {
            if (false == System.IO.File.Exists(filename))
            {
                return(null);
            }
            Encoding     encoding = Encoding.Default;
            FileStream   fs       = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
            StreamReader sr       = new StreamReader(fs, encoding);
            string       content  = sr.ReadToEnd();

            sr.Close();
            fs.Close();
            if (null == content)
            {
                return(null);
            }
            string[] arrLine = content.Split('\n');
            if (null == arrLine)
            {
                return(null);
            }

            valueInfoList reta    = new valueInfoList();
            string        listKey = "";
            valueInfo     viNode  = new valueInfo();

            for (int i = 0; i < arrLine.Length - 1; i++)
            {
                string strLine = arrLine[i];
                //每行末尾有一个‘/r’
                strLine = strLine.Remove(arrLine[i].Length - 1);

                if (string.IsNullOrWhiteSpace(strLine))
                {
                    continue;
                }

                if (strLine.Trim()[0] == '[')
                {
                    if (listKey != "")
                    {
                        reta.m_infoList.Add(listKey, viNode);
                        listKey = "";
                        viNode  = new valueInfo();
                    }
                    listKey = strLine.Substring(1, strLine.Length - 2);
                }
                else
                {
                    string[] arrWord = strLine.Split('=');
                    if (arrWord.Length > 1)
                    {
                        viNode.SetValue(arrWord[0], arrWord[1]);
                    }
                }
            }
            if (listKey != "")
            {
                reta.m_infoList.Add(listKey, viNode);
            }
            else if (viNode.Count > 0)
            {
                reta.m_infoList.Add("CONFIG", viNode);
            }

            return(reta);
        }