Ejemplo n.º 1
0
        static void LoadLookupFile(string fileName)
        {
            // Extract name
            var lookupname = Path.GetFileNameWithoutExtension(fileName).ToLower();
            // Create new list
            DataLookupList dll = new DataLookupList();

            // Add it
            LookupLists.Add(lookupname, dll);
            // Load file
            List <string> sl = File.ReadAllLines(fileName).ToList();

            // Parse File
            foreach (string line in sl)
            {
                string[] fields = line.Split(';');
                if (fields.Length > 1)
                {
                    if (TryFieldParse(fields[0], out UInt64 newID))
                    {
                        DataLookupEntry dle = new DataLookupEntry();
                        dle.ID  = newID;
                        dle.Val = fields[1];
                        if (fields.Length > 2)
                        {
                            dle.Extra = fields[2];
                        }
                        dll.data.Add(newID, dle);
                    }
                }
            }
        }
        public static DataLookupList NLUOrCreate(string lookupName)
        {
            DataLookupList res;

            if (LookupLists.TryGetValue(lookupName, out res))
            {
                return(res);
            }
            res = new DataLookupList();
            LookupLists.Add(lookupName, res);
            return(res);
        }
        static bool LoadLookupFile(string fileName)
        {
            // Extract name
            var lookupname = Path.GetFileNameWithoutExtension(fileName).ToLower();

            // Remove a old list if it already exists
            if (LookupLists.TryGetValue(lookupname, out _))
            {
                LookupLists.Remove(lookupname);
            }

            // Create new list
            DataLookupList dll = new DataLookupList();

            // Add it
            LookupLists.Add(lookupname, dll);
            // Load file
            List <string> sl = File.ReadAllLines(fileName).ToList();
            // Parse File
            var linenumber = 0;

            foreach (string line in sl)
            {
                linenumber++;
                try
                {
                    string[] fields = line.Split(';');
                    if (fields.Length > 1)
                    {
                        if (TryFieldParse(fields[0], out int newID))
                        {
                            DataLookupEntry dle = new DataLookupEntry();
                            dle.ID  = (UInt64)newID;
                            dle.Val = fields[1];
                            if (fields.Length > 2)
                            {
                                dle.Extra = fields[2];
                            }
                            dll.data.Add((UInt64)newID, dle);
                            // for autocomplete
                            AllValues.Add(dle.Val);
                        }
                    }
                }
                catch (Exception x)
                {
                    AllLoadErrors += string.Format("\n\r\n\rException loading {0} at line {1} :\n\r{2}\r\n=> {3}", fileName, linenumber, x.Message, line);
                    return(false);
                }
            }
            return(true);
        }
        public static void RegisterCustomLookup(string customListName, UInt64 customID, string customValue)
        {
            customListName = customListName.ToLower();
            if (customListName == "@math")
            {
                return;
            }
            if (!customListName.StartsWith("@"))
            {
                customListName = "@" + customListName;
            }
            DataLookupList list = null;

            foreach (var ll in LookupLists)
            {
                if (ll.Key.ToLower() == customListName)
                {
                    list = ll.Value;
                    break;
                }
            }
            if (list == null)
            {
                list = new DataLookupList();
                LookupLists.Add(customListName, list);
            }
            foreach (var li in list.data)
            {
                // If a value is already in here, overwrite it
                if (li.Key == customID)
                {
                    var listv = li.Value;
                    // Special case, don't update if this is a "null string" parsed
                    if ((customValue != "NULL") && (listv.Val != customValue))
                    {
                        listv.Val = customValue;
                    }
                    listv.Extra = string.Empty;
                    return;
                }
            }
            var newlistv = new DataLookupEntry();

            newlistv.ID    = customID;
            newlistv.Val   = customValue;
            newlistv.Extra = string.Empty;
            list.data.Add(customID, newlistv);
            AllValues.Add(customValue);
        }