Ahmad Masykur

Share your knowledge although one function!

About the author

Ahmad Masykur is a Software Architecture Engineer at PT. Freeport Indonesia Jakarta Indonesia.
In this blog, I share things of interest to me. Most topics are likely to be related to software development, but don't hold me to it.



Powered by

Widget Prayer Time not found.

There is an error in XML document (4, 16278).X

Page List


Ahmad Masykur

Get Microsoft Certifications at 10% discount and free retake

Staying Ahead in Your Career with Microsoft Certification

A challenging economic climate is driving many organizations to re-examine their operations. Ensuring employees have the skills to utilize the latest software capabilities helps companies fully realize the potential value of their technology investments while achieving reduced costs and improved staffing efficiencies.

As responsible IT professional, it is essential to stay current on the latest technologies and proactively upgrade one’s skills. This will help the team to provide the necessary expertise to improve the organization’s IT environment. Certification, which encompasses training and skills validation, is a proven way to maximize the effectiveness of IT professionals. Check out more information from TechRepublic on 10 reasons why certification will be important in 2009

How do you decide on the relevant Certification to invest in? Find out more on the demand of IT Skills and Certification available in the market. Some reports you can refer to include TechRepublic’s The industry's 10 best IT certifications, IT [email protected] – An Asia Pacific Perspective by Kelly IT Resources (October 2008) and TechRepublic’s IT Salary Survey 2009.

This is the best time to join the
Microsoft Certified Professional community!
If you are interested in getting a Microsoft Certification, here’s the good news … go to www.learnANDcertify.com by April 30, 2009 and key in the Promo Code : ID4747BA to enjoy a 10% discount on your next Microsoft Certification exam. Even better, you will enjoy a free retake if you fail the exam. (Limited to Indonesia usage only)

Note : Once you decided on obtaining a Microsoft Certification, you can participate in the upcoming Live Meeting on “Getting Started with Microsoft Certification” on April 7, 2009 11:30pm Jakarta Time or April 8, 2009 9:30am Jakarta Time. Also you can visit www.learnANDcertify.com to find out more on the resources available.

Yours sincerely,
Ahmad Masykur
Microsoft ASP.NET MVP

Categories: Certification
Permalink | Comments (1) | Post RSSRSS comment feed

How To Create Silverlight Avatar for INDC blogs site

I have created Silverlight avatar for Community Server blog list page (http://geeks.netindonesia.net/blogs) a week ago as requested by Naren. I think its no difficult to replace HTML avatar with Silverlight avatar on the fly. Just query DOM using jQuery for existing avatar, grab photo Url information, hide it and replace with new Silverlight avatar. Here is step by step to create Silverlight avatar for CS theme on geeks site.

Create Silverlight project using Expression Blend.

I'm created two path to put avatar image and two StackPanel contain text-boxes for view counter text. Second path and StackPanel will mirrored-down to make shadow-mirror effect. These path will be binded by same image.


Here is the XAML for that design.

    Width="133" Height="130">
    <Grid x:Name="LayoutRoot" Clip="M0,0 L133,0 L133,130 L0,130 z">
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF8FC2E4"/>
                <GradientStop Color="#FFFFFFFF" Offset="1"/>
            <Canvas Margin="48 1 1 10" >
                <Path Data="M0,0 L82,0 L82,102 L0,91 z" Stretch="Fill" Stroke="#CCFFFFFF" >
                        <ImageBrush x:Name="Photo" />
                <Path Canvas.Top="193.5" Data="M1.5,12 L81,0 L81.75,73.5 L0.25,82.5 z" Stretch="Fill" Stroke="#CCFFFFFF" RenderTransformOrigin="0,0" Height="102.188" Width="82.5" Canvas.Left="0.125" >
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.4,0">
                            <GradientStop Color="#AAFFFFFF" Offset="1"/>
                            <GradientStop Color="#00FFFFFF" Offset="0"/>
                        <ImageBrush x:Name="PhotoShadow" />
                            <ScaleTransform ScaleY="-1"/>
                            <TranslateTransform X="0" Y="0"/>
            <Canvas Margin="2,0,0,0">
                <Path Height="18" Width="134" Canvas.Left="-3" Canvas.Top="86.25" Data="M128,103.25 L-3,86.25" Fill="#FFFFFFFF" Stretch="Fill" Stroke="#B2FFFFFF"/>
                <StackPanel Canvas.Top="48" RenderTransformOrigin="0.5,0.5">
                            <SkewTransform AngleY="6.972"/>
                            <TranslateTransform Y="4.006"/>
                    <TextBlock x:Name="ViewCount" Text="9999" TextWrapping="Wrap" FontFamily="Arial" FontSize="20" Foreground="#FF023D9E" HorizontalAlignment="Right"/>
                    <TextBlock Text="Views" TextWrapping="Wrap" FontFamily="Arial" FontSize="16" Foreground="#FF023D9E" HorizontalAlignment="Right"/>
                <StackPanel Canvas.Top="84" RenderTransformOrigin="0.5,0.5">
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#00FFFFFF"/>
                            <GradientStop Color="#AAFFFFFF" Offset="1"/>
                            <ScaleTransform ScaleY="-1"/>
                            <SkewTransform AngleY="7.585"/>
                            <TranslateTransform Y="3.288"/>
                    <TextBlock x:Name="ViewCountShadow" Text="9999" TextWrapping="Wrap" FontFamily="Arial" FontSize="20" Foreground="#FF023D9E" HorizontalAlignment="Right"/>
                    <TextBlock Text="Views" TextWrapping="Wrap" FontFamily="Arial" FontSize="16" Foreground="#FF023D9E" HorizontalAlignment="Right"/>

Write code-behind to bind avatar image and view counter.

This code-behind used to bind avatar image and view counter. The image url and view counter passed by InitParams property from javascript. The App.xaml.cs code-behind used to get InitParams and Page.xaml.cs used to bind the image and text from parameter values.


 1 using System.Windows;
 2 using System;
 3 using System.Windows.Browser;
 5 namespace Avatar
 6 {
 7     public partial class App : Application 
 8     {
 9         public App() 
10         {
11             this.Startup += this.OnStartup;
12             this.Exit += this.OnExit;
13             this.UnhandledException += this.Application_UnhandledException;
15             InitializeComponent();
16         }
18         private void OnStartup(object sender, StartupEventArgs e)
19         {
20             var page = new Page();
21             // Read application parameter
22             var imageSourceUrl = string.Empty;
23             int viewCountInteger = 0;
24             if (e.InitParams.Count > 0)
25             {
26                 var viewCount = string.Empty;
27                 if (e.InitParams.ContainsKey("ImageSourceUrl"))
28                     imageSourceUrl = HttpUtility.HtmlDecode(e.InitParams["ImageSourceUrl"]);
29                 if (e.InitParams.ContainsKey("ViewCount")) viewCount = e.InitParams["ViewCount"];
30                 // Load the main control here
31                 if (!string.IsNullOrEmpty(viewCount))
32                     int.TryParse(viewCount, out viewCountInteger);
33             }
35             page.SetImageSource(imageSourceUrl);
36             page.SetViewCount(viewCountInteger);
37             this.RootVisual = page;
38         }
40         private void OnExit(object sender, EventArgs e) 
41         {
42         }
44         private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
45         {
46             // If the app is running outside of the debugger then report the exception using
47             // the browser's exception mechanism. On IE this will display it a yellow alert 
48             // icon in the status bar and Firefox will display a script error.
49             if (!System.Diagnostics.Debugger.IsAttached)
50             {
51                 // NOTE: This will allow the application to continue running after an exception has been thrown
52                 // but not handled. 
53                 // For production applications this error handling should be replaced with something that will 
54                 // report the error to the website and stop the application.
55                 e.Handled = true;
56                 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
57             }
58         }
60         private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
61         {
62             try
63             {
64                 string errorMsg = e.ExceptionObject.Message + @"\n" + e.ExceptionObject.StackTrace;
65                 errorMsg = errorMsg.Replace("\"", "\\\"").Replace("\r\n", @"\n");
67                 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
68             }
69             catch (Exception)
70             {
71             }
72         }
73     }
74 }



 1 using System;
 2 using System.Windows;
 3 using System.Windows.Browser;
 4 using System.Windows.Controls;
 5 using System.Windows.Media.Imaging;
 7 namespace Avatar
 8 {
 9     public partial class Page : UserControl
10     {
11         public Page()
12         {
13             // Required to initialize variables
14             InitializeComponent();
16         }
17         public void SetImageSource(string imageSourceUrl)
18         {
19             if (!string.IsNullOrEmpty(imageSourceUrl))
20             {
21                 var url = new Uri(imageSourceUrl, UriKind.RelativeOrAbsolute);
22                 if (!url.IsAbsoluteUri)
23                 {
24                     url = new Uri(HtmlPage.Document.DocumentUri, url);
25                 }
26                 var image = new BitmapImage(url);
27                 Photo.ImageFailed += Photo_ImageFailed;
28                 PhotoShadow.ImageFailed += Photo_ImageFailed;
29                 Photo.ImageSource = image;
30                 PhotoShadow.ImageSource = image;
31             }
32         }
33         public void SetViewCount(int viewCount)
34         {
35             ViewCount.Text = viewCount.ToString();
36             ViewCountShadow.Text = viewCount.ToString();
37         }
38         void Photo_ImageFailed(object sender, ExceptionRoutedEventArgs e)
39         {
40         }
41     }
42 }


Note: You must get absolute Url for downloading photo with query string, see line 21-25 above. Silverlight will ignored query string if you are not provide absolute url for image source.


Grab DOM using jQuery

jQyery is very powerful tool for DOM manipulation. You can query and modify DOM with single line of code. Before query the DOM, you should be knows the DOM structure of page. Target of DOM is the avatar image. Open IE development toolbar to get the DOM of avatar. Find ID or CSS classes that used by Avatar to be replaced by Silverlight avatar.


From this information you can analyze that every blog entry placed inside DIV element with content_main_con_be CSS class. This DIV element contain view count and avatar image DIV in first and second child element. Based on this information, you can query the DOM using jQuery as script in line number 11 and 12 below.

 1 /*
 2     Filename: avatar.js
 3     Project : INDC Geeks
 4     Ver.    : 1.0
 5     Date    : March, 4th 2009
 6     Author  : Ahmad Masykur - www.masykur.web.id
 7 */
 9 $(document).ready(function() {
10     if (Silverlight.isInstalled('2.0')) {
11         var viewCountElements = $("div.content_main_con_be div:nth-child(1) > span:even");
12         var pictureBoxes = $("div.content_main_con_be div:nth-child(2)")
13         pictureBoxes.each(function(i, element) {
14             $(element).width(132).height(130);
15             var imageSourceUrl = $('img', element).attr('src');
16             createSilverlight(element, imageSourceUrl, $(viewCountElements[i]).text());
17         });
18         $("div.content_main_con_be div:nth-child(1)").hide();
19     }
20 });
22 function createSilverlight(host, imageSourceUrl, viewCount) {
23     Silverlight.createObject(
24         '/ClientBin/Avatar.xap?v=0.2',
25         host, host +"_Plugin",
26         {
27             width: "100%", height: "100%",
28             background: "#E8CFB0", 
29             version: "2.0.31005.0" 
30         },
31         { onLoad: null },
32         'ImageSourceUrl=' + imageSourceUrl + ', ViewCount=' + viewCount);
33 }

Description of script above are.

  • The script above will be execute when DOM is ready (evaluated in line 9).
  • Line 10 will verify if Silverlight 2 is installed in the machine. If Silverlight 2 is installed, DOM will be replaced with Silverlight object.
  • Line 11 and 12 is getting view counter and picture box elements.
  • Line 13: Make a loop the selected DOM. 
  • Line 14: Set the width and height of element that will be used for Silverlight host
  • Line 15: Get image Url information from IMG element
  • Line 16: Create Silvelight object using javascript.
  • Line 22-33 is function to create Silverlight object.
  • Line 32: Set InitParams value to be passing to Silverlight application.

This script required Silverlight.js and jQuery 1.3.2. The last steps are upload xap file of Silverlight application and required scripts also included the script above, Silverlight.js and jquery-1.3.2.min.js into blog.master of theme.

<script src="/JavaScripts/Silverlight.js" type="text/javascript"></script> 
<script src="/JavaScripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/JavaScripts/avatar.js" type="text/javascript"></script>

Finally, the geeks portal have a new theme with Silverlight avatar. This avatar will available both installed Silverlight plung-ins or not. User will see HTML version of avatar if they don't have Silverlight plug-ins installed on the machine.


I would like to say thank you to Wely and Naren that support me to make it running well in geeks portal.

Categories: Silverlight
Permalink | Comments (3) | Post RSSRSS comment feed

Parsing Array Parameter in SQL Server Stored Procedure

If we develop application to select multiple data in grid and selected data to be process in stored procedure at same time, we need to pass the values of keys to stored procedure parameters. The problem is SQL Server has not array parameter. Here is some ways to resolve the problem.

  1. Use EXEC to execute dynamic query and passing the stored procedure parameter in WHERE clause.
  2. 2. Use XML as parameter and using OPENXML keyword to convert it to table.

First option is vary simple but it bad practice to use dynamic query. SQL Server can’t save statistic of dynamic query. Second option is better way but more complicated. We need simplest way to passing an array to stored procedure parameter.

Other option we can create table function to parse delimited string to table. Here is sample function to do that.

CREATE FUNCTION [dbo].[fn_ParseDelimitedStrings](@String nvarchar(MAX), @Delimiter char(1))
     RowId int Not Null IDENTITY(1,1) PRIMARY KEY
    ,Value nvarchar(255) Not Null
    DECLARE  @startPos smallint
            ,@endPos smallint

    IF (RIGHT(@String, 1) != @Delimiter)
        SET @String = @String + @Delimiter
    SET @startPos = 1
    SET @endPos = CharIndex(@Delimiter, @String)
    WHILE @endPos > 0
            INSERT @Values(Value)
            SELECT LTRIM(RTRIM(SUBSTRING(@String, @startPos, @endPos - @startPos)))
            -- remove the delimiter just used
            SET @String = STUFF(@String, @endPos, 1, '')
            -- move string pointer to next delimiter
            SET @startPos = @endPos
            SET @endPos = CHARINDEX(@Delimiter, @String)

This function can be used in sample stored procedure below.

    @customerIDs AS nvarchar
    DECLARE @custIDs AS table (Value nvarchar(255) Not Null)
    INSERT INTO @custIDs
        SELECT Value FROM [fn_ParseDelimitedStrings](@customerIDs, ',') 
    SELECT * FROM Orders WHERE CustomerID IN (SELECT Value FROM @custIDs)

It very simple query. Just declare memory table and parse the delimited string into table to be used in select criteria.

I hope this tips is helpful for you.

Categories: SQL Server | Tips
Permalink | Comments (7) | Post RSSRSS comment feed

Updating Prayer Widget due to Previous IP to Geo Service was Unavailable

I was developed Prayer Time widget a month ago. I was used IP to geo service that not available anymore. This update using hostip.info service instead. The hostip.info service is not reliable enough for all IP world wide. Some IPs are not covered yet but more stable than previous service.

Here’s core of my code to retrieve geographic information from hostip.info.

WebClient webClient = new WebClient();
string responseString = null;
    responseString =
catch (WebException)
    responseString = string.Empty;
catch (Exception)
    responseString = string.Empty;
Regex regex = new Regex("Country\\:\\s(?<Country>[A-Za-z0-9]+)\\s\\((?<CountryId>[A-Z]{2})\\)\\nCity\\:\\s(?<City>[A-Za-z0-9]+)\\nLatitude\\:\\s(?<Latitude>\\-?[0-9\\.]+)\\nLongitude\\:\\s(?<Longitude>\\-?[A-Za-z0-9\\.]+)");
if (!string.IsNullOrEmpty(responseString))
    Match m = regex.Match(responseString);
    if (m.Success)
        city = m.Groups["City"].Value;
        country = m.Groups["Country"].Value;
        countryId = m.Groups["CountryId"].Value;
        longitude = m.Groups["Longitude"].Value;
        latitude = m.Groups["Latitude"].Value;

The complate source code can be downloaded here.

I hope this update will be more reliable that previous version.

Categories: BlogEngine
Permalink | Comments (3) | Post RSSRSS comment feed

Resolving SQL BPA Command Line Problem when Running SQL Server 2005 Upgrade Advisor

Currently, I want to upgrade our SQL Server 2000 databases to SQL Server 2005. The first step is running Microsoft SQL Server Upgrade Advisor. I was installed this tool on my computer and no error in installation. When I running this tool and try to analyze database engine, it returning error message:

"SQL BPA command line has encountered a problem and needs to close. We are sorry for the inconvenience."

I confused about this error because I was use this tool a few year ago without any problems. What is the problem, my database, my account or the tool problem? I'm forget that used SQL Server 2005 Upgrade Advisor with Service Pack 1 that different with previous version that was used. I think it the tool problem. I'm try to look at the forum that any suggestions. One of the suggestions is to registering BPAClient.dll to the GAC. It resolve the problem for me.

To resolve this problem, follow the instructions below.

  1. Open Visual Studio 2005/2008 Command Prompt
  2. Change directory to C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\BPA\bin or based on your software installation path.
  3. Type following command:
    C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\BPA\bin>gacutil /i BPAClient.dll

I hope this information is helpful.

Categories: SQL Server | Tips
Permalink | Comments (4) | Post RSSRSS comment feed

Win32/Conficker Removal Tool

Last week, Microsoft released a version of the Malicious Software Removal tool (MSRT) that can help remove variants of Win32/Conficker and other resources. 


Win32/Conficker.B exploits a vulnerability in the Windows Server service (SVCHOST.EXE) for Windows 2000, Windows XP, Windows Vista, Windows Server 2003, and Windows 2008. While Microsoft addressed this issue in October with Microsoft Security Bulletin MS08-067, and Forefront antivirus and OneCare (as well as other vendor’s anti-virus products) helped protect against infections, many systems that have not been patched manually through Server Update Services and Microsoft/Windows Update or through Automatic Updates have recently come under attack by this worm.  Attacked systems may lock out users, disable our update services and block access to security-related Web sites:

In response to this threat, Microsoft has:

It is our hope that these resources can assist you in resolving issues with unpatched, infected systems and that you can apply MS08-067 to any other unpatched systems as soon as possible to avoid this threat.

Permalink | Comments (4) | Post RSSRSS comment feed

How to Resolve WCF Issue: Can't host WCF service in a website with multiple identities

When a WCF service is hosted in a IIS website which has multiple identities, that is, responds on different hostnames/ports, the WCF service, when created, throws the exception below:

This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.
Parameter name: item

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.
Parameter name: item

I am aware that this behavior is by design and I believe that it can be resolved. I'm searching to forums, MSDN and blogs but no solution was found. I'm only found one solution to create a custom ServiceHostFactory which filters the additional base addresses and instantiates the service on one of them only. Thank to Zeddy for the helps. This issue can be resolved by creating a custom ServiceHostFactory which clear all baseAddresses then override Behaviors and ServiceEndPoint described below.

Create Custom ServiceHostFactory

Create new class for custom ServiceHostFactory below.

using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Linq;
using System.ServiceModel.Description;

public class MultipleIISBindingSupportServiceHostFactory : ServiceHostFactory
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        // return the emply list Uri to make it automatically select baseAddresses by endpoint configuration
        var host = base.CreateServiceHost(serviceType, new Uri[] {/*empty*/ });

        // Setup MEX dynamically
        var behavior = new ServiceMetadataBehavior
                               HttpGetEnabled = true,
                               HttpGetUrl = baseAddresses.Where(addr => addr.Scheme == "http").First()
        // Setup Endpoint configuration dynamically
        foreach (var uri in baseAddresses)
            // Service endpoint support http scheme only, exclude https scheme
            if (uri.Scheme == "http")
                                        new BasicHttpBinding(BasicHttpSecurityMode.None),
        return host;


Modify WCF Service Markup

To modify WCF Service Markup, right click on the MyService.svc file and then click "View Markup".

<%@ ServiceHost Language="C#" Debug="true" 
    Factory="MultipleIISBindingSupportServiceHostFactory" %>

Modify Web.config File

Open web.config file and going to line with <system.serviceModel> element, replace <system.serviceModel> and all child elements with following config.

    <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true"/>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

After all steps above was done, the multiple identities issue should be resolved.

I hope this tips will be helpful.

Categories: WCF
Permalink | Comments (9) | Post RSSRSS comment feed

Google Talk is Crashing when Changing Status to “Show current music track” using Winamp 5.5

Winamp is my favorite music player with classic theme. Winamp is very simple music player. I’m using winamp for MP3 and online radio streaming player. I wanna share my winamp track status in GTalk but it getting hang. Please follow the steps below to resolve the issue:

  1. Exit Winamp and Google Talk
  2. Open notepad, keep blank document. Note: you must run notepad in administrator mode (right click and run as administrator in Windows Vista).
  3. Save the blank file to %PROGRAMFILES%\Winamp\winamp.m3u or %PROGRAMFILES(X86)%\Winamp\winamp.m3u for x64 OS.
  4. Open Winamp and Google Talk again.

Now, you can change your GTalk status to “Show current music track” without causing hang.

Categories: Tips
Permalink | Comments (1) | Post RSSRSS comment feed

Prayer Time Widget for BlogEngine.NET 1.4.x

Prayer Time is time schedule for moslem prayer. This widget shows the daily prayer time based on user location. Thispicture below shows prayer time at January 11, 2009 in Jakarta. If you are from outside of Jakarta, the prayer time will automatically calculate base on your location.


I’m using prayer time algorithm from here and previous post here. This widget use Shafii and Muslim World League calculation except Indonesia and Malay use custom calculation.

Complete source code can be downloaded from here. The installation is very easy, follow installation steps below:

  1. Extract the zip file to widget folder of your BlogEngine.NET site
  2. Login as Administrator
  3. Goto buttom of page
  4. Select “Prayer Time” from available widgets in combo box as picture below.
  5. Click Add.
  6. You can also move the widget to another location by refreshing the browser and drag n drop “Prayer Time” widget to desired location.



I hope this widget be useful for moslem blogger.

Categories: BlogEngine
Permalink | Comments (15) | Post RSSRSS comment feed

Upgrade to BlogEngine.NET 1.4.5

Alhamdulillah, my weblog already upgraded from BlogEngine 1.2 to BlogEngine.NET 1.4.5. Upgrading process is easy but should be carefully because there are incompatible settings and themes between BlogEngine 1.2 and BlogEngine 1.4.5. To upgrade BlogEngine from version 1.3 or 1.2 to version 1.4.x, you must prepare following items before upgrading:

  1. Upgrade theme if you are using custom theme (not included in theme package).
  2. Backup your xml data or database
  3. Backup your settings
  4. Create custom widget (if needed).

I’m alredy updated my theme (Cogitation) for BlogEngine 1.4.x and create new widget (Image List) for displays image in the side bar. You can download Cogitation theme and Image List widget from following links.

After upgrading BlogEngine, theme and installing widget, you might be need to reconfigure widgets. Rearange and add widget that you want to display in side bar.

I hope my theme and widget are useful for you.

Categories: BlogEngine
Permalink | Comments (17) | Post RSSRSS comment feed