public LicenseKeyService(ISmallKeyGenerator staticSmallKeyGenerator, ILargeKeyGenerator staticLargeKeyGenerator, IPackingService packingService, IClientLicenseService clientLicenseService) { keyGenerator = staticSmallKeyGenerator; _largeKeyGenerator = staticLargeKeyGenerator; _packingService = packingService; _clientLicenseService = clientLicenseService; // Need to find a way to get these passed in correctly //keyGenerator = ObjectLocator.GetInstance<IKeyGenerator>(InstanceNames.SmallKeyGenerator); //_largeKeyGenerator = ObjectLocator.GetInstance<IKeyGenerator>(InstanceNames.LargeKeyGenerator); }
private void btnGenerateKeys_Click(object sender, System.Windows.RoutedEventArgs e) { if (IsGenerationFormValid()) { loadingAnimation.Visibility = Visibility.Visible; BackgroundWorker worker = new BackgroundWorker(); LicenseGenerationOptions licenseGenerationOptions = new LicenseGenerationOptions(); int keysToGenerate = int.Parse(txtKeysToGenerate.Text); if (cboSingleUser.IsChecked.HasValue && cboSingleUser.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.SingleUser; } else if (cboMultiUser.IsChecked.HasValue && cboMultiUser.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.MultiUser; } else if (cboHardwareLock.IsChecked.HasValue && cboHardwareLock.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.HardwareLock; } else if (cboUnlimited.IsChecked.HasValue && cboUnlimited.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.Unlimited; } else if (cboEnterprise.IsChecked.HasValue && cboEnterprise.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.Enterprise; } else if (cboHardwareLockLocal.IsChecked.HasValue && cboHardwareLockLocal.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.HardwareLockLocal; licenseGenerationOptions.HardwareFingerprint = txtHardwareKeyData.Text; keysToGenerate = 1; // Can only generate 1 local hardware locked key at a time. } licenseGenerationOptions.LicenseSetId = ((LicenseSet)cboLicenseSet.SelectedValue).LicenseSetId; worker.DoWork += delegate(object s, DoWorkEventArgs args) { object[] data = args.Argument as object[]; ISmallKeyGenerator smallKeygen = ObjectLocator.GetInstance <ISmallKeyGenerator>(); ILargeKeyGenerator largeKeygen = ObjectLocator.GetInstance <ILargeKeyGenerator>(); ILicenseActiviationProvider licenseActiviationProvider = ObjectLocator.GetInstance <ILicenseActiviationProvider>(); IPackingService packingService = ObjectLocator.GetInstance <IPackingService>(); IClientLicenseService clientLicenseService = ObjectLocator.GetInstance <IClientLicenseService>(); if ((string)data[2] == InstanceNames.SmallKeyGenerator) { ((LicenseGenerationOptions)data[0]).GeneratorType = KeyGeneratorTypes.StaticSmall; } else { ((LicenseGenerationOptions)data[0]).GeneratorType = KeyGeneratorTypes.StaticLarge; } LicenseKeyService service = new LicenseKeyService(smallKeygen, largeKeygen, packingService, clientLicenseService); List <string> keys = service.GenerateLicenseKeys(UIContext.License.KeyPair.PrivateKey, UIContext.License, (LicenseGenerationOptions)data[0], int.Parse(data[1].ToString())); args.Result = keys; }; worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) { LicenseKeys = new BindingList <string>((List <string>)args.Result); lstLicenseKeys.ItemsSource = LicenseKeys; loadingAnimation.Visibility = Visibility.Collapsed; }; worker.RunWorkerAsync(new object[] { licenseGenerationOptions, keysToGenerate, GetGeneratorName() }); } else { MessageBox.Show("Please select a license set, license type to generate and a amount."); } }