Sunday, June 10, 2012

Say what? Nothing beat it like trying!

Recently I've been trying to install VS SDK (VsSDK_sfx.exe) and been cursing it for not allowing me to proceed the installation as I did not have TFS or some other dependent component. I've always been getting this error.


Couple of VS kills, system reboots, the result is still the same. I do not have TFS with me and also it sounded very stupid to require TFS for a VS SDK! 

I badly wanted this to be working so that I could proceed with a VS plugging that i've started work on, could continue. 

Tried google but with no luck and now what? Here is what i tried. 

Run the installer till it gives you this message. And it would extract the files for the setup somewhere in your file system. In my case it was under D:\






Run the setup from the VSSDK.MSI, it works like charm. Now don't ask me why, cuz I dont know the exact reason for this to work and the VsSDK_sfx.exe not to. 

There' nothing wrong with trying, eh? 

Thursday, November 26, 2009

Converting a word document to use unicode characters

One of my friend recently had a problem like this. He wanted some word documents to be converted to Unicode. These files are in Sinhala but not in Sinhala unicode. They are in plain English letters but based on the font-type only they were displayed in Sinhala. What he wanted is to convert these documents to use Sinhala unicode characters. Since he is from Java background he wanted me to bring in some help as how to do it using .NET.

Our approach was something like this. Read thru the document, get all the words and check their font type , and if that font type is a font that uses English letters to be displayed in Sinhala(e.g. Kaputa, Thibas) we would replace the characters with a matching unicode character. Hope this approach is fair enough? If you guys could think of something smarter, please do let me know.

Here is what i do,

Declare some private members,


#region Private Members

Document wordDoc;
ApplicationClass wordApplication = new ApplicationClass();

#endregion


In a button event, open a dialog box and get the document to be converted;


DialogResult dialogResult = openFileDialog1.ShowDialog();
object documentPath;
object o_null = System.Reflection.Missing.Value;

if (dialogResult == DialogResult.OK)
{
maskedTextBox1.Text = openFileDialog1.FileName;
documentPath = openFileDialog1.FileName;

wordDoc = wordApplication.Documents.Open(ref documentPath, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null,
ref o_null, ref o_null, ref o_null, ref o_null, ref o_null,
ref o_null, ref o_null, ref o_null, ref o_null, ref o_null);

}


In another button event , do the convertion ;



Words words = wordDoc.Words;
IEnumerator enumerator = words.GetEnumerator();
object o_null = System.Reflection.Missing.Value;


while (enumerator.MoveNext())
{
Range range = enumerator.Current as Range;
Microsoft.Office.Interop.Word.Font font = range.Font;

string word = range.Text.Trim();
char[] characters = word.ToCharArray();
char[] newCharArray = new char[characters.Length];

for(int i=0 ; i < characters.Length ; i++)
{
//Should take the proper character from the mapping
newCharArray[i] = 'S';
}
string newWord = new string(newCharArray);

if (!string.IsNullOrEmpty(word))
{
range.Text = range.Text.Replace(word, newWord);
enumerator.MoveNext();
}
}



Finally save the document as a new one in another event handler,


Object oSaveAsFile = (Object)"C:\\SampleDoc.doc";
object o_null = System.Reflection.Missing.Value;

wordDoc.SaveAs(ref oSaveAsFile, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null,
ref o_null, ref o_null, ref o_null, ref o_null, ref o_null,
ref o_null, ref o_null, ref o_null, ref o_null, ref o_null);

Friday, November 20, 2009

Cannot place .js files in Themes folder in ASP.NET MVC

Yes! I have been struggling with this for couple of days and it is a problem. The MVC engine only parses .css files from the Themes folder. So if you are used to put .js files in your Themes folder (a habit of ASP.NET designers), well you have to think twice here. Whether you absultely need .js files in the Themes folder ? Otherwise dont put them and expect the framework to automatically dump them to the response. You have to explicitly put a script references in the Master page.

Cheers!
/Bumble Bee.

Thursday, November 19, 2009

WebMethods in aspx and calling them thru javascript

I came across a situation today which I thought worth making a note about !

Problem : I have a collapsible grid. Where upon clicking a certain button, there should appear another row with some additional fields. When the grid is created the table which contains my dynamic row is getting dumped to the output stream as follows,

System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
table.RenderControl(htw);
the table object basically contains few text box controls (ASP.NET) and labels. The problem is when i define a event handler for text change event in the text box controls, they do not wireup properly. And hence I cannot make them to do a asynchronous postback to do save their values upon leaving the text boxes. This is purely due to fact that the html content for these controls are created then and there and they wont capture these during the page-life cycle.

Solution : One solution is I can call a javascript function from either onleave or onblue events and then do a postback on that. Than doing a post back and let the full page lifecycle to run, if i can call a method in the page and do the expected saving, it would be worth it. This is the first time I used this technique but there may be guys who are experts on this. Just correct me if there are is any false in what i say :)

Step 1 : Define a web method is the webpage (yes in the web page, i did not know about if that is possible to have a web-method in any other place than a asmx but it can be done. Just have a public static method and attribute it with [WebMethod]). In my situation it was not a page that i had to deal with but it was a User Control. And here is the other problem. [WebMethod] s are not allowed in user controls. They can only be placed in .aspx pages. So how I am going to resolve the issue. I put my [WebMethod] in the page that contains my user control . Then define a static method in the user control and call it thru the [WebMethod]. Another issue! my user control is a instance member and i cannot call a instance member thru a static method. Hack: make the user control a static member thru the designer.cs [Are there any side affects of doing this, I dont think so ;)]

[WebMethod]
public static void DynamicTextBoxTextChanged(string invoiceUniqueId, string textBoxValue, string textBoxType)
{
<>.DynamicTextBoxTextChanged(invoiceUniqueId, textBoxValue, textBoxType);
}


In the user control,

public static void DynamicTextBoxTextChanged(string invoiceUniqueId , string textBoxValue , string textBoxType)
{
//Logic to do the saving
}


Step2 : Now we are half way done. Only thing left is to call the WebMethod thru a javascript in the page.

As simple as this,

function CallPageMethod(key, textBox, textBoxType) {

PageMethods.DynamicTextBoxTextChanged(key, textBox.value, textBoxType);
}
and my text box will have to have a attribute like this onchange="javascript:CallPageMethod('somekey' , this , 'sometype')"

We are not quite done yet, where does this PageMethods comes from? and how does it know that there is a [WebMethod] called DynamicTextBoxTextChanged in my page? That happens thru the ScriptManger. The ScriptManger should have the attribute EnablePageMethods="true".

And that is it. It should good to go!

Hands off the keyboard,
Bumble Bee

Monday, October 19, 2009

Localizing images

It is a common practice these days to localize applications. Well there are are number of options to localize the static text labels in an application. But how many times you have wanted to have some texts in your images and load them based on the current-thread's locale? One option is you can programatically set the ImageUrl to the asp.net image controls based on the current locale. But how many lines of code you would have to write to get this done? With .Net 2.0 Implicit Localization you can achieve this with zero code lines. Here is how we would do it.


step 1 : have your images placed on different directories based on the locale. i.e images/en/image1.jpg , images/es/image1.jpg and so on.

step 2 : have a resource key in the respective resource files pointing to the above images.
i.e in Page.es.resx file we might have a key BannerImage.ImageUrl with the value "~/images/es/image1.jpg"

step 3 : make the implicit localization do the rest of the job by properly formatting it.



Now when ever the BannerImage is rendered in the page life cycle, the ImageUrl will be picked from the resource files and based on the value for the current locale.

Hope that helps.

/BB

Friday, March 20, 2009

Steps to setup CRM 3.0

I tried to setup CMR 3.0 once and it was the craziest installation that I have ever done. I did it in my Win Server 2003 box and what I initially had was a crack; in the middle of the installation it asks to upgrade SP2 after which it doesn't allow to login to the OS without registration. So my advice is , don't try this unless you have Win Server 2003 genuine or crack with SP2.

CRM Server can only be setup on server operating systems as it requires certain server only features like Active Directory and DNS.

Step 1 : Setup Active Directory

Authorization for CRM happens via the AD so it is required to have AD setup before the installation.This documents a comprehensive steps to setup the active directory for Server 2003.

Step 2: Install SQL Server 2005 as the default instance.

It is important to setup SQL Server 2005 as the default instance since named instances are not working for CRM and it is difficult to change a named instance to a default instance after the setup. In theory CRM 3.0 should work with SQL 2000 but i was never able to get it to work even after doing all the patches that is said are required. So best option is to start with 2005.

Step 3: Install SQL Server 2000 and 2K Reporting Services

Sounds crazy to install two versions of DBMS to work with single product but that the way it worked for me :). It doesn't work with 2005 reporting services so you have to have a 2000 instance to install reporting servieces. This can be a named instance. After installing the Database engine there it should be patched with SP3 for SQL. The database engine would be a named instance as we already have a Default 2005 engine.

Step 4. Install CRM 3.

Sunday, December 28, 2008

Damaged cable in Mediterranean sea


It was reported that both SEA-ME-WE4 and SEA-ME-WE3 (primary optical cables that connect Asia-Middle East and Europe) were damaged and hence internet connections between Asia and Europe will be disrupted most probably till end of 2008. These two cables are the primary links between Asia, Middle East and Europe and obviously are carrying a significant amount of load. SEA-ME-WE3 is the longest optical cable link in the world and since it was not sufficient enough to bear the heavy load SEA-ME-WE4 was added to complement it. 

From the way it looks, seems both the cables are heavily damaged this time probably by a trawler net or a anchor of a ship. Whatever it is the French company who has undertaken the repair work claims that the cables are dragged long distance apart and the cables need to be taken to the ship in order to do the reconnection which is a complex process that may take days. 

This incident took me interested to see what are the cables that connect Sri Lanka and the rest of the world. 

contains the map as of end 2008. 



Following are the names of the cables incase the map is not so clear :) . 

Bharat Lanka Cable System
Maldives-Sri Lanka
SEA-ME-WE 4 
SEA-ME-WE 3 
SEA-ME-WE 2