private void buttonLicense_Click(object sender, EventArgs e) { var sfd = new SaveFileDialog() { Filter = "*.liblicense|*.liblicense" }; if (sfd.ShowDialog(this) != DialogResult.OK) { return; } var license = new LicenseDto { Features = new List <LicenseFeatures>(), ToWhom = textBox1.Text, ValidFrom = dateTimePicker1.Value, ValidTo = dateTimePicker2.Value }; if (checkBox1.Checked) { license.Features.Add(LicenseFeatures.Read); } if (checkBox2.Checked) { license.Features.Add(LicenseFeatures.Write); } CreateLicenseFile(license, sfd.FileName); }
public void CreateLicenseFile(LicenseDto dto, string fileName) { var ms = new MemoryStream(); new XmlSerializer(typeof(LicenseDto)).Serialize(ms, dto); // Create a new CspParameters object to specify // a key container. // Create a new RSA signing key and save it in the container. RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(); rsaKey.FromXmlString(LibraryLicense.Properties.Resources.PrivateKey); // Create a new XML document. XmlDocument xmlDoc = new XmlDocument(); // Load an XML file into the XmlDocument object. xmlDoc.PreserveWhitespace = true; ms.Seek(0, SeekOrigin.Begin); xmlDoc.Load(ms); // Sign the XML document. SignXml(xmlDoc, rsaKey); // Save the document. xmlDoc.Save(fileName); }
public async Task <IActionResult> Edit(Guid id, [FromForm] LicenseDto item) { if (ModelState.IsValid) { if (!context.Licenses.Any(x => x.Id == item.Id)) { return(NotFound()); } item.Id = id; var entity = context.Licenses.Update(item); var successful = await context.SaveChangesAsync() == 1; entity.State = EntityState.Detached; if (!successful) { return(BadRequest("Could not update the item.")); } return(RedirectToAction("Index")); } else { return(View("Edit", model: item)); } }
public void GivenLicenseDto_ReturnsLicenseProduct() { // Arrange var license = new LicenseDto { Id = Guid.NewGuid(), Products = new List <LicenseProductDto> { new LicenseProductDto { Name = "Product Name", Expiration = DateTime.UtcNow } } }; // Act var result = license.ToResponse(); // Assert Assert.Multiple(() => { Assert.That(result.Id, Is.EqualTo(license.Id)); Assert.That(result.Products[0].Name, Is.EqualTo(result.Products[0].Name)); DiagnoseaAssert.That(result.Products[0].Expiration, Is.EqualTo(result.Products[0].Expiration)); }); }
internal static License FromDto(LicenseDto dto) { return(new License { AllowedAttended = dto.Allowed?.Attended, AllowedDevelopment = dto.Allowed?.Development, AllowedNonProduction = dto.Allowed?.NonProduction, AllowedUnattended = dto.Allowed?.Unattended, UsedAttended = dto.Used?.Attended, UsedDevelopment = dto.Used?.Development, UsedNonProduction = dto.Used?.NonProduction, UsedUnattended = dto.Used?.Unattended, AttendedConcurrent = dto.AttendedConcurrent, DevelopmentConcurrent = dto.DevelopmentConcurrent, Id = dto.Id, HostLicenseId = dto.HostLicenseId, Code = dto.Code, CreationTime = dto.CreationTime, ExpireDate = UnixTimeStampToDateTime(dto.ExpireDate ?? 0), IsExpired = dto.IsExpired, IsRegistered = dto.IsRegistered, }); }
public async Task <IActionResult> Add([FromForm] LicenseDto newItem) { if (ModelState.IsValid) { newItem.Id = Guid.NewGuid(); newItem.GeneratedAt = DateTime.UtcNow; newItem.Key = Guid.NewGuid().ToString(); var entity = await context.Licenses.AddAsync(newItem); var successful = await context.SaveChangesAsync() == 1; entity.State = EntityState.Detached; if (!successful) { return(BadRequest("Could not add item.")); } return(RedirectToAction("Index")); } else { return(View("Add", model: newItem)); } }
public LicenseService(IOptions <LicenseDto> licenseOptions, IHttpContextAccessor httpContextAccessor, IEncryptionService encryptionService) { _licenseOptions = licenseOptions.Value; _httpContextAccessor = httpContextAccessor; _encryptionService = encryptionService; }
public static LicenseResponse ToResponse(this LicenseDto license) { return(new LicenseResponse { Id = license.Id, Products = license.Products.Select(x => x.ToResponse()).ToList() }); }
public async Task DeleteLicenseAsync(LicenseDto input) { var license = _licenseRepository.FirstOrDefault(input.Id); if (license == null) { throw new UserFriendlyException("license not Found!"); } await _licenseRepository.DeleteAsync(license); }
public async Task <bool> PostLicense(LicenseDto license) { HttpResponseMessage response = await _client.PostAsJsonAsync <LicenseDto>("api/licenses", license); if (!response.IsSuccessStatusCode) { string responseMessage = await response.Content.ReadAsStringAsync(); return(false); } return(true); }
private void button2_Click(object sender, EventArgs e) { if (License != null) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { var dto = new LicenseDto(); dto.LicenseeName = textBox2.Text; dto.ValidUntil = dateTimePicker1.Value; License.CreateLicenseFile(dto, saveFileDialog1.FileName); MessageBox.Show("Лицензия:" + saveFileDialog1.FileName); } } }
private void button2_Click(object sender, EventArgs e) { if (License != null) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { var dto = new LicenseDto(); dto.LicenseeName = textBox2.Text; dto.ValidUntil = dateTimePicker1.Value; dto.AllowedFeatures = new List <string>(); foreach (var val in textBox1.Text.Split(',')) { dto.AllowedFeatures.Add(val.Trim()); } License.CreateLicenseFile(dto, saveFileDialog1.FileName); MessageBox.Show("Лицензия:" + saveFileDialog1.FileName); } } }
private void GetLicense() { RequestApi requestApi = new RequestApi(ApiRoutes.GetLicenseRequest); _logger.Info("Starting get license info..."); requestApi.OnFinish += response => { ResponseApi responseApi = (ResponseApi)response; try { string jsonData = responseApi.Data.ToString(); LicenseDto licenseDto = jsonData.JsonDeserialize <LicenseDto>(); LicenseInfo.Value = licenseDto.License; if (LauncherErrorManager.Instance) { LauncherErrorManager.Instance.License(LicenseInfo.Value); } _logger.Info("License ok! Edition is " + LicenseInfo.Value.EditionId); _licenseGot = true; } catch (Exception e) { LauncherErrorManager.Instance.ShowFatal(ErrorHelper.GetErrorDescByCode(Varwin.Errors.ErrorCode.LicenseKeyError), e.Message); _logger.Fatal("License information error"); _licenseGot = false; } }; requestApi.OnError += s => { LauncherErrorManager.Instance.ShowFatal(ErrorHelper.GetErrorDescByCode(Varwin.Errors.ErrorCode.LicenseKeyError), s); _logger.Fatal("License information error"); _licenseGot = false; }; }
private void Generate_Click(object sender, RoutedEventArgs e) { FieldErrorLabel.Visibility = Visibility.Hidden; KeyErrorLabel.Visibility = Visibility.Hidden; SuccessLabel.Visibility = Visibility.Hidden; string name = NameTextBox.Text; if (name == "" || FromDateBox.SelectedDate == null || ToDateBox.SelectedDate == null) { FieldErrorLabel.Visibility = Visibility.Visible; return; } string privateKey, publicKey; try { privateKey = File.ReadAllText(privateKeyPath); publicKey = File.ReadAllText(publicKeyPath); if (privateKey == "" || publicKey == "") { throw new Exception("Keys not found."); } } catch (Exception) { KeyErrorLabel.Visibility = Visibility.Visible; return; } LicenseDto dto = new LicenseDto(publicKey, name, FromDateBox.SelectedDate.Value, ToDateBox.SelectedDate.Value); var fileName = string.Join("", DateTime.Now.ToString().Where(c => char.IsDigit(c))); new LicenseHelper(privateKey).CreateLicenseFile(dto, fileName + ".gh_license"); SuccessLabel.Visibility = Visibility.Visible; }
public Task UpdateLicense(LicenseDto input) { throw new NotImplementedException(); }