protected override void OnKeyDown(KeyEventArgs e) { if (Byte == null) { return; } if (KeyValidation(e)) { return; } //MODIFY BYTE if (!ReadOnlyMode && KeyValidator.IsHexKey(e.Key)) { switch (_parent.DataStringVisual) { case DataVisualType.Hexadecimal: #region Edit hexadecimal value string key; key = KeyValidator.IsNumericKey(e.Key) ? KeyValidator.GetDigitFromKey(e.Key).ToString() : e.Key.ToString().ToLower(); //Update byte var byteValueCharArray = ByteConverters.ByteToHexCharArray(Byte.Value); switch (_keyDownLabel) { case KeyDownLabel.FirstChar: byteValueCharArray[0] = key.ToCharArray()[0]; _keyDownLabel = KeyDownLabel.SecondChar; Action = ByteAction.Modified; Byte = ByteConverters.HexToByte( byteValueCharArray[0] + byteValueCharArray[1].ToString())[0]; break; case KeyDownLabel.SecondChar: byteValueCharArray[1] = key.ToCharArray()[0]; _keyDownLabel = KeyDownLabel.NextPosition; Action = ByteAction.Modified; Byte = ByteConverters.HexToByte( byteValueCharArray[0] + byteValueCharArray[1].ToString())[0]; //Insert byte at end of file if (_parent.Length != BytePositionInFile + 1) { _keyDownLabel = KeyDownLabel.NextPosition; OnMoveNext(new EventArgs()); } break; case KeyDownLabel.NextPosition: //byte[] byteToAppend = { (byte)key.ToCharArray()[0] }; _parent.AppendByte(new byte[] { 0 }); OnMoveNext(new EventArgs()); break; } #endregion break; case DataVisualType.Decimal: //Not editable at this moment, maybe in future break; } } UpdateCaret(); base.OnKeyDown(e); }
public void ActivationTask(String email, String key) { string activationStatusStr = ""; KeyValidator keyVal = null; try { // validate the generated key. This sequence of code is also used in the actual product to validate the entered license key keyVal = new KeyValidator(Tmpl_); keyVal.SetKey(key); } catch (Exception ex) { OnActivation(false, "Key is incorrect"); log.Error("Key validation failed " + ex.Message); return; } try { keyVal.SetValidationData("Email", email); // the key will not be valid if you set a different user name than the one you have set at key generation LicensingClient licensingClient = new LicensingClient("https://activation.identamaster.com:444", Tmpl_, key, keyVal.QueryValidationData(null), CurrentHWID_, PRODUCT_ID); licensingClient.AcquireLicense(); LicenseKey_ = key; Email_ = email; ActivationKey_ = licensingClient.ActivationKey; HWID_ = CurrentHWID_; // save keys SaveKeys(); if (!licensingClient.IsLicenseValid()) { switch (licensingClient.LicenseStatus) { case LICENSE_STATUS.InvalidActivationKey: activationStatusStr = "invalid activation key"; break; case LICENSE_STATUS.InvalidHardwareId: activationStatusStr = "invalid hardware id"; break; case LICENSE_STATUS.Expired: { // the license expiration date returned by LicenseExpirationDate property is only valid if IsLicenseValid() returns true, // or if IsLicenseValid() returns false and LicenseStatus returns LicenseStatus.Expired DateTime expDate = licensingClient.LicenseExpirationDate; activationStatusStr = "license expired (expiration date: " + expDate.Month + "/" + expDate.Day + "/" + expDate.Year + ")"; } break; default: activationStatusStr = "unknown"; break; } OnActivation(false, activationStatusStr); } else { State = STATE.ACTIVATED; OnActivation(true, ""); return; } } catch (System.Net.WebException ex) { switch (ex.Status) { case System.Net.WebExceptionStatus.ConnectFailure: OnActivation(false, "Couldn't access activation server"); log.Error("Could not connect to server " + ex.Message); break; case System.Net.WebExceptionStatus.ProtocolError: OnActivation(false, "Server didn't validate this key"); log.Error("Key validation failed " + ex.Message); break; default: OnActivation(false, "Network error"); log.Error("Unknown network error " + ex.Message); break; } return; } catch (Exception ex) { OnActivation(false, "Failed"); log.Error("Key validation failed " + ex.Message); return; } }