Exemplo n.º 1
0
        /// <summary>
        /// This method allows to load a token from a previously generated stream
        /// and the attached metadata
        /// </summary>
        /// <param name="tokenStream"></param>
        /// <param name="additionalMetaData"></param>
        /// <returns></returns>
        public ICloudStorageAccessToken DeserializeSecurityToken(Stream tokenStream, out Dictionary <String, String> additionalMetaData)
        {
            // load the data in our list
            var serializer = new DataContractSerializer(typeof(Dictionary <String, String>));

            // check the type
            Object obj = serializer.ReadObject(tokenStream);

            if (!obj.GetType().Equals(typeof(Dictionary <String, String>)))
#if SILVERLIGHT || MONODROID || MONOTOUCH
            { throw new Exception("A List<String> was expected"); }
#else
            { throw new InvalidDataException("A List<String> was expected"); }
#endif

            // evaluate the right provider
            Dictionary <String, String> tokendata = (Dictionary <String, String>)obj;

            // find the right provider by typename
            ICloudStorageProviderInternal provider = GetProviderByConfigurationTypeName(tokendata[TokenProviderConfigurationType]);

            // set the output parameter
            additionalMetaData = new Dictionary <string, string>();

            // fill the metadata
            foreach (KeyValuePair <String, string> kvp in tokendata)
            {
                if (kvp.Key.StartsWith(TokenMetadataPrefix))
                {
                    additionalMetaData.Add(kvp.Key.Remove(0, TokenMetadataPrefix.Length), kvp.Value);
                }
            }

            // build the token
            return(provider.LoadToken(tokendata));
        }
Exemplo n.º 2
0
 /// <summary>
 /// This method generated a access token from the given data
 /// string list
 /// </summary>
 /// <param name="tokendata">the string list</param>
 /// <returns>The unserialized token</returns>
 internal ICloudStorageAccessToken LoadToken(Dictionary <String, String> tokendata)
 {
     return(_provider.LoadToken(tokendata));
 }