Capturing Payments Using Mastercard MIGS Service and ASP.NET Core


Good day everyone! Today we will explore Mastercard MIGS payment service and learn how to capture payments from your clients through the provided API using C# and ASP.NET Core.

It is worth mentioning that the payment component we are going to create can be used from any project (not just ASP.NET core projects.) Moreover, it is very easy to port our test code to MVC, WebForms or even console/desktop apps.

Continue reading

My C# Implementation of Basic Linear Algebra Concepts


Photo Credit: Wikipedia

Today, I will be sharing with you my C# implementation of the basic linear algebra concepts. This code has been posted to GitHub under a MIT license, so feel free to modify and deal with code without any restrictions or limitations (no guarantees of any kind too.) And please let me know your feedback, comments, suggestions, and corrections.

Continue reading

Matrix Multiplication in C#; Applying Transformations to Images


Today I will show you my implementation of matrix multiplication C# and how to use it to apply basic transformations to images like rotation, stretching, flipping, and modifying color density.

Please note that this is not an image processing class. Rather, this article demonstrates in C# three of the core linear algebra concepts, matrix multiplication, dot product, and transformation matrices.

Continue reading

Accessing Protrack API (an Object-Oriented Approach)


Protrack is one of the well-known web-based GPS tracking software and today we will learn how to access its API using C# and .NET Framework. We will create a little wrapper around the API and use it to track GPS devices in a target account. This lesson will show you some of object-oriented concepts in action.

Continue reading

Using Video Markers in Silverlight

هذه المقالة متوفرة أيضا باللغة العربية، اقرأها هنا.


Markers are text annotations embedded at certain points in a media file. They help you in several cases. For example, you might use markers to set captions or subtitles for a video file, or maybe you use it to identify particular points in a media file so you can play the media starting at particular points.


Marker Support

Silverlight has native support for video markers, you can subscribe to the MarkerReached event of MediaElement control to get notified whenever you reach a marker. However, in order to use video markers you need to encode them in the video file. The best application that you can use to encode markers in a video file for Silverlight is Microsoft Expression Encoder.


Marker Encoding

After you have your video file added to Expression Encoder, you can use the timeline to set the markers at the desired locations. You can add a marker by moving to the position where you want to set the marker at, then right-clicking the timeline and selecting Add Marker to add a new marker.

You then go to the Markers window where you can set marker text (value) and manage existing markers.

Notice that every marker is identified on the timeline by a symbol like diamond (♦). You can change marker position by moving this symbol, and you can remove it by right-clicking it and choosing Remove (you can also use the Markers window.)

Now encode the video and prepare it to be used in Silverlight.



After you have created your MediaElement and prepared it with the video, you can then subscribe to the MarkerReached event and handle the marker when the video reaches it. An example of handling markers is to display the marker text on the screen if, for example, it is a caption/subtitle for the video:

void theMedia_MarkerReached(object sender, TimelineMarkerRoutedEventArgs e)
    theTextBlock.Text = e.Marker.Text;

And you can also load the markers to a list box (for example) and let the user moves to the position of the markers he chooses (worth mentioning that markers are only available after MediaOpened event is raised):

void theList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    if (this.theList.SelectedIndex > -1)
        theMedia.Position = theMedia.Markers[theList.SelectedIndex].Time;

Makes sense?

What’s New in Silverlight 5? – Performance and Other Improvements

What’s New in Silverlight 5?

شاهد كورس كامل سيلفرلايت 5 مجانا هنا.

This content is based on Beta release, expect many changes in the final release.

Read What’s New in Silverlight 5 series here.




In this article, we’ll have a brief discussion of the performance, networking, and other improvements in Silverlight 5.



Performance has been improved in Silverlight 5 in a number of ways:

  • Significant improvement in performance through the entire product
  • Startup performance has been improved using a multi-core background JIT compiler
  • XAML parsing time has been improved especially for UserControl and ResourceDictionary
  • Added 64-bit runtime version. Not in beta
  • Hardware accelerated rendering in Internet Explorer 9 in windowless mode



And networking has its share of improvements:

  • Network latency has been improved significantly
  • 90% performance improvements in ClientHttpWebRequest scenarios



Added support for WS-Trust in WCF. (WS-Trust is a specification aimed to improve security and validation.)


Profiling and Testing

  • Automated UI testing
  • Improved profiling support:
    • Memory
    • CPU
    • Thread contention



  • Support for Windows Azure
  • In-Browser HTML support
  • Many more fixes and improvements throughout the product


Now, check out other What’s New in Silverlight 5? articles.

What’s New in Silverlight 5? – Elevated-Trust Changes

What’s New in Silverlight 5?

شاهد كورس كامل سيلفرلايت 5 مجانا هنا.

This content is based on Beta release, expect many changes in the final release.

Read What’s New in Silverlight 5 series here.

Download Sample Code



In this article, we’ll have a brief discussion of the new features in elevated-trust applications in Silverlight 5.



Elevated-trust applications have undergone few changes in Silverlight 5:

  • In-Browser Support
  • Multiple Windows Support
  • File System Access
  • Platform Invocation

Let’s see those changes in details.


In-Browser Support

Unlike previous versions, in Silverlight 5 you don’t have to run your application as OOB to get elevated-trust features, you can now run elevated-trust applications in the browser and get all the features you need.

There’re two security considerations to be taken in order to run your elevated-trust application in browser:

  1. You must enable running your application in browser via either the Client Access Policy file or the Windows Registry. Using the policy file allows your application to run in a private network. Using the Windows Registry approach allows your application to run on a single machine. In either approaches, you cannot deploy in-browser elevated-trust applications to everyone on the web.
  2. In addition, your XAP must be signed with a trusted certificate e.g. X.509 certificate) available in the Trusted Publisher Certificate store.

Without any of those requirements, you won’t be able to run your elevated-trust application in browser. But wait, there’s a catch!

In your development machine you can run elevated-trust applications in browser only on whitelisted domains. For example, by default, localhost is whitelisted, so you can easily run an elevated-trust application in the browser in localhost. If you change to another domain, ensure that you add this name to the whitelist, or you won’t be able to run the application. More comes about this later.

The last thing to keep in mind is that in the Beta version, in-browser elevated-trust applications are supported in Windows only. Other platforms are going to be available in the final version.

Client Access Policy Approach

If you want your application to be available in a private network, you need to do some changes to the client access policy file in order to allow it to run in browser as elevated-trust. The changes are as the following; just set the ElevatedPermissions property of SecuritySettings to Required:

    <SecuritySettings ElevatedPermissions="Required" />

Windows Registry Approach

The other approach you have is to use the Windows Registry to enable in-browser elevated-trust applications to run on a particular machine. To do this, go to HKEY_LOCAL_MACHINESOFTWAREMicrosoftSilverlight. In this registry key, you have several values related to elevated-trust applications:

  • AllowElevatedTrustAppsInBrowser:
    Set to TRUE (0x00000001) to enable running elevated-trust applications in browser.
  • AllowInstallOfElevatedTrustApps:
    Set to TRUE to enable installation of elevated-trust applications to the PC (i.e. OOB.)
  • AllowLaunchOfElevatedTrustApps:
    Set to TRUE to enable launching elevated-trust applications (in-browser or OOB.)


To run an elevated-trust application in browser you need first to enable OOB and elevated-trust features from project properties. After that, create a Web application and link it to the Silverlight application to host it. If you didn’t do this, your Silverlight application will run as OOB. Your application is able now to run as elevated-trust in browser. To ensure this, you can check for the Application.HasElevatedPermissions property:

  theTextBlock.Text = "Is Elevated-Trust: " +

Now try something more interesting. Try reading a file in the file system that only elevated-trust applications have access to:

theTextBlock.Text =

As you see, the application works as expected, and has all the elevated-trust features as OOB applications.

Now let’s try changing the domain from localhost to another domain. Go to Web application project properties, switch to the Web tab, then go to Server settings and change the server from Visual Studio Development Server to Local IIS Web Server and use your machine name as the domain and save the settings. (You might be asked to confirm virtual directory creation, it’s because you have changed to another domain and used another virtual directory.)

Now try to run the application. The application won’t be able to run and you’ll get a security exception, that’s because the new domain is not whitelisted like localhost.


Multiple Windows Support

Multiple Windows Support or Ad-hoc Windows is a feature that enables elevated-trust OOB applications in Silverlight 5 to have windows other than the main window. The feature is available through the Window class which is now instantiable. You use the Window class to create another window and set its contents through the Content property and show it using the Visibility property.

The following code creates a Window that’s 400 pixels wide and 300 pixels long, and has just a button in the interface:

    Window wnd = new Window();
    wnd.Width = 400;
    wnd.Height = 300;
    wnd.Content = new Button { Content = "Say Hello" };
    wnd.Visibility = System.Windows.Visibility.Visible;

Notice that you can end the application by closing the main window; it doesn’t matter if you close any other window.

You’re not limited to just a button or a single object in the window contents. You can create another page (i.e. user control) and set it to be the content of the window:

    Window wnd = new Window();
    wnd.Width = 400;
    wnd.Height = 300;
    wnd.Content = new MyOtherPage();
    wnd.Visibility = System.Windows.Visibility.Visible;

And you can also create windows with custom chrome by removing the toolbar and borders and create them yourself via code:

    Window wnd = new Window();
    wnd.Width = 400;
    wnd.Height = 300;
    wnd.Content = new MyOtherPageWithCustomChrome();
    wnd.WindowStyle = WindowStyle.None;
    wnd.Visibility = System.Windows.Visibility.Visible;

Notice that if you don’t have elevated-trust features, you won’t be able to spawn other windows. And if you tried to, you’ll get a security exception.


File System Access

Unlike elevated-trust applications in Silverlight 4 which have access to only My Documents folder, Silverlight 5 elevated-trust applications (in-browser and out-of-browser) have full access to the file system. But keep in mind that although you have full access to the file system, you still restricted by the rights of the user running your application. If the user doesn’t have access to a specific file or folder, then you don’t have access to that file or folder.

To test this feature, try reading contents from a file in the system folder (for instance):

theTextBlock.Text =

As you see, you have access to that file.

By default, if you’re running Windows Vista or Windows 7, your user wouldn’t have administrator privileges as long as he doesn’t launch Visual Studio (or your application) in elevated mode. So if you don’t have admin privileges and tries to gain the write access to the same file your application would fail, that’s because your application is restricted by user rights and the user don’t have write access to that file:


Same results when trying to write to the system drive without elevated permissions for the user:

    File.WriteAllText(@"C:test.txt", "Foo");


Platform Invocation

Silverlight 4 has introduced support for automation and COM components. Silverlight 5 has added support for Platform Invocation (or P/Invoke.) Platform Invocation allows you to call native code (e.g. DLLs and Windows API) from your Silverlight application. This is a great improvement of course. It uses the same mechanism as other WinForms applications. Unfortunately, this feature is currently not available in the Beta.



The following changes have been happened to elevated-trust applications in Silverlight 5:

  • In-Browser Support:
    You can now run elevated-trust applications in Silverlight 5 in browser. Must be enabled via client access policy file or Windows Registry, and XAP must be signed with a trusted certificate.
  • Multiple Windows Support:
    Allows elevated-trust OOB applications to span windows other than the main window.
  • File System Access:
    Allows you to have full access to the file system with the rights of the current user.
  • Platform Invocation:
    Allows you to call native code like DLLs and Windows API from your Silverlight application. Not available in Beta.

Now, check out other What’s New in Silverlight 5? articles.