Esempio n. 1
0
		public void CloseChannel(IAzureServiceManagement channel)
		{
			var clientChannel = channel as IClientChannel;
			if (clientChannel != null)
			{
				clientChannel.Close();
				clientChannel.Dispose();
			}
		}
Esempio n. 2
0
		bool TryFindDeployment()
		{
			if (!_enabled || _status != ManagementStatus.Unknown)
			{
				throw new InvalidOperationException();
			}

			if (_channel == null)
			{
				if (_client == null)
				{
					_client = new ManagementClient(_certificate.Value);
				}

				_channel = _client.CreateChannel();
			}


			var deployments = new List<Pair<Deployment, HostedService>>();
			try
			{
				var hostedServices = _retryPolicy.Get(() => _channel.ListHostedServices(_subscriptionId.Value));
				foreach (var hostedService in hostedServices)
				{
					var service = _retryPolicy.Get(() => _channel.GetHostedServiceWithDetails(_subscriptionId.Value, hostedService.ServiceName, true));
					if (service == null || service.Deployments == null)
					{
						_log.Warn("Azure Self-Management: skipped unexpected null service or deployment list");
						continue;
					}

					foreach (var deployment in service.Deployments)
					{
						deployments.Add(Tuple.From(deployment, service));
					}
				}
			}
			catch (MessageSecurityException)
			{
				_status = ManagementStatus.AuthenticationFailed;
				return false;
			}
			catch (Exception ex)
			{
				_log.Error(ex, "Azure Self-Management: unexpected error when listing all hosted services.");
				return false;
			}

			if (deployments.Count == 0)
			{
				_log.Warn("Azure Self-Management: found no hosted service deployments");
				_status = ManagementStatus.DeploymentNotFound;
				return false;
			}

			var selfServiceAndDeployment = deployments.FirstOrEmpty(pair => pair.Key.PrivateID == _deploymentId.Value);
			if (!selfServiceAndDeployment.HasValue)
			{
				_log.WarnFormat("Azure Self-Management: no hosted service deployment matches {0}", _deploymentId.Value);
				_status = ManagementStatus.DeploymentNotFound;
				return false;
			}

			_status = ManagementStatus.Available;
			_service = selfServiceAndDeployment.Value.Value;
			_deployment = selfServiceAndDeployment.Value.Key;
			return true;
		}
Esempio n. 3
0
		void PrepareRequest()
		{
			if (!_enabled)
			{
				throw new InvalidOperationException("not enabled");
			}

			if (_channel == null)
			{
				if (_client == null)
				{
					_client = new ManagementClient(_certificate.Value);
				}

				_channel = _client.CreateChannel();
			}

			if (_status == ManagementStatus.Unknown)
			{
				TryFindDeployment();
			}

			if (_status != ManagementStatus.Available)
			{
				throw new InvalidOperationException("not operational");
			}
		}