Saturday, January 16, 2016

Issues with VS2015.1.exe

Exclusive Amazon Deals
Few days back I downloaded Update 1 of Visual Studio 2015 using VS2015 Extensions. It ran quickly but in the end it reported that .Net Framework 4.6.1 RC had not been installed. On restart and installation, it was successfully installed.
But when I tried to open and run my already created ASP.NET application, I landed up with another issue. Visual Studio 2015 was not able to launch IIS Express. This was not an end.
I noticed another strange thing. Although my installation was successful, Extension's dialog was still showing that Update 1 is available. Now I was left with only one option – uninstall and reinstall Visual Studio 2015.
So, I went to control panel and selected Visual Studio Enterprise. As soon as I clicked on that, a notification popped up:
 
 
 
 
 
 
 
I clicked on Update and noticed that check box provided for VS 2015 Update 1 was still unchecked in the newly opened window as shown below:

 
 
 
 
 
 
 
 
 
 








Once update is completed, all my things are in place.

If you don’t want to suffer like me then my recommendation is to do update directly from Control Panel, rather than doing it using VS2015.1.exe. Hope you enjoyed troubleshooting.

Sunday, December 13, 2015

What is this Business Store ?

Setting context
Those who are using Windows 8 or later are already aware about apps available in Windows store. Those apps can be can be installed on Phone, Surface , PC, HoLoLens and other devices having Windows operation system. Few of them are free and remaining ones are paid. One needs an internet connection to get these apps on devices. Now question is, is just by having an internet connection brings an app to our devices? What if you are in some enterprise network? In that case, in spite of having an internet connection, you may not be able to download an app from Windows Store. And the very well-known reason for this is organization’s FIREWALL L.

As you are protected by your enterprise firewall, you may not be able to download the required app from Windows Store. Now question is how to get the required app. To get rid of this shortcoming, Microsoft came up with a new store called Business Store for Windows 10. Those who all have attended Build 2015 may already aware of it J

How to connect to Business Store?
In Windows 10, IT administrators can access a new web-based store portal precisely for enterprises and access the Business Store. In order to connect to this Business Store, you can associate your work identity to store. Hence you don’t need MSA. You can connect that to Azure Active Directory via internet.

Benefit of this new store?
Using this store, employers cannot only customize the apps their employees see but can also privately add internal LoB apps using various distribution options. IT administrators can dispense apps to people in the organization, who will be directed to download via an emailed link. This store provide the same experience as consumer store, but it will accept business payment methods. More details on setting up the account for Business Store can be found here.

Important: As of now, all the apps purchased from Business Store will work only on Windows 10 devices.

Hope you find this brief introduction useful.

Thursday, December 10, 2015

Recent announcement on .Net Fx

In one of the recently made announcements, Microsoft decided to end support for
few of the .Net frameworks .Net 4, 4.5 and 4.5.1 on January 12, 2016. Apart
from these, rest of the frameworks will still be supported till further notice.
If your application is using any of these mentioned versions then you can run
those applications on the later .Net framework because those have compatibility
using quirking. More information of .Net framework migration can be found here.

Saturday, January 3, 2015

MVP award for consecutive 2nd time


I received a very wonderful gift from C# corner on the occasion of New Year :)
Yes, I received yet another MVP award for the consecutive 2nd time. More

Saturday, December 20, 2014

When to use void and Task as return type for Async method

As most of us are aware that there can be 3 return types of the method marked as Async.
  • Task
  • Task<T>
  • void
When any Async method has return type as void, it means not to return anything. In case of synchronous, this is fine. But situations become difficult when it comes to asynchronous operations.

While dealing with asynchronous operations, void behaves like ‘fire and forget’. It means whatever happens, but do not let caller know anything. So, it means, caller will not at all aware about the operation stage, whether it is successful or unsuccessful. As data type is void, method will not even propagate exceptions, which can be very harmful in some cases.

So, always use the word void with caution. If you don’t want your Async method to return anything, then also one should prefer to use return type as Task so that at least exceptions will be propagated to the caller.

Thursday, November 27, 2014

What and Why of CDN

What is CDN?
CDN is short for Content Delivery Network. A CDN in simple terms is a collection of servers that are spread across the globe. In other words, a CDN is a network of servers in which each request will go to the closest server.

Why Do We Need CDN?
For any web application, data can be categorized into either static or dynamic content. Dynamic content is the one which generally comes from a database. Static content is the one like CSS, images, JavaScript, flash files, video files, etc.

Now one may ask, how are requests served when a user enters an URL in the browser? Interesting… let’s take a look at it. Before knowing a CDN and its usage, it is very important to understand this process.

How is a Web Page Served?
When a client requests any URL, let’s say www.google.com in the browser, there is a server configured to listen to any request that comes in for www.google.com. A server in turn performs some computations and sends raw HTML back to the client.

Raw HTML contains lots of links like CSS, JavaScript, etc. Now for each and every link (CSS, JavaScript, etc.), the client will make more requests to other servers, which means for each and every static resource, the client will make a request to the server. Now one can easily imagine the number of requests sent for a single web page. You can view this by using any of the debugging tools.

In case of a small website, all these requests are served from a single server. So, a single client is having many connections with the same server.

For a server to be serving millions and millions of requests, it may run out of resources. Can’t we optimize something here?











If you will look at the figure shown above, the points marked in red are the intermediate nodes which serve free of cost and nodes at both ends fall in the paid category. We may have very good bandwidth at the first and last node but those intermediate nodes hardly guarantee for any performance or throughput. In essence, the further the user is from our infrastructure, the more he will notice these performance issues.

A CDN has been designed to solve all these shortcomings. There are many CDN providers available in the market today (i.e. Akamai, Interwoven). One of the CDNs that I worked with is KeyCDN.

KeyCDN
KeyCDN has points of presence (POPs) all around the world. So, whenever a request for a webpage is submitted by a client, it will go to the closest server available. In this manner, your request doesn’t need to go a long distance plus there won’t be many number of requests between the actual server and the client. KeyCDN also provides various ways to control your settings including delivery status and reporting. It also has a very intuitive dashboard and the most impressive thing is, it is affordable!

A CDN will deliver all the static content. So, actual dynamic content is kept on company’s server and the static content is redirected to CDN provider. So, there are multiple advantages of doing this.

Advantages of using CDN
  • Client request will go to the closest POP to get the static content rather than going all the way to the web server.
  • The actual web server will have more bandwidth available as the CDN takes a lot of load.
  • Failover: In case a server goes down, the CDN will automatically reroute the traffic to the next available server
  • The biggest advantage is caching. Whenever a request comes in for the first time, the content will be cached on an edge server. When the next request comes in, it will read the data directly from its cache.
Enjoy learning!!!

Saturday, November 22, 2014

Handling UI control's events in ViewModel [Prism 5.0]

Recently I came across a requirement in which I was supposed to data bind a command from my viewModel to an event. In other words, my code-behind was not supposed to contain any code related to event handlers of a control.

After digging more into Prism, luckily I found my answer. Above requirement can be achieved using InvokeCommandAction provided in Prism 5.0.

Well, so my article will elaborate more on how to achieve this.

InvokeCommandAction
InvokeCommandAction consents us to invoke ICommand implementation on our viewModel to an event that exist on our control. It basically means, we are no longer bound or required to have a command property on a control in order to invoke a command.

Now, you may say you have seen this similar thing before.
And you are right because Blend SDK ships one. But the InvokeCommandAction which Prism provides is little bit different in two ways:
  • First, it manages the state of the element. It updates the enable state of the control that is attached to based on the return value of the command CanExecute. So, here you are getting the same behavior that you do for any control, which is super cool. Isn't it?
  • Second, it allows us to pass event arguments as a parameter to the command.
Now one may ask a question, whether we have to pass entire EventArgs as an parameter or we can just pass the required stuff ?

And the answer is YES. Of course, you are not forced to pass entire EventArgs to your viewModel. One can also pass specific portion of an EventArgs which is really required. This can be achieved by setting TriggerPathParameter on the InvokeCommandAction.
Let's quickly jump on to the code.

Using Code
In order to explain the notion of InvokeCommandAction, I'll create a very simple application having a ListBox and a Label.  The Label will be updated based on the selected item in the list.
Expectation: Whenever an item is selected in the list, we have to listen to the SelectionChanged event and then handle that event in viewModel through command and then update the selected text item on Label.

Setting up a View
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
      <ListBox Height="100" Width="300" Margin="1,20,0,0" ItemsSource="{Binding ListOfItems}" SelectionMode="Single"/>
      <LabelFontWeight="Bold" Width="170" Height="30" Content="Please select"/>
</StackPanel>
I am setting datacontext for this view in code-behind. But same can be done in XAML also.

Setting up a ViewModel
Here I'll not explain each and every line of viewModel's code as I already covered the same in my other articles in detailed manner.
public class MainWindowViewModel:BindableBase
    {
        public ObservableCollection<string> ListOfItems { get; set; }
        public ICommand SelectCommand { get; set; }

        private string _selectedItem = string.Empty;
        public string SelectedItem
        {
            get { return _selectedItem; }
            set { SetProperty<string>(ref _selectedItem, value); }
        }

        public MainWindowViewModel()
        {
            ListOfItems = new ObservableCollection<string>() {"One","Two", "Three", "Four", "Five"};
            SelectCommand = new DelegateCommand<object[]>(SetSelectedItem);           
        }

        private void SetSelectedItem(object[] listOfItems)
        {
            if (listOfItems != null && listOfItems.Count()>0)
            {
                 SelectedItem=listOfItems.FirstOrDefault().ToString();
            }
        }
    }
 
If you will notice the parameter of DelegateCommand, it is an object array. That's because our viewModel is going to expect a command action in the form of object array from the list of items we want to choose from.
Next thing is to handle a SelectionChanged event of our ListBox but we don't want to handle that in our code-behind as we are dealing with MVVM structure. So, in order to achieve this behavior, we will use triggers.

Let's go ahead and add a reference of System.Windows.Interactivity and add the namespace in XAML as:

xmlns:interactivity="http://schemas.microsoft.com/expression/2010/interactivity"

Now above namespace can be used to attach the interaction triggers to the attached property as:
<ListBox Height="100" Width="300" Margin="1,20,0,0" ItemsSource="{Binding ListOfItems}" SelectionMode="Single">
<interactivity:Interaction.Triggers>
        ...
 </interactivity:Interaction.Triggers>
</ListBox>
 
Next we need to add is the EventTrigger with EventName property set as SelectionChanged. Please note, your EventName should match with the event of the control. In this case, we are interested in ListBox's SelectionChanged event.
Now whenever this event occurs, we want to invoke our command. So, this is where we are using our Prism's InvokeCommandAction as:


Let's quickly run the application and see how it reacts.

As soon as you try to select any item in ListBox, you will get a BIG exception:


It looks like, the parameter being passed to a command is the SelectionChangedEventArgs. We don't want that. We want something specific, we want our object. So, let's come back to our InvokeCommandAction and set property TriggerParamaterPath with the path of incoming EventArgs of the trigger. In our case, we want the AddedItems. Hence,
 <ListBox Height="100" Width="300" Margin="1,20,0,0" ItemsSource="{Binding ListOfItems}" SelectionMode="Single">
       <interactivity:Interaction.Triggers>
           <interactivity:EventTrigger EventName="SelectionChanged">
                  <prism:InvokeCommandAction Command="{Binding SelectCommand}" TriggerParameterPath="AddedItems"/>
           </interactivity:EventTrigger>
       </interactivity:Interaction.Triggers>
 </ListBox>

Now when you will run the application, you will get the output as expected.

Hope you enjoyed learning!!!

Friday, November 14, 2014

Skype calls in browser

Microsoft just announced that soon we will be able to make voice and video calls from our web browser. This Skype for Web (beta) calls will work on Firefox, Safari, Chrome and of course IE. As of now, it will work as a plugin but soon it will work natively on all browsers without plugins. So, are you excited to try this out ???

Friday, November 7, 2014

Microsoft to unveil its first Nokia-less Lumia on November 11

Yes, its true. Soon Microsoft is about to reveal its own Lumia having 5-inch display, 1.2 GHz processor, 1GB of RAM, 8GB of storage and 3G-only connectivity. First look of this Lumia is already out:














More info

Thursday, October 23, 2014

PopUps with Interactivity using ConfirmationRequest [Prism 5.0]

In continuation to my previous blog on PopUps with Interactivity, here we will see how to implement IConfirmation request. In order to make this post short, I'll implement IConfirmation request on top of previous example. 

Let's open our viewModel and add property for InteractionRequest of type IConfirmation  as:

public InteractionRequest<IConfirmation> ConfirmationRequest { get; set; }

Now for every getter/setter we should have a corresponding command, which will help us in invoking this request:

public ICommand ConfirmationCommand { get; set; }

Just like NotificationRequest, we need to create instances of these objects in constructor as:







If you will see above snippet closely, you will notice that in case of Confirmation, we are handling Status in slight different manner.


Next step is to update our View as we did for NotificationRequest.








Now everything is in place. Let's quickly run the application and click on PopUp button:
















Based on user's choice, whether OK or Cancel button is clicked, status message will be displayed as shown:












Hope you understood the use of ConfirmationRequest.