#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")]
public class DiagProcess : DiagItem
{
public DiagProcess()
{
RegistrationMode = RegistrationMode.NA;
}
public DiagProcess(XElement el)
: this()
{
Id = (string)el.Attribute("Id");
Name = (string)el.Attribute("Name");
ProcessName = (string)el.Attribute("ProcessName");
ProcessId = TryParse<int>((string)el.Attribute("ProcessId"), int.Parse) ?? 0;
InstanceName = (string)el.Attribute("InstanceName");
Uri = (string)el.Attribute("Uri");
State = ParseEnum<OnlineState>((string)el.Attribute("State")) ?? OnlineState.Unknown;
RegistrationMode = ParseEnum<RegistrationMode>(el.Attribute("RegistrationMode").Value) ?? RegistrationMode.Auto;
Message = (string)el.Attribute("Message");
LastOnline = TryParse<DateTime>(el.Attribute("LastOnline").Value, DateTime.Parse);
}
[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; }
public override XElement CreateXElement()
{
XElement el = new XElement("Process");
AddAttribute(el, "Id", Id);
AddAttribute(el, "Name", Name);
AddAttribute(el, "ProcessId", ProcessId);
AddAttribute(el, "ProcessName", ProcessName);
AddAttribute(el, "InstanceName", InstanceName);
AddAttribute(el, "Uri", Uri);
AddAttribute(el, "State", State);
AddAttribute(el, "RegistrationMode", RegistrationMode);
AddAttribute(el, "Message", Message);
if (LastOnline != null)
AddAttribute(el, "LastOnline", LastOnline.Value.ToString("d MMM yyyy HH:mm:ss"));
return el;
}
}
}