using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Perforce.P4
{
///
/// The tagged output of a command.
///
public class TaggedObject : Dictionary
{
///
/// Basic constrictor
///
public TaggedObject() : base() { }
///
/// Copy constructor
///
/// Source object
public TaggedObject(TaggedObject obj) : base(obj) { }
};
///
/// A list of tagged objects.
///
public class TaggedObjectList : List { };
///
/// List of info messages.
///
public class InfoList : List
{
///
/// Cast to a String[].
///
///
///
public static implicit operator String[](InfoList l)
{
String[] r = new String[l.Count];
int idx = 0;
foreach (InfoLine i in l)
r[idx++] = i.ToString();
return r;
}
///
/// Cast to a String. Messages are separated by \r\n
///
///
///
public static implicit operator String(InfoList l)
{
StringBuilder r = new StringBuilder(l.Count * 80);
foreach (InfoLine i in l)
{
r.Append(i.ToString());
r.Append("/r/n");
}
return r.ToString();
}
}
///
/// A single line of output from an 'info' message.
///
public class InfoLine
{
///
/// The level of the message (0-9)
///
public int Level;
///
/// The level of the message (0-9)
///
public uint CommandId;
///
/// The message
///
public String Info;
///
/// Create a new InfoLine
///
/// Level of the message
/// Message text.
public InfoLine(uint cmdId, int nLevel, String nInfo)
{
CommandId = cmdId;
Level = nLevel;
Info = nInfo;
}
///
/// Convert the info to text
///
/// String representation
public override string ToString()
{
String levelDots = String.Empty;
for (int idx = 0; idx < Level; idx++)
levelDots += ".";
return String.Format("{0}{1}", levelDots, Info);
}
}
///
/// Base class for objects returned by a command as 'tagged' data.
///
///
/// Contains a Hashtable of the field values for the object.
/// Derived object can provide properties to directly access
/// their standard attributes.
///
public class TaggedInfoItem : TaggedObject
{
private String name;
///
/// String that that is the field that identifies this object
///
public String Name
{
get { return name; }
}
///
/// The raw data returned from the server
///
public TaggedObject ItemData
{
get { return (TaggedObject)this; }
}
///
/// Default constructer
///
public TaggedInfoItem()
{
name = String.Empty;
}
}
}