Removed duplicate code; correction setting the request timeout in a session constructor;

renamed method to be more descriptive.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2018-04-08 02:42:54 +01:00 committed by Mihaela Stoica
parent a8efbbfba2
commit a112bd73fb
2 changed files with 24 additions and 29 deletions

View File

@ -47,8 +47,9 @@ namespace XenAPI
public bool IsElevatedSession = false;
private Session(int timeout, IXenConnection connection, string url)
: this(CreateProxy(url, timeout), connection)
:this(timeout, url)
{
Connection = connection;
proxy.RequestEvent += LogRequest;
proxy.ResponseEvent += LogResponse;
}
@ -67,7 +68,7 @@ namespace XenAPI
public Session(Session session, Proxy proxy, IXenConnection connection)
: this(proxy, connection)
{
InitAD(session);
CopyADFromSession(session);
}
/// <summary>
@ -79,21 +80,25 @@ namespace XenAPI
{
if (session.JsonRpcClient != null)
{
JsonRpcClient = new JsonRpcClient(session.Url) {JsonRpcVersion = session.JsonRpcClient.JsonRpcVersion};
JsonRpcClient = new JsonRpcClient(session.Url)
{
JsonRpcVersion = session.JsonRpcClient.JsonRpcVersion,
Timeout = timeout
};
JsonRpcClient.RequestEvent += LogJsonRequest;
}
else
{
proxy = CreateProxy(session.Url, timeout);
InitializeXmlRpcProxy(session.Url, timeout);
proxy.RequestEvent += LogRequest;
proxy.ResponseEvent += LogResponse;
}
Connection = connection;
InitAD(session);
CopyADFromSession(session);
}
private void InitAD(Session session)
private void CopyADFromSession(Session session)
{
opaque_ref = session.opaque_ref;
APIVersion = session.APIVersion;
@ -104,21 +109,6 @@ namespace XenAPI
permissions = session.Permissions;
}
private static Proxy CreateProxy(string url, int timeout)
{
var xmlrpcProxy = XmlRpcProxyGen.Create<Proxy>();
xmlrpcProxy.Url = url;
xmlrpcProxy.NonStandard = XmlRpcNonStandard.All;
xmlrpcProxy.Timeout = timeout;
xmlrpcProxy.UseIndentation = false;
xmlrpcProxy.UserAgent = UserAgent;
xmlrpcProxy.KeepAlive = true;
xmlrpcProxy.Proxy = Proxy;
// reverted because of CA-137829/CA-137959: _proxy.ConnectionGroupName = Guid.NewGuid().ToString(); // this will force the Session onto a different set of TCP streams (see CA-108676)
return xmlrpcProxy;
}
/// <summary>
/// When the CacheWarming flag is set, we output logging at Debug rather than Info level.
/// This means that we don't spam the logs when the application starts.

View File

@ -74,14 +74,7 @@ namespace XenAPI
public Session(int timeout, string url)
{
proxy = XmlRpcProxyGen.Create<Proxy>();
proxy.Url = url;
proxy.NonStandard = XmlRpcNonStandard.All;
proxy.Timeout = timeout;
proxy.UseIndentation = false;
proxy.UserAgent = UserAgent;
proxy.KeepAlive = true;
proxy.Proxy = Proxy;
InitializeXmlRpcProxy(url, timeout);
}
public Session(string url)
@ -139,6 +132,18 @@ namespace XenAPI
return newSession;
}
private void InitializeXmlRpcProxy(string url, int timeout)
{
proxy = XmlRpcProxyGen.Create<Proxy>();
proxy.Url = url;
proxy.NonStandard = XmlRpcNonStandard.All;
proxy.Timeout = timeout;
proxy.UseIndentation = false;
proxy.UserAgent = UserAgent;
proxy.KeepAlive = true;
proxy.Proxy = Proxy;
}
/// <summary>
/// Applies only to API 1.6 (george) and above.
/// </summary>