using System;
namespace Perforce.P4
{
///
/// A versioned object that describes an individual file in a Perforce repository.
///
public class File : FileSpec
{
///
/// What change contains this file?
///
public int ChangeId;
///
/// Last Action taken on this file
///
public FileAction Action;
///
/// FileType of the file
///
public FileType Type;
///
/// DateTime when file was last submitted
///
public DateTime SubmitTime;
///
/// The revision of this file which is in the client/workspace
///
public Revision HaveRev;
///
/// The user which created this file
///
public string User;
///
/// The client/workspace name which contains this file.
///
public string Client;
///
/// Default constructor
///
public File() { }
///
/// Fully parameterized constructor
///
/// Server Depot Path
/// Client workspace Path
/// Latest Revision of this file
/// Revision of this file in the workspace
/// Change ID which contains this file
/// Last Action taken on this file
/// The file type
/// The time when the file was submitted
/// the User which created this file
/// the name of the client/workspace which contains this file
public File(
DepotPath depotPath,
ClientPath clientPath,
Revision rev,
Revision haveRev,
int change,
FileAction action,
FileType type,
DateTime submittime,
string user,
string client)
: base(depotPath, clientPath, null, rev)
{
ChangeId = change;
Action = action;
Type = type;
SubmitTime = submittime;
HaveRev = haveRev;
User = user;
Client = client;
}
///
/// Given a Tagged object from the server, instantiate this File from the object
///
/// Tagged Object to Parse
public void ParseFilesCmdTaggedData(TaggedObject obj)
{
if (obj.ContainsKey("depotFile"))
{
base.DepotPath = new DepotPath(obj["depotFile"]);
}
if (obj.ContainsKey("clientFile"))
{
base.ClientPath = new ClientPath(obj["clientFile"]);
}
if (obj.ContainsKey("rev"))
{
int rev = -1;
int.TryParse(obj["rev"], out rev);
base.Version = new Revision(rev);
}
if (obj.ContainsKey("haveRev"))
{
int rev = -1;
int.TryParse(obj["haveRev"], out rev);
HaveRev = new Revision(rev);
}
if (obj.ContainsKey("change"))
{
int change = -1;
int.TryParse(obj["change"], out change);
ChangeId = change;
}
if (obj.ContainsKey("action"))
{
Action = (FileAction) new StringEnum(obj["action"], true, true);
}
if (obj.ContainsKey("type"))
{
Type = new FileType(obj["type"]);
}
if (obj.ContainsKey("time"))
{
SubmitTime = FormBase.ConvertUnixTime(obj["time"]);
}
if (obj.ContainsKey("user"))
{
User = obj["user"];
}
if (obj.ContainsKey("client"))
{
Client = obj["client"];
}
}
///
/// Return a File from a parsed Tagged Object
///
/// Tagged object to parse
/// a new File
public static File FromFilesCmdTaggedData(TaggedObject obj)
{
File val = new File();
val.ParseFilesCmdTaggedData(obj);
return val;
}
}
}