/// <summary>
        /// Deserializes an association from the database.
        /// </summary>
        /// <param name="association">The association from the database.</param>
        /// <returns>The deserialized association.</returns>
        private static Association DeserializeAssociation(OpenIdAssociation association)
        {
            if (association == null)
            {
                throw new ArgumentNullException("association");
            }

            byte[] privateData = new byte[association.PrivateDataLength];
            Array.Copy(association.PrivateData, privateData, association.PrivateDataLength);
            return(Association.Deserialize(association.AssociationHandle, association.ExpirationUtc, privateData));
        }
示例#2
0
        /// <summary>
        /// Saves an <see cref="Association"/> for later recall.
        /// </summary>
        /// <param name="distinguishingFactor">The Uri (for relying parties) or Smart/Dumb (for providers).</param>
        /// <param name="association">The association to store.</param>
        /// <remarks>
        /// TODO: what should implementations do on association handle conflict?
        /// </remarks>
        public void StoreAssociation(Uri distinguishingFactor, Association association)
        {
            using (var dataContext = new TransactedDatabaseEntities(System.Data.IsolationLevel.ReadCommitted)) {
                var sharedAssociation = new OpenIdAssociation {
                    DistinguishingFactor = distinguishingFactor.AbsoluteUri,
                    AssociationHandle    = association.Handle,
                    ExpirationUtc        = association.Expires,
                    PrivateData          = association.SerializePrivateData(),
                };

                dataContext.AddToOpenIdAssociations(sharedAssociation);
            }
        }
        /// <summary>
        /// Deserializes an association from the database.
        /// </summary>
        /// <param name="association">The association from the database.</param>
        /// <returns>The deserialized association.</returns>
        private static Association DeserializeAssociation(OpenIdAssociation association)
        {
            if (association == null)
            {
                throw new ArgumentNullException("association");
            }

            byte[] privateData = new byte[association.PrivateDataLength];
            Array.Copy(association.PrivateData, privateData, association.PrivateDataLength);
            return Association.Deserialize(association.AssociationHandle, association.ExpirationUtc, privateData);
        }
        /// <summary>
        /// Saves an <see cref="Association"/> for later recall.
        /// </summary>
        /// <param name="distinguishingFactor">The Uri (for relying parties) or Smart/Dumb (for providers).</param>
        /// <param name="association">The association to store.</param>
        /// <remarks>
        /// TODO: what should implementations do on association handle conflict?
        /// </remarks>
        public void StoreAssociation(Uri distinguishingFactor, Association association)
        {
            using (var dataContext = new TransactedDatabaseEntities(System.Data.IsolationLevel.ReadCommitted))
            {
                var sharedAssociation = new OpenIdAssociation
                {
                    DistinguishingFactor = distinguishingFactor.AbsoluteUri,
                    AssociationHandle = association.Handle,
                    ExpirationUtc = association.Expires,
                    PrivateData = association.SerializePrivateData(),
                };

                dataContext.AddToOpenIdAssociations(sharedAssociation);
            }
        }