/// <summary> /// Carries out an operation on a <see cref="Tenant"/> on this plaform identified by the request. /// </summary> /// <param name="tenantRequest">The request.</param> /// <returns>The response.</returns> public TenantInfoResponse TenantOperation(TenantOperationRequest tenantRequest) { using (Profiler.Measure("CastActivityService.TenantOperation")) { var response = new TenantInfoResponse { Tenants = new TenantList() }; try { if (tenantRequest == null) { throw new ArgumentNullException("tenantRequest"); } if (string.IsNullOrEmpty(tenantRequest.Name)) { throw new ArgumentException("Tenant name may not be empty."); } if (!CastService.GetIsCastConfigured()) { throw new InvalidOperationException(); } var name = tenantRequest.Name; switch (tenantRequest.Operation) { case Operation.Create: TenantService.Create(name); break; case Operation.Delete: TenantService.Delete(name); break; case Operation.Enable: TenantService.Enable(name); break; case Operation.Disable: TenantService.Disable(name); break; case Operation.Rename: TenantService.Rename(tenantRequest.Id, tenantRequest.Name); break; default: throw new NotSupportedException(tenantRequest.Operation.ToString()); } if (tenantRequest.Operation != Operation.Delete) { var ti = TenantService.GetTenant(name); if (ti != null) { response.Tenants.Add(ti); } } } catch (Exception e) { response.IsError = true; response.Error = e.Message; } return(response); } }