public void Test002_CreateClient() { p4.Client = "UnicodeTest"; p4ClientRootDirectory = Path.Combine(Path.GetTempPath(), "p4temprootU"); if (Directory.Exists(p4ClientRootDirectory)) { // what to do??? } else { Directory.CreateDirectory(p4ClientRootDirectory); } P4Form client = p4.Fetch_Form("client"); //test the indexer client["Root"] = p4ClientRootDirectory; //test the Fields collection client.Fields["Description"] = "Created from unit test"; P4UnParsedRecordSet result = p4.Save_Form(client); Assert.AreEqual(result.Messages.Length, 1, "While saving client spec, unexpected number of messages"); Assert.AreEqual(result[0], "Client UnicodeTest saved.", "Unable to save client spec"); }
//--------------------------------- private void BuildClientDepotPath() { P4Form myClient = p4.Fetch_Form("client"); String[] newView = new String[myClient.ArrayFields["View"].Length + 1]; myClient.ArrayFields["View"].CopyTo(newView, 0); String client = myClient["Client"]; clientRoot = myClient["Root"]; if (newView[0].Contains("playtest")) { newView[0] = newView[1]; } String[] pathConstructor = newView[0].Split('/'); for (int i = 0; i < pathConstructor.Length - 2; i++) { pathConstructor[i] = pathConstructor[i + 2]; } pathConstructor[pathConstructor.Length - 1] = pathConstructor[pathConstructor.Length - 2] = null; String[] pathArr = newView[0].Split(' '); String path = pathArr[1].Replace(String.Concat("//", client), clientRoot); clientPath = path.Replace("\\", "/"); clientPath = clientPath.Replace("//", "/"); clientPath = clientPath.Replace("/...", ""); depotPath = pathArr[1]; }
private void BuildLabel(string JobName, P4Connection p4, EventLog log) { string LabelName = string.Format(_labelNameFormat, JobName); // delete the label... it may not exist, but finding that out is worse performance // than just deleting and assuming it doesn't exist. // The '-f' flag may cause problems if the p4 account running this command isn't a // super user. You should be able to remove the flag... so long as no one // manually monkey's with the labels. P4UnParsedRecordSet labelDel = p4.RunUnParsed("label", "-f", "-d", LabelName); List <int> JobChanges = new List <int>(); // Run a fixes to get all the changelists we need to add P4RecordSet fixes = p4.Run("fixes", "-j", JobName); // Spin the recordset to build a unique list of changelists foreach (P4Record fix in fixes) { JobChanges.Add(int.Parse(fix["Change"])); } // Sort them to be certain they are ascending JobChanges.Sort(); // only build the label if there are indeed fixes if (JobChanges.Count > 0) { //re-create the label P4Form labelForm = p4.Fetch_Form("label", "-t", _labelTemplate, LabelName); // make sure the form is unlocked labelForm["Options"] = "unlocked"; // make sure we're the owner labelForm["Owner"] = _p4user; p4.Save_Form(labelForm); int ChangesAdded = 0; //now need to labelsync to all latest changes foreach (int change in JobChanges) { // using tag here so a valid client spec is not needed. // for older servers, you could substitue for labelsync, // but you'd need to pass in and set a valid client spec P4UnParsedRecordSet ls = p4.RunUnParsed("tag", "-l", LabelName, string.Format("@={0}", change)); // this is why we set exception level to NoExceptionOnErrors if (ls.HasErrors()) { if (ls.ErrorMessage.StartsWith("Can't use a pending changelist number for this command.")) { // Nothing to worry about. p4 fixes returns fix records for pending changelists, // but we don't know that going into this. It's likely more performant to just // assume it is a submitted changelist and ignore this error. } else { // Something's gone ary. Should throw an Exception. // But I'm lazy so we just log the error. log.WriteEntry(ls.ErrorMessage); } } else { ChangesAdded++; } } // If ChangesAdded is still 0, then we should delete the label since // there are no files anyway if (ChangesAdded == 0) { p4.RunUnParsed("label", "-f", "-d", LabelName); } else { // now lock the label labelForm["Options"] = "locked"; p4.Save_Form(labelForm); // Note this trick. You can re-save a form as many times as you need, // no need to fetch before each save. In fact you can use the form to save // new objects... like: // labelForm["Label"] = "newLabelName"; // p4.Save_Form(labelForm); // and you created a new label named newLabelName. // Cool, huh? Well, I don't deserve the credit... it's the way the // native C++ API works. } } }