Sunday, August 28, 2011

MS ReadyBoost Implementation Tips - Do Not Bother

Recently I got a small Lenovo V470 IdeaPad and have been playing with it with Windows 7 Pro 64 bit version. Along with it I found out about the ReadyBoost technology they have added into the OS since Vista.

Initially ReadyBoost does not seem to be doing anything. In fact, initially it even slows you down as it builds the cache, and actually does not make Booting faster by much. What it makes faster is applications to launch faster, especially when more applications are running consuming more RAMs and disks are working hard to service the applications.

I ran into a couple of snags thought I resolved it so here is a quick summary of how you can implement Readyboost on your laptops.
  • As far as I know this works only with the Built-In SD card slot which is wired into the PCI bus and does not go through the USB.
  • Get at least a 16 GB SD card with at least Category 10 capability. I had Category 4 and that failed the qualification step to activate ReadyBoost.
  • Before doing anything, Format the card with NTSF and not FAT32. The reason for this is that for FAT32, the maximum file size will be limited to 4 GB.  For your laptop applications, you would want as much Readyboost cache space as possible. Typically this is 3 times or more of the RAM. Given most PCs are sold with 4 GB RAM. Having a 16 GB SD would be sufficient.
  • Don't use Readyboost on your laptop unless it is connected to the AC power (this makes ReadyBoot almost useless while in battery operation.) As soon as you boot, it starts to cache data and also re-encrypts data. This means this activity occurs during every reboot and every wake-up from hibernation. NOTE: If you run into this situation while in battery operation, you can pull the card out without causing a problem. Re-encryption cannot be turned off on external devices so there is no easy way to turn this off.
  • If you have lots of RAM, you may not notice the difference.
Hope this helps.

Sunday, August 21, 2011

MSMQ, You Get "Invalid queue path name" Exception When Opening a Remote Private Queue

Example Symptom:
  • You have a remote computer named XYZZY
  • Inside it is a private queue named MyQueue
  • You have written the MSMQ code in C# (or .NET)
  • When accessing locally within XYZZY, you can use .\private$\MyQueue it works.
  • When trying to get to the queue using "XYZZY\private$\MyQueue from another computer even on the same subnet and no firewall enabled, you now get an MSMQ exception stating "Invalid Queue Path Name"
Try This:

Instead of

XYZZY\private$\MyQueue

Try this way.

FormatName:DIRECT=OS:XYZZY\private$\MyQueue

Note, spell FormatName exactly how it is. It is the only part that is case sensitive!

--
This was tested on Windows Server 2008 R2 with .NET 3.5

Tuesday, August 02, 2011

Tortoise Git Annoyance Fixes and Tips Collection

I am collecting some quick fixes that I had to do to make this work the way I want it. I am using Windows 7 64-bits these days. If you are encountering other annoyances or want to share your fixes, please feel free to ask or comment on this article.

Annoyance 1: Cannot Delete A Folder, Folder in Use

This is because tgitcache.exe is running and not releasing the folder. You can temporarily kill this program from the task manager and then you can delete the folder.

Annoyance 2: The Icon Overlay on Folders are Gone

  • If the overlay icons are showing on certain drives then it is just the setup on the Tortoise Git. Just open the settings and look under Icon Overlays section. It is likely Network or Removable Drives are not checked.
  • If that is not the case then your computer has gone over the 11 icon limit as you may likely have installed DropBox or JungleDisk or such things that take up icons. If you are brave enough and take your responsibility then here is where the icons are referenced.

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers
    and then remove anything you don't need above and beyond 11 total that's allowed
Want to use the Git behind an HTTP proxy? Read this article.

Friday, July 29, 2011

How To Use Your DropBox.COM Folder As a Git Repository with Tortoise Git

Update: If you have lost your Tortoise Git overlay icons, you need to do some registry work. See the bottom of this article.

You probably came to this article because you are new to the Git Revision Control System and want to know where to store the "source control database" somewhere other than your own computer.

In my specific situation, I develop software under the Windows OS and I may have some side-project such as some research I am doing outside of my work.

GitHub.com is great, and I use it for my business but in order to get your own private GiT repository, you have to pay. They only allows you to let you have a repository if it is open to the public. But in my case, I use Git not just for software source code but many other types of files, for example, my next epic surf novel.

The main problem for me is that I would like to maintain my small repositories without a need to have an elaborate GiT server. Fortunately a GiT repository server can be nothing more than a file system that's accessible from your computer, and even better there are many "cloud disk" services around, many of them are free. The Dropbox.com based cloud disk is very convenient because it maintains the local cache, so the interaction with GiT is very fast. You just need to remember to allow it the time to synchronize the data.

Before moving forward with my example, I assume that you have installed the Windows Git and Tortoise Git on your Windows machine. I also assume that you have used Git for other stuff, for example at your work, so you are generally familiar with synchronizing your own Git repository against the server.

So here are some very straight forward steps to do.

  1. On your DropBox, create a folder which has the name of your repository. For now I will call it MyRepo
  2. From your explorer go inside MyRepo
  3. Right click and select "Git create repository here..."
  4. A dialog box will appear with a box that says "Make it bare." You need to click that check box and OK.
  5. On  any other local disk, I assume you already have your project Git that you want to synchronize.
  6. Go your local project Git folder.
  7. Right click on the folder from the Explorer and select Tortoise Git, and select Settings submenu
  8. On the dialog box navigate down to the Git node and select the Remote sub node.
  9. You are likely to have the "origin" as the remote repository, but you may have others. Select whichever one you would like to connect it to the one on the Dropbox.
  10. On the URL box, type in the path on the dropbox containing the bare bone repo you have just created. For example, C:\Users\Manabu\Dropbox\MyRepo
Now you can synchronize between your repo and the one on the Dropbox.

Fixing the Lost Overlay Icons

Go to http://www.sitepoint.com/missing-tortoisesvn-file-status-overlay-icons/ for more information. But the key for this is to go to


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers


and then remove anything you don't need above and beyond 11 total that's allowed.






Saturday, July 23, 2011

Do and Don’ts of Email


While I am on the email topic from my previous post, I would like to pass on some of the things that made my email in work more effective. You may want to read some of my tips.

Consider Your Subject Line is Being Like a Tweet

Pack in as much useful information in the Subject line. I consider the subject line the Tweet area to contain almost the “body” of the message. This works because most people actually don’t read all email messages. They look at the subject line list and decide whether they will read the message or not.

Start Your Subject Line with the Name of Your Recipient

Again, compare these lines of subjects

1.     “Tonight’s Dinner Plan”
2.     “Want Join us for a dinner?”
3.     “John Let’s Have a Dinner at French Landry at 6”

Which do you think is most effective? To me, it is the third one. If you read the subject line #3, you almost don’t need to read the body of the email. And I know you will click the email to read on.

Start Your Subject Line with a Verb

Your email will be more effective if you start your subject line more in the “Call for Action” style.

Consider the following examples,

1.     “Blood Donation Drive This Afternoon”
2.     “Donate Your Blood This Afternoon!”

Do Not Send Additional Messages in a Quick Succession

My experience is that if you do that the recipients will only read either the first or the last message and they ignore the rest.

Carefully Time When To Send a Message

This is a bit tricky, but you need to know when your recipient will read your email message.  Most people have their email client set so that the most recent one would appear on top and messages are downloaded automatically. They usually scan only the top 10-20 lines of subject lines on their email clients. So if your message does not make it in that top 10 at the time they are reading, then you might as well consider the message lost.

Another strategy is actually just save it in your draft folder, phone call the recipient and then during the conversation mention to the person you have just send an email.

Typical times people read messages include;

The first thing in the morning
During or just after lunch
Just after dinner

You may want to start tracking the most effective time with respect to your important recipients.

Limit The Message Body Size to One Screen

People are busy (even if they really are not) they can only devote about 1 min of their time to read a message. If you wrote a message that do not fit in one screen then they tend stop reading it, moving on to the next one and never come back to your message.

Organize the Email For The Recipient

You have been frustrated with people who repeatedly ask you to send the same email message over and over again. It is not entirely the recipient’s fault; it is that the email is difficult to manage. Over time you will learn who would be asking for repeats, and in that case, make a CC copy of it on your end, put the copy in a folder with the recipient’s name on it. Then you can quickly re-send.

Use The Phone and Voicemail

If you are dealing with some emotional stuff such as one of you being frustrated, angry or extremely happy etc., then call the person up, or at least use the voicemail to leave your live message. Unless you are a NY Times Best Seller author, it is much easier to convey your emotions via voice. Talk to the person live!


Thursday, July 21, 2011

So What’s So Wrong About Email?


Everyone uses email, even if we asked them not to. I ask people to write issues into our issue tracking system. I ask people not to do attachments, instead upload them to our Google Docs and send links in the email to the document, even then people continue to attach documents, and when it comes to dealing with people outside of our organization, they don’t want to log into Basecamp account we provided, they claim they often cannot see Docs shared on the Google Docs…  Some people in my company think I am the search engine and send emails to me essentially the query to our KB or to the Google.

So what’s wrong with all these? Why can’t they use email for all of the above? It is super convenient to write about a product issue and send an email to someone whom you think can handle. Attachments are one of the best file transfer protocol there is, and I can push files to just about anyone without thinking about FTP or user accounts and passwords.

I am starting to think, can we get rid of the web, and we only use the email? It is an extreme thinking but can such a technology possible?

How would I go about to make this happen in a more realistic way? I think that the future email engines would contain a search engine front-end, a lot more statistics driven choice of automated answers, intelligent filters. This sounds awfully a lot like how Gmail works, for example, and I think they are doing a great job.

Email as the Search Engine:

I would like the search engine to already scan the KB or other places I designate based on the content I received and also the prior usage or response pattern, and suggests  possible responses I may have already written. I often get, “send me the server specifications PDF” email several times a quarter from the same person. I would like to tell the email system, next time this happens, just auto generate a reply. I then do not have to repeat myself.

I am experimenting with this using the “canned” response on Gmail but that’s not very smart yet, and it fires unnecessary responses.

Email as a File Version Control System:

If the email works a bit more like GiT and automatically aggregate the versions of different attachments that come by, and when I look for the attachments, it can give me a list of all versions, this will solve the problem of versions in attachments. This will also bring down the size of the in-box as duplicate files would be normalized.

Email as an Issue Tracking System

Gmail does this fairly well now, perhaps if I tag an email as an issue to track, then all of the related email messages will be visible by the team that I designate as a separate in-box where other people can respond, and workflow tag such as In Progress, Solved are also easy to put in. Assigning an issue is a snap then, I just forward the email to the person. 

Email as a Knowledgebase

May be I can tag some email as a knowledge and the next time I am writing on some topic, dynamic search would be performed to either suggest a response that I already wrote, or other similar email messages I have written in the past.

Most or all of the above can become possible without changing the existing email infrastructure. They are about how email servers are implemented, so it will not break the rest of the world, we do not have to change the behaviors of any of the people I am dealing with now.


Monday, July 18, 2011

DotNetNuke 5 Module Development Tips with Visual Studio 2010

I am jotting down some things I need to remember to know when starting a new C# DotNetNuke module development using the Starter Kit, most of the steps are described elsewhere, notably HERE, but sometimes they contain  wrong information in the original text that you need to dig through the user comments to find out the solution. Also there are a few key things I need to remember to do every time.

Local IIS is a Must for a Newbee DNN Module Developer

Install the base DNN in the local IIS and get that going completely first. It will complicate less for module development as it will need to look up images and other resources in the directory structure.


Where To Store The Project?

The best place seems to be within the DesktopModules folder, create a project directly in there. Then all the references are good to go. By the way, target your project to .NET 3.5

Be sure to uncheck Create Solution Folder box when creating a project in this manner.


What To Type into The Assembly Name and Default Namespace?
  • Type in the same info on both field by replacing YourCompany in the Assembly Name part with what you do, and then copy and paste that to the Default Namespace. This is for C#. I don't know VB at all so I will leave that up to you for VB.
  • Do not do a Globally Replace of YourCompany to whatever. See below!

Do Not Globally Replace YourCompany With Your Real Company


You will get the following type of error message from Edit....ascx.deginer.cs  if you immediately try to compile the project.

DotNetNuke Error 11 'System.Web.UI.UserControl' does not contain a definition for 'Text'

The reason why this happened was that global::DotNetNuke.UI. classes was inadvertently changed by the Visual Studio to global::System.Web.UI

How To Replace YourCompany


Note that order in which this is done is very important. Do not do these in out of sequence.

  1. Make a backup copy of the module project folder so that if you mess these steps, you can get them back.
  2. Open any of the classes in the control. And on the Namespace, right click over YourCompany and use the Refractor menu to change this to whatever you like.
  3. Open the Manifiest file (the one that ends with .dnn). On this one Replace YourCompany. with empty string. This fixes the install folder name from YourCompany.YourModule (make sure that the path does match with how you created your module root directory in the DesktopModules folder.
  4. Save everything.
  5. Make a backup copy of this folder again.
  6. You can now Quick Replace the rest of the files containing YourCompany (for example SQL Provider files). Use the Quick Replace at the Solution level.

Configure the Project's IIS

Next Configure the Project to Use the Local IIS Server so that images, controls and other resources in your development environment. Otherwise, your design surface will have errors. Also if any of the controls on the design surface errors out with a COM error, that means you probably did not follow my previous steps to refactor the classes properly which swapped the controls to the system default ones (not DotNetNuke.UI.Control ones), and ended up globally replacing YourCompany in the classes. You need to start over the project and follow the steps.
  1. Open the project property
  2. Select the Web tab on the left.
  3. Select "Use Local IIS Server"
  4. In the project URL, point it to the URL of your project within the DesktopModules folder. For example, http://localhost/DNN/DesktopModules/MT3 would be that I have the module project named MT3, and I have installed the DNN root at localhost/DNN
  5. Click Override application URL and type in the base URL for the DNN, for example, on my machine it is http://localhost/DNN
  6. This will also create web.config files in the folder which will interfere with the module loading. Rename it to xweb.config just in case you need it in the future.
Debugging

If everything is set right and the DNN itself is a debug version then you can attach to the IIS process w3wp.exe locally and you should be able to set a breakpoint in the project. I will write more as I find out how to do this a bit better without needing to rebuild the DNN from the source.


Sunday, July 10, 2011

GoToMeeting Mac - Microphone Level Adjustment Annoying You?

Symptom:

Every time I start GoToMeeting on my Mac, the microphone level adjusts to a very low level, and you'd need to open the System Preferences to re-adjust this level. You would want to get a single click solution to fix this issue.

Solution:

Use the Automator and create an level adjust applet. It is quite easy to do.

  • On the spotlight search on top right of your finder, type in Automator to locate it.
  • Click on the Automator to launch it.
  • Choose Application (and begin creating an application)
  • Select Utilities from the Libraries
  • Select Adjust Computer Volume
  • Adjust the Input Volume slider to the level you like.
  • Save the Application it creates.
  • Put it on the desktop or somewere you can readily click it.

Monday, June 13, 2011

Emacs csharp (C#) Mode Installation and Automatic Enable with Auto Hook on Windows

I like the editor in Visual Studio a lot.  But when it comes to do some repetitious editing, for example, writing code to insert or update database fields based on some pattern, it is a lot easier to do cut-paste-search-replace with Emacs than the GUI based editor by recording some macros.

So I do often use Emacs. And now we have the csharp mode available, the environment is quite nice.

I am not an Elsip hacker so by the time I need to do something more internal with Emacs, I have usually forgotten what I did the last time. So in order to save my own time in the future, for example, to duplicate what I have done on my home PC with another one somewhere, this article will help me do this. Perhaps you also may want to do the same thing.
  • Be sure that your emacs is installed at your C:\Program Files\ directory, for example, C:\Program Files\emacs.23.2 Unless you know a whole lot more about Emacs (in which case you should not be reading this), it is not correct to install it anywhere else, because the load-path really only points to that directory. Please do note, that even this is a 32-bit app, you still want to put the program in C:\Program Files and not in the X86 directory.
  • First, download the csharp mode Lisp code. You can Google for it as to where. But I got one from the Emacs Wiki under csharp-mode.el  Clicking this link will give you the content of the Elisp, so I would copy this into a suitable text editor (for some reasons, I tend to use Notepad for this sort of thing.) then Save As csharp-mode.el
  • Copy csharp-mode.el to site-lisp directory in your emacs installation. If the directory does not exist, I'd say it's OK to make one there. (For example, C:\Program Files\emacs-23.2\site-lisp).
  • Next, go to your Windows user home directory (at very top, above Documents), then create a .emacs file. The easiest way to do this by far is to create one from Emacs. Notepad does not allow creating files that start with a period. Just Control-X F and type in ~/.emacs   NOTE: On Windows 7, your home directory for .emacs is usually c:\Users\/AppData\Roaming\  If you used emacs to edit this, emacs will know this.
  • Now cut and paste the following lines of Elisp. I have added a bonus hook to enable HTML editing mode for aspx and ascx below. Save the file, re-launch emacs and you are good to go.
(autoload 'csharp-mode "csharp-mode" "C# Mode" t)
(setq auto-mode-alist (append '(("\\.cs$" . csharp-mode))
auto-mode-alist))
(setq auto-mode-alist (append '(("\\.aspx$" . html-mode))
auto-mode-alist))
(setq auto-mode-alist (append '(("\\.ascx$" . html-mode))
auto-mode-alist))

Sunday, June 12, 2011

Building DotNetNuke 5.6.2 Source with Visual Studio 2010 Professional

This weekend, I have finally decided to download the DotNetNuke Community Edition source code and decided to build it with Visual Studio 2010 Professional Edition.

It took several trial and errors so I am going to write down what has worked, mainly so that the next time I will remember how I did it and worked.
  • If you are on Windows 7 (and should be), be sure to permanently enable the Visual Studio to run as Administrator. This will save a lot of time re-running it as DNN projects install and configure IIS 7 and that requires an elevated privilege. If I tell you to just open the  privilege setting is in the Property of the Shortcut, then you know how to set this up even if you have not done that before. Still not making sense? See this Technet KB Article
  • Make sure you have a working SMTP server. You will most likely need to setup an email address then a password which is usually needed for modern SMTP servers.
  • Unzip it to Some Simple Directory, like C:\DNN  You will be editing the solution file pointing to this new location. When the solution loads, it will create a Virtual Dir on IIS 7 (that means you have to install IIS 7 beforehand
  • Add Web Management Tools -> IIS 6 Management Compatibility -> IIS Management Console AND IIS Metabase and IIS 6 configuration compatibility
  • Under the World Wide Web Services -> Application Development Features, ASP.NET should be added.
  • Make a first backup copy of the Unzipped version to somewhere safe. You will likely mess up the next step and will likely accidentally launch the solution (.sln) file before the required hand-edit,and corrupt it beyond repair.
  • Don't Launch the Solution File yet. You need to hand-edit it first.
    • Text Edit the Web Root name (the line that has http: in it) to something short and sweet like http://localhost/dnn  
    • To make sure you don't do an accidental start of the project, edit the solution file using Notepad by starting the Notepad then do the File->Open.
    • Go and find any places that has E:\blah\blah on it, and make the change that correspond to where you put the unzipped directory.
    • But don't change where it says VirtualPath that will break the loading of the web project.
    • If none of the above is making any sense to you, then definitely make a backup of the solution file before you do anything  and ask someone who might know.
  • On IIS if you don't have one create an Application Pool to .NET 4.0 Framework
  • Set the Application Pool User to Network Service. This can be done in the Advanced property menu. It is a lot simpler for me to use the Network Service than something else especially on a local develop machine. By default the Application Pool it uses is the Default Application Pool.
  • Give Full R/W permission to Network Service for the entire DNN tree.
  • Backup the DNN Directory to Another Directory. If you (are likely to) fail after the following steps any work you have done won't go to waste.
  • Now you can launch the Solution, and let it build. This should go smoothly.
  • Create a Database
  • Create a login account for the database on the SQL (Express) server and assign the dbo capability to the account. 
  • Copy development.config to web.config
  • Set the web project as the startup (this should be indicated as the URL you specified when you edited the solution file.)
  • Go to IIS Admin and make sure that the Virtual Directory is pointing at "Website" directory within  the  DNN development directory tree and assign the Application Pool that is running the .NET Framework 4.0
  • Then start the the debug session of the web project.
  • If everything compiles fine and the web site runs OK, then exit the Visual Studio, make a backup copy of the entire directory. In fact, you should always do this before a major change to your project, such as adding or removing a project. It is also a big time saver to back up your DNN database prior to making a major change to the DNN configuration, such as adding or removing a module.
Failure Recovery

The initial debug run goes exactly like installing a brand new site. If the startup jams during SQL script part, then without a hesitation, drop the database and create a fresh one. There will be some unfinished stored procedure or other stuff dangling and it won't install the second time.

Teralic Installation Issues during setup: I ignored this issue and the site is working fine. I will report if there will be issues.


Tuesday, April 12, 2011

LINQ To SQL DatabaseContext Insertion Memory Bloat & Clearing the Cache

Symptom:

You have inserted a huge number of records using the InsertOnSubmit(row) call, and you have ran out of memory in your .NET program using LINQ TO SQL technique.

Cause

The DatabaseContext caches all previously inserted rows.

Solution

There are many articles on the net using the Reflection locate the internal ClearCache then call it. This is not the intended use of the DatabaseContext object. It is a light-weight object and thus, you should simply dispose a object and create a new one. In my situation after a few thousand consecutive insertions, I dispose (i.e., new the object into the variable previously held the old context object.) This is also significantly more efficient way of clearing the cache held.

Friday, February 11, 2011

Installing Drupal 7.0 Experience on Joyent SmartMachine

This is a quick note to myself regarding the installation of Drupal 7 on Joyent SmartMachine

  • Creating the database and user is done from the Webmin->Servers->MySQL_Database_Server.  Be sure that the you give the select, create, drop and insert permission to the mySQL user that you will give to Drupal
  • SSH Login as the admin user then sudo bash
  • The content of the drupal tar goes into /home//web/public so in other words in that directory, you should have install.php
  • PDO may be disabled (it was in my case). To enable it, edit /opt/local/etc/php.ini and uncomment pdo.so and pdo_mysel.so uncomment to mean to remove the semicolon.
  • From the shell reboot the machine by tying in "reboot"  This will activate the PDO (there are other ways to do this, this is one of the quick ways to do it.)

Sunday, February 06, 2011

Annoyed by: System.Xml: The node to be inserted is from a different document context?

 Symptom:

You try to copy one or more XML Nodes (usually elements though) from one XMLDocument and another, and you get the following error:


System.Xml: The node to be inserted is from a different document context.

My Fix, Hint:

(Note from 1/21/2012: Try using the XDocument class and LINQtoXML, it's much easier to deal with!)

There is an official way to fix this using clone, import and InsertBefore or After. But that's too difficult to figure out, in my case I still get the above mentioned exceptions. I often do not know which node to insert (you are supposed to find the parent node then insert) or afraid to insert something at a wrong node level.

Rather than wasting a whole lot of time, I do this entirely in text using StringBuilder and such. You will find the following methods very handy.

XmlNode.OuterXML

  • This contains the Text representation of XML including the node itself and all of the children.

XmlNode.InnerXML

  • This contains the Text representation of XML node of all its children.

You know that you can build up a string using StringBuilder.Append(string) you can form the basis for the new XML document which some of the node data copied from another XML document WITHOUT having any issues with copies being prohibited between two documents.

As an added bonus, you can see exactly the new XML document being formed since it is in the string form.

Once you form the destination XML, there is a handy function LoadXML(string), and you are back to have the new XMLDocument. There absolutely is no need to create a StringReader or stream of any kind.



XmlDocument xd = new XmlDocument();
var sx = sDoc.ToString();
xd.LoadXml(sx);

Hope I gave you enough hint here, but if you need a more complete coding example, please post a comment and next time I come back here I will write one up for you.
 

Thursday, August 19, 2010

Notes on Amazon EC2 Image Creation Fails for Windows Machines

Disclaimer:
  • This is my notes on the topic and not necessarily a complete solution. In fact, probably it contains some very inaccurate information (but you can help to rectify this via your comments.)
  • This article also pertains to EBS Backed Windows EC2 running instances.
One of the things all of us should do is that once we have a stable machine running, we'd want to save the image of it so that if, for some reason, we completely trash the running image, we have something to go back to without spending a lot of time putting the machine back from the scratch.

Obviously I have tried this with varying degree of success and information on this is scattered around the Amazon AWS forums and on the web. The most common of the errors would be that the Image creation begins and then after a long while it says "Failed" but without much explanations why. Some people on the net are saying the success rate is 40%. I was actually relieved to find this because I thought it was just me that's suffering this much failure rate!

The Amazon documentation is not very clear to me as to what and how to do these things. It seems to require you have gained some more "under-the-hood" knowledge of this. And as a just a casual user of the system I expect that I should not need to learn everything to use it.

In addition to that as a "basic" user, I don't get any direct support from Amazon. That's at least $100/mo or much more for silver or gold support privilege even in these kind of the situations when the failure (even just to explain what to do) is on their side.

I also highly suggest you install Elasticfox on your browser. Since the following descriptions will be based on how I'd do things on Elasticfox.

My Findings on Creating a Copy of Running Image
  • To do this on Elasticfox, go to the Instances list, right click and select Create Images (AMI) item.
  • Many people reported that when creating a copy from the running image, it will stop and restart the instance. This does happen. Worse yet, it will be stopped for the entire duration of when it is taking the snapshot, depending, this could be 10s of minutes. You'd probably want to schedule a down time. I should have done this just as soon as I have created the initial instance before went into production. Elasticfox does have a menu item not to reboot the instance I have not yet tried this.
  • Some people say it has to be a Running instance, but that seems to be not true. I can image from a stopped instance as well and I have made images successfully this way via Elasticfox. In fact, that has more success rate than doing it on a running instance.

Some of The Issues I Have Discovered That Cause Failures
  • Again, copying the running instance will cause a restart, so be prepared for the downtime.
  • If you have already stopped the instance, it is at least more likely the imaging will succeed. A few caveats on this are that, at least in my case, the Elastic IP will get disassociated with the instance as shutting down the instance will detach the Elastic IP (wish they did not, at least for a short time), and also the machine's local addresses will change after restarting. This means that if you are locally pointing systems, for example, SQL, then the that address have to be re-configured in each application.
  • Processes like SQL or other high I/O or CPU consumer items should be stopped. In fact, you should pare down the services to essentials (like SQL, agents, browser etc.) before taking the image copy. The one exception to this is not to stop the Amazon's EC2 services that came with the original Windows image whichever they exist.
  • If you have other volumes mounted that also leads to a failure. Stop all services and applications you don't need to be running then dismount any "drives" and then make the image copy. This seems not be an issue if you are imaging a stopped instance.
Well, good luck and if you find this article correct or wrong, please let me know in the comments so that I can actually improve it.



Wednesday, August 18, 2010

IIS 6: Installing Duplicate Certificates to Multiple IIS 6 Servers For Server Farm Implementation

Symptom:

You have more than one servers that are hosted through a load-balanced router. The external address is assigned to (obviously) a single Fully Qualified Domain Name (FQDN). You want to install the same server certificate that represents the same domain name across all your IIS 6 based servers.

Procedure:

First off, yes you can do this. The procedure is very clearly explained in this Microsoft article:


Just in case we lose above article, here is the gist of how it is done.
  • Request and install the cert on the first server as you would normally do. Don't do the request from other servers, if you do, remove any pending cert requests.
  • Open the MMC and add the Certificate module.
  • Open the Computer Account then Personal certificate folder.
  • Navigate down to the Web Certificate you want to export.
  • Right click tasks and Export.
  • In the wizard select to include the Private Key and include all certificates in the path in the next page.
  • Copy the exported result to another server
  • Do the same MMC stuff
  • Import the stuff you exported into the Personal store
  • From the IIS certificate section of the Directory Security, do the "Assign an Existing Certificate"
That's basically all you need to do.



Getting an XmlNode (or XmlElement) Out of XPathNodeIterator (C#)

Symptom:

You have a code you iterate through a group of Xml Nodes (for most people that's XmlElement). You have however noticed that once you get to a specific spot, there is no easy way to perform the complete node operations against the iterator since Casting of the iterator to XmlElement results in a compilation error.

So, you cannot cast the Current of the iterator like

XmlNode node = (XmlNode) i.Current;

(I really think this is a poor design myself since it goes against all our intuition.)

Solution:

Well, there actually is a way to "cast" this to an element, but the syntax is a bit more involved.

XmlNode node = ((IHasXmlNode) i.Current).GetNode();

Or in most cases you can cast this to XmlElement by

XmlElement node = (XmlElement) ((IHasXmlNode) i.Current).GetNode();

Get a Permission Error When Creating A New Scheduled Task

Symptom:

You tried to create a new Scheduled Task on Windows XP (may be other version of Windows) and you get a Permission Denied error even though you are logged in as the local administrator.

Fix:

The Schedules are stored under C:\Windows\Tasks Unfortunately if you try to alter the permission on the specific folder you may not be able to.

In order to get around this, you can 'Mount a Network Drive" of the path \\[YourComptuerName]\c$\Windows\Tasks

Be sure that Tasks is the top level of the share.

Now you can right mouse click the mounted drive and you can change the permissions.

Friday, July 23, 2010

The Difference Between XmlNode and XmlElement

Symptom:

You are confused why there are XmlNode and XmlElement classes.

Answer:

I was confused by this too. The confusion stems from the fact that if we deal with XML text (especially coming from the understanding of HTML and editing them with Notepad or whatever), what we normally deal with in XML are XmlElements. But in the Xml Standard, even the attributes within an element is a Node.

The detail is that XmlElements are the ones that has tags.

The second source of confusion is that just about everything in Xml is a subclass of XmlNode. That includes attributes in an XmlElement.

We should also note that in System.Xml namespace, XmlElement is a subclass of XmlLinkedNode class which is worthwhile examining in the Microsoft document.

All of this stems from the fact that Xml DOM (Document Object Model) dictates that everything is derived from the single Node class and System.Xml class classes closely follow this hierarchy.





Sunday, July 18, 2010

Creating XMLDocument from Program Embedded String in C#

Problem:

You want to quickly create a simple XML document without needing to write data to a file.

Solution:

Use StringReader class and feed that into the Load() function.

 Example Code:
XmlDocument doc = new XmlDocument();
doc.Load(new StringReader("<myNode>Hello</myNode>"));


Update: Well, that was doing too much, Load(string) would have worked just as well.

How To Use InsertAfter() in XmlDocument and Copy Nodes from another XmlDocument

Symptom:

You tried to insert an element (actually it has to be an XmlNode) using InsertAfter() or InsertBefore() method as doing so results in an exception with "The reference node is not a child of this node."

You also want to do the same but take a node from one XmlDocument to another.

Personally I feel that the Xml classes in the .NET Framework is not very intuitive. If you approach them as if they are regular List or Tree class type collection, then you will get a bunch of exceptions.

In terms of InsertAfter() type operations, this is a Node based operation and you normally cannot run InsertAfter() against the XmlDocument object. You must at least go down to the first child of the document, then invoke InsertAfter() at the node with the new node data (to be inserted) and the reference node location. This is most puzzling to me but that's what you need to do.

In terms of copying the data from a node in one document to another, all the nodes created or inserted in one XmlDocument have the membership to that XmlDocument. This is why new nodes must be created from the originating document using CreateElement() type calls. If you are familiar with creating a new row from the DataTable class, then you also know that you have to add that row to the table later is similar to this approach.

To confuse the matter, there are Clone type functions in XmlNode (see note below*). In this context they seem to be of no use (again that's not intuitive to me, since I tend to think if you clone it, I would say you created a detached instance.)

In actuality though, it is an error condition if you simply copy the node to another XmlDocument. This is also separate from where the node resides in overall tree of the nodes. ImportNode() simply buys the membership in another XmlDocument without reserving exactly where your own seat is.

Another important point to remember is that the Node (or Element) you insert to another XmlDocument should be the one returned from the ImportNode() method and not the one you passed to ImportNode(). If you try to insert the node that you passed to the ImportNode() method, you will get an exception "The node to be inserted is from a different document context."

XmlNode useThisNode = doc.ImortNode( myOriginalNode );


Solution Example:

The following code example demonstrates how InsertAfter() should (or at least could) be used, then add yet another node from another XmlDocument (created in-line in the code).

 XmlDocument Insertion Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.XPath;
namespace XMLDocumentExample
{
class Program
{
static void Main(string[] args)
{
// === EXAMPLE 1: How To Use InsertAfter in XMLDocuments ========================
XmlDocument doc1 = new XmlDocument();
// This XPathNavigator creates a convenient way to Write out the tree on the console.
// we don't use it for nothing else in this example.
XPathNavigator nav1 = doc1.CreateNavigator();
// This creates the root document, which all XML documents will need.
// i.e. <doc1></doc1>
XmlElement e = doc1.CreateElement("doc1");
doc1.AppendChild(e);
// Everything in thid document are the child of the root. I will purposely make a
// Mistake here so that I don't have doc1.2.0 element. I will demonstrate inserting
// doc1.2.0 using InsertAfter.
/*
*
* <doc1>
<doc1.0.0 />
<doc1.1.0 />
<doc1.3.0 />
</doc1>
*
*/
XmlElement c = doc1.CreateElement("doc1.0.0");
e.AppendChild(c);
c = doc1.CreateElement("doc1.1.0");
e.AppendChild(c);
c = doc1.CreateElement("doc1.3.0");
e.AppendChild(c);
Console.WriteLine(nav1.OuterXml); // Will show you you have doc1.0.0, doc1.1.0 and doc1.3.0 now.
// Now we will try to add the missing doc1.2.0 and just as a bonus I will attach doc1.2.1 as the
// child of doc1.2.0
// First let's get to the node AFTER where we will insert doc1.2.0, so that will be doc1.1.0
// Note you can either use /doc1/doc1.1.0 or //doc1.1.0 as the XPath query.
XmlNode nod1_1_0 = doc1.SelectSingleNode("//doc1.1.0");
// This block of code assembles doc1.2.0 node and its child doc1.2.1
XmlElement n2 = doc1.CreateElement("doc1.2.0");
XmlElement n2c = doc1.CreateElement("doc1.2.1");
n2.AppendChild(n2c);
// This is the most tricky important part. You have to ask the parent node to InsertAfter, and not
// directly with doc1.
//XmlNode myParent = nod1_1_0.ParentNode;
//myParent.InsertAfter(n2, nod1_1_0);
XmlNode mp = doc1.FirstChild;
mp.InsertAfter(n2, nod1_1_0);
// The result would look like this:
/*
<doc1>
<doc1.0.0 />
<doc1.1.0 />
<doc1.2.0>
<doc1.2.1 />
</doc1.2.0>
<doc1.3.0 />
</doc1>
* */
// Write the tree out on the console.
Console.WriteLine(nav1.OuterXml);
// === EXAMPLE 2: Copy A Node from One XMLDocument to Another ==============
// Create the Second XmlDocument, and then copy a node in the second
// document into the first document.
XmlDocument doc2 = new XmlDocument();
doc2.AppendChild(doc2.CreateElement("doc2"));
doc2.FirstChild.AppendChild(doc2.CreateElement("doc2.0.0"));
XPathNavigator nav2 = doc2.CreateNavigator();
Console.WriteLine(nav2.OuterXml);
XmlNode node_2_0_0 = doc2.SelectSingleNode("//doc2.0.0");
// Note that this does not append the node, it simply says that
// a foreign node can now belong to the first document.
XmlNode importableNode = doc1.ImportNode(node_2_0_0, true);
doc1.SelectSingleNode("/doc1/").AppendChild(importableNode);
Console.WriteLine(nav1.OuterXml);
Console.ReadLine();
}
}
}



*Note: Cloning of a node is required when you need to make a copy of a node and insert that back into the same XmlDocument. It appears that you cannot make a reference to a node and insert that (of course, if you can do that then there is a side effect of both node data changing if you edit the content of one node.)