//lvl4 public List <string> MakeIndexForID(string fileName) { this.reader.BaseStream.Seek(0, SeekOrigin.Begin); List <string> idList = new List <string>(); string text = File.ReadAllText(fileName); using (var rearder = new StringReader(text)) using (var trackingReader = new TrackingTextReader(rearder)) { string line; while ((line = trackingReader.ReadLine()) != null) { if (line.StartsWith(">", StringComparison.Ordinal)) { string[] metadata = line.Split(null); foreach (string data in metadata) { if (data.StartsWith(">", StringComparison.Ordinal)) { int index = trackingReader.Position - (line.Length + 1); string id = data.Remove(0, 1) + " " + index; idList.Add(id); } } } } } return(idList); }
protected TrackingTextReader OpenControlFile() { while (true) { try { var file = File.Open(this.controlFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None); // if open succeeded, read the first line - to refresh the SceneGenerator information var reader = new TrackingTextReader(new StreamReader(file)); this.sceneGeneratorClassName = reader.ReadLine(); this.OutputPath = reader.ReadLine(); var res = reader.ReadLine(); var fps = reader.ReadLine(); var qual = reader.ReadLine(); var tokens = res.Split(' '); this.XResolution = Int32.Parse(tokens[0]); this.YResolution = Int32.Parse(tokens[1]); this.Fps = Int32.Parse(fps); this.RenderQuality = (RenderQuality)Enum.Parse(typeof(RenderQuality), qual); return(reader); } catch (IOException exc) { Console.WriteLine("Control file locked, retrying..."); } catch (Exception exc) { Console.WriteLine("Error reading control file!"); Console.WriteLine(exc.ToString()); Console.WriteLine(exc.StackTrace); return(null); } Thread.Sleep(1000); } return(null); }