public bool Run(PerforceConnection Perforce, TextWriter Log, out string ErrorMessage) { bool bExists; if (!Perforce.ClientExists(Settings.Name, out bExists, Log)) { ErrorMessage = String.Format("Unable to determine if client already exists.\n\n{0}", Log.ToString()); return(false); } if (bExists) { ErrorMessage = String.Format("Client '{0}' already exists.", Settings.Name); return(false); } PerforceSpec Client = new PerforceSpec(); Client.SetField("Client", Settings.Name); Client.SetField("Owner", Owner); Client.SetField("Host", HostName); Client.SetField("Stream", Settings.Stream); Client.SetField("Root", Settings.RootDir); Client.SetField("Options", "rmdir"); string Message; if (!Perforce.CreateClient(Client, out Message, Log)) { ErrorMessage = Message; return(false); } ErrorMessage = null; return(true); }
public bool TryGetStreamSpec(string StreamName, out PerforceSpec Spec, TextWriter Log) { List <string> Lines; if (!RunCommand(String.Format("stream -o {0}", StreamName), out Lines, CommandOptions.None, Log)) { Spec = null; return(false); } if (!PerforceSpec.TryParse(Lines, out Spec, Log)) { Spec = null; return(false); } return(true); }
/// <summary> /// Parses a spec (clientspec, branchspec, changespec) from an array of lines /// </summary> /// <param name="Lines">Text split into separate lines</param> /// <returns>Array of section names and values</returns> public static bool TryParse(List <string> Lines, out PerforceSpec Spec, TextWriter Log) { Spec = new PerforceSpec(); for (int LineIdx = 0; LineIdx < Lines.Count; LineIdx++) { if (Lines[LineIdx].EndsWith("\r")) { Lines[LineIdx] = Lines[LineIdx].Substring(0, Lines[LineIdx].Length - 1); } if (!String.IsNullOrWhiteSpace(Lines[LineIdx]) && !Lines[LineIdx].StartsWith("#")) { // Read the section name int SeparatorIdx = Lines[LineIdx].IndexOf(':'); if (SeparatorIdx == -1 || !Char.IsLetter(Lines[LineIdx][0])) { Log.WriteLine("Invalid spec format at line {0}: \"{1}\"", LineIdx, Lines[LineIdx]); return(false); } // Get the section name string SectionName = Lines[LineIdx].Substring(0, SeparatorIdx); // Parse the section value StringBuilder Value = new StringBuilder(Lines[LineIdx].Substring(SeparatorIdx + 1).TrimStart()); for (; LineIdx + 1 < Lines.Count; LineIdx++) { if (Lines[LineIdx + 1].Length == 0) { Value.AppendLine(); } else if (Lines[LineIdx + 1][0] == '\t') { Value.AppendLine(Lines[LineIdx + 1].Substring(1)); } else { break; } } Spec.Sections.Add(new KeyValuePair <string, string>(SectionName, Value.ToString().TrimEnd())); } } return(true); }
public bool TryGetStreamSpec(string StreamName, out PerforceSpec Spec, TextWriter Log) { List<string> Lines; if(!RunCommand(String.Format("stream -o {0}", StreamName), out Lines, CommandOptions.None, Log)) { Spec = null; return false; } if(!PerforceSpec.TryParse(Lines, out Spec, Log)) { Spec = null; return false; } return true; }
/// <summary> /// Parses a spec (clientspec, branchspec, changespec) from an array of lines /// </summary> /// <param name="Lines">Text split into separate lines</param> /// <returns>Array of section names and values</returns> public static bool TryParse(List<string> Lines, out PerforceSpec Spec, TextWriter Log) { Spec = new PerforceSpec(); for(int LineIdx = 0; LineIdx < Lines.Count; LineIdx++) { if(Lines[LineIdx].EndsWith("\r")) { Lines[LineIdx] = Lines[LineIdx].Substring(0, Lines[LineIdx].Length - 1); } if(!String.IsNullOrWhiteSpace(Lines[LineIdx]) && !Lines[LineIdx].StartsWith("#")) { // Read the section name int SeparatorIdx = Lines[LineIdx].IndexOf(':'); if(SeparatorIdx == -1 || !Char.IsLetter(Lines[LineIdx][0])) { Log.WriteLine("Invalid spec format at line {0}: \"{1}\"", LineIdx, Lines[LineIdx]); return false; } // Get the section name string SectionName = Lines[LineIdx].Substring(0, SeparatorIdx); // Parse the section value StringBuilder Value = new StringBuilder(Lines[LineIdx].Substring(SeparatorIdx + 1).TrimStart()); for(; LineIdx + 1 < Lines.Count; LineIdx++) { if(Lines[LineIdx + 1].Length == 0) { Value.AppendLine(); } else if(Lines[LineIdx + 1][0] == '\t') { Value.AppendLine(Lines[LineIdx + 1].Substring(1)); } else { break; } } Spec.Sections.Add(new KeyValuePair<string,string>(SectionName, Value.ToString().TrimEnd())); } } return true; }