/// <summary> /// Checks if this profile group is equivelent to another object /// </summary> /// <remarks> /// Returns true if all properties are true, and each of the <c>Items</c> collections contain equivelent profiles. /// Order of the profiles does not matter. /// </remarks> /// <param name="obj">object to compare against</param> /// <returns>true if equal, false if not</returns> public override bool Equals(object obj) { ProfileGroup rhs = obj as ProfileGroup; if (((object)rhs) == null) { return(false); } bool mainMembersEqual = ((this.Name == rhs.Name) && (this.DefaultProfileName == rhs.DefaultProfileName) && (this.Comment == rhs.Comment)); if ((mainMembersEqual) && (this.Items != null) && (rhs.Items != null)) { if (this.Items.Count != rhs.Items.Count) { return(false); } for (int i = 0; i < this.Items.Count; i++) { if (this.Items[i] != rhs.Items[i]) { return(false); } } return(true); } return(false); }
/// <summary> /// generates a ProfileGroup from a local file /// </summary> /// <param name="groupName"> /// If groupName contains path separator characters, then it is assumed to be a fully qualified file path. /// If it does not, then it is interpreted as the name of the profile group to load. /// </param> /// <returns>returns a ProfileGroup</returns> public static ProfileGroup LoadFromFile(string groupName) { FileStream fileStream = null; try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(ProfileGroup)); string filename; if (groupName.Contains(Path.DirectorySeparatorChar.ToString()) || groupName.Contains(Path.AltDirectorySeparatorChar.ToString())) { filename = groupName; } else { filename = PathMapper.ConfigProfiles(groupName + @".xml"); } fileStream = new FileStream(filename, FileMode.Open); ProfileGroup profileGroup = (ProfileGroup)xmlSerializer.Deserialize(fileStream); return(profileGroup); } finally { if (fileStream != null) { fileStream.Close(); fileStream.Dispose(); } } }
/// <summary> /// Deserializes all of the <see cref="T:ProfileGroup"/> files found in the app_data/Profiles/ and puts them into a <see cref="T:ProfileGroups"/>. /// </summary> /// <returns>a new instance of <see cref="T:ProfileGroups"/></returns> public static ProfileGroups LoadFromFile() { lock (_cacheLock) { if (_cachedProfileGroups == null) { _cachedProfileGroups = new ProfileGroups(); string[] files = Directory.GetFiles(PathMapper.ConfigProfiles("")); foreach (string profileFileName in files) { _cachedProfileGroups.Items.Add(ProfileGroup.LoadFromFile(profileFileName)); } } } return(_cachedProfileGroups); }
/// <summary> /// Does a deep-clone of <c>this</c> and returns it. /// </summary> /// <returns></returns> public object Clone() { ProfileGroup clone = new ProfileGroup(); clone.Name = (this.Name != null) ? (string)this.Name.Clone() : null; clone.DefaultProfileName = (this.DefaultProfileName != null) ? (string)this.DefaultProfileName.Clone() : null; clone.Comment = (this.Comment != null) ? (string)this.Comment.Clone() : null; foreach (Profile p in this.Items) { clone.Items.Add((Profile)p.Clone()); } return(clone); }