/// <summary> /// Read in this object from xml. /// </summary> /// <param name="reader">The reader to read from.</param> public void ReadXml(XmlReader reader) { Name = reader["name"]; FileName = reader["fileName"]; ChangedBy = new User(reader["changedById"], reader["changedByName"]); ChangedOn = DateTime.Parse(reader["changedOn"]); CreatedBy = new User(reader["createdById"], reader["createdByName"]); CreatedOn = DateTime.Parse(reader["createdOn"]); State = (SourceFileState)Enum.Parse(typeof(SourceFileState), reader["state"]); FileType = new SourceFileType(reader["fileType"], null); List <SourceFile> children = new List <SourceFile>(); if (!reader.IsEmptyElement) { XmlReader subTree = reader.ReadSubtree(); if (subTree.ReadToDescendant("child")) { while (subTree.NodeType == XmlNodeType.Element && subTree.Name == "child") { SourceFile child = new SourceFile(); child.ReadXml(subTree); children.Add(child); } } } Children = children.ToArray(); reader.Read(); }
/// <summary> /// Constructor. /// </summary> /// <param name="id">The id.</param> /// <param name="type">The file type name.</param> /// <param name="name">The name.</param> /// <param name="fileName">The file name.</param> /// <param name="checkedOutBy">CheckedOutBy.</param> public SourceFile(string id, string type, string name, string fileName, User checkedOutBy) { if (String.IsNullOrWhiteSpace(type)) { throw new ArgumentException("type is null or whitespace.", "type"); } if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name is null or whitespace.", "name"); } FileType = new SourceFileType(type, null); Name = name; Id = id; FileName = fileName; Parent = null; ChangedBy = null; ChangedOn = DateTime.MinValue; CreatedBy = null; CreatedOn = DateTime.MinValue; Children = new SourceFile[0]; State = SourceFileState.None; CheckedOutBy = checkedOutBy; }
/// <summary> /// Constructor. /// </summary> /// <param name="fileType">The type of file.</param> /// <param name="fileProperties">The file properties.</param> public SourceFile(SourceFileType fileType, SalesForceAPI.Metadata.FileProperties fileProperties) { if (fileType == null) { throw new ArgumentNullException("fileType"); } if (fileProperties == null) { throw new ArgumentNullException("fileProperties"); } Id = fileProperties.id; FileType = fileType; Name = fileProperties.fullName; FileName = fileProperties.fileName; Parent = null; ChangedBy = new User(fileProperties.lastModifiedById ?? String.Empty, fileProperties.lastModifiedByName); ChangedOn = fileProperties.lastModifiedDate.ToLocalTime(); CreatedBy = new User(fileProperties.createdById ?? String.Empty, fileProperties.createdByName); CreatedOn = fileProperties.createdDate.ToLocalTime(); Children = new SourceFile[0]; State = GetState(fileProperties); // salesforce defect workaround if (FileName != null && FileName.StartsWith("Workflow/")) { FileName = FileName.Replace("Workflow/", "workflows/"); } CheckedOutBy = null; }
/// <summary> /// Compare the other object with this one to see if the other object should preceed or follow this object. /// The comparison is done by evaulating the name. null values will always follow source file types. /// </summary> /// <param name="obj">The object to compare with this one.</param> /// <returns> /// A negative Integer if this object precedes the other object. /// A positive Integer if this object follows the other object. /// Zero if this object is equal to the other object. /// </returns> public int CompareTo(object obj) { SourceFileType other = obj as SourceFileType; if (other == null) { return(-1); } return(String.Compare(this.Name, other.Name)); }
/// <summary> /// Constructor. /// </summary> /// <param name="name">Name.</param> /// <param name="parent">The parent for this file type. Can be null if there is no parent.</param> internal SourceFileType(string name, SourceFileType parent) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name is null or whitespace.", "name"); } Name = name; Parent = parent; Children = new SourceFileType[0]; InFolder = false; MetaFile = false; }
/// <summary> /// Create a source file from a data result for one of the Apex objects. /// </summary> /// <param name="data">The data to create this source file from.</param> public SourceFile(DataTable data) { if (data == null) { throw new ArgumentNullException("data"); } if (data.Rows.Count != 1) { throw new ArgumentException("data doesn't have exactly one row."); } FileType = new SourceFileType(data.TableName, null); Name = data.Rows[0]["Name"] as string; switch (FileType.Name) { case "ApexClass": FileName = String.Format("classes\\{0}.cls", Name); break; case "ApexTrigger": FileName = String.Format("triggers\\{0}.trigger", Name); break; case "ApexPage": FileName = String.Format("pages\\{0}.page", Name); break; case "ApexComponent": FileName = String.Format("components\\{0}.component", Name); break; default: throw new ArgumentException("Unsupported type: " + FileType.Name); } Id = data.Rows[0]["Id"] as string; ChangedBy = new User(data.Rows[0]["CreatedById"] as string, null); ChangedOn = DateTime.Parse(data.Rows[0]["CreatedDate"] as string).ToLocalTime(); CreatedBy = ChangedBy; CreatedOn = ChangedOn; Children = new SourceFile[0]; Parent = null; State = SourceFileState.None; IsNameUpdated = false; CheckedOutBy = null; }
/// <summary> /// Compare two source file type objects. /// The comparison is done by evaulating the name. null values will always follow source file types. /// </summary> /// <param name="a">The source file type to compare with b.</param> /// <param name="b">The source file type to compare with a.</param> /// <returns> /// A negative Integer if a precedes b. /// A positive Integer if a follows b. /// Zero if a is equal to b object. /// </returns> public static int Compare(SourceFileType a, SourceFileType b) { if (a == null && b == null) { return(0); } if (a == null) { return(1); } if (b == null) { return(-1); } return(a.CompareTo(b)); }
/// <summary> /// Constructor. /// </summary> /// <param name="fileType">The type of file.</param> /// <param name="fileProperties">The file properties.</param> /// <param name="children">The child files for this file.</param> internal SourceFile(SourceFileType fileType, SalesForceAPI.Metadata.FileProperties fileProperties, IEnumerable <SourceFile> children) : this(fileType, fileProperties) { if (children == null) { Children = new SourceFile[0]; } else { Children = children.ToArray(); } foreach (SourceFile child in Children) { child.Parent = this; } Array.Sort(Children); }
/// <summary> /// Don't use. Required by xml serializer. /// </summary> public SourceFileType() { Children = new SourceFileType[0]; }