private static void GetInstanceOfResourceOwner()
 {
     if (_resourceOwners == null)
     {
         _resourceOwners = new ResourceOwners();
     }
 }
        internal static void LoadFromIsoStore()
        {
            using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                _resourceOwners = new ResourceOwners(NewResourceOwnerSetting.CleanEmptyInstance);

                if (!storageFile.FileExists(FileName))
                {
                    return;
                }

                using (var fileStream = new IsolatedStorageFileStream(FileName, FileMode.Open, FileAccess.Read, storageFile))
                {
                    XDocument document = XDocument.Load(fileStream);
                    foreach (var element in document.Root.Elements("ResourceOwner"))
                    {
                        _resourceOwners.Add(ResourceOwner.FromXElement(element));
                    }
                }
            }
        }
示例#3
0
        public static Token FromXElement(XElement element)
        {
            if (element.Element("Server") == null)
            {
                throw new RequiredElementMissingException("Server", element);
            }
            if (element.Element("ResourceOwner") == null)
            {
                throw new RequiredElementMissingException("ResourceOwner", element);
            }

            var server =
                ServersWithAuthorizationCode.GetServerWithAuthorizationCode(new Guid(element.Element("Server").Value));
            var resourceOwner = ResourceOwners.GetResourceOwner(element.Element("ResourceOwner").Value);
            var token         = new Token(server, resourceOwner);

            if (element.Element("Expires") != null)
            {
                token.Expires = DateTime.Parse(element.Element("Expires").Value);
            }
            if (element.Element("AccessToken") != null)
            {
                token.AccessToken = element.Element("AccessToken").Value;
            }
            if (element.Element("RefreshToken") != null)
            {
                token.RefreshToken = element.Element("RefreshToken").Value;
            }
            if (element.Element("AuthorizationCode") != null)
            {
                token.AuthorizationCode = element.Element("AuthorizationCode").Value;
            }
            if (element.Element("RedirectUri") != null)
            {
                token.RedirectUri = new Uri(element.Element("RedirectUri").Value);
            }

            return(token);
        }
 internal static void CleanUpForTests()
 {
     _resourceOwners = new ResourceOwners(NewResourceOwnerSetting.CleanEmptyInstance);
 }