|
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Windows.Forms;
namespace CPBrowser
{
/// <summary>
/// This class stores the required information necessary to download a Code
/// Project zip file.
/// </summary>
public class DownloadInfo
{
private Uri m_projectUrl = null;
private Uri m_articleUrl = null;
private HtmlDocument m_htmlDocument = null;
private CookieCollection m_cookies = null;
private string m_unzipDirectory = null;
public DownloadInfo(Uri projectUrl, Uri articleUrl, HtmlDocument htmlDocument)
{
m_projectUrl = projectUrl;
m_articleUrl = articleUrl;
m_htmlDocument = htmlDocument;
ParseCookies(htmlDocument.Cookie);
}
public Uri ProjectUrl
{
get { return m_projectUrl; }
set { m_projectUrl = value; }
}
public Uri ArticleUrl
{
get { return m_articleUrl; }
set { m_articleUrl = value; }
}
public HtmlDocument Document
{
get { return m_htmlDocument; }
set { m_htmlDocument = value; }
}
public CookieCollection Cookies
{
get { return m_cookies; }
set { m_cookies = value; }
}
public string UnzipDirectory
{
get { return m_unzipDirectory; }
set { m_unzipDirectory = value; }
}
/// <summary>
/// These are the cookies that allow us to remain in a logged in state.
/// This is required because Code Project requires you to be signed in
/// to download files. I got help in learning how to use these from
/// http://blogs.msdn.com/dgorti/archive/2005/08/16/452347.aspx
/// </summary>
private void ParseCookies(string cookieString)
{
try
{
string[] token = new String[] { "; " };
String[] cookieArray = cookieString.Split(token, StringSplitOptions.RemoveEmptyEntries);
m_cookies = new CookieCollection();
for (Int32 i = 0; i < cookieArray.Length; i++)
{
char[] tokenChar = new Char[] { '=' };
String[] cookie = cookieArray[i].Split(tokenChar, 2, StringSplitOptions.RemoveEmptyEntries);
if (cookie.Length == 2)
m_cookies.Add(new Cookie(cookie[0], cookie[1]));
else if (cookie.Length == 1)
m_cookies.Add(new Cookie(cookie[0], String.Empty));
}
}
catch (Exception e)
{
string errMsg = "Unable to parse page cookies: " + e.Message;
throw new Exception(errMsg, e);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
SlickEdit Inc. provides software developers with multi-language development tools and the most advanced code editors available. Power programmers, from Fortune 500 companies to individuals, have chosen SlickEdit as their development tool of choice for over 19 years. Proven on Windows, Linux, UNIX, and Mac OS X platforms, SlickEdit products enable even the most accomplished developers to write more code faster, and more accurately. For more information about SlickEdit and free trial downloads, please visit
http://www.slickedit.com.