コード例 #1
0
ファイル: CookieStorage.cs プロジェクト: sadersa/Leaf.xNet
        /// <summary>
        /// Загружает <see cref="CookieStorage"/> из файла.
        /// </summary>
        /// <param name="filePath">Путь к файлу с куками</param>
        /// <returns>Вернет <see cref="CookieStorage"/>, который задается в свойстве <see cref="HttpRequest"/> Cookies.</returns>
        // ReSharper disable once UnusedMember.Global
        public static CookieStorage LoadFromFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException($"Файл с куками '${filePath}' не найден", nameof(filePath));
            }

            using (var fs = new FileStream(filePath, FileMode.Open))
                return((CookieStorage)Bf.Deserialize(fs));
        }