using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Perforce.P4
{
///
/// Identifies a specific revision or revision range of a Perforce managed SCM resource.
///
public abstract class VersionSpec
{
public abstract override string ToString();
public static HeadRevision Head = new HeadRevision();
public static HaveRevision Have = new HaveRevision();
public static NoneRevision None = new NoneRevision();
}
///
/// A revision range specifier consisting of a lower and upper revision.
///
public class VersionRange : VersionSpec
{
///
/// A revision range specifier consisting of a lower and upper revision.
///
///version spec to get lower revision
///version spec to get upper revision
public VersionRange(VersionSpec lower, VersionSpec upper)
{
if (lower == null)
{
throw new ArgumentNullException("lower");
}
if (upper == null)
{
throw new ArgumentNullException("upper");
}
Lower = lower;
Upper = upper;
}
///
/// A revision range specifier consisting of a lower and upper revision.
///
///int to get lower revision
///int to get upper revision
public VersionRange(int lower, int upper)
{
Lower = new Revision(lower);
Upper = new Revision(upper);
}
///
/// Lower version revision.
///
public VersionSpec Lower { get; set; }
///
/// Upper version revision.
///
public VersionSpec Upper { get; set; }
///ToString method for for VersionRange
/// String version range
public override string ToString()
{
return String.Format( "{0},{1}", Lower, Upper);
}
///Equals method for for VersionRange
///object to get version range
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
VersionRange o = obj as VersionRange;
if (o.Lower != null)
{
if (o.Lower.Equals(this.Lower) == false)
{ return false; }
}
else
{
if (this.Lower != null)
{ return false; }
}
if (o.Upper != null)
{
if (o.Upper.Equals(this.Upper) == false)
{ return false; }
}
else
{
if (this.Upper != null)
{ return false; }
}
return true;
}
}
///
/// A revision specifier #head.
///
public class HeadRevision : VersionSpec
{
///ToString method for for HeadRevision
/// #head
public override string ToString()
{
return "#head";
}
///Equals method for for HeadRevision
///object to get head revision
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
return true;
}
}
///
/// A revision specifier #have.
///
public class HaveRevision : VersionSpec
{
///ToString method for for HaveRevision
/// #have
public override string ToString()
{
return "#have";
}
///Equals method for for HaveRevision
///object to get have revision
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
return true;
}
}
///
/// A revision specifier #none.
///
public class NoneRevision : VersionSpec
{
///ToString method for for NoneRevision
/// #none
public override string ToString()
{
return "#none";
}
///Equals method for for NoneRevision
///object to get none revision
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
return true;
}
}
///
/// A revision specifier that is a single revision.
///
public class Revision : VersionSpec
{
///
/// A revision specifier that is a single revision.
///
public Revision(int rev) { Rev = rev; }
public int Rev { get; private set; }
///ToString method for for Revision
/// String client revision version
public override string ToString()
{
if (Rev >= 0)
{
return String.Format("#{0}", Rev);
}
return string.Empty;
}
///Equals method for for Revision
///object to get revision
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
Revision o = obj as Revision;
if (o.Rev != this.Rev)
{
return false;
}
return true;
}
}
///
/// A revision specifier that is a date and time.
///
/// The date/time.
public class DateTimeVersion : VersionSpec
{
/// The date/time.
public DateTimeVersion(DateTime date)
{
Version = date;
}
///get Version as date/time
public DateTime Version { get; private set; }
///ToString method for for DateTimeVersion
/// String date/time version
public override string ToString()
{
return String.Format("@{0}", Version.ToString("yyyy/M/d"));
}
///Equals method for for DateTimeVersion
///object to get date/time
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
DateTimeVersion o = obj as DateTimeVersion;
if (o.Version != this.Version)
{
return false;
}
return true;
}
}
///
/// A revision specifier that is a label name.
///
public class LabelNameVersion : VersionSpec
{
/// The label.
public LabelNameVersion(string LabelName)
{
Version = LabelName;
}
///get Version as label
public string Version { get; private set; }
///ToString method for for LabelNameVersion
/// String label version
public override string ToString()
{
return String.Format("@{0}",Version);
}
///Equals method for for LabelNameVersion
///object to get label
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
LabelNameVersion o = obj as LabelNameVersion;
if (o.Version != this.Version)
{
return false;
}
return true;
}
}
///
/// A revision specifier that is a changelist id.
///
public class ChangelistIdVersion : VersionSpec
{
/// The changelist.
public ChangelistIdVersion(int Changelist)
{
ChanglistId = Changelist;
}
///get Version as changelist
public int ChanglistId { get; private set; }
///ToString method for for ChangelistIdVersion
/// String changelist version
public override string ToString()
{
return String.Format("@{0}", ChanglistId);
}
///Equals method for for ChangelistIdVersion
///object to get changelist
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
ChangelistIdVersion o = obj as ChangelistIdVersion;
if (o.ChanglistId != this.ChanglistId)
{
return false;
}
return true;
}
}
///
/// A revision specifier that is a client name.
///
public class ClientNameVersion : VersionSpec
{
/// The client name.///
public ClientNameVersion(string ClientName)
{
Version = ClientName;
}
///get Version as client name
public string Version { get; private set; }
///ToString method for for ClientNameVersion
/// String client name version
public override string ToString()
{
return String.Format("@{0}", Version);
}
///Equals method for for ClientNameVersion
///object to get client name
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
ClientNameVersion o = obj as ClientNameVersion;
if (o.Version != this.Version)
{
return false;
}
return true;
}
}
///
/// A revision specifier that is a file action.
///
public class ActionVersion : VersionSpec
{
/// The file action.///
public ActionVersion(string Action)
{
Version = Action;
}
///get Version as action
public string Version { get; private set; }
///ToString method for for ActionVersion
/// String action version
public override string ToString()
{
return String.Format("@{0}", Version);
}
///Equals method for for ActionVersion
///object to get action type
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
ActionVersion o = obj as ActionVersion;
if (o.Version != this.Version)
{
return false;
}
return true;
}
}
///
/// A revision specifier for a file that is shelved in a changelist id.
///
public class ShelvedInChangelistIdVersion : VersionSpec
{
/// The changelist.
public ShelvedInChangelistIdVersion(int Changelist)
{
ChanglistId = Changelist;
}
///get Version as changelist
public int ChanglistId { get; private set; }
///ToString method for for ChangelistIdVersion
/// String changelist version
public override string ToString()
{
return String.Format("@={0}", ChanglistId);
}
///Equals method for for ChangelistIdVersion
///object to get changelist
/// True/False
public override bool Equals(object obj)
{
if (obj == null)
{ return false; }
if (obj.GetType() != this.GetType())
{
return false;
}
ChangelistIdVersion o = obj as ChangelistIdVersion;
if (o.ChanglistId != this.ChanglistId)
{
return false;
}
return true;
}
}
}