void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.WriteAttributeString(nameof(Id), Id.ToString());
            writer.WriteAttributeString(nameof(ProductName), ProductName);
            writer.WriteAttributeString(nameof(ProductVersion), ProductVersion);
            writer.WriteAttributeString(nameof(CustomerName), CustomerName);
            writer.WriteAttributeString(nameof(UniqueId), UniqueId);
            writer.WriteAttributeString(nameof(CreationTime), CreationTime.ToString("s", CultureInfo.InvariantCulture));
            writer.WriteAttributeString(nameof(ExpirationTime), ExpirationTime.ToString());

            if (_features.Count > 0)
            {
                writer.WriteStartElement(nameof(Features));

                foreach (var feature in _features)
                {
                    writer.WriteStartElement("Feature");

                    writer.WriteAttributeString(nameof(LicenseFeature.Name), feature.Name);
                    writer.WriteAttributeString(nameof(LicenseFeature.Value), feature.Value);
                    writer.WriteAttributeString(nameof(LicenseFeature.DisplayName), feature.DisplayName);

                    if (!string.IsNullOrWhiteSpace(feature.Description))
                    {
                        writer.WriteElementString(nameof(LicenseFeature.Description), feature.Description);
                    }

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }

            if (_attributes.Count <= 0)
            {
                return;
            }

            writer.WriteStartElement(nameof(Attributes));

            foreach (var attribute in _attributes)
            {
                writer.WriteStartElement("Attribute");

                writer.WriteAttributeString("Name", attribute.Key);
                writer.WriteString(attribute.Value);

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Beispiel #2
0
        public void ExpireAt(ExpirationTime time)
        {
            if (time == null) throw new ArgumentNullException(nameof(time));
            if (time.Expired) throw new ArgumentNullException(nameof(time), "ExpirationTime should not be expired.");

            if (Signed) throw new InvalidOperationException("This license already is signed.");

            ExpirationTime = time;
        }