private async Task CreateEndpointsAsync(HttpClient httpClient, IList <EndpointDescription> endpointDescriptions) { IReadOnlyCollection <Endpoint> existingEndpoints = await EndpointHelpers.GetEndpointsAsync(httpClient, JsonSerializerSettings); foreach (EndpointDescription endpointDescription in endpointDescriptions) { if (existingEndpoints.Any(e => e.Type == endpointDescription.type && e.EventTypes.Intersect(endpointDescription.eventTypes).Any())) { // Assuming that if endpoing matching Type, Path, and EventTypes already exists then its connection strings are already correct continue; } Endpoint endpoint = endpointDescription.ToDigitalTwins(EventHubConnectionString, EventHubSecondaryConnectionString, EventHubName); Console.WriteLine($"Creating Endpoint: {JsonConvert.SerializeObject( endpoint, Formatting.Indented, JsonSerializerSettings )}"); var request = HttpMethod.Post.CreateRequest("endpoints", JsonConvert.SerializeObject(endpoint, JsonSerializerSettings)); var response = await httpClient.SendAsync(request); if (!response.IsSuccessStatusCode) { Console.WriteLine("Failed to create endpoint."); } } Console.WriteLine(); }
private static async Task RemoveAllExistingEndpoints(HttpClient httpClient) { IReadOnlyCollection <Endpoint> existingEndpoints = await EndpointHelpers.GetEndpointsAsync(httpClient, JsonSerializerSettings); if (!existingEndpoints.Any()) { return; } Console.WriteLine(); Console.WriteLine($"Removing {existingEndpoints.Count} endpoints."); foreach (Endpoint endpointToRemove in existingEndpoints) { bool success = await endpointToRemove.DeleteEndpointAsync(httpClient, JsonSerializerSettings); if (!success) { Console.WriteLine($"Failed to remove Endpoint, please try manually. (Id: {endpointToRemove.Id})"); } } Console.WriteLine(); }
/// <summary> /// Gets a <see cref="TatsuGuildRankings"/> instance using the provided <paramref name="guildID"/>, and applies the provided <paramref name="offset"/>. /// </summary> /// <param name="guildID">The ID of the guild.</param> /// <param name="offset">The offset.</param> public async Task <TatsuGuildRankings> GetAllTimeGuildRankings(string guildID, ulong offset) => await Get <TatsuGuildRankings>(EndpointHelpers.GetAllTimeGuildRankings(guildID, offset));
/// <summary> /// Gets a universal user profile (<see cref="TatsuUser"/>) used across the entirety of Tatsu. /// </summary> /// <param name="userID">The ID of the user you want to access.</param> public async Task <TatsuUser> GetUserProfile(string userID) => await Get <TatsuUser>(EndpointHelpers.GetUserProfile(userID));
/// <summary> /// Gets a <see cref="TatsuGuildMemberRanking"/> instance with the given <paramref name="guildID"/> and <paramref name="userID"/>. /// </summary> /// <param name="guildID">The guild you want to get rankings from.</param> /// <param name="userID">The ID of the user who you want to get the rankings of.</param> public async Task <TatsuGuildMemberRanking> GetAllTimeGuildMemberRanking(string guildID, string userID) => await Get <TatsuGuildMemberRanking>(EndpointHelpers.GetAllTimeGuildMemberRanking(guildID, userID));