Kris Mattson's Tech Blog

Monday, March 07, 2011

Low Budget E-commerce site

Like I mentioned in my previous post, I use nopCommerce open source shopping cart. I host it at home and use dyndns for dynamic dns service which basically maps your host name to your home IP address if your ISP uses DHCP, which most, like Qwest or Comcast do. Usually, you would have to upgrade to a business account to get a static IP. Lastly, I use montastic for free site monitoring.
You'll most likely end up paying for the dyndns servcie, unless someone else out there knows of a better/cheaper way. Everything else...FREE.

Monday, May 31, 2010

New Web Site

Used NopCommerce for building a new E-commnerce website. I would recommend it if you want to get an e-commerce site up and running quickly. http://www.nopcommerce.com/

You can view my website here Bloom'n Babies

Wednesday, December 12, 2007

Who changed that file?

Windows doesn't actually track who changes a file unless you tell it to. Right click on your directory -> Properties -> Security -> Advanced -> Auditing -> Add Everyone -> Check access control attributes you want to change (in my case "Write Attributes").

Start tracking changes using FileSystemWatcher and EventLog :

private void StartFileMon()
{
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = @"C:\test\temp";
fsw.EnableRaisingEvents = true;
fsw.Changed += new FileSystemEventHandler(fsw_changed);
}
private void fsw_changed(object Sender, FileSystemEventArgs E)
{
Console.WriteLine("The file" + E.FullPath + " was " + E.ChangeType.ToString() + " on " + System.DateTime.Now.ToString());
DateTime timespan = System.DateTime.Now.Subtract(TimeSpan.FromSeconds(60));
EventLog Log = new EventLog("Security");
EventLogEntry[] Entries = EventLogSearch.FindInstanceId(Log.Entries, 560);
Entries = EventLogSearch.FindTimeGeneratedAtOrAfter(Entries, timespan);
foreach (EventLogEntry Entry in Entries)
{
Console.WriteLine("Message: " + Entry.Message);
Console.WriteLine("InstanceId: " + Entry.InstanceId);
Console.WriteLine("Category: " + Entry.Category);
Console.WriteLine("EntryType: " + Entry.EntryType.ToString());
Console.WriteLine("Source: " + Entry.Source);
Console.WriteLine("Source: " + Entry.UserName);
}
}
public static EventLogEntry[] FindTimeGeneratedAtOrAfter(
IEnumerable logEntries, DateTime timeGeneratedQuery)
{
ArrayList entries = new ArrayList();
foreach (EventLogEntry logEntry in logEntries)
{
if (logEntry.TimeGenerated >= timeGeneratedQuery)
{
entries.Add(logEntry);
}
}
EventLogEntry[] entriesArray = new EventLogEntry[entries.Count];
entries.CopyTo(entriesArray);
return (entriesArray);
}
public static EventLogEntry[] FindInstanceId(IEnumerable logEntries,
int instanceIDQuery)
{
ArrayList entries = new ArrayList();

foreach (EventLogEntry logEntry in logEntries)
{
if (logEntry.InstanceId == instanceIDQuery)
{
entries.Add(logEntry);
}
}

EventLogEntry[] entriesArray = new EventLogEntry[entries.Count];
entries.CopyTo(entriesArray);
return (entriesArray);
}

Searching the EventLogs is slow so use common sense when doing this.

For more info buy this book: http://www.oreilly.com/catalog/csharpckbk2/

Tuesday, November 21, 2006

Web Service Application proxy for Ajax Cross Domain requests

Calling web services using Ajax (XMLHTTPRequest) should be an easy thing to do, however due to a constraint that inhibits the browser from calling a web service on another machine (for security reasons). See the following article for more details, http://www.xml.com/pub/a/2005/11/09/fixing-ajax-xmlhttprequest-considered-harmful.html.

I submit a C# application proxy like this:
[WebMethod]
public XmlDocument ServiceRequest()
{
System.Web.HttpRequest req = this.Context.Request;
ASCIIEncoding encoding = new ASCIIEncoding();
// The url parameter is the destination web service you are calling
string url = req.Form.Get("url");
string postData = req.Form.ToString();

byte[] buffer = encoding.GetBytes(postData);

HttpWebRequest myRequest = (HttpWebRequest)
WebRequest.Create(url);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = buffer.Length;
Stream newStream = myRequest.GetRequestStream();

newStream.Write(buffer, 0, buffer.Length);
newStream.Close();

HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse();

Stream streamResponse = myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string strResult = streamRead.ReadToEnd();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strResult);
streamRead.Close();
streamResponse.Close();
myHttpWebResponse.Close();
return xmlDoc;

}

Using javascript construct your POST request and pass the destination url and one of the parameters.

digg / Technology