예제 #1
0
        /// <summary>
        /// Converts a <see cref="Contact"/> from its secure string representation
        /// into a live object.
        /// </summary>
        /// <typeparam name="TContact">Effective type of contact class.</typeparam>
        /// <typeparam name="TParser">Parser to decode contact string representation.</typeparam>
        /// <param name="content">Contact safe string representation.</param>
        /// <returns>A new <see cref="Contact"/> filled with information from specified string.</returns>
        /// <exception cref="InvalidOperationException">
        /// Always for public builds. this method requires <code>PRIVATE_BUILD</code>
        /// because to decrypt contact private key is required.
        /// </exception>
        /// <exception cref="LicenseException">
        /// <paramref name="content"/> does not contain a valid contact (it may be empty,
        /// corrupted or of an unknown format).
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="content"/> is <see langword="null"/>.
        /// </exception>
        /// <remarks>
        /// When using custom <code>Contact</code> classes you should also
        /// provide your own <see cref="IContactTextConverter"/> parser implementation
        /// otherwise extra properties will not be deserialized. If you do not have
        /// a custom implementation you should alwasy use non generic <see cref="FromString"/>
        /// overloaded version.
        /// <br/><strong>This function is available only on <em>private builds</em></strong>
        /// with access to encryptor private key.
        /// </remarks>
        public static TContact FromString <TContact, TParser>(string content)
            where TContact : Contact, new()
            where TParser : IContactTextConverter <TContact>, new()
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            return(new TParser().Parse(ServerSecureCommunication.DecodeMessageFromClient(content)));
        }
예제 #2
0
 /// <summary>
 /// Convert license to a string.
 /// </summary>
 /// <typeparam name="TLicense">Type of the license.</typeparam>
 /// <typeparam name="TConverter">Converter used to transform the license into text.</typeparam>
 /// <param name="license">License to be converted.</param>
 /// <returns>A string with the full content of the given license.</returns>
 public static string ToString <TLicense, TConverter>(TLicense license)
     where TLicense : License
     where TConverter : ILicenseTextConverter <TLicense>, new()
 {
     return(ServerSecureCommunication.EncodeMessageFromServer(new TConverter().ToString(license)));
 }