private void CloseVasaHost() { if (_vasaHost == null) { return; } try { var closeTimeout = System.TimeSpan.FromSeconds(60); _vasaHost.Close(closeTimeout); var disposable = _vasaHost as IDisposable; if (disposable != null) { disposable.Dispose(); } } catch (System.Exception ex) { _appLog.WriteMessage(ApplicationLogMessageType.Error, Resources.ProviderClose_Exception, ex.ToString()); } _appLog.WriteMessage(ApplicationLogMessageType.Information, Resources.ProviderClose); }
protected override void OnStart(string[] args) { _appLog = ApplicationLog.OpenLogSession(ApplicationLogConfiguration.GetDefault()); var providerConfiguration = ConfigManager.GetDefaultConfiguration(); if (_vasaHost == null) { _vasaHost = new VasaServiceHost(typeof(VasaService)); var customHttpsBinding = new CustomBinding( new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.Soap12 }, new HttpsTransportBindingElement()); _vasaHost.AddServiceEndpoint(typeof(vasaServicePortType), customHttpsBinding, providerConfiguration.VasaUri); } if (_versioningHost == null) { _versioningHost = new WebServiceHost(typeof(VasaVersioningService), providerConfiguration.VasaVersionUri); } if (_taskManager == null) { _taskManager = TaskManager.Instance; } _vasaHost.Open(); _appLog.WriteMessage(ApplicationLogMessageType.Information, Resources.ProviderRun); _versioningHost.Open(); _appLog.WriteMessage(ApplicationLogMessageType.Information, Resources.VersioningRun); _taskManager.Open(); }
public setContextResponse setContext(setContextRequest request) { //TODO [request.usageContext.sessionTimeoutInSeconds] is always 0 String hostId; var isEsxHost = false; List <Model.HostInitiatorInfo> hostInitiators = null; if (request.usageContext != null && !String.IsNullOrWhiteSpace(request.usageContext.vcGuid)) { hostId = request.usageContext.vcGuid; if (!String.IsNullOrWhiteSpace(request.usageContext.hostGuid)) { hostId = request.usageContext.hostGuid; isEsxHost = true; hostInitiators = GetHostInitiators(hostId, request.usageContext.hostInitiator); } } else { var msg = String.Format(Properties.Resources.VasaRequest_ExceptionOccurredSetContext, Properties.Resources.InvalidArgument_UsageContext_VCGuidNotSpecified); _appLog.WriteMessage(ApplicationLogMessageType.Error, msg); _traceSource.TraceEvent(TraceEventType.Error, 0, msg); throw new FaultException <VMware.Vim.Vasa20.DataContract.InvalidArgument>( new VMware.Vim.Vasa20.DataContract.InvalidArgument(msg), msg); } try { var session = _sessionManager.OpenSession(hostId, hostInitiators); SetVasaSessionId(session.Id); if (isEsxHost) { var serveTask = new ServePETask { HostId = request.usageContext.hostGuid }; TaskManagerHelper.AddTask(serveTask); } var response = Execute <setContextResponse>("setContext", request, false); [email protected] = String.Format("{0}", session.Id); return(response); } catch (System.Exception ex) { var msg = String.Format(Properties.Resources.VasaRequest_ExceptionOccurredSetContext, ex.ToString()); _appLog.WriteMessage(ApplicationLogMessageType.Error, msg); _traceSource.TraceEvent(TraceEventType.Error, 0, msg); throw new FaultException <VMware.Vim.Vasa20.DataContract.StorageFault>( new VMware.Vim.Vasa20.DataContract.StorageFault( Properties.Resources.DataCore_StorageFault_RequestUnexpectedException, new NameValuePair { parameterName = Properties.Resources.DataCore_StorageFault_RequestParam, parameterValue = Properties.Resources.SetContext_Request }, new NameValuePair { parameterName = Properties.Resources.DataCore_StorageFault_ExceptionParam, parameterValue = ex.Message }), ex.Message); } }