Add GetSite to observer client. Add runtimesiteslotmap model into models project

This commit is contained in:
Hawk Foreste 2018-03-21 14:58:02 -07:00
Родитель 69de85ead3
Коммит 005dffd1f8
3 изменённых файлов: 42 добавлений и 8 удалений

Просмотреть файл

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using Diagnostics.ModelsAndUtils.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
@ -8,6 +9,8 @@ namespace Diagnostics.DataProviders
{
public interface ISupportObserverDataProvider
{
Task<dynamic> GetSite(string siteName);
Task<dynamic> GetSite(string stampName, string siteName);
Task<IEnumerable<string>> GetSiteHostNames(string siteName);
Task<string> GetSiteResourceGroupName(string siteName);
Task<IEnumerable<Dictionary<string, string>>> GetSitesInResourceGroup(string subscriptionName, string resourceGroupName);
@ -23,7 +26,7 @@ namespace Diagnostics.DataProviders
Task<JObject> GetAdminSitesBySiteName(string stampName, string siteName);
Task<JObject> GetAdminSitesByHostName(string stampName, string[] hostNames);
Task<string> GetStorageVolumeForSite(string stampName, string siteName);
Task<JObject> GetRuntimeSiteSlotMap(string siteName);
Task<JObject> GetRuntimeSiteSlotMap(string stampName, string siteName);
Task<Dictionary<string, List<RuntimeSitenameTimeRange>>> GetRuntimeSiteSlotMap(string siteName);
Task<Dictionary<string, List<RuntimeSitenameTimeRange>>> GetRuntimeSiteSlotMap(string stampName, string siteName);
}
}

Просмотреть файл

@ -4,7 +4,9 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Diagnostics.ModelsAndUtils.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Diagnostics.DataProviders
@ -49,14 +51,20 @@ namespace Diagnostics.DataProviders
throw new NotImplementedException();
}
public Task<JObject> GetRuntimeSiteSlotMap(string siteName)
public async Task<Dictionary<string, List<RuntimeSitenameTimeRange>>> GetRuntimeSiteSlotMap(string siteName)
{
throw new NotImplementedException();
var response = await GetObserverResource($"sites/{siteName}/runtimesiteslotmap");
var slotTimeRangeCaseSensitiveDictionary = JsonConvert.DeserializeObject<Dictionary<string, List<RuntimeSitenameTimeRange>>>(response);
var slotTimeRange = new Dictionary<string, List<RuntimeSitenameTimeRange>>(slotTimeRangeCaseSensitiveDictionary, StringComparer.CurrentCultureIgnoreCase);
return slotTimeRange;
}
public Task<JObject> GetRuntimeSiteSlotMap(string stampName, string siteName)
public async Task<Dictionary<string, List<RuntimeSitenameTimeRange>>> GetRuntimeSiteSlotMap(string stampName, string siteName)
{
throw new NotImplementedException();
var response = await GetObserverResource($"stamp/{stampName}/sites/{siteName}/runtimesiteslotmap");
var slotTimeRangeCaseSensitiveDictionary = JsonConvert.DeserializeObject<Dictionary<string, List<RuntimeSitenameTimeRange>>>(response);
var slotTimeRange = new Dictionary<string, List<RuntimeSitenameTimeRange>>(slotTimeRangeCaseSensitiveDictionary, StringComparer.CurrentCultureIgnoreCase);
return slotTimeRange;
}
public Task<IEnumerable<Dictionary<string, string>>> GetServerFarmsInResourceGroup(string subscriptionName, string resourceGroupName)
@ -72,7 +80,7 @@ namespace Diagnostics.DataProviders
public async Task<IEnumerable<string>> GetSiteHostNames(string siteName)
{
var response = await GetObserverResource($"sites/{siteName}/hostnames?api-version=2.0");
var hostnames = response.Split(new char[] { ',' });
var hostnames = response.Remove(0, 1).Remove(response.Length - 2, 1).Split(new char[] { ',' });
return hostnames;
}
@ -106,6 +114,18 @@ namespace Diagnostics.DataProviders
throw new NotImplementedException();
}
public async Task<dynamic> GetSite(string siteName)
{
var response = await GetObserverResource($"sites/{siteName}");
var siteObject = JsonConvert.DeserializeObject(response);
return siteObject;
}
public async Task<dynamic> GetSite(string stampName, string siteName)
{
return await GetSite(siteName);
}
private async Task<string> GetObserverResource(string url)
{
var request = new HttpRequestMessage(HttpMethod.Get, url);

Просмотреть файл

@ -0,0 +1,11 @@
using System;
namespace Diagnostics.ModelsAndUtils.Models
{
public class RuntimeSitenameTimeRange
{
public string RuntimeSitename { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
}