Пример #1
0
        private static License ReadLicenseFromStream(Stream stream)
        {
            License result;

            try
            {
                License      license      = new License();
                BinaryReader binaryReader = new BinaryReader(stream, Encoding.Unicode);
                OldLicenseSerializer.OldLicenseType oldLicenseType = (OldLicenseSerializer.OldLicenseType)binaryReader.ReadByte();
                license.PurchaseId = "shareit:" + binaryReader.ReadInt64().ToString();
                license.Version    = binaryReader.ReadByte();
                DateTime dateTime = OldLicenseSerializer.ReadDateTime(binaryReader);
                string   text     = OldLicenseSerializer.ReadBytePrefixedString(binaryReader);
                string   text2    = OldLicenseSerializer.ReadBytePrefixedString(binaryReader);
                license.LicensedTo = text;
                if (text2.Length > 0 && text2 != text)
                {
                    License expr_79 = license;
                    expr_79.LicensedTo = expr_79.LicensedTo + ", " + text2;
                }
                license.Capacity = 1;
                license.Binding  = LicenseBinding.User;
                if (oldLicenseType == OldLicenseSerializer.OldLicenseType.Real)
                {
                    if (text2.Length > 0)
                    {
                        license.Type    = LicenseType.Corporate;
                        license.Binding = LicenseBinding.Seat;
                    }
                    else
                    {
                        license.Type = LicenseType.Personal;
                    }
                    license.StartTime    = DateTime.MinValue;
                    license.EndTime      = DateTime.MaxValue;
                    license.PurchaseDate = dateTime;
                }
                else
                {
                    license.Type         = LicenseType.Evaluation;
                    license.StartTime    = dateTime;
                    license.EndTime      = dateTime.AddDays(30.0);
                    license.PurchaseDate = dateTime;
                }
                result = license;
            }
            catch (Exception inner)
            {
                throw new LicensingException("Can not parse license.", inner);
            }
            return(result);
        }