Exemple #1
0
        public static bool TryParseNameMessage(string message, out string id, out string name)
        {
            id   = "";
            name = "";
            bool success = InitialMessageCheck(message, MessageType.Name, out message);

            if (!success)
            {
                return(false);
            }

            NeaReader reader = new NeaReader(message);

            try {
                id   = reader.ReadWord();
                name = reader.ReadSection('[', ']');
            }
            catch { return(false); }
            return(true);
        }
        private void LoadDefaultFiles()
        {
            string[] filePaths = null;
            string   file      = "config.ini";

            //config data
            try {
                NeaReader     r     = new NeaReader(new StreamReader(file));
                ReadState     state = ReadState.FindNextEntry;
                string        group = "ERROR";
                List <string> list  = new List <string>();

                while (r.Peek() != -1)
                {
                    NeaReader line = new NeaReader(r.ReadLine());
                    string    temp;

                    line.SkipWhiteSpace();
                    if ((char)line.Peek() == '#')                     // comment
                    {
                        continue;
                    }

                    switch (state)
                    {
                    case ReadState.FindNextEntry:
                        temp = line.ReadWord();
                        if (temp == "Group:")
                        {
                            line.SkipWhiteSpace();
                            group = line.ReadToEnd();
                            state = ReadState.FindNextKGM;
                        }
                        else if (temp == "Ratio:")
                        {
                            string[] ratio = new string[2];
                            ratio[0] = line.ReadSection('[', ']');
                            ratio[1] = line.ReadSection('[', ']');
                            ratios.Add(ratio);
                        }
                        break;

                    case ReadState.FindNextKGM:
                        line.SkipWhiteSpace();
                        if (line.Peek() != -1)
                        {
                            list.Add(line.ReadWord());
                        }
                        else
                        {
                            groups.Add(group, list.ToArray());
                            list.Clear();
                            state = ReadState.FindNextEntry;
                        }
                        break;
                    }
                }
                r.Close();
            }
            catch (FileNotFoundException fnf) {
                StreamWriter w = new StreamWriter("config.ini");
                w.Write("Fill this with data");
                w.Close();
            }
            catch (Exception e) {
            }
            filePaths = null;
            file      = null;
            //ranking data
            try {
                filePaths = Directory.GetFiles("rankingdata//", "*.csv");
            }
            catch (Exception e) {
            }
            if (filePaths != null)
            {
                if (filePaths.Length == 1)
                {
                    file = filePaths[0];
                }
            }

            if (file == null)
            {
                SetText(StatusText, "Ingen fil fundet.\nVælg venligst en at indlæse.");
                Dispatcher.BeginInvoke(new Action(() => {
                    LoadButton.IsEnabled = true;
                }));
            }
            else
            {
                Dispatcher.BeginInvoke(new Action(() => { LoadingProgressBar.IsIndeterminate = true; }));
                SetText(StatusText, "Indlæser filen:\n" + file);
                dataHandler = new DataHandler();
                Thread thread = new Thread(() => { dataHandler.LoadFile(file, this); });
                thread.Start();
            }
        }
Exemple #3
0
		public static bool TryParseNameMessage(string message, out string id, out string name) {
			id = "";
			name = "";
			bool success = InitialMessageCheck(message, MessageType.Name, out message);
			if (!success)
				return false;

			NeaReader reader = new NeaReader(message);

			try {
				id = reader.ReadWord();
				name = reader.ReadSection('[', ']');
			}
			catch { return false; }
			return true;
		}