| Josh's profileJosh's SpaceBlogListsSkyDrive | Help |
Josh's Space<LiveSpace owner="Josh" permissions="public" purpose="ramble" /> |
|||||
|
|
ScriptManager.RegisterStartupScript{
} Dictionay<T, K>.Remove(T);{
} Merry Christmas!{
} Bootstraps BootsLearn something new everday, right? Well maybe not everyday, but today I did!
I learned about Bootstrapper, a technology that comes wrapped in Visual Studio. What is it, you ask?
A recent project I just wrapped up is a Tutorial Making software. Very basic of course, but functional. In fact, all it does is records whatever you're doing. I threw this together after realizing we were going to need some good Word, Excel, Powerpoint, etc tutorials on our newly deployed intranet (DNN).
Anyways, the Tutorial Maker makes use of the Windows Media 9 Encoder. I chose to use ClickOnce for its simplicity, rather than creating a custom setup project. When deploying with ClickOnce, you can select from a list of prerequisites, such as .NET 2.0, SQL Express, etc. Unfortunately, Windows Media Encoder 9 was not in the list.
Here is a quick walk-through on how to add Windows Media Encoder 9 (or some other MSI installer) to the list of available prerequisites that are required with your ClickOnce application.
Ok! Here are the contents of the two XML files. I just copied the Windows Media Encoder eula to eula.txt. product.xml: <?xml version="1.0" encoding="utf-8" ?> <RelatedProducts> <PackageFiles> <InstallChecks> <Commands> <InstallConditions> <ExitCodes> package.xml: <?xml version="1.0" encoding="utf-8" ?> <PackageFiles> <Strings> Hello, MACI am back! It's been a while since I've blogged. I kept saving these drafts but never actually sat down to write about them.
Sorry they all seem to be code related. That's not really what all this blog is about! Pretty soon I'll start throwing up pictures and stuff.
But not in this post.
By the way... Keefe Bruyette & Woods IPO [finally] went public last week. And boy is it about time! That'll be an interesting thing to watch.
Again, that's for another post though. This post is about (believe it or not) more coding! In one of my [other] recent projects, I needed a good method of tracking individual users. IP address isn't a good solution, since user's IP address changes.
My project involved creating a web application that would reside on the DHCP server of a LAN, that could either be accessed wirelessly or from our internal network. I needed a good way to track individual users. So I decided to go the MAC address route.
I googled around for a while and basically found two ways: from the web application start a new Windows process to query DHCP, or copy the log file and read from the copy every time. I find both solutions unacceptable. Starting a new process for every time a user hits the site would severely impact the performance, as would trying to copy the log file and read from it everytime.
I tried to read from the log file directly, like so:
StreamReader read = new StreamReader("C:\\WINDOWS\system32\\dhcp\\DhcpSrvLog-Mon.log");
But as the user of the second solution clearly pointed out, you cannot read directly from it because you will get a 'File In Use' exception.
Now that stumped me for a while, because I couldn't find anything else on the web.
But then I browsed to the file itself, and opened it up in notepad (as I've done before) and that's when I realized, that there most certainly is a way to read directly from it - otherwise Notepad couldn't open it.
After another five minutes of research, I quickly found my solution.
The problem is, when you use "new StreamReader(string)" the StreamReader class attempts to open the file exclusively, but will fail miserably due to DHCP writing to it.
We need to open it so that other files can also open and write to it. Here's how: the File.Open method provides 3 overloads, one of which allows you to specify whether or not to 'share' the file with other programs. Here it is:
File.Open("C:\\WINDOWS\\system32\\dhcp\\DhcpSrvLog-" + DateTime.Now.DayOfWeek.ToString().Substring(0, 3) + ".log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
There is your solution.
First argument is the file to read (which in the above example, is today's log), the second argument tells it to only open the file (don't try to create it if it doesn't exist), third argument says we only want Read access and no more, which is very important; fourth argument - which is the silver doughnut - tells it to share the file with other applications. public string GetMACAddress(string ip)
{
string mac = null;
string line;
if (File.Exists("C:\\WINDOWS\\system32\\dhcp\\DhcpSrvLog-" + |
||||
|
|