protected void btnDeleteMachine_Click(object sender, EventArgs e) { try { if (lstRecords.SelectedIndex == -1) { throw new Exception("Please select a machine from the list above."); } string str = lstRecords.SelectedItem.Value; string[] parts = str.Split(','); string mc = parts[0].TrimEnd(' '); mc = mc.Replace("Machine Code: ", ""); if (!chkUseHashedMachineCodes.Checked) { byte[] temp = Encoding.UTF8.GetBytes(mc); mc = Convert.ToBase64String(temp); } string settingsFilePath = Path.Combine(install.basePath, cmbSettingFiles.SelectedValue); LicenseServiceClass srvc = new LicenseServiceClass(); srvc.Generator.ServiceParamEncryptionMode = ServiceParamEncryptionMode.None; string dc = srvc.Deactivate(txtLicenseCode.Text, mc, settingsFilePath); string message = "Deleted: " + lstRecords.SelectedItem.Value; btnGetActivationData_Click(null, null); lblMessage.Text = message; lblMessage.ForeColor = Color.Empty; } catch (Exception ex) { lblMessage.Text = "Error: " + ex.Message; lblMessage.ForeColor = Color.Red; } }
protected void btnGetValidationData_Click(object sender, EventArgs e) { try { lstRecords.Items.Clear(); string settingsFilePath = Path.Combine(install.basePath, cmbSettingFiles.SelectedValue); LicenseServiceClass srvc = new LicenseServiceClass(); ValidationData vd = srvc.GetValidations(txtLicenseCode.Text, settingsFilePath); foreach (Validation v in vd.validations) { string str = v.machineCode; if (!chkUseHashedMachineCodes.Checked) { byte[] temp = Convert.FromBase64String(str); str = Encoding.UTF8.GetString(temp); } lstRecords.Items.Add( "Machine Code: " + str + ", IP: " + v.ip + ", Validated: " + v.dateValidated.ToString() ); } lblMessage.Text = string.Empty; lblMessage.ForeColor = Color.Empty; } catch (Exception ex) { lblMessage.Text = "Error: " + ex.Message; lblMessage.ForeColor = Color.Red; } }
protected void btnCreateTables_Click(object sender, EventArgs e) { try { LicenseServiceClass srvc = new LicenseServiceClass(); txtStatus.Text = srvc.CreateDBTables(txtConnectionString.Text, txtTableNamePrefix.Text); } catch (Exception ex) { txtStatus.Text = "Failed to create tables in database : " + ex.Message; } txtStatus.Visible = true; }
protected void btnImport_Click(object sender, EventArgs e) { try { if (!FileUpload1.HasFile) { lblResult.ForeColor = System.Drawing.Color.Red; lblResult.Text = "Please specify a valid file first."; return; } int succeddedCount = 0; int failedCount = 0; string settingsFilePath = Path.Combine(install.basePath, cmbSettingFiles.SelectedValue); LicenseServiceClass srvc = new LicenseServiceClass(); StringBuilder sb = null; if (cmbTables.SelectedIndex == 0) { sb = srvc.ImportLicensesIntoLicenseTable(settingsFilePath, FileUpload1.PostedFile.InputStream, ref succeddedCount, ref failedCount); } else { sb = srvc.ImportLicensesIntoDisabledLicenseTable(settingsFilePath, FileUpload1.PostedFile.InputStream, ref succeddedCount, ref failedCount); } lblResult.ForeColor = System.Drawing.Color.Black; lblResult.Text = succeddedCount.ToString() + " entries successfully imported into database. "; if (failedCount > 0) { lblResult.ForeColor = System.Drawing.Color.Red; lblResult.Text += failedCount.ToString() + " entries failed."; } if (sb != null && sb.Length > 0) { txtStatus.Text = sb.ToString(); txtStatus.Visible = true; } else { txtStatus.Visible = false; } } catch (Exception ex) { lblResult.Text = "Failed to import into license database:" + ex.Message; lblResult.ForeColor = System.Drawing.Color.Red; } }
protected void btnTestConnection_Click(object sender, EventArgs e) { try { LicenseServiceClass srvc = new LicenseServiceClass(); srvc.TestDBConnection(txtConnectionString.Text); lblTestConnectionResult.Text = "Connection established successfully with database"; lblTestConnectionResult.ForeColor = System.Drawing.Color.Black; } catch (Exception ex) { lblTestConnectionResult.Text = "Connection cannot be established with database. " + ex.Message; lblTestConnectionResult.ForeColor = System.Drawing.Color.Red; } }
protected void btnGetActivationData_Click(object sender, EventArgs e) { try { lstRecords.Items.Clear(); string settingsFilePath = Path.Combine(install.basePath, cmbSettingFiles.SelectedValue); LicenseServiceClass srvc = new LicenseServiceClass(); ActivationData data = srvc.GetActivations(txtLicenseCode.Text, settingsFilePath); foreach (ActivationPSF apsf in data.activations) { string str = apsf.machineCode; if (!chkUseHashedMachineCodes.Checked) { byte[] temp = Convert.FromBase64String(str); str = Encoding.UTF8.GetString(temp); } lstRecords.Items.Add( "Machine Code: " + str + ", IP: " + apsf.ip + ", Activated: " + apsf.activationDateTime.ToString() + ((data.license.ActivationsAreFloating && (data.license.HasFloatingHeartBeatInterval || data.license.HasFloatingLeasePeriod)) ? ", ValidTill: " + apsf.leaseValidTill.ToString() : "") ); } lblStat.Text = "Maximum Activations = " + data.license.MaxActivations.ToString() + ", Used Activations = " + data.numActivations.ToString() + ", Remaining Activations = " + (data.license.MaxActivations - data.numActivations).ToString() + ", Floating = " + data.license.ActivationsAreFloating.ToString() + (data.license.HasFloatingHeartBeatInterval ? ", HeartBeat = " + data.license.FloatingHeartBeatInterval.ToString() + "ms" : "") + (data.license.HasFloatingLeasePeriod ? ", Lease Period = " + data.license.FloatingLeasePeriod.ToString() : "") ; lblMessage.Text = string.Empty; lblMessage.ForeColor = Color.Empty; } catch (Exception ex) { lblMessage.Text = "Error: " + ex.Message; lblMessage.ForeColor = Color.Red; } }
protected void btnActivateMachine_Click(object sender, EventArgs e) { try { string settingsFilePath = Path.Combine(install.basePath, cmbSettingFiles.SelectedValue); LicenseServiceClass srvc = new LicenseServiceClass(); srvc.Generator.ServiceParamEncryptionMode = ServiceParamEncryptionMode.None; string newLicenseCode = srvc.Activate(txtLicenseCode.Text, txtMachineCode.Text, settingsFilePath); if (newLicenseCode.StartsWith(exceptionPrefix)) { throw new Exception(newLicenseCode.Substring(exceptionPrefix.Length)); } lblMessage.Text = "Machine Activated. Machine-Locked License Code Returned By License Service:<br><br>" + newLicenseCode; lblMessage.ForeColor = Color.Empty; } catch (Exception ex) { lblMessage.Text = "Error: " + ex.Message; lblMessage.ForeColor = Color.Red; } }