Beispiel #1
0
        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");
        }
Beispiel #2
0
        /// <summary>
        /// Connect to Perforce if not already connected.
        /// </summary>
        /// <exception cref="System.ArgumentException">Thrown when null or empty P4Options.Port, or when P4Options.Client is invalid</exception>
        /// <exception cref="P4API.Exceptions.PerforceInitializationError">Thrown P4Options.Port is invalid</exception>
        public void Connect()
        {
            if (IsConnected)
            {
                return;
            }

            try
            {
                // .Api must be set before the call to Connect()
                _p4.Api = 65; // 2009.1, to support P4 Move. See http://kb.perforce.com/article/512/perforce-protocol-levels

                _p4.Connect();
            }
            catch (P4API.Exceptions.PerforceInitializationError)
            {
                Log.Error(String.Format(Resources.Unable_To_Connect, _p4.Port, _p4.Client));
                IsConnected = false;
                throw;
            }

            // There seems to be a problem in P4.Net IsValidConnection() -- the login check always succeeds.
            IsConnected = _p4.IsValidConnection(true, true);
            if (!IsConnected)
            {
                Log.Error(String.Format(Resources.Unable_To_Connect, _p4.Port, _p4.Client));
                throw new ArgumentException("Not a valid workspace.");
            }

            P4Form client;

            try
            {
                client = _p4.Fetch_Form("client");
            }
            catch (Exception ex)
            {
                Log.Error("Unable to fetch client form.\n" + ex.Message);
                return;
            }

            var root = client["Root"];

            _map.SetRoot(root);
        }
Beispiel #3
0
        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.
                }
            }
        }