Пример #1
0
        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);
        }
Пример #2
0
        private void ValidateLicense(byte[] licenseData)
        {
            if (licenseData != null)
            {
                try
                {
                    var result = new LicenseResult(licenseData, _client);

                    _info = LicenseInfo.Deserialize(result.AsString());
                    if (_info == null)
                    {
                        throw new LicenseException("License info can't be read");
                    }
                    if (!_info.IsValid())
                    {
                        throw new LicenseException("License info invalid");
                    }
                    //If all ok - save to store
                    try
                    {
                        using (var isoStore = IsolatedStorageFile.GetMachineStoreForAssembly())
                            using (
                                var file = new IsolatedStorageFileStream(_client.GetSerialNumber().Encode(),
                                                                         FileMode.OpenOrCreate, isoStore))
                            {
                                var dataTs = BitConverter.GetBytes(DateTime.UtcNow.Ticks);
                                file.Write(dataTs, 0, dataTs.Length);
                                file.Write(licenseData, 0, licenseData.Length);
                            }
                    }
                    catch (Exception e)
                    {
                        Warnings.Add(new LicenseException("Failed to save license to offline storage", e));
                    }
                }
                catch (Exception e)
                {
                    throw new LicenseValidationException("License invalid", e);
                }
            }
            else
            {
                throw new LicenseException("License can't be retrieved");
            }
        }
Пример #3
0
 internal void Refresh(bool useServer)
 {
     _info = null;
     Initialize(!useServer);
 }