258 lines
7.2 KiB
C#
258 lines
7.2 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright © 2009-2012, Intel Corporation. All rights reserved.
|
|
//
|
|
// File: Connection.cs
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
using System.Runtime.Serialization;
|
|
using System.IO;
|
|
using Intel.Management.Wsman;
|
|
|
|
namespace UCT
|
|
{
|
|
[Serializable]
|
|
/// <summary>
|
|
/// This class hold the basic information data.
|
|
/// Used for the remeber the machines wich we connect them on the past.
|
|
/// </summary>
|
|
public class Connection : ISerializable
|
|
{
|
|
#region - Members -
|
|
|
|
/// <summary>
|
|
/// The amt hostname
|
|
/// </summary>
|
|
public string HostName { set; get; }
|
|
|
|
/// <summary>
|
|
/// AMT User name
|
|
/// </summary>
|
|
public string UserName { set; get; }
|
|
|
|
/// <summary>
|
|
/// Indicate if Kerberos is enable
|
|
/// </summary>
|
|
public bool KerberosEnable { set; get; }
|
|
|
|
/// <summary>
|
|
/// Indicate if TLS is enable
|
|
/// </summary>
|
|
public bool TLSEnable { set; get; }
|
|
|
|
/// <summary>
|
|
/// Indicate if TLS is enable
|
|
/// </summary>
|
|
public bool MTLSEnable { set; get; }
|
|
|
|
/// <summary>
|
|
/// Hold the client ceritficate name
|
|
/// </summary>
|
|
public string ClientCertificate { set; get; }
|
|
|
|
/// <summary>
|
|
/// Indicate if Cira is enable
|
|
/// </summary>
|
|
public bool CiraEnable { set; get; }
|
|
|
|
/// <summary>
|
|
/// Hold the proxy host name
|
|
/// </summary>
|
|
public string ProxyHost { set; get; }
|
|
|
|
/// <summary>
|
|
/// Hold the proxy port
|
|
/// </summary>
|
|
public ushort ProxyPort { set; get; }
|
|
|
|
/// <summary>
|
|
/// Hold the proxy user name
|
|
/// </summary>
|
|
public string ProxyUserName { set; get; }
|
|
|
|
|
|
#endregion
|
|
|
|
#region ISerializable Members
|
|
|
|
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region - Constructors -
|
|
|
|
public Connection(string host, string username, bool kerberos, bool tls, bool mtls, string cert,
|
|
bool cira, string proxyHost, ushort proxyPort, string proxyUser, string proxyPass)
|
|
{
|
|
HostName = host;
|
|
UserName = username;
|
|
KerberosEnable = kerberos;
|
|
TLSEnable = tls;
|
|
MTLSEnable = mtls;
|
|
ClientCertificate = cert;
|
|
CiraEnable = cira;
|
|
ProxyHost = proxyHost;
|
|
ProxyPort = proxyPort;
|
|
ProxyUserName = proxyUser;
|
|
}
|
|
public Connection() { }
|
|
|
|
#endregion
|
|
|
|
#region - Operators -
|
|
|
|
public static bool operator ==(Connection x, Connection y)
|
|
{
|
|
// If one is null, but not both, return false.
|
|
if (((object)x == null) || ((object)y == null))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (x.HostName == y.HostName &&
|
|
x.UserName == y.UserName &&
|
|
x.KerberosEnable == y.KerberosEnable &&
|
|
x.TLSEnable == y.TLSEnable &&
|
|
x.ClientCertificate == y.ClientCertificate &&
|
|
x.MTLSEnable == y.MTLSEnable &&
|
|
x.CiraEnable == y.CiraEnable &&
|
|
x.ProxyHost == y.ProxyHost &&
|
|
x.ProxyPort == y.ProxyPort &&
|
|
x.ProxyUserName == y.ProxyUserName )
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool operator !=(Connection x, Connection y)
|
|
{
|
|
return !(x == y);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return base.Equals(obj);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
[Serializable]
|
|
public class ConnectionHistory
|
|
{
|
|
// This attribute enables the ArrayList to be serialized:
|
|
[XmlArray("Items")]
|
|
[XmlArrayItem("ConnectionItem", typeof(Connection))]
|
|
/// <summary>
|
|
/// Host all the connections
|
|
/// </summary>
|
|
private List<Connection> _connections;
|
|
|
|
[XmlIgnore]
|
|
private XmlSerializer _serializer;
|
|
|
|
/// <summary>
|
|
/// Constuctor
|
|
/// </summary>
|
|
public ConnectionHistory()
|
|
{
|
|
if (_connections == null)
|
|
{
|
|
_connections = new List<Connection>();
|
|
_serializer = new XmlSerializer(typeof(List<Connection>));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add new connection information
|
|
/// </summary>
|
|
/// <param name="conToAdd"></param>
|
|
public bool CheckExistingConnectionInfo(Connection con)
|
|
{
|
|
if (_connections.Exists(e => e.HostName == con.HostName) == false)
|
|
{
|
|
AddConnectionInfo(con);
|
|
return false;
|
|
}
|
|
if (_connections.Find(e => e.HostName == con.HostName) == con)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add new connection information
|
|
/// </summary>
|
|
/// <param name="conToAdd"></param>
|
|
public void AddConnectionInfo(Connection conToAdd)
|
|
{
|
|
_connections.Add(conToAdd);
|
|
SaveConnections();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove new connection information
|
|
/// </summary>
|
|
/// <param name="conToAdd"></param>
|
|
public void ReplaceConnectionInfo(Connection conToAdd)
|
|
{
|
|
_connections.Remove(_connections.Find(e => e.HostName == conToAdd.HostName));
|
|
AddConnectionInfo(conToAdd);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save all the connection
|
|
/// </summary>
|
|
private void SaveConnections()
|
|
{
|
|
try
|
|
{
|
|
// Serialize the connections list
|
|
using (StringWriter writer = new StringWriter())
|
|
{
|
|
_serializer.Serialize(writer, _connections);
|
|
string serializedXml = writer.ToString();
|
|
writer.Close();
|
|
|
|
// Save the serialized xml
|
|
Properties.Settings.Default.CONNECTION_HISTORY = serializedXml;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save all the connection
|
|
/// </summary>
|
|
public List<Connection> LoadConnections()
|
|
{
|
|
try
|
|
{
|
|
if (Properties.Settings.Default.CONNECTION_HISTORY != string.Empty)
|
|
{
|
|
_connections = (List<Connection>)_serializer.Deserialize(new StringReader(Properties.Settings.Default.CONNECTION_HISTORY));
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
return _connections;
|
|
}
|
|
}
|
|
}
|