示例#1
0
 public void Login()
 {
     while (true)
     {
         var result  = Rcon.GetConsole();
         var newName = Re.GetSubString(result, @"Server name '(.*?)'");
         if (!String.IsNullOrWhiteSpace(newName))
         {
             Name = newName;
             break;
         }
         else
         {
             Thread.Sleep(1000);
         }
     }
 }
示例#2
0
        private void SetValue(string section, string name, string value)
        {
            var sectionContent = Re.GetSubString(this.configContent, string.Format(RE_SECTION, section));

            if (string.IsNullOrWhiteSpace(sectionContent))
            {
                return;
            }

            var replacement = Regex.Replace(sectionContent, string.Concat(@"[\s|\t]*", name, RE_PARAMETER),
                                            Environment.NewLine);

            replacement        = string.Concat(replacement, string.Format("{2}\t{0} = {1}", name, value, Environment.NewLine));
            this.configContent = this.configContent.Replace(sectionContent, replacement);

            Util.Try(() => File.WriteAllText(this.configFilePath, this.configContent));
        }
示例#3
0
文件: Util.cs 项目: xedoc/IL2CDR
        public static int[] SequenceToIntArray(string seq)
        {
            var result = new int[] {};

            if (String.IsNullOrWhiteSpace(seq))
            {
                return(result);
            }

            var values = Re.GetSubString(seq, @"([\d|\.|,]+)");

            if (String.IsNullOrWhiteSpace(values))
            {
                return(result);
            }

            return(values.Split(',')
                   .Select(x => { int i = 0; int.TryParse(x, out i); return i; })
                   .ToArray());
        }
示例#4
0
        public void ReadMissionHistory(string firstMissionLogFile = null)
        {
            //missionReport(2015-02-25_11-43-53)[0].txt

            if (firstMissionLogFile == null)
            {
                firstMissionLogFile = Util.GetNewestFilePath(MissionLogFolder, "missionReport(*)[0].txt");
                if (String.IsNullOrWhiteSpace(firstMissionLogFile))
                {
                    Log.WriteError("Mission log not found in {0}", MissionLogFolder);
                    return;
                }
            }
            else
            {
                firstMissionLogFile = this.With(x => Re.GetSubString(firstMissionLogFile, @"(missionReport\([\d+|\-|_]+\))\[\d+\].txt"))
                                      .With(x => String.Concat(x, "[0].txt"));
            }


            if (String.IsNullOrWhiteSpace(firstMissionLogFile))
            {
                Log.WriteError("Malformed log filename {0}", firstMissionLogFile);
                return;
            }

            Log.WriteInfo("Reading events history from {0}", firstMissionLogFile);


            StartNewMission(firstMissionLogFile);

            if (MissionStartDateTime.Equals(default(DateTime)))
            {
                return;
            }


            var missionFiles = Util.GetFilesSortedByTime(MissionLogFolder, String.Format("missionReport({0})[*].txt", missionDateTimePrefix), true);

            var readException = Util.Try(() => {
                foreach (var file in missionFiles)
                {
                    var fileInfo = new FileInfo(file);
                    if (fileInfo.Length > 0 && !String.IsNullOrWhiteSpace(file))
                    {
                        if (tracker != null)
                        {
                            tracker.AddFileOffset(file, fileInfo.Length);
                        }

                        var lines = File.ReadAllLines(file);
                        if (lines != null)
                        {
                            foreach (var line in lines)
                            {
                                var data = MissionLogDataBuilder.GetData(line, MissionStartDateTime, GetCurrentEventNumber(), server);
                                if (data is MissionLogEventHeader)
                                {
                                    var header         = data as MissionLogEventHeader;
                                    header.MissionFile = Path.GetFileName(file);
                                    AddHistory(data);
                                }
                            }
                        }
                    }
                }
            });
        }