public BasketAbstract(GlobalServeDbContext dbContext, ConfigurationService configurationService, ApplicationUserService userService) { _userService = userService; _configurationService = configurationService; _dbContext = dbContext; standardApiResponse = new StandardApiResponse(); }
private async Task RegistrationSuccessfull(dynamic data) { StandardApiResponse <bool> result = null; StandardApiResponse <bool> expectedResult = new StandardApiResponse <bool>(true, "1.0", true); using (var client = new HttpClient()) { Guid requestId = Guid.NewGuid(); await GenHeandersWithBearerToken(client, requestId); var response = await client.PostAsync($"{IdentityApiUrl}/account/register", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <StandardApiResponse <bool> >(content); if (!result.Success) { Assert.False(true, await response.Content.ReadAsStringAsync()); } } else { Assert.False(true, await response.Content.ReadAsStringAsync()); } } Assert.Equal(expectedResult.Success, result.Success); Assert.Equal(expectedResult.Result, result.Result); }
public void GivenTheFollowingCoursesExist(Table table) { _courseResponses = table.CreateSet <Apis.Courses.StandardResponse>(); foreach (var course in _courseResponses) { var apiResponse = new StandardApiResponse { Level = course.Level, Title = course.Title, ApprenticeshipFunding = new List <SharedOuterApi.InnerApi.Responses.ApprenticeshipFunding> { new SharedOuterApi.InnerApi.Responses.ApprenticeshipFunding { Duration = course.CourseDuration, EffectiveFrom = new System.DateTime(2020, 1, 1), EffectiveTo = new System.DateTime(2030, 1, 1) } } }; _context.CoursesInnerApi.MockServer .Given( Request.Create() .WithPath($"/api/courses/standards/{course.Id}") .UsingGet()) .RespondWith( Response.Create() .WithStatusCode((int)HttpStatusCode.OK) .WithHeader("Content-Type", "application/json") .WithBody(JsonConvert.SerializeObject(apiResponse))); } }
public async Task Registration003() { var data = new RegistrationForm { Username = UserIdGlobal, Email = "*****@*****.**", Password = StdPassword, Pin = 132456, Country = "Indonesia", CountryCode = "IDN", MobileNumber = "+6289613773993", SecurityQuestion = "Who is your President?", SecurityAnswer = "Jokowi" }; await RegistrationSuccessfull(data); var requestConfirmEmail = new ValidationEmailForm { userName = UserIdGlobal, token = getTokenValidation(UserIdGlobal) }; StandardApiResponse <bool> confirmEmailResult = null; StandardApiResponse <bool> confirmEmailExpectedResult = new StandardApiResponse <bool>(true, "1.0", true); using (var client = new HttpClient()) { Guid requestId = Guid.NewGuid(); await GenHeandersWithBearerToken(client, requestId); var response = await client.PostAsync($"{IdentityApiUrl}/account/confirm-email", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); confirmEmailResult = JsonConvert.DeserializeObject <StandardApiResponse <bool> >(content); if (!confirmEmailResult.Success) { Assert.False(true, await response.Content.ReadAsStringAsync()); } } else { Assert.False(true, await response.Content.ReadAsStringAsync()); } } Assert.Equal(confirmEmailExpectedResult.Success, confirmEmailResult.Success); Assert.Equal(confirmEmailExpectedResult.Result, confirmEmailResult.Result); }
public string TransferFromUrl(string contentUrl, string styleUrl) { DeepAI_API api = new DeepAI_API(_configuration.GetValue <string>("DeepAISettings:ApiKey")); StandardApiResponse resp = api.callStandardApi("fast-style-transfer", new { content = contentUrl, style = styleUrl }); return(api.objectAsJsonString(resp)); }
public string CompararImagen() { DeepAI_API api = new DeepAI_API(apiKey: "quickstart-QUdJIGlzIGNvbWluZy4uLi4K"); StandardApiResponse resp = api.callStandardApi("image-similarity", new { image1 = File.OpenRead(@"C:\Users\juan.jose.agudelo\source\repos\DesparcheBackend\DesparcheBackend\temp\imagen1.jpeg"), image2 = File.OpenRead(@"C:\Users\juan.jose.agudelo\source\repos\DesparcheBackend\DesparcheBackend\temp\imagen2.jpeg"), }); string diferencia = api.objectAsJsonString(resp.output); return(diferencia); }
static void Main(string[] args) { DeepAI_API api = new DeepAI_API(apiKey: "c374d52f-84ce-46a6-8a4f-598ba5b9e988"); StandardApiResponse resp = api.callStandardApi("nsfw-detector", new { image = File.OpenRead(@"C:\Users\www\Desktop\1\sasha2.jpg"), }); // File.WriteAllText("file.txt", api.objectAsJsonString(resp)); Console.WriteLine(api.objectAsJsonString(resp)); Console.ReadLine(); }
public string TransferFromFile(string contentPath, string stylePath) { DeepAI_API api = new DeepAI_API(_configuration.GetValue <string>("DeepAISettings:ApiKey")); using var contentStream = File.OpenRead(contentPath); using var styleStream = File.OpenRead(stylePath); StandardApiResponse resp = api.callStandardApi("fast-style-transfer", new { content = contentStream, style = styleStream }); return(api.objectAsJsonString(resp)); }
public async Task Registration002() { var data = new RegistrationForm { Username = "******", Email = "*****@*****.**", Password = StdPassword, Pin = 132456, Country = "Indonesia", CountryCode = "IDN", MobileNumber = "+6289613773993", SecurityQuestion = "Who is your President?", SecurityAnswer = "Jokowi" }; StandardApiResponse <bool> result = null; StandardApiResponse <bool> expectedResult = new StandardApiResponse <bool>(false, "1.0", false); using (var client = new HttpClient()) { GenHeadersWithBasicAuth(client); var response = await client.PostAsync($"{IdentityApiUrl}/account/register", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { result = JsonConvert.DeserializeObject <StandardApiResponse <bool> >(await response.Content.ReadAsStringAsync()); } else { switch (response.StatusCode) { case System.Net.HttpStatusCode.BadRequest: Assert.False(true, response.ReasonPhrase + await response.Content.ReadAsStringAsync()); break; case System.Net.HttpStatusCode.InternalServerError: Assert.False(true, "Internal code error - please check the source code" + await response.Content.ReadAsStringAsync()); break; } } } Assert.Equal(expectedResult.Success, result.Success); Assert.Equal(expectedResult.Result, result.Result); }
public IActionResult GenerateProduct(Product product) { WebClient webClient = new WebClient(); StandardApiResponse imgResp = api.callStandardApi("text2img", new { text = product.Name }); StandardApiResponse descResp = api.callStandardApi("text-generator", new { text = product.Name }); Product newProduct = new Product(product.Name, descResp.output.ToString()); context.Products.Add(newProduct); context.SaveChanges(); newProduct.ImageURL = "/image/" + newProduct.Id + ".jpg"; context.Update(newProduct); context.SaveChanges(); webClient.DownloadFile(imgResp.output_url, "wwwroot/Image/" + newProduct.Id + ".jpg"); return(Redirect("/product/" + newProduct.Id)); }
public static int GetSimilarScore(string localFile, string hostFileUrl) { api = new DeepAI_API(apiKey: "ed6a1b7c-f7ab-428f-997f-474ea0c1e1dc"); if (api == null) { throw new InvalidOperationException("The API Ket did not work"); } // Ensure your DeepAI.Client NuGet package is up to date: https://www.nuget.org/packages/DeepAI.Client StandardApiResponse resp = api.callStandardApi("image-similarity", new { image1 = File.OpenRead(localFile), // local file image2 = hostFileUrl, // host file }); var re = JsonConvert.DeserializeObject <ImageSimilarityResponse>(api.objectAsJsonString(resp.output)); return(re.distance); }
private void btnKarsilastir_Click(object sender, EventArgs e) { DeepAI_API api = new DeepAI_API(apiKey: "df10d4f7-7797-4030-b0f6-e5243e869c91"); string a = resim1.FileName; string a2 = resim2.FileName; StandardApiResponse resp = api.callStandardApi("image-similarity", new { //image1 = resim1.FileName.ToString(), //image2 = resim2.FileName.ToString(), image1 = File.OpenRead(a), image2 = File.OpenRead(a2), //File.OpenRead("C:\\path\\to\\your\\file.jpg"), }); string gelen = api.objectAsJsonString(resp.output); lblSonuc.Text = api.objectAsJsonString(resp.output).ToString(); }
private void button2_Click(object sender, EventArgs e) { if (openFileDialog1.CheckFileExists && isFileSelected) { pictureBox1.Visible = false; MessageBox.Show("Please wait a few seconds! Your file is being uploaded and upscaled."); DeepAI_API api = new DeepAI_API(apiKey: "Enter your DeepAI Licencekey here."); StandardApiResponse resp = api.callStandardApi("torch-srgan", new { image = File.OpenRead(openFileDialog1.FileName), }); dynamic d = JObject.Parse(api.objectAsJsonString(resp)); Console.Write(d.output_url); pictureBox1.ImageLocation = d.output_url; pictureBox1.Visible = true; MessageBox.Show("Your file has been upscaled and is now available in the output folder."); } }
public async Task Login001() { var data = new LoginForm { userName = UserIdGlobal, password = "******" }; StandardApiResponse <bool> result = null; StandardApiResponse <bool> expectedResult = new StandardApiResponse <bool>(true, "1.0", true); using (var client = new HttpClient()) { GenHeadersWithBasicAuth(client); var response = await client.PostAsync($"{IdentityApiUrl}/account/login", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { result = JsonConvert.DeserializeObject <StandardApiResponse <bool> >(await response.Content.ReadAsStringAsync()); } else { switch (response.StatusCode) { case System.Net.HttpStatusCode.BadRequest: Assert.False(true, response.ReasonPhrase + await response.Content.ReadAsStringAsync()); break; case System.Net.HttpStatusCode.InternalServerError: Assert.False(true, "Internal code error - please check the source code" + await response.Content.ReadAsStringAsync()); break; } } } Assert.Equal(expectedResult.Success, result.Success); Assert.Equal(expectedResult.Result, result.Result); }
public async Task Registration007() { var data = new ValidationEmailForm { userName = "******", token = getTokenOTPValidation("+6289613773993") }; StandardApiResponse <bool> result = null; StandardApiResponse <bool> expectedResult = new StandardApiResponse <bool>(false, "1.0", false); using (var client = new HttpClient()) { GenHeadersWithBasicAuth(client); var response = await client.PostAsync($"{IdentityApiUrl}/account/confirm-phone-number", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { result = JsonConvert.DeserializeObject <StandardApiResponse <bool> >(await response.Content.ReadAsStringAsync()); } else { switch (response.StatusCode) { case System.Net.HttpStatusCode.BadRequest: Assert.False(true, response.ReasonPhrase + await response.Content.ReadAsStringAsync()); break; case System.Net.HttpStatusCode.InternalServerError: Assert.False(true, "Internal code error - please check the source code" + await response.Content.ReadAsStringAsync()); break; } } } Assert.Equal(expectedResult.Success, result.Success); Assert.Equal(expectedResult.Result, result.Result); }
public async Task Registration006() { var data = new ValidationEmailForm { userName = UserIdGlobal, token = getTokenOTPValidation("+6289613773993") }; StandardApiResponse <bool> result = null; StandardApiResponse <bool> expectedResult = new StandardApiResponse <bool>(true, "1.0", true); using (var client = new HttpClient()) { Guid requestId = Guid.NewGuid(); await GenHeandersWithBearerToken(client, requestId); var response = await client.PostAsync($"{IdentityApiUrl}/account/confirm-phone-number", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <StandardApiResponse <bool> >(content); if (!result.Success) { Assert.False(true, await response.Content.ReadAsStringAsync()); } } else { Assert.False(true, await response.Content.ReadAsStringAsync()); } } Assert.Equal(expectedResult.Success, result.Success); Assert.Equal(expectedResult.Result, result.Result); }
public async Task Registration005() { var data = new ValidationEmailForm { userName = "******", token = "OASUHDALSHDIUASHDOUIHASUIDHASUID" }; StandardApiResponse <bool> result = null; StandardApiResponse <bool> expectedResult = new StandardApiResponse <bool>(false, "1.0", false); using (var client = new HttpClient()) { Guid requestId = Guid.NewGuid(); await GenHeandersWithBearerToken(client, requestId); var response = await client.PostAsync($"{IdentityApiUrl}/account/confirm-email", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <StandardApiResponse <bool> >(content); if (!result.Success) { Assert.False(true, await response.Content.ReadAsStringAsync()); } } else { Assert.False(true, await response.Content.ReadAsStringAsync()); } } Assert.Equal(expectedResult.Success, result.Success); Assert.Equal(expectedResult.Result, result.Result); }
public async Task Login001() { var data = new LoginForm { userName = UserIdGlobal, password = "******" }; StandardApiResponse <bool> result = null; StandardApiResponse <bool> expectedResult = new StandardApiResponse <bool>(true, "1.0", true); using (var client = new HttpClient()) { Guid requestId = Guid.NewGuid(); await GenHeandersWithBearerToken(client, requestId); var response = await client.PostAsync($"{IdentityApiUrl}/account/login", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <StandardApiResponse <bool> >(content); if (!result.Success) { Assert.False(true, await response.Content.ReadAsStringAsync()); } } else { Assert.False(true, await response.Content.ReadAsStringAsync()); } } Assert.Equal(expectedResult.Success, result.Success); Assert.Equal(expectedResult.Result, result.Result); }
static void Main(string[] args) { //args = new string[] { "-k=983cc50b-cd6f-48ad-85c9-b3aae4f7f26f ", "-is=SM-0003.www.ebay.co.uk.311858508219.jpg", "-is=SM-0016.www.ebay.co.uk.123752402471.jpg", "-is=SM-0016_.www.ebay.co.uk.183994826038.jpg"}; bool show_help = false; string apiKey = ""; List <string> images = new List <string>(); DeepAI_API m_DeepAI_API = null; var p = new OptionSet() { { "k|key=", "DeepAI api key", v => apiKey = v }, { "r", "Use remote files with url", v => useLocalFiles = v == null }, { "is|imgsource=", "Images to compare", (string v) => images.Add(v) }, { "v", "increase debug message verbosity", v => { if (v != null) { ++verbosity; } } }, { "h|help", "show this message and exit", v => show_help = v != null } }; List <string> extra; try { extra = p.Parse(args); } catch (OptionException e) { Console.Write("daic: "); Console.WriteLine(e.Message); Console.WriteLine("Try `daic --help' for more information."); return; } if (show_help) { ShowHelp(p); return; } if (extra.Count > 0) { } else { } if (images.Count < 2) { Console.WriteLine("Images count must be lager that 2."); Console.WriteLine("Try `daic --help' for more information."); return; } if (string.IsNullOrEmpty(apiKey)) { Console.WriteLine("Deep Api key not specified!"); Console.WriteLine("Try `daic --help' for more information."); return; } var results = new List <StandardApiResponse>(); m_DeepAI_API = new DeepAI_API(apiKey: apiKey); var comparsionCount = images.Count - 1; var firstImage = images[0]; for (int i = 1; i <= comparsionCount; i++) { var opt = BuildInputOptions(firstImage, images[i]); StandardApiResponse resp = m_DeepAI_API.callStandardApi("image-similarity", opt); results.Add(resp); } var distances = new List <int>(); foreach (var result in results) { Newtonsoft.Json.Linq.JObject distance = (Newtonsoft.Json.Linq.JObject)result.output; var value = JObjectToInt(distance); distances.Add(value); } var outputStr = string.Join(";", distances.ToArray()); Console.Write(outputStr); //Console.ReadKey(); /* * // Ensure your DeepAI.Client NuGet package is up to date: https://www.nuget.org/packages/DeepAI.Client * DeepAI_API api = new DeepAI_API(apiKey: "983cc50b-cd6f-48ad-85c9-b3aae4f7f26f"); * StandardApiResponse resp = api.callStandardApi("image-similarity", new * { * image1 = "YOUR_IMAGE_URL", * image2 = "YOUR_IMAGE_URL", * }); * Console.Write(api.objectAsJsonString(resp)); */ }