public static LicenseInfo Deserialize(string serialized) { var info = new LicenseInfo(); try { var doc = XDocument.Parse(serialized).Root; info.Issued = DateTime.FromFileTimeUtc(long.Parse(doc.Element("issued").Value)); info.ValidTo = DateTime.FromFileTimeUtc(long.Parse(doc.Element("valid").Value)); info.Features = doc.Element("params").Elements("feature").ToDictionary(x => x.Attribute("name").Value, y => y.Attribute("value").Value); info.Limits = doc.Element("params").Elements("limit").ToDictionary(x => x.Attribute("name").Value, y => y.Attribute("value").Value); info.CodeExecutionChain = doc.Element("params").Elements("execute").ToDictionary(x => x.Attribute("entry").Value, y => DataEncoder.FromString(y.Value)); info.CustomValidators = doc.Element("params").Elements("validate").Select(x => DataEncoder.FromString(x.Value)).ToList(); //Try execute foreach (var codeExec in info.CodeExecutionChain) { var asembly = Assembly.Load(codeExec.Value); var typeToCreate = asembly.GetType(codeExec.Key, true); Activator.CreateInstance(typeToCreate); } } catch (Exception e) { throw new LicenseValidationException("Can't parse", e); } return(info); }
public static LicenseRequest FromNameValueCollection(NameValueCollection collection) { string typeString = collection["type"]; string clientIdString = collection["cid"]; string key = collection["sign"]; //Validate key first string validationKey = GetValidationKey(typeString, clientIdString, HashSecret.GetSecret()); if (!string.Equals(validationKey, key, StringComparison.Ordinal)) { throw new SecurityException("Validation keys doesn't match"); } var type = (RequestType)Enum.Parse(typeof(RequestType), typeString, true); var clientId = DataEncoder.FromString(clientIdString); if (type == RequestType.Activate && (collection["cert"] == null || collection["lid"] == null)) { throw new ArgumentException( "Request form must contain certificate information and license id when activating"); } var licenseRequest = new LicenseRequest(type) { ClientId = clientId }; if (type == RequestType.Activate) { licenseRequest.Certificate = DataEncoder.FromString(collection["cert"]); licenseRequest.LicenseKey = DataEncoder.FromString(collection["lid"]); } return(licenseRequest); }