/******************************************************************************* Copyright (c) 2011, Perforce Software, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ /******************************************************************************* * Name : Job.cs * * Author : dbb * * Description : Class used to abstract a job in Perforce. * ******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Perforce.P4 { //public class JobStatus { } /// /// A Job in the Repository. /// /// /// A job specification has only one required field, "Job". If /// a Perforce installation uses a complex Job specification than /// the simple parsing and string formatting provided by the Form /// object cannot properly support the data, the Job object can /// subclassed to provide custom parsing and form generation /// ///
p4 help job ///
///
job -- Create or edit a job (defect) specification ///
///
p4 job [-f] [jobName] ///
p4 job -d jobName ///
p4 job -o [jobName] ///
p4 job -i [-f] ///
///
The 'p4 job' command creates and edits job specifications using an ///
ASCII form. A job is a defect, enhancement, or other unit of ///
intended work.The 'p4 fix' command associates changelists with jobs. ///
///
With no arguments, 'p4 job' creates an empty job specification ///
and invokes the user's editor. When the specification is saved, ///
a job name of the form jobNNNNNN is assigned. If the jobName ///
parameter is specified on the command line, the job is created or ///
opened for editing. ///
///
As jobs are entered or updated, all fields are indexed for searching ///
Text fields are broken into individual alphanumeric words (punctuation ///
and whitespace are ignored) and each word is case-folded and entered ///
into the word index. Date fields are converted to an internal ///
representation (seconds since 1970/01/01 00:00:00) and entered ///
into the date index. ///
///
The fields that compose a job are defined by the 'p4 jobspec' command. ///
Perforce provides a default job specification that you can edit. ///
///
The -d flag deletes the specified job. You cannot delete a job if ///
it has pending or submitted fixes associated with it. ///
///
The -o flag writes the job specification to the standard output. ///
The user's editor is not invoked. ///
///
The -i flag reads a job specification from the standard input. The ///
user's editor is not invoked. ///
///
The -f flag enables you set fields that are read-only by default. ///
The -f flag requires 'admin' access, which is granted using the ///
'p4 protect' command. ///
///
///
public class Job : FormBase { /// /// The job name /// public string Id { get { object jobID; TryGetValue("Job", out jobID); if (jobID != null) { return jobID.ToString(); } return null; } set { // keep the underlying dictionary in sync this["Job"] = value; } } /// /// Convert to a Job specification /// /// public override string ToString() { return base.ToString(); } /// /// Parse the tagged output of a 'job' command /// /// public virtual void FromJobCmdTaggedOutput(TaggedObject obj) { SetValues(obj); if (obj.ContainsKey("Job")) { Id = obj["Job"]; } } /// /// Parse a Job spec /// /// public override bool Parse(string spec) { base.Parse(spec); if (ContainsKey("Job")) { Id = (string) this["Job"]; } return true; } /// /// Convert the Job to a Spec Def /// /// /// public static string[] ToStrings(IList list) { if (list == null) return null; string[] value = new string[list.Count]; for (int idx = 0; idx < list.Count; idx++) { value[idx] = list[idx].Id; } return value; } /// /// Convert an array of Jobs to a list of JobIds to be passed as /// parameters to a command /// /// /// public static string[] ToStrings(Job[] list) { if (list == null) return null; string[] value = new string[list.Length]; for (int idx = 0; idx < list.Length; idx++) { value[idx] = list[idx].Id; } return value; } } }