static List <Branch> GetQueuedBranches(string filePath) { List <Branch> result = new List <Branch>(); try { if (!File.Exists(filePath)) { return(result); } foreach (string line in File.ReadAllLines(filePath)) { Branch branch; if (!BranchParser.TryParse(line, out branch)) { mLog.ErrorFormat("Malformed line while reading branches file: {0}", line); continue; } result.Add(branch); } } catch (Exception ex) { LogException("Error reading the queued branches to '{0}': {1}", ex, filePath); } return(result); }
internal static void WriteQueuedBranches(IEnumerable <Branch> branches, string filePath) { if (branches == null) { return; } try { using (StreamWriter file = new StreamWriter(filePath)) { foreach (Branch branch in branches) { file.WriteLine(BranchParser.ToString(branch)); } } } catch (Exception ex) { LogException("Error writing the queued branches to '{0}': {1}", ex, filePath); } }
internal static void EnqueueBranch(Branch branch, string filePath) { string line = string.Empty; try { line = BranchParser.ToString(branch); if (Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } using (StreamWriter file = new StreamWriter(filePath, true)) { file.WriteLine(line); } } catch (Exception ex) { LogException("Error saving branch '{0}' to '{1}': {2}", ex, branch.FullName, filePath); } }