Searching google groups for "eightypercent" turns up someone who likes to post in lots of bondage forums. For the record, that isn't me. :)
Searching google groups for "eightypercent" turns up someone who likes to post in lots of bondage forums. For the record, that isn't me. :)
I have the "comparison before saving" stuff working and that is cutting down my upload times dramatically. This is almost like a real blogging tool now. However, one function -- called TransformAndSaveDoc -- turned out really nasty. This function transforms an xml document with an xslt style sheet. It then compares the result to what is already on disk and only writes the new result to disk if the new version is different from the old version.
Suggestions for making this tighter? Is there some functionality (memcmp?) that I'm missing in the .Net framework? Since I don't have comments working, send mail to eightypercent@bedafamily.com and I'll post the best comments up here with credit and eternal thanks.
private void TransformAndSaveDoc(XslTransform xslt, XmlDocument xmlSource, string fileName) { using (MemoryStream memstrm = new MemoryStream()) { bool fFileDifferent = false; xslt.Transform(xmlSource, null, memstrm); FileInfo fi = new FileInfo(fileName); // Check for simple things first if (!File.Exists(fileName) || fi.Length != memstrm.Length) fFileDifferent = true; // Actually compare the file to the stream if (!fFileDifferent) { Byte[] buffer1 = new Byte[8096]; Byte[] buffer2 = new Byte[8096]; // compare the existing file with the memory stream using (FileStream fileStream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { memstrm.Seek(0, SeekOrigin.Begin); int size1 = 0, size2 = 0; while( !fFileDifferent && (0 != (size1 = memstrm.Read(buffer1, 0, 8096)))) { size2 = fileStream.Read(buffer2, 0, 8096); Debug.Assert(size1 == size2); for (int i = 0; i < size1; i++) { if (buffer1[i] != buffer2[i]) { fFileDifferent = true; break; } } } } } // Write that puppy out if (fFileDifferent) { using (FileStream fileStream = File.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { memstrm.Seek(0, SeekOrigin.Begin); Byte[] buffer = new Byte[8096]; int size; while(0 != (size = memstrm.Read(buffer, 0, 8096))) { fileStream.Write(buffer, 0, size); } } } } }
I have the dictionary done so now I don't upload files that haven't changed. Now all I have to do is change my generation code so that it doesn't actually write to files that haven't changed.
I could do this by making sure that I track which data files have changed and figuring out which output files that means that I have to generate.
Or, I could just always generate every output file, but compare it to what is on disk before writing it. If it is exactly the same as what is already there, I can just throw away my in memory copy and not write anything.
Radio took the first approach, except it didn't get it completely right. If you added a new entry in Radio, it wouldn't update any of the archive pages. The problem is that you would always see links going further back on the calendar but never going forward, as it would never update one of the archive pages. With the second approach it may take a little longer to generate the site, but you'll be sure to update everything that needs to be updated.
I think that I'm going to go with the second approach. I can adapt and implement the first as needed (perhaps on a more granular level.
If you see this then I uploaded everything using my new FTP support.
Right now I just upload everything every time. However, it shouldn't be difficult for me to keep a dictionary of file times so I can keep track of what is new since the last upload.
I also need to do the uploading on a different thread and report status.
I'm back in Boise and Chris is still kicking my ass with BlogX.
I got mail from Gary Burd that my RSS feed was valid. The problem was that I was using relative URLs in some of my entries. I've fixed up the problem and I'll be sure to keep an eye on that in the future.
At least I'm putting out good XML, unlike Radio...
Dejan Jelovic sent me some mail pointing to his managed wrapper on wininet.
This looks pretty cool and wininet is pretty well tested, if a little quirky. However, I think that I'm going to do my own thing just for the sake of doing it. I'm having fun with the little victories of doing something pretty fundamental from the ground up.
Chris recommends The Rise of Theodore Roosevelt. I'm reading this right now and probably about 3/4 of the way done. I'm also amazed at the productivity and veriety of experiences this man had at so young an age. It really drives me to get off of my ass and do something.
A few weeks ago I finished The First American by H. W. Brands. This is a biography of Benjamin Franklin. I'd also highly recommend it. Again, this is someone who went out and created his own destiny.
In reading these two back to back, you can't help but see the contrasts. Roosevelt was the jock intellectual, Franklin was the geek of his time.
I love american history. In college I took quite a few courses on 20th century american history. In the last couple of years I've started reaching back a little further. It is just so amazing to me to make the connection between now and say, 100 years ago. When you start reading these histories, time tends to compress and a century is a lot closer than it appears. Hell, a little over 100150 years ago we were invading Mexico (Mexican/American War).
I'm busy getting my FTP support up and working. Learning all of this new stuff is fun. I'm working directly off of RFC 959 and looking at the debug log stuff in SmartFTP.
So far I can connect, log in, create a passive connection and list the root directory. Once I have enough support to upload a file (real close now) I'll be set. I probably have another hour or two to get that working.
However, I'm going to be travelling back to Seattle the rest of this week so I won't be able to work on my little tool here.
So, MichaelW invited me to the Montreal F1 races this summer. I would love to be able to go but it is just too much money. I haven't been at Microsoft as long as Michael has...
Instead, I'm in the process of trying to sign up to go on this photo workshop, led by Steve Kossack. This will be the first of this type of trip that I will have gone on. It still isn't cheap but looks to be in line with similar excursions. It also isn't this trip.