Esempio n. 1
0
        /// <summary>
        /// Clear cookie
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="rcookie"></param>
        /// <param name="uri"></param>
        private async void Savecookie(string filename, CookieContainer rcookie, Uri uri)
        {
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFile   sampleFile  = await localFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

            using (StorageStreamTransaction transaction = await sampleFile.OpenTransactedWriteAsync())
            {
                SerializeCookie.Serialize(rcookie.GetCookies(uri), uri, transaction.Stream.AsStream());
                await transaction.CommitAsync();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Load cookie for requests
        /// </summary>
        private async void Loadcookie(string filename)
        {
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFile   sampleFile;

            try
            {
                sampleFile = await localFolder.GetFileAsync(filename);

                if (sampleFile == null)
                {
                    return;
                }
                using (Stream stream = await sampleFile.OpenStreamForReadAsync())
                {
                    CookieSession = SerializeCookie.Deserialize(stream, new Uri("http://www.onliner.by"));
                }
            }
            catch
            {
                await localFolder.CreateFileAsync("cookie", CreationCollisionOption.ReplaceExisting);
            }
            await Task.CompletedTask;
        }