Sunday, December 17, 2006

Tampa WCF Trip

Went to Tampa to learn Windows Communication Foundation. Lots of Data, Service, Operation, and Message Contracts.



Cuban Sandwich shop



Arturo Cigar shop

Monday, December 04, 2006

Virtual PC 2007 - Correction

I found out how to get the session to share my VPN connection with my machine. You set the Ethernet adapter setting to NAT. What a relief. We are still switching to VMWare, but I accept Virtual PC as a great tool now.

Wednesday, September 06, 2006

Create Dallas Dates .vbs



Dim otl
Set otl = CreateObject("Outlook.Application")
Const olAppointmentItem = 1

Sub CreateGame(Start, EndDate,Name)
Set e1 = otl.CreateItem(olAppointmentItem)
e1.Start = Start
e1.End = EndDate
e1.Subject = Name
' e1.Location = "TV"
e1.Save
End Sub


CreateGame "8/12/2006 9:00PM", "8/12/2006 11:00PM", "DAL @ Seattle"
CreateGame "8/21/2006 7:00PM", "8/21/2006 9:00PM", "DAL New Orleans @ Shreveport, LA (ESPN) "
CreateGame "8/26/2006 7:00PM", "8/26/2006 9:00PM", "DAL SAN FRANCISCO "
CreateGame "8/31/2006 7:00PM", "8/31/2006 9:00PM", "DAL MINNESOTA"
CreateGame "9/10/2006 3:15PM", "9/10/2006 5:15PM", "DAL @ Jacksonville"
CreateGame "9/17/2006 7:15PM", "9/17/2006 9:15PM", "DAL WASHINGTON"
CreateGame "9/24/2006 12:00PM", "9/24/2006 2:00PM", " DAL BYE"
CreateGame "10/1/2006 12:00PM", "10/1/2006 2:00PM", "DAL @ Tennessee"
CreateGame "10/8/2006 3:15PM", "10/8/2006 5:15PM", "DAL @ Philadelphia"
CreateGame "10/15/2006 12:00PM","10/15/2006 2:00PM", "DAL HOUSTON"
CreateGame "10/23/2006 7:30PM", "10/23/2006 9:30PM", "DAL NY GIANTS"
CreateGame "10/29/2006 7:15PM", "10/29/2006 9:15PM", "DAL @ Carolina"
CreateGame "11/5/2006 12:00PM", "11/5/2006 2:00PM", "DAL @ Washington"
CreateGame "11/12/2006 3:15PM", "11/12/2006 5:15PM", "DAL @ Arizona"
CreateGame "11/19/2006 12:00PM","11/19/2006 2:00PM", "DAL INDIANAPOLIS"
CreateGame "11/23/2006 3:15PM", "11/23/2006 5:15PM", "DAL TAMPA BAY"
CreateGame "12/3/2006 12:00PM", "12/3/2006 2:00PM", "DAL @ NY Giants"
CreateGame "12/10/2006 12:00PM","12/10/2006 2:00PM", "DAL NEW ORLEANS"
CreateGame "12/16/2006 7:00PM", "12/16/2006 9:00PM", "DAL @ Atlanta"
CreateGame "12/25/2006 4:00PM", "12/25/2006 6:00PM", "DAL PHILADELPHIA"
CreateGame "12/31/2006 12:00PM","12/31/2006 2:00PM", "DAL DETROIT"

Set otl = Nothing
Msgbox "Finished"

Friday, July 14, 2006

Virtual PC is FREE!

Virtual PC is FREE!

This is totally cool. You can now run multiple copies of multiple operating systems on one machine for no extra cost. All you need is a big hard drive and lots of memory.

Wednesday, June 21, 2006

XML Namespace fun

What seemed like a steep mysterious challenge turned into a moldable, layered problem with many partial and a few complete easy solutions. I wrote some code to parse values out of and into elements of an XML document adhering to a schema. Very good, until I learn that schema can change infinitely. So I needed what I called an "agnotistic parser", a way to read and write the document without worrying about the namespace. Microsoft provides a NamespaceManager object in .Net for allowing you to run XPath statements against an XML document having schema information included.

So the only solution so I thought was to figure out how to tell the NamespaceManager what to use for the prefix used on the XML nodes.

It turns out one answer is to not attach a namespace manager and XPath as in :
*[local-name() = 'the-element-name-here']

from "Martin Honnen --- MVP XML".

More interesting to me is the looping over namespaces and adding them as found in microsoft.public.dotnet.xml :

foreach (XmlAttribute att in
Document.DocumentElement.Attributes)
if (att.LocalName == "ns1")
xmlNSMgr.AddNamespace(att.LocalName,
att.Value);

But this requires hard-coding the LocalName to be used in XPath queries.

The best answer I think is what my boss suggested. Get the defaults from the Root node of the doc as in:

xmlDoc.DocumentElement.Prefix;
xmlDoc.DocumentElement.Attributes["xmlns:" + xPathPrefix].Value;


And then add them to the Namespace Manager.

Friday, June 16, 2006

4 Favorite Keyboard Shortcuts

Or combination key strokes :

1. ALT + F4 was taught to me by our summer co-op student from Carnegie Melon. This shuts down a browser window (or any other window) faster than you can say "supervisor".

2. ALT + K is a new one I just learned for finishing somebody's name from an Exchange Server in Microsoft Outlook. I love this, and went the longest without knowing it, losing the most productivity.

3. CTRL + ENTER is an old standby for web surfing in Internet Explorer. Turns "google" into "www.google.com".

4. CTRL + SPACE will cause code-completion to happen for you in Visual Studio .NET. This was another long-time-coming shortcut, but not as bad as ALT K. Can't imagine life without this one as a developer.

P.S.
Somebody should pass a law against the CAPS LOCK key.

Thursday, May 18, 2006

Am I sitting on a gold mine? (updated 10 years later..)


According to my neighbor, my condo may actually benefit me most by not selling because of the Metro rail stops coming way out in the future. Interesting source of hope, atleast.


Here is my condo for sale listing online :

ParcReston Condos For Sale


http://www.dullescorridorrail.com/project.htm


.... 10 years later .. Sadly No. Prices have dropped further.

Saturday, May 06, 2006

Derby Day (2006 KY Derby 10 years later..)





My picks are :

Brother Derek
Bob And John
Point Determined
Sinister Minister

Tie Breakers :
Barbaro
AP Warrior

I like to cheer Bob Baffert's horses because I read an interesting story about his life in Sports Illustrated. Just seems like an inspiring guy.



10 years later ...
I still follow Bob Baffert in racing, and of course that has been popular, and for good reason. Bob has won the Triple Crown with American Pharoah and has been one of the most successful trainers of all time.
For the longest stretches of time, I simply put all of my money on his horses with blind faith, and that would end the day positive. Unfortunately, Baffert is the 1990's Dallas Cowboys of horse racing. Bettors rush to the windows when he runs a horse, bringing down the payout for a win. That's just fine, as I have learned since, that trainers run tons of horses over time, and they are not all equal. Betting involves analyzing not just win/loss(placing) records for the athlete, but also speed figures, scheduling, training, surface selection, pedigree, weather bias, and competition that day as well as countless other factors. As a pure fan of racing, regardless of how it affects my bank balance, this article just pinpoints a good observation by a brand new fan in 2006. ( Now 2017 )


I don't remember what exactly a "tie breaker" was in that post above. But, we all know Barbaro won the Derby that year. Sadly, Barbaro died from a leg injury shortly after. Brother Derek went on to be sire of tons of successful race horses. I am not sure about the others which were from the Baffert barn.

Friday, May 05, 2006

GridView challenge

How to get a button column that will confirm on the client side, but that does not have one of the standard "Select", "Delete", "Edit", "Update" command name property values?

Much is buzzing on the internet about the wonderful "onClientClick" property which you can set for a LinkButton inside of an ItemTemplate of a GridView. Now I have seen Scott Guthrie and Fritz Onion writing about it. And I certainly love the ability to simply ask "window.confirm" in the on-client event for the "Delete" button for example. But I am wondering can I do this for some other use cases, such as when I have no SQLDataSource bound to the grid, just a DataSet pumped into it at Page Load, or I have an SQLDataSource but with only "Select" command defined?
I wonder if the onClientClick -> Confirm technique can apply for a regular button column, not part of an ItemTemplate?

Maybe this is no biggie, I have worked around it thusfar. Maybe GridViewGirl knows the answer?



Link to my question to Fritz Onion, ASP .NET expert.



I have found a way to the RowIndex of the item clicked, even if it is not marked up with standard CRUD database operation attributes.

Using :


((e.CommandSource as ImageButton).Parent.Parent as GridViewRow).RowIndex;


I can get to the DataKey I need in the array of DataKeys in the grid.

Tuesday, May 02, 2006

To Page or Not to Page?

This is going somewhere I promise.
Visual Studio 2005 makes very easy the whole listing of data with paging links at the bottom. If we use a SQLDataSource object on the ASP page, all the paging and sorting is handled automatically, and can even have an AJAX kind of functionality if we turn on "EnablePagingAndSortingCallbacks". the grid pages and sorts without what some people consider to be a nasty page flash.

In a meeting about 2 months ago, some ultra-powerful managers shreaked in fear of the little numbered paging links at the bottom of the page. They demanded the pages be switched to scrolling wherever possible. So I promptly wrapped my GridView controls in DIV tags with style "overflow-y:scroll". This accomplished some immediate relief but not without some hangover.

If the user does some interacting with your list items, and a PostBack occurs, your page will refresh with the scroll position back to the top and the item down in the list the user was playing with, will be invisible. Thanks to Scott Guthrie for reminding us of the "ScrollIntoView" javascript function.

That article

One thing I would warn about is that controls get named AGAIN with unique names by the ASPX page when they are rendered, so you have to get that unique name down to the client javascript for it to be able to find the GridView row you want "scrolled into view". The control on the client side will end up with an ID such as

"ctl00_ContentPlaceHolder1_GridViewMyListOfItems_ctl51_ctl00"

What a mess.

here is a partial code sample to attempt to scroll this thing :



// Assuming you wanted the 112th row and
// had an index variable to use here,
// not a hardcoded one
Control control =
myGrid.Rows[112].Cells[1].Controls[1] as Control;

string scriptText =
"< script >
document.getElementById('" +
control.ClientID +
"').scrollIntoView(); < /script >";




Doing all this in the PreRender phase of the page lifecycle, you can get the script into action with a call to "ClientScript.RegisterStartupScript" or some other variant in the array of new client scripty things in .Net.

Now if we could just get my management to agree on a standard for this, my days would be half as long ;-)

XSLT Woes

Today I have a Google groups dialogue in progress with a major XML guru,

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

I think this may have some wide appeal to those of us who want to use XML/XSL for formatting things. With the new versions of the browser, Microsoft .NET, and the XML standards in general, I have been stuck in the mud on getting something out of my transformations.

I link to my Google post here and will paste the solution, if there is one

Thread Here


ANSWER!!
It is all about the NameSpace. I wondered if that could be a problem, but had no hint as to how I would solve it.
Seems my XML came from Microsoft .NET with a nice big tacky


xmlns="http://tempuri.org/PurchaseData.xsd"


This required me to declare the namespace in my XSLT as :


xmlns:prd=
"http://tempuri.org/PurchaseData.xsd"
exclude-result-prefixes="pd"


And to be sure the prefix my selection criteria in the actual XSL commands with that namespace and a colon.

I was wanting to use this technology for an emailed report thing, but have since gone on to employ a Page_PreRender event handler which captures all the HTML of a page by calling RenderChildControls, and then emails that.

Thursday, April 27, 2006

Today's .Net Nuances (Crystal, Old IIS, SQL @@ERROR )

Well to me anyway.

1. When using the latest version of Crystal Reports, save yourself the 2 hours I wasted today learning not to put multiple datatables in my report data schema. This caused great confusion for the report tool, even though one of the overloads to the SetDataSource() function is with a DataSet parameter [by definition means can have many tables]. My day went better after simply joining the parent and child tables on the SQL Server and letting the report tool clean up the mess of grouping at the proper levels and computing subtotals.

2. When upgrading a website on an IIS Server from the .Net Framework 1.x to 2.x, remember that if the site is only a Virtual Directory, not a full Site, then its Framework version MUST match that of the other Virtual Directories. UNLESS, you go to the trouble of creating Application Pools for the different Virtual's which allows you to upgrade in the chaotic fashion I have unwittingly employed.

3. Remember to check @@ERROR in your stored procedures on SQL Server. This can be helpful for say, when you want to know if you should COMMIT or ROLLBACK a transaction. I am quite embarassed about forgetting this, but luckily in only one small place in my current app.

Monday, April 24, 2006

Thursday, April 20, 2006

Some obscure .NET tips

1. Avoid declaring page class variables as STATIC. This creates all kinds of confusion, because they end up shared across the whole application for every rendering of that page. A coworker of mine did this and we kicked it around for a few minutes before I convinced her to use VIEWSTATE or SESSION as a persistence mechanism.

2. Don't assume pressing enter will cause a BUTTON object to get a click event when you are inside of a textbox. A POSTBACK, yes, but a button click no. I trap that event and send it to the button in a javascript snippet, but am sure there are other ways to do it as well.

3. Use the AS casting technique for object variables. If you use the double parens (DataSet) for example, and the object is not hydrated, an exception will be thrown. Using the AS (myThing AS DataSet) for example, the Framework will convert your object to NULL. Traditional cast or a CONVERT function is the way for Value types.

4. In C# use the USING wrapper around DISPOSABLE types. For example :
Using (SQLConnection myConnection = new SQLConnection) {
bunch of code
}
// This is just cool and the right way to get disposal. I am new to this style.

5. And read this somewhere in Google, but useful for maintaining sanity, forget all about using .EQUALS for comparing VALUE types. It reads badly and runs slower because the system looks all around for an overridden implementation of the EQUALS comparison function.

6. Use STRING.EMPTY or use STRING.LENGTH for comparison to string variables instead of the dreaded double-quotes. Performance, Localization and readability.

My $0.02 on some things I am seeing lately, if I may be so bold.

Wednesday, April 19, 2006

Figuring out the whole Image Upload thing



My favorite episode of South Park, Eric Cartman with the Mexican Staring Frog of Southern Sri Lanka.

(Needed to make the uploading page a Trusted Site in IE)

Poor man's code generator

Much is being said lately about CodeSmith, which I am sure is an awesome tool for building the data access layer for your application, and maintaining it.

I only talk to SQL Server databases lately, so I am most familiar with its handy INFORMATION_SCHEMA.Columns view. This can give you the column listing for any table. A companion to this is the SYSOBJECTS table which harbors a list of the parameters in your Stored Procedures. Remember the XTYPE='P' in your where clause.

As the picture begins to render on how to do this, I want to tell somebody really bad about using CodeDom namespace for building the actual code. You could use StringBuilder to concatenate a big bunch of text, but the CodeDom does it more elegantly.

Getting started it always the hardest with new white canvas so I post the opener :


// Declare a Class
CodeTypeDeclaration ct = new CodeTypeDeclaration("data");
ct.IsClass = true;


Another tricky thing for me was making the code concise by having the declaration and the instancing of the variables on one line :


// Declare a Connection
csne = new CodeSnippetExpression("this.ConnectionString");
// You need a Param array of things passed to a constructor.
CodeExpression[] cParams = { csne };
coc = new CodeObjectCreateExpression("SqlConnection", cParams);
// Then .. all the instancing and declaring on one line :
codeVar =
new CodeVariableDeclarationStatement("SqlConnection", "sqlConnection", coc);
cmm.Statements.Add(codeVar);


Finally, building the actual class code from your heap of objects in memory could be elusive since you have been buried in the CodeDom bits for a few hours :


// This could be a VB thing as well.
CodeDomProvider prov = new Microsoft.CSharp.CSharpCodeProvider();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
TextWriter tw = new StringWriter(sb);
prov.GenerateCodeFromMember(ct, tw, null);


HTH
- Brian

Thursday, April 13, 2006

First Bee in my bonnet (Working with Trusted Sites..)

I have long struggled with security in Internet Explorer, having been infected a few times since my Windows 95 days by various viruses. Not to say they were all the fault of IE, but some were. Since then, I am very careful which sites I allow to run scripts or ActiveX controls on my machine.
Because I still like Internet Explorer better than Mozilla and really appreciate the "Trusted Sites" zone feature, I created a solution to all the dialog boxes required to get a new site added to the zone. It involves a small piece of script that is run from a custom context menu item I add to the standard ones. Internet Explorer allows for adding a link to an HTML page you write via a registry entry which I add with the following :


' BRIAN ONEIL
Dim fsDim sh
Set sh = CreateObject("WScript.Shell")

sh.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\ MenuExt\ Add To &Trusted Sites\","file:\\C:\Program Files\TrustedSiteContextMenu\TrustedSiteAdder.HTML"

sh.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\ MenuExt\ Add To &Trusted Sites\Flags",1,"REG_DWORD"
Set sh = Nothing
MsgBox "Registry Entries Created."


The HTML file referenced by the registry contains the following script for adding the current site you are viewing to your Trusted Sites list :


// Brian O'Neil

// alert("Adding the current page to Trusted Sites...");
var parentwin = external.menuArguments;
var doc = parentwin.document;

var urlParts = doc.URL.split("/");
var httpColon = urlParts[0].substring(0,urlParts[0].indexOf(":"));

var domain = urlParts[2];
var domainParts = domain.split(".");
var domainName = domainParts[domainParts.length-2] +
"." + domainParts[domainParts.length-1];
var prefix =
domain.substring(0,domain.indexOf(domainName)-1);

Sh = new ActiveXObject("WScript.Shell");
var key =
"HKEY_CURRENT_USER\\ Software\\Microsoft\\Windows\\ CurrentVersion\\ Internet Settings\\ ZoneMap\\ Domains\\"
key = key + domainName;
key = key + "\\" + prefix;
Sh.RegWrite(key + "\\" + httpColon, 2, "REG_DWORD");

Sh = null;
parentwin = null;
doc = null;

alert("To Undo this action, remove key "
+ key
+ " from the Registry.");
window.close();


All of the above assumes a directory called
C:\Program Files\TrustedSiteContextMenu


If anybody is interested, I have a WinZip file which decompresses all that is needed for this into the proper folders. Another caveat I forgot to mention is the browser needs to have permissions to execute script on the "Local Intranet Zone".

Had to have my own one of these (re: Blogging)

I have named this Blog after some technology used in my family's business. To learn more about foundry, visit my brother's site http://www.okfoundrycompany.com. I have to imagine if the foundry business were less industrial and more boutique, cafe' kind of thing, there would be a restaurant called "The Cope and Drag". Or at least a shady night club by that name.

My name is Brian and I work in the software business in Sterling, VA near my home of Reston, VA. My language of choice is C# and the platform is Microsoft .Net. I often have a craving to tell somebody about some of the things I learn to do in developing ASP. Net code or javascript, or just refer somebody to a site where I read such an instruction. Maybe this Blog will work well for that. Let's see. If not, I will post some of my other interests and worries here.

Welcome!