/// <summary> /// Fill in the fields for the changelist using the tagged output of a "change' command /// </summary> /// <param name="objectInfo">The tagged output of a "change' command</param> /// <param name="GetShelved">Access shelved files or not</param> /// <param name="offset">Offset within array</param> /// <param name="dst_mismatch">Daylight savings time for conversions</param> public void FromChangeCmdTaggedOutput(TaggedObject objectInfo, bool GetShelved, string offset, bool dst_mismatch) { // need to check for tags starting with upper and lower case, it the 'change' command's // output the tags start with an uppercase character whereas with the 'changes' command // they start with a lower case character, i.e. "Change" vs "change" _baseForm = new FormBase(); _baseForm.SetValues(objectInfo); if (objectInfo.ContainsKey("Change")) { int v = -1; if (int.TryParse(objectInfo["Change"], out v)) { Id = v; } } else if (objectInfo.ContainsKey("change")) { int v = -1; if (int.TryParse(objectInfo["change"], out v)) { Id = v; } } if (objectInfo.ContainsKey("Date")) { DateTime v; DateTime.TryParse(objectInfo["Date"], out v); ModifiedDate = v; } else if (objectInfo.ContainsKey("time")) { long v; if (long.TryParse(objectInfo["time"], out v)) { DateTime UTC = FormBase.ConvertUnixTime(v); DateTime GMT = new DateTime(UTC.Year, UTC.Month, UTC.Day, UTC.Hour, UTC.Minute, UTC.Second, DateTimeKind.Unspecified); ModifiedDate = FormBase.ConvertFromUTC(GMT, offset, dst_mismatch); } } if (objectInfo.ContainsKey("Client")) { ClientId = objectInfo["Client"]; } else if (objectInfo.ContainsKey("client")) { ClientId = objectInfo["client"]; } if (objectInfo.ContainsKey("User")) { OwnerName = objectInfo["User"]; } else if (objectInfo.ContainsKey("user")) { OwnerName = objectInfo["user"]; } if (objectInfo.ContainsKey("Status")) { Pending = true; String v = objectInfo["Status"]; if (v == "submitted") { Pending = false; } } else if (objectInfo.ContainsKey("status")) { Pending = true; String v = objectInfo["status"]; if (v == "submitted") { Pending = false; } } if (objectInfo.ContainsKey("Description")) { Description = objectInfo["Description"]; } else if (objectInfo.ContainsKey("desc")) { Description = objectInfo["desc"]; } char[] array = { '\r', '\n' }; Description = Description.TrimEnd(array); Description = Description.Replace("\r", ""); Description = Description.Replace("\n", "\r\n"); if (objectInfo.ContainsKey("Type")) { _type = objectInfo["Type"]; } else if (objectInfo.ContainsKey("changeType")) { _type = objectInfo["changeType"]; } if (objectInfo.ContainsKey("shelved")) { Shelved = true; } int idx = 0; String key = "Jobs0"; if (objectInfo.ContainsKey(key)) { idx = 1; Jobs = new Dictionary <string, string>(); do { Jobs.Add(objectInfo[key], null); key = String.Format("Jobs{0}", idx++); } while (objectInfo.ContainsKey(key)); } else { key = "jobs0"; if (objectInfo.ContainsKey(key)) { idx = 1; Jobs = new Dictionary <string, string>(); do { Jobs.Add(objectInfo[key], null); key = String.Format("jobs{0}", idx++); } while (objectInfo.ContainsKey(key)); } } key = "Files0"; if (objectInfo.ContainsKey(key)) { idx = 1; Files = new List <FileMetaData>(); do { FileMetaData file = new FileMetaData(); file.DepotPath = new DepotPath(PathSpec.UnescapePath(objectInfo[key])); Files.Add(file); key = String.Format("Files{0}", idx++); } while (objectInfo.ContainsKey(key)); } else { key = "files0"; if (objectInfo.ContainsKey(key)) { idx = 1; SimpleList <FileMetaData> files = new SimpleList <FileMetaData>(); do { FileMetaData file = new FileMetaData(); file.DepotPath = new DepotPath(PathSpec.UnescapePath(objectInfo[key])); Files.Add(file); key = String.Format("files{0}", idx++); } while (objectInfo.ContainsKey(key)); Files = (List <FileMetaData>)files; } } if (GetShelved) { key = "depotFile0"; String actionKey = "action0"; String typeKey = "type0"; String revKey = "rev0"; String sizeKey = "fileSize0"; String digestKey = "digest0"; if (objectInfo.ContainsKey(key)) { SimpleList <ShelvedFile> shelvedFiles = new SimpleList <ShelvedFile>(); idx = 1; do { ShelvedFile file = new ShelvedFile(); file.Path = new DepotPath(PathSpec.UnescapePath(objectInfo[key])); StringEnum <FileAction> action = objectInfo[actionKey]; file.Action = action; file.Type = new FileType(objectInfo[typeKey]); string revstr = objectInfo[revKey]; if (revstr == "none") { revstr = "0"; } int rev = Convert.ToInt32(revstr); file.Revision = rev; if (objectInfo.ContainsKey(sizeKey)) { long size = -1; long.TryParse(objectInfo[sizeKey], out size); file.Size = size; } if (objectInfo.ContainsKey(digestKey)) { file.Digest = objectInfo[digestKey]; } shelvedFiles.Add(file); key = String.Format("depotFile{0}", idx); actionKey = String.Format("action{0}", idx); typeKey = String.Format("type{0}", idx); revKey = String.Format("rev{0}", idx); sizeKey = String.Format("fileSize{0}", idx); digestKey = String.Format("digest{0}", idx++); } while (objectInfo.ContainsKey(key)); ShelvedFiles = (List <ShelvedFile>)shelvedFiles; } } else { key = "depotFile0"; String actionKey = "action0"; String typeKey = "type0"; String revKey = "rev0"; String sizeKey = "fileSize0"; String digestKey = "digest0"; if (objectInfo.ContainsKey(key)) { idx = 1; SimpleList <FileMetaData> fileList = new SimpleList <FileMetaData>(); do { FileMetaData file = new FileMetaData(); file.DepotPath = new DepotPath(PathSpec.UnescapePath(objectInfo[key])); StringEnum <FileAction> action = objectInfo[actionKey]; file.Action = action; file.Type = new FileType(objectInfo[typeKey]); string revstr = objectInfo[revKey]; int rev = Convert.ToInt32(revstr); file.HeadRev = rev; if (objectInfo.ContainsKey(sizeKey)) { long size = -1; long.TryParse(objectInfo[sizeKey], out size); file.FileSize = size; } if (objectInfo.ContainsKey(digestKey)) { file.Digest = objectInfo[digestKey]; } fileList.Add(file); key = String.Format("depotFile{0}", idx); actionKey = String.Format("action{0}", idx); typeKey = String.Format("type{0}", idx); revKey = String.Format("rev{0}", idx); sizeKey = String.Format("fileSize{0}", idx); digestKey = String.Format("digest{0}", idx++); } while (objectInfo.ContainsKey(key)); Files = (List <FileMetaData>)fileList; } } key = "job0"; String statKey = "jobstat0"; if (objectInfo.ContainsKey(key)) { idx = 1; Jobs = new Dictionary <string, string>(); do { string jobStatus = string.Empty; string jobId = objectInfo[key]; if (objectInfo.ContainsKey(statKey)) { jobStatus = objectInfo[statKey]; } Jobs.Add(jobId, jobStatus); key = String.Format("job{0}", idx); statKey = String.Format("jobstat{0}", idx++); } while (objectInfo.ContainsKey(key)); } }
/// <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> /// Expand the directory by filling in the list of child directories /// and file within the directory. /// </summary> /// <returns>false if an error prevented completion</returns> public bool Expand() { if (String.IsNullOrEmpty(depotPath)) { return(false); } // if we have the depot path, get a list of the subdirectories from the depot if (!String.IsNullOrEmpty(depotPath)) { IList <string> subdirs = _repository.GetDepotDirs(null, String.Format("{0}/*", depotPath)); if ((subdirs != null) && (subdirs.Count > 0)) { subdirectories = P4DirectoryMap.FromDirsOutput(_repository, Workspace, this, subdirs); foreach (P4Directory dir in subdirectories.Values) { dir.InDepot = true; } } IList <FileMetaData> fileList = _repository.GetFileMetaData(null, FileSpec.DepotSpec(String.Format("{0}/*", depotPath))); // get a list of the files in the directory if (fileList != null) { files = P4FileMap.FromFstatOutput(fileList); // if the directory contains files from the depot, we can use // the local path of one of those files to determine the local // path for this directory if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0)) { foreach (FileMetaData f in files.Values) { if ((f.LocalPath != null) && !String.IsNullOrEmpty(f.LocalPath.Path)) { localPath = f.LocalPath.GetDirectoryName(); break; } } } } } // if we have a workspace and a local path, match the files and // subdirectories in the depot with the files in the file system if ((!String.IsNullOrEmpty(localPath)) && (Workspace != null)) { DirectoryInfo[] directoryList = null; FileInfo[] fileList = null; try { DirectoryInfo di = new DirectoryInfo(localPath); directoryList = di.GetDirectories(); fileList = di.GetFiles(); } catch (Exception ex) { //LogFile.LogException( "Initializing Directory from Workspace", ex ); } // get the subdirectories listed in the file and match them up // with the one in the list from the depot if ((directoryList != null) && (directoryList.Length > 0)) { foreach (DirectoryInfo di in directoryList) { string itemName = di.Name; if (subdirectories.ContainsKey(itemName)) { subdirectories[itemName].InWorkspace = true; } else { P4Directory subDir = new P4Directory(_repository, Workspace, itemName, null, di.FullName, parentDirectory); subDir.InDepot = false; subDir.InWorkspace = true; subdirectories[itemName] = subDir; } } } // get the files listed in the subdirectory and match them up // with the one in the list from the depot if ((fileList != null) && (fileList.Length > 0)) { foreach (FileInfo fi in fileList) { string itemName = fi.Name; if (files.ContainsKey(itemName) == false) { FileMetaData file = new FileMetaData(); file.LocalPath = new LocalPath(fi.FullName); file.DepotPath = null; file.FileSize = fi.Length; files[itemName] = file; } } } } return(true); }