public T[] ToArray() { if (Head == null) { return(null); } T[] value = new T[Count]; SimpleListItem <T> curItem = Head; int idx = 0; while ((curItem != null) && (idx < Count)) { value[idx++] = curItem.Item; curItem = curItem.Next; } return(value); }
public override string ToString() { if (Head == null) { return(null); } StringBuilder sb = new StringBuilder(Count * 80); SimpleListItem <T> curItem = Head; int idx = 0; while ((curItem != null) && (idx < Count)) { if (idx > 0) { sb.Append("\r\n"); } sb.Append(curItem.Item.ToString()); curItem = curItem.Next; } return(sb.ToString()); }
/// <summary> /// Parse the fields from a branch specification /// </summary> /// <param name="spec">Text of the branch specification in server format</param> /// <returns></returns> public bool Parse(String spec) { _baseForm = new FormBase(); _baseForm.Parse(spec); // parse the values into the underlying dictionary if (_baseForm.ContainsKey("Branch")) { Id = _baseForm["Branch"] as string; } if (_baseForm.ContainsKey("Owner")) { if (_baseForm["Owner"] is string) { Owner = _baseForm["Owner"] as string; } if (_baseForm["Owner"] is IList <string> ) { IList <string> strList = _baseForm["Owner"] as IList <string>; Owner = string.Empty; for (int idx = 0; idx < strList.Count; idx++) { if (idx > 0) { Owner += "\r\n"; } Owner += strList[idx]; } } if (_baseForm["Owner"] is SimpleList <string> ) { SimpleList <string> strList = _baseForm["Owner"] as SimpleList <string>; Owner = string.Empty; SimpleListItem <string> current = strList.Head; bool addCRLF = false; while (current != null) { if (addCRLF) { Owner += "\r\n"; } else { addCRLF = true; } Owner += current.Item; current = current.Next; } } } if (_baseForm.ContainsKey("Update")) { DateTime v = DateTime.MinValue; DateTime.TryParse(_baseForm["Update"] as string, out v); Updated = v; } if (_baseForm.ContainsKey("Access")) { DateTime v = DateTime.MinValue; DateTime.TryParse(_baseForm["Access"] as string, out v); Accessed = v; } if (_baseForm.ContainsKey("Description")) { if (_baseForm["Description"] is string) { Description = _baseForm["Description"] as string; } if (_baseForm["Description"] is IList <string> ) { IList <string> strList = _baseForm["Description"] as IList <string>; Description = string.Empty; for (int idx = 0; idx < strList.Count; idx++) { if (idx > 0) { Description += "\r\n"; } Description += strList[idx]; } } if (_baseForm["Description"] is SimpleList <string> ) { SimpleList <string> strList = _baseForm["Description"] as SimpleList <string>; Description = string.Empty; SimpleListItem <string> current = strList.Head; bool addCRLF = false; while (current != null) { if (addCRLF) { Description += "\r\n"; } else { addCRLF = true; } Description += current.Item; current = current.Next; } } } if (_baseForm.ContainsKey("Options")) { #pragma warning disable 618 Options = _baseForm["Options"] as string; #pragma warning restore 618 } if (_baseForm.ContainsKey("View")) { if (_baseForm["View"] is IList <string> ) { IList <string> lines = _baseForm["View"] as IList <string>; ViewMap = new ViewMap(lines.ToArray()); } else if (_baseForm["View"] is SimpleList <string> ) { SimpleList <string> lines = _baseForm["View"] as SimpleList <string>; ViewMap = new ViewMap(lines.ToArray()); } } return(true); }
/// <summary> /// Parse the fields from a changelist specification /// </summary> /// <param name="spec">Text of the changelist specification in server format</param> /// <returns>true if parse successful</returns> public bool Parse(String spec) { _baseForm = new FormBase(); _baseForm.Parse(spec); // parse the values into the underlying dictionary if (_baseForm.ContainsKey("Change")) { int v = -1; int.TryParse((string)_baseForm["Change"], out v); Id = v; } if (_baseForm.ContainsKey("Date")) { DateTime v; DateTime.TryParse((string)_baseForm["Date"], out v); ModifiedDate = v; } if (_baseForm.ContainsKey("Client")) { ClientId = (string)_baseForm["Client"]; } if (_baseForm.ContainsKey("User")) { OwnerName = (string)_baseForm["User"]; } if (_baseForm.ContainsKey("Status")) { Pending = true; String v = (string)_baseForm["Status"]; if (v == "submitted") { Pending = false; } } if (_baseForm.ContainsKey("Type")) { _type = (string)_baseForm["Type"]; } if (_baseForm.ContainsKey("Description")) { if (_baseForm["Description"] is string) { Description = (string)_baseForm["Description"]; } else if (_baseForm["Description"] is SimpleList <string> ) { SimpleList <string> strList = _baseForm["Description"] as SimpleList <string>; Description = string.Empty; SimpleListItem <string> current = strList.Head; bool addCRLF = false; while (current != null) { if (addCRLF) { Description += "\r\n"; } else { addCRLF = true; } Description += current.Item; current = current.Next; } } else if (_baseForm["Description"] is IList <string> ) { IList <string> strList = _baseForm["Description"] as IList <string>; Description = string.Empty; for (int idx = 0; idx < strList.Count; idx++) { if (idx > 0) { Description += "\r\n"; } Description += strList[idx]; } } } if (_baseForm.ContainsKey("Jobs")) { if (_baseForm["Jobs"] is IList <string> ) { IList <string> strList = _baseForm["Jobs"] as IList <string>; Jobs = new Dictionary <string, string>(strList.Count); foreach (string job in strList) { if (job.Contains('#')) { string[] parts = job.Split('#'); Jobs[parts[0].Trim()] = null; } else { Jobs[job] = null; } } } else if (_baseForm["Jobs"] is SimpleList <string> ) { SimpleList <string> strList = _baseForm["Jobs"] as SimpleList <string>; Jobs = new Dictionary <string, string>(strList.Count); SimpleListItem <string> current = strList.Head; while (current != null) { string job = current.Item; if (job.Contains('#')) { string[] parts = job.Split('#'); Jobs[parts[0].Trim()] = null; } else { Jobs[job] = null; } current = current.Next; } } } if (_baseForm.ContainsKey("Files")) { if (_baseForm["Files"] is IList <string> ) { IList <string> files = (IList <string>)_baseForm["Files"]; Files = new List <FileMetaData>(files.Count); foreach (string path in files) { FileMetaData file = new FileMetaData(); if (path.Contains('#')) { string[] parts = path.Split('#'); file.DepotPath = new DepotPath(parts[0].Trim()); } else { file.DepotPath = new DepotPath(path); } Files.Add(file); } } else if (_baseForm["Files"] is SimpleList <string> ) { SimpleList <string> files = (SimpleList <string>)_baseForm["Files"]; Files = new List <FileMetaData>(files.Count); SimpleListItem <string> current = files.Head; while (current != null) { FileMetaData file = new FileMetaData(); if (current.Item.Contains('#')) { string[] parts = current.Item.Split('#'); file.DepotPath = new DepotPath(parts[0].Trim()); } else { file.DepotPath = new DepotPath(current.Item); } Files.Add(file); current = current.Next; } } } return(true); }
/// <summary> /// Parse the fields from a label specification /// </summary> /// <param name="spec">Text of the label specification in server format</param> /// <returns></returns> public bool Parse(String spec) { _baseForm = new FormBase(); _baseForm.Parse(spec); // parse the values into the underlying dictionary if (_baseForm.ContainsKey("Label")) { Id = _baseForm["Label"] as string; } if (_baseForm.ContainsKey("Owner")) { Owner = _baseForm["Owner"] as string; } if (_baseForm.ContainsKey("Update")) { DateTime v = DateTime.MinValue; DateTime.TryParse(_baseForm["Update"] as string, out v); Update = v; } if (_baseForm.ContainsKey("Access")) { DateTime v = DateTime.MinValue; DateTime.TryParse(_baseForm["Access"] as string, out v); Access = v; } if (_baseForm.ContainsKey("Description")) { object d = _baseForm["Description"]; if (d is string) { Description = _baseForm["Description"] as string; } else if (d is string[]) { string[] a = d as string[]; Description = string.Empty; for (int idx = 0; idx < a.Length; idx++) { if (idx > 0) { Description += "\r\n"; } Description += a[idx]; } } else if (d is IList <string> ) { IList <string> l = d as IList <string>; Description = string.Empty; for (int idx = 0; idx < l.Count; idx++) { if (idx > 0) { Description += "\r\n"; } Description += l[idx]; } } else if (d is SimpleList <string> ) { SimpleList <string> l = d as SimpleList <string>; Description = string.Empty; SimpleListItem <string> current = l.Head; bool addCRLF = false; while (current != null) { if (addCRLF) { Description += "\r\n"; } else { addCRLF = true; } Description += current.Item; current = current.Next; } } } if (_baseForm.ContainsKey("Options")) { #pragma warning disable 618 Options = _baseForm["Options"] as string; #pragma warning restore 618 } if (_baseForm.ContainsKey("Revision")) { Revision = _baseForm["Revision"] as string; } if (_baseForm.ContainsKey("ServerID")) { Revision = _baseForm["ServerID"] as string; } if (_baseForm.ContainsKey("View")) { if (_baseForm["View"] is IList <string> ) { IList <string> lines = _baseForm["View"] as IList <string>; ViewMap = new ViewMap(lines.ToArray()); } if (_baseForm["View"] is SimpleList <string> ) { SimpleList <string> lines = _baseForm["View"] as SimpleList <string>; ViewMap = new ViewMap(lines.ToArray()); } } return(true); }