// Copyright 2005 by Omar Al Zabir. All rights are reserved.
//
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
//
// website http://www.oazabir.com, email OmarAlZabir@gmail.com, msn oazabir@hotmail.com
using System;
using System.Text;
using System.Net;
using System.Web;
using System.Xml;
using System.IO;
using System.Reflection;
namespace RSSFeeder.Helpers{
[Serializable]
public class ErrorReportItem
{
public string Summary;
public string Details;
public ErrorReportItem( string summary, string details )
{
this.Summary = string.Format( "{0} - {1}", Environment.UserName, summary );
string versionNo = string.Empty;
try
{
versionNo = Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
catch {}
this.Details = string.Format( "Hi, my name is {0}. I am using version {3}. I had the following error: {1}{2}",
Environment.UserName, Environment.NewLine, details, versionNo );
}
}
/// <summary>
/// Helper class to communicate with webserver for reporting errors, notifications, ...
/// </summary>
public class ErrorReportHelper
{
/// <summary>
/// This is my project's group ID
/// </summary>
public const string GROUP_ID = "140453";
public static void PostTrackerItem( string summary, string details )
{
const string ATT_ID = "746427";
HttpPost( "http://sourceforge.net/tracker/index.php",
"http://sourceforge.net/tracker/?func=add&group_id=" + GROUP_ID + "&atid=" + ATT_ID,
"group_id", GROUP_ID, "atid", ATT_ID, "func", "postadd", "summary", summary,
"details", details );
}
public static void HttpPost( string url, string referer, params string [] formVariables )
{
HttpWebRequest req = null;
try
{
req = (HttpWebRequest) HttpWebRequest.Create(new Uri(url));
}
catch
{
return;
}
CookieContainer CookieCont= new CookieContainer();
req.AllowAutoRedirect = true;
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
req.CookieContainer = CookieCont;
req.Referer = referer;
req.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/vnd.ms-powerpoint, application/vnd.ms-excel, */*";
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
StringBuilder postData = new StringBuilder();
for( int i = 0; i < formVariables.Length; i += 2 )
{
postData.AppendFormat("{0}={1}&", HttpUtility.UrlEncode(formVariables[i]), HttpUtility.UrlEncode(formVariables[i+1]));
}
postData.Remove(postData.Length - 1, 1);
byte[] postDataBytes = Encoding.UTF8.GetBytes(postData.ToString());
req.ContentLength = postDataBytes.Length;
Stream postDataStream = req.GetRequestStream();
postDataStream.Write(postDataBytes, 0, postDataBytes.Length);
postDataStream.Close();
// Get the response stream in order to complete a full HTTP POST
HttpWebResponse resp = null;
try
{
resp = (HttpWebResponse) req.GetResponse();
}
catch
{
return;
}
// We are not interested to read anything
Stream rcvStream = resp.GetResponseStream();
resp.Close();
rcvStream.Close();
}
}
}
|