502 lines
16 KiB
C#

//Generated using MontoyaTech.Rest.Net - 2/18/2024
public class Client
{
public string BaseUrl;
public System.Net.CookieContainer CookieContainer;
public System.Net.Http.HttpMessageHandler MessageHandler;
public System.Net.Http.HttpClient HttpClient;
public System.Action<System.Net.Http.HttpRequestMessage> RequestHandler;
public TestApi Test;
public AuthApi Auth;
public StreamApi Stream;
public FormApi Form;
public Client(string baseUrl, System.Net.Http.HttpMessageHandler handler = null, System.Action<System.Net.Http.HttpRequestMessage> requestHandler = null)
{
if (string.IsNullOrWhiteSpace(baseUrl))
throw new System.ArgumentException("baseUrl must not be null or whitespace.");
if (baseUrl.EndsWith('/'))
baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
this.BaseUrl = baseUrl;
this.CookieContainer = new System.Net.CookieContainer();
if (handler == null)
{
handler = new System.Net.Http.HttpClientHandler()
{
AllowAutoRedirect = true,
UseCookies = true,
CookieContainer = this.CookieContainer,
AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate
};
}
this.MessageHandler = handler;
this.RequestHandler = requestHandler;
this.HttpClient = new System.Net.Http.HttpClient(handler);
this.HttpClient.DefaultRequestHeaders.Add("Accept", "*/*");
this.HttpClient.DefaultRequestHeaders.Add("Connection", "keep-alive");
this.HttpClient.DefaultRequestHeaders.Add("Accept-Encoding", "identity");
this.Test = new TestApi(this);
this.Auth = new AuthApi(this);
this.Stream = new StreamApi(this);
this.Form = new FormApi(this);
}
public class TestApi
{
public Client Client;
public TestApi(Client client)
{
this.Client = client;
}
public string Status()
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/status");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return Newtonsoft.Json.JsonConvert.DeserializeObject<string>(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
public string Add(double a, double b)
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{this.Client.BaseUrl}/add/{a}/{b}");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return Newtonsoft.Json.JsonConvert.DeserializeObject<string>(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
public string Compress()
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/compress");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return Newtonsoft.Json.JsonConvert.DeserializeObject<string>(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
public string CompressFile()
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/file/compress");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return Newtonsoft.Json.JsonConvert.DeserializeObject<string>(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
}
public class AuthApi
{
public Client Client;
public AuthApi(Client client)
{
this.Client = client;
}
public bool UserExists(string name)
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/auth/{name}");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return bool.Parse(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
public void Signup(UserDto request, bool compress = false)
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{this.Client.BaseUrl}/auth/signup");
this.Client.RequestHandler?.Invoke(message);
if (compress)
{
using (var uncompressedStream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(request))))
{
using (var compressedStream = new System.IO.MemoryStream())
{
using (var gzipStream = new System.IO.Compression.GZipStream(compressedStream, System.IO.Compression.CompressionMode.Compress, true))
uncompressedStream.CopyTo(gzipStream);
message.Content = new System.Net.Http.ByteArrayContent(compressedStream.ToArray());
message.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(System.Net.Mime.MediaTypeNames.Application.Json);
message.Content.Headers.ContentEncoding.Add("gzip");
}
}
}
else
{
message.Content = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(request));
message.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(System.Net.Mime.MediaTypeNames.Application.Json);
}
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (!response.IsSuccessStatusCode)
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
public UserDto Get()
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/auth/");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return Newtonsoft.Json.JsonConvert.DeserializeObject<UserDto>(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
public dynamic Dynamic()
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/auth/dynamic");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
public UserRole GetRole()
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/auth/role");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return Newtonsoft.Json.JsonConvert.DeserializeObject<UserRole>(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
}
public class StreamApi
{
public Client Client;
public StreamApi(Client client)
{
this.Client = client;
}
public void Upload(System.IO.MemoryStream request, bool compress = false)
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{this.Client.BaseUrl}/upload");
this.Client.RequestHandler?.Invoke(message);
request.Seek(0, System.IO.SeekOrigin.Begin);
message.Content = new System.Net.Http.StreamContent(request);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (!response.IsSuccessStatusCode)
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
public System.IO.MemoryStream Download()
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/download");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var stream = new System.IO.MemoryStream();
response.Content.CopyToAsync(stream).GetAwaiter().GetResult();
return stream;
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
}
public class FormApi
{
public Client Client;
public FormApi(Client client)
{
this.Client = client;
}
public System.Collections.Generic.Dictionary<string, string> FormTest()
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{this.Client.BaseUrl}/form");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(content))
return default;
return Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, string>>(content);
}
else
{
throw new System.Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
}
}
}
public class IncludedType
{
public int Test;
public IncludedType() { }
public IncludedType(IncludedType instance)
{
this.Test = instance.Test;
}
public IncludedType(int Test = 0)
{
this.Test = Test;
}
}
public class UserDto : BaseUser
{
public System.PlatformID MachineType;
public string Name;
public System.Collections.Generic.List<string> List;
public System.String[] Array;
public ulong Property { get; set; }
public UserDto() { }
public UserDto(UserDto instance)
{
this.MachineType = instance.MachineType;
this.Name = instance.Name;
this.List = instance.List;
this.Array = instance.Array;
this.Property = instance.Property;
}
public UserDto(System.PlatformID MachineType = 0, string Name = null, System.Collections.Generic.List<string> List = null, System.String[] Array = null, ulong Property = 0)
{
this.MachineType = MachineType;
this.Name = Name;
this.List = List;
this.Array = Array;
this.Property = Property;
}
}
public class BaseUser
{
public string Id;
public char FirstInitial;
public System.Collections.Generic.List<Permission> Permissions;
public UserRole Role { get; set; }
public BaseUser() { }
public BaseUser(BaseUser instance)
{
this.Id = instance.Id;
this.FirstInitial = instance.FirstInitial;
this.Permissions = instance.Permissions;
this.Role = instance.Role;
}
public BaseUser(string Id = null, char FirstInitial = '\0', System.Collections.Generic.List<Permission> Permissions = null, UserRole Role = 0)
{
this.Id = Id;
this.FirstInitial = FirstInitial;
this.Permissions = Permissions;
this.Role = Role;
}
public class Permission
{
public string Name;
public Types Type;
public Permission() { }
public Permission(Permission instance)
{
this.Name = instance.Name;
this.Type = instance.Type;
}
public Permission(string Name = null, Types Type = 0)
{
this.Name = Name;
this.Type = Type;
}
public enum Types : int
{
Read = 0,
Write = 1,
}
}
}
public enum UserRole : byte
{
Unknown = 0,
Admin = 2,
User = 1,
}
}