public LonLat GetFromFile(int index, string file) { string path = getMappedPath(file); if (currentFile == null || !file.Equals(currentFile) || index < lineNumber) { currentFile = file; sr = new StreamReader(path); lineNumber = 0; } string line = null; while (index != lineNumber) { line = sr.ReadLine(); if (line == null) { break; // there are less than 15 lines in the file } lineNumber++; } if (line == null || line.Equals(Environment.NewLine)) { // End of file return(null); } LonLat lonLat = LonLat.FromString(line); return(lonLat); }
public LonLat GetCoordinatesAndSave(string ip, int port, string file) { LonLat x = GetCoordinatesFromServer(ip, port); if (x == null) { return(null); } fileManager.AppendToFile(x, file); return(x); }
public void AppendToFile(LonLat lonLat, string file) { string path = getMappedPath(file); if (!File.Exists(path)) { // Create file and dispose of stream opened for it File.CreateText(path).Dispose(); } // Append LonLoat to file File.AppendAllText(path, lonLat.toString() + Environment.NewLine); }
public LonLat GetCoordinatesFromServer(string ip, int port) { double[] arr; lock (syncLock) { /* critical code */ dataRequester.ChangeConnectionIfNeeded(ip, port); arr = dataRequester.RequestData(); } LonLat x = new LonLat(arr[0], arr[1]); return(x); }