|
#region Copyright
// Diagnostic Explorer, a .Net diagnostic toolset
// Copyright (C) 2010 Cameron Elliot
//
// This file is part of Diagnostic Explorer.
//
// Diagnostic Explorer is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Diagnostic Explorer is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Diagnostic Explorer. If not, see <http://www.gnu.org/licenses/>.
//
// http://diagexplorer.sourceforge.net/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Diagnostics;
using System.IO;
using System.Xml;
namespace DiagnosticExplorer
{
[DataContract(Namespace = "http://diagnosticexplorer.com/2010")]
[Serializable]
public class DiagnosticGroup
{
public DiagnosticGroup()
{
Items = new List<DiagnosticGroup>();
RegistrationMode = RegistrationMode.NA;
}
[DataMember]
public string Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string ProcessName { get; set; }
[DataMember]
public int ProcessId { get; set; }
[DataMember]
public string InstanceName { get; set; }
[DataMember]
public string Uri { get; set; }
[DataMember]
public OnlineState State { get; set; }
[DataMember]
public RegistrationMode RegistrationMode { get; set; }
[DataMember]
public string Message { get; set; }
[DataMember]
public DateTime? LastOnline { get; set; }
[DataMember]
public List<DiagnosticGroup> Items { get; set; }
public static DiagnosticGroup Deserialise(string xml)
{
DataContractSerializer ser = new DataContractSerializer(typeof(DiagnosticGroup));
using (XmlReader xmlReader = new XmlTextReader(xml, XmlNodeType.Document, null))
return (DiagnosticGroup)ser.ReadObject(xmlReader);
}
public string Serialise()
{
DataContractSerializer ser = new DataContractSerializer(typeof(DiagnosticGroup));
using (StringWriter writer = new StringWriter())
using (XmlTextWriter xmlWriter = new XmlTextWriter(writer))
{
xmlWriter.Formatting = Formatting.Indented;
ser.WriteObject(xmlWriter, this);
return writer.ToString();
}
}
}
public static class DiagnosticGroupExtensions
{
const StringComparison _ignoreCase = StringComparison.CurrentCultureIgnoreCase;
public static IEnumerable<DiagnosticGroup> EnumerateAll(this DiagnosticGroup group)
{
yield return group;
foreach (DiagnosticGroup child in group.Items)
foreach (DiagnosticGroup item in child.EnumerateAll())
yield return item;
}
public static DiagnosticGroup FindByUri(this IEnumerable<DiagnosticGroup> list, string uri)
{
return list.FirstOrDefault(x => string.Equals(x.Uri, uri, _ignoreCase));
}
public static DiagnosticGroup FindById(this IEnumerable<DiagnosticGroup> list, string id)
{
return list.FirstOrDefault(x => string.Equals(x.Id, id, _ignoreCase));
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a software developer originally from Auckland, New Zealand. I have lived and worked in London since 2005.