private ArrayList getUnpublishedFiles(String path) { this.Cursor = Cursors.WaitCursor; if (scan == false) { int trimIndex = path.IndexOf("art"); path = path.Substring(trimIndex, path.Length - trimIndex); path = "//depot/phoenix/xbox/published/" + path.Replace("\\", "/"); } p4 = new P4Connection(); p4.Connect(); p4I = new P4Interface(); ArrayList unpublished = new ArrayList(); String[] args = { "-n", "-d", "-i", "-t", "-v", "-b", "phx_published", path }; P4RecordSet record = p4I.Run("integrate", args); foreach (P4Record entry in record) { unpublished.Add(entry.Fields["fromFile"]); } this.Cursor = Cursors.Default; return(unpublished); p4.Disconnect(); }
//----------------------------------------------------------------------------------------- // create connection // public bool connect() { try { m_connection.Connect(); try { m_connection.Login(m_config.Password); if (ClientIsValid()) { m_connected = true; return(true); } } catch {} if (Authentification()) { m_connected = true; return(true); } } catch (System.Exception ex) { m_error = ex.ToString(); } try { m_connection.Disconnect(); } catch { } return(false); }
/// <summary> /// Disconnect from Perforce. /// </summary> public void Disconnect() { if (_p4 != null) { _p4.Disconnect(); } IsConnected = false; }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { try { p4.Disconnect(); } catch (System.Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
public void Test003_AddFiles() { p4.Disconnect(); p4.Charset = "utf16le-bom"; p4.Connect(); string testPath = Path.Combine(p4ClientRootDirectory, "TestUnicode"); //Create some test files Directory.CreateDirectory(testPath); P4PendingChangelist cl = p4.CreatePendingChangelist("TestUnicode"); string[] args = new string[13]; args[0] = "-c"; args[1] = cl.Number.ToString(); args[2] = "-tunicode"; for (int i = 0; i < 10; i++) { string fn = string.Format("File{0}", i); string contents = string.Format("this is file: {0}\nEn español.\nΚαλημέρα κόσμε\nこんにちは 世界", i); StreamWriter sw = new StreamWriter(Path.Combine(testPath, fn), false, System.Text.Encoding.Unicode); sw.Write(contents); sw.Close(); args[i + 3] = Path.Combine(testPath, fn); } P4UnParsedRecordSet r = p4.RunUnParsed("add", args); Assert.AreEqual(r.Messages.Length, 10, "Invalid response from p4 add"); for (int i = 0; i < 10; i++) { Assert.AreEqual(string.Format("//depot/TestUnicode/File{0}#1 - opened for add", i), r.Messages[i], "Invalid response from p4 add"); } r = cl.Submit(); Assert.AreEqual("Submitting change 8.", r.Messages[0], "Unexpected output from p4 submit"); }
private static string executeP4Cmd(string cmd, string [] args) { string results = ""; try { P4Connection p4 = new P4Connection(); p4.Connect(); P4RecordSet recSet = p4.Run(cmd, args); foreach (object obj in recSet.Messages) { results += String.Format("{0}\r\n", (string)obj); } foreach (P4Record rec in recSet) { FieldDictionary fd = rec.Fields; if (cmd.Equals("opened")) { results += fd["clientFile"]; } else { foreach (string key in fd.Keys) { results += String.Format("{0}\t\t{1}\r\n", key, fd[key]); } } results += "\r\n"; } p4.Disconnect(); } catch (Exception ex) { return(ex.Message); } return(results); }
public Form1() { InitializeComponent(); appSettings = new Settings("data.dat"); p4 = new P4Connection(); p4.ExceptionLevel = P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings; p4.Connect(); if (!p4.IsValidConnection(true, true)) { MessageBox.Show("No valid p4 connection."); } p4I = new P4Interface(); p4I.Connect(); if (!p4I.IsValidConnection()) { MessageBox.Show("No valid p4I connection."); } checkedNodes = new ArrayList(); foreach (String user in p4I.GetUsers()) { comboBoxUsers.Items.Add(user.ToLower()); } comboBoxUsers.SelectedItem = p4.User.ToLower().ToString(); BuildLocalPaths(); MarkUnpublishedFolders(getUnpublishedFiles()); ExpandNode(treeView1.Nodes[0]); p4.Disconnect(); }
private ArrayList getUnpublishedFiles() { this.Cursor = Cursors.WaitCursor; Scanning scan = new Scanning(); scan.StartPosition = FormStartPosition.CenterParent; scan.Show(); scan.Refresh(); p4 = new P4Connection(); p4.Connect(); p4I = new P4Interface(); ArrayList unpublished = new ArrayList(); String[] args = { "-n", "-d", "-i", "-t", "-v", "-b", "phx_published", "//depot/phoenix/xbox/published/..." }; // logging String tmp = ""; foreach (String t in args) { tmp += t; tmp += " "; } LogLine(String.Concat("Running: Integrate ", tmp)); P4RecordSet record = p4I.Run("integrate", args); LogLine(String.Concat("Total Records: ", record.Records.Length)); foreach (P4Record entry in record) { if (checkBoxFilter.Checked) { String file = entry.Fields["depotFile"]; String delim = "/"; int trimIndex = -1; if (file.Split(delim.ToCharArray())[6] == "art") { trimIndex = file.IndexOf("art"); } else if (file.Split(delim.ToCharArray())[6] == "scenario") { trimIndex = file.IndexOf("scenario"); } file = file.Substring(trimIndex, file.Length - trimIndex); file = "//depot/phoenix/xbox/published/" + file.Replace("\\", "/"); String[] args2 = { file.Replace("//depot/phoenix/xbox/published", localPath).Replace("\\", "/") }; P4RecordSet changes = p4I.Run("changes", args2); if (changes.Records.Length > 0 && changes[0].Fields["user"] == comboBoxUsers.SelectedItem.ToString()) { LogLine(String.Concat("Record: ", entry.Fields["depotFile"])); unpublished.Add(entry.Fields["fromFile"]); } } else { unpublished.Add(entry.Fields["fromFile"]); } } scan.Close(); this.Cursor = Cursors.Default; return(unpublished); p4.Disconnect(); }
protected void DisconnectP4() { _p4.Disconnect(); }
public void ProcessRequest(HttpContext context) { // Don't allow this response to be cached by the browser. context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache.SetNoStore(); context.Response.Cache.SetExpires(DateTime.MinValue); // Create a new p4 connection, and set the appropriate properties P4Connection p4 = new P4Connection(); AppSettingsReader appSettings = new AppSettingsReader(); p4.Port = (string)appSettings.GetValue("P4PORT", typeof(string)); p4.User = (string)appSettings.GetValue("P4USER", typeof(string)); p4.Client = (string)appSettings.GetValue("P4CLIENT", typeof(string)); p4.Password = (string)appSettings.GetValue("P4PASSWD", typeof(string)); try { p4.Connect(); //Figure out the clientPath for the file string clientPath = string.Format("//{0}/{1}", p4.Client, context.Request.AppRelativeCurrentExecutionFilePath.Substring(2)); if (!clientPath.EndsWith("/")) { // We have a path to a file // find the MIME type and set it string ext = Path.GetExtension(clientPath); string mimeType = getMimeType(ext); context.Response.ContentType = mimeType; //stream the results ... will throw an exception if the path isn't found try { p4.PrintStream(context.Response.OutputStream, clientPath); context.Response.OutputStream.Flush(); } catch (P4API.Exceptions.FileNotFound) { context.Response.StatusCode = 404; } } else { // we have a directory... let's look for a default "index" file and redirect // My Rule for a default page is: // :: "index.htm" or "index.html" in the current directory (case insensitive) // // I don't rely on the Perforce server to be case insensitive, so I will run an fstat for // all files in the directory and see if there are any "index.htm*" files P4RecordSet rs = p4.Run("fstat", "-Op", clientPath + "*"); foreach (P4Record r in rs) { if (r["depotFile"].ToLower().EndsWith("index.html") || r["depotFile"].ToLower().EndsWith("index.htm")) { // the -Op switch means client file will be //<clientname>/<clientpath> clientPath = r["clientFile"]; break; } } if (clientPath.EndsWith("/")) { // clientPath not updated, means we can't find a default page // For now, just 404... in the future we could allow directory browsing // (which we be a lot bigger than a sample application ;-) context.Response.StatusCode = 404; } else { // redirect to the index page string redirect = "~" + clientPath.Substring(p4.Client.Length + 2); context.Response.Redirect(redirect, false); } } } catch (Exception e) { // unhandled exception... send a 500 to the browser System.Diagnostics.Trace.WriteLine(e.StackTrace); context.Response.StatusCode = 500; } finally { p4.Disconnect(); context.Response.End(); } }
//Guts of the logic. This is where the app will dynamicaly build the job labels public void RunLabeler(EventLog log) { P4Connection p4 = null; try { p4 = new P4Connection(); p4.Port = _p4port; p4.User = _p4user; if (!_useLogin) { p4.Password = _p4password; } p4.Connect(); if (_useLogin) { p4.Login(_p4password); } // Don't throw an exception on a Perforce error. We handle these manually. p4.ExceptionLevel = P4ExceptionLevels.NoExceptionOnErrors; //Use unparsed b/c older server versions do not support //parsed output for the counter command. And, it's easy //to parse by hand. P4UnParsedRecordSet counter = p4.RunUnParsed("counter", _p4counter); int counterValue = int.Parse(counter[0]); int LastSequenceNumber = 0; List <string> JobList = new List <string>(); //Run p4 logger to find all the changes and jobs since the last run P4RecordSet loggers = p4.Run("logger", "-c", counterValue.ToString()); //spin the results, and get a unique list of jobs foreach (P4Record r in loggers) { if (r.Fields["key"] == "job") { string JobName = r.Fields["attr"]; if (!JobList.Contains(JobName)) { JobList.Add(JobName); } } LastSequenceNumber = int.Parse(r.Fields["sequence"]); } // We're done with loggers, so lets remove the reference and // give the GC a chance to clean memory. If it's been a long time // since the last run, it could be thousands of jobs to catch up. loggers = null; // Now spin all the jobs and build the label foreach (string JobName in JobList) { BuildLabel(JobName, p4, log); } //Now we update the counter to the last sequence number from logger. p4.RunUnParsed("counter", _p4counter, LastSequenceNumber.ToString()); } catch (Exception e) { // rethrow... b/c I'm lazy :-) throw e; } finally { // All done here... time to disconnect. p4.Disconnect(); } }