Categories
Sitecore

Docker: Fixing Sitecore docker-compose error

First thanks to Sitecore Slack Chat #docker channel in helping to find solution to issues that I faced in my very first days of learning and playing with Docker and Sitecore with Docker.

Here I’m trying to document the solution that might help others who face the same issue as me.

To begin with, first I started to learn about Docker and then about Sitecore with Docker. I had watched some videos on YouTube and Pluralsight course on Docker and read GitHub Gists from fellow Sitecore community Devs before starting with anything and then started with installing and playing with Docker shortly and followed this course as per my understanding of everything so far.

Getting Started with Docker with Sitecore

Steps:

  1. Install Docker for Windows
  2. Clone Docker for Sitecore repository
  3. Executed below commands, trying to get the vanilla Sitecore up and running in docker.
> Open powershell window in administrator mode

> CD into directory where you cloned the repository in my case it was 'C:\Projects\docker-images\'

> .\Build.ps1 -SitecoreUsername SITECORE_DEV_EMAIL -SitecorePassword SITECORE_DEV_PASSWORD -SitecoreVersion 9.3.0 -Topology xp -WindowsVersion 1803 -IncludeSpe

# I had edited Build.ps1 to allow '1803' windows version here because it matched with my windows OS version at that point

> .\Set-LicenseEnvironmentVariable.ps1 -Path C:\license\license.xml

> docker image ls

> cd .\windows\tests\9.3.x

> docker-compose -f .\docker-compose.xp.yml up

Got stuck on this Docker error

At this point, I got stuck with error message as below:

Pulling sql (sitecore-xp-sqldev:9.3.0-windowsservercore-ltsc2019)…
 ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.
 Continue with the new image? [yN]<strong>y</strong>
 Pulling sql (sitecore-xp-sqldev:9.3.0-windowsservercore-ltsc2019)…
 ERROR: pull access denied for sitecore-xp-sqldev, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

First Fix: Windows Update

As I checked in the #docker channel in the Sitecore Slack and learned that I had to update my Windows OS to at-least 1903 version so I spent next day or two waiting for system updates to complete. Please note: The time taken depends on your machine and internet speed.

If you are thinking how to check Windows OS version?

Check this out. Press Windows Key + I and then click on System tile then click on About from left navigation and it should show your system version as below –

Windows OS version.

This is noteworthy – After system update I tried Build.ps1 with new version i.e. 1903 (earlier it was 1803) as below, it started doing more than what was done in last time so that was good sign:

.\Build.ps1 -SitecoreUsername SITECORE_DEV_EMAIL -SitecorePassword SITECORE_DEV_PASSWORD -SitecoreVersion 9.3.0 -Topology xp -WindowsVersion 1903 -IncludeSpe

This time Build.ps1 took around 2-3 hours to complete and once it completed I tried docker-compose -f .\docker-compose.xp.yml up command again and still had the same error at this point.

Final Fix: Update environment file

Another quick chat in slack and I found the final fix. Update .env file under /windows/tests/9.3.x/ folder as below:

Updated Docker .env file.

I had to update WINDOWSSERVERCORE_VERSION from ltsc2019 to 1909 and NANOSERVER_VERSION from 1803 to 1909. I think these values got messed up when I was first trying to get it to work.

Quick note: Here I’m trying to setup Sitecore XP0 (XP standalone) for version 9.3.0 that is why I’m using ‘9.3.x’ folder so this folder can be different for you based what version you are targeting.

Finally, I re-ran the docker-compose -f .\docker-compose.xp.yml up command again and there it started composing without the error.

That is all to resolve the said error with docker-compose.

Finally, I was able to see my vanilla Sitecore instance from browser at http://localhost:44001/ locally. Please note that the port number here depends on the configuration as I kept the default values that came from https://github.com/Sitecore/docker-images it is port 44001 here.

Also, It is advised to use docker-compose with flag -d which will cut down the verbose logging seen in console and from what I’m hearing it’s called Detached mode.

Start following #docker channel in Sitecore Slack for more fun stuff.

Thanks to Michael West, Aaron Bickle, and Dylan Young for all the help…

Happy Sitecoring!

Categories
Sitecore

Sitecore SXA – ‘Open in Overlay’ checkbox missing?

If any of you have faced this issue that Sitecore SXA’s feature Open in Overlay is missing then this might help you.

Fix:

The root cause of the issue was that the rich text editor was not using the customized HyperlinkManager and was using the default Telerik HyperlinkManager, to fix this please do the following:
  • Open the \**Website Root**\sitecore\shell\Controls\Rich Text Editor\EditorPage.aspx file
  • Add the following attribute to the <telerik:radeditor ID="Editor" inside of the EditorPage.aspx file
    • ExternalDialogsPath="~/sitecore/shell/controls/rich text editor/Dialogs/"
  • Clear browser cache

Sitecore Support reference for this fix is # 228508

Note that I was using Sitecore SXA version 1.8.1 when I got this issue.

Categories
Sitecore

Sitecore SXA – Fix for missing items in VariantSection template

Here is a quick post about a known issue in Sitecore SXA version 1.8.1 with Sitecore 9.0

Issue is the VariantSection template in Rendering Variant is missing some items on the IsLink field that is Droplink just on VariantSection template.

Sitecore Support has provided the package that installs the missing items. If anyone needs, I have shared the link at the end of this post.

Screenshot showing the issue is as below:Sitecore SXA - VariantSection IsLink Field

After applying the fix it should look as below:Fixed VariantSection template IsLink Field

Just in case if you need Sitecore public reference number for this issue is 326111

Download Sitecore Support Package (326111-items.zip)

Categories
.NET ASP.NET MVC Umbraco

Umbraco CMS with ASP.NET MVC – Part 4 The MVC Recipe

Dear readers,

Its been very long time that I have written any blog posts and in meantime there has been significant changes in Umbraco and its documentation on ASP.NET MVC.

Few updates on this topic before I start,

  1. ASP.NET MVC is now enabled out of the box rather than WebForms in Umbraco.
  2. This blog series was first started with Umbraco version 7.1.1 but concept is same in latest version 7.2.8 also.
  3. Documentation on ASP.NET MVC support for Umbraco has improved a lot.

In this post we will see how to develop website using Umbraco CMS and ASP.NET MVC.

In the Introduction post you can read the brief on this blog series.

Before starting please note that this may take a while to understand the concept wholly but let us try & understand, also you can refer Umbraco documentation such as Implementing Custom controller.

There are two parts of this story ASP.NET MVC side and Umbraco side.

First Part of this story – ASP.NET MVC

First let us see what we have in ASP.NET MVC part of the story. So we have three basic things to know. It is possible that you know these things already so you may skip to next section –

  1. Model
  2. View
  3. Controller

Concept MVC Recipe in Umbraco CMSBrief for each of these is –

Model

Model is POCO which contains getter and setter properties and sometimes we have ViewModel for certain complex scenarios.

View

View is just outputting html. View is written in Razor sharp syntax in .cshml or ASP.NET syntax in .aspx

Controller

Controller is C# class. It is the main class which controls how the request would be served. It knows what Model and View will go together, How to validate incoming request and application data whereabouts. As you might know that there are many ways controller works; it all depends on requirements and skill-set of the developers working on the solution.

Second PART OF THIS STORY – Umbraco Page

Now second part of the story – Creating a page in Umbraco. So we have three basic things here to know,

  1. Document Type
  2. Template
  3. Content Item

Building Blocks of an Umbraco PageBrief for each of these is –

Document Type

Document Type is the definition content item. Like we define database table and columns in SQL, here we define the properties that we require in a Page. Each Document Type has Standard Values associated with it. Standard Values are to define default property values that gets initialized as a new Content is created. We can image this like constructor of a Class. For sake of simplicity Standard Values are not depicted in the diagram.

Now to we will see how Document Type looks like as we talk about this.

Document Type
Document Type ‘HelloWorld’ that has Template with same name.

Properties of Document Type
Properties tab of Document Type

Above image shows the properties of Document Type. For example purpose here Document Type ‘HelloWorld’ has one property defined as ‘Page Title’. To use this property in code we refer this using Alias i.e. ‘pageTitle’, which is also shown in the image above.

Template

Template is the Layout definition content item. Template file extension can be .aspx and .cshml depending on configuration. We can imagine ‘Template’ as two-dimensional thing, one is Logical i.e. Content Item and other is Physical i.e. html file (.chtml or .aspx). As shown in diagram each Template has association with Content Item and both exists independently.

Here is how Template looks like.

Template alongwith View in Visual Studio
Template along with View in Visual Studio

In the image above we can see how Template in Umbraco is directly related to View in Visual Studio. To make a clear understanding here, two different screens are stitched together in the image.

Content Item

To create new Page we need to create Content Item. Content Item is the central part of all three, sometimes also referred as Web Page. Content Item is based on Document Type and presentation is controlled by Template. Also I have noticed practices to define Content Items which does not have any functional presentation, it means they are nothing but just Data Repository which can be reused anywhere in the Website such as Navigation, Contact Information, Office Address, etc.

So here is how Content Item looks like.

Content Item
Content Item

Reference Book

Read Information Architecture for more regarding how to structure and re-purpose data in Content Management System.

Refer above UML diagram to understand the relationship of Document Type, Template and Content Item.

I hope everything is clear until this point. Now comes the Final part where we see how the ASP.NET MVC and Umbraco work together.

Final Part of the Story – ASP.NET MVC + Umbraco

Here we will try to relate each concept from ASP.NET MVC to Umbraco,

MVC Model== C# Model

There is no special requirement for creating Model classes. However by default Umbraco layout uses RenderModel class in Controllers but no hard dependency.

Model in Visual Studio
Model in Visual Studio

MVC Controller== Document Type Name

Document Type name suffixed with ‘Controller’ becomes Controller.

For example Document Type with name ‘HelloWorld’ becomes ‘HelloWorldController’ Controller.

By default Controller inherits from SurfaceController but if we intend to write custom logic within Controller then it should inherit from RenderMvcController

MVC Action method name== Template Name

Controller should always have default Action ‘Index’ and otherwise we can create Action with any name e.g. ‘GetProducts’ Action.

Note that if Umbraco engine is not able to map request to any defined Actions in the Controller then default action ‘Index’ of that Controller class will get executed.

Controller and Action in Visual Studio
Controller and Action in Visual Studio

Concluding

Therefore, each Content Item of Umbraco maps uniquely to one Controller and one View only. We can change which View should get executed for particular Content Item by selecting appropriate Template directly on Content Item or at the Document Type.

Here is the final output how this whole stuff looks like and This just starting of the entire story that we can build with Umbraco and ASP.NET MVC.

Hello World Page
Hello World Page

I hope this helps you and do comment for any suggestions or questions.

Categories
.NET ASP.NET MVC Setup Umbraco

Umbraco CMS with ASP.NET MVC – Part 3 Inside Visual Studio

In this post for Umbraco CMS we will learn regarding creating Visual Studio Solution. Main motive behind creating VS Solution is to work in proper structured manner and when work in team it is helpful so that Team can Commit their file changes under Source Control when developing with Umbraco CMS.

In the Introduction post you can read the brief roadmap about posts on Umbraco CMS and MVC development. Part 2 of this series describes about Umbraco installation and IIS configurations.

For this post I have used Visual Studio 2013 but 2012 version will also do. This version of Umbraco is using .NET Framework 4.5

Step 1 – Create Blank Solution for UMBRACO CMS

Start Visual Studio and use the shortcut for create new project i.e. Ctrl+Shift+N

Create a Blank Visual Studio Solution.

In Visual Studio 2013, Navigate to ‘Visual C#‘ > ‘Web’ > Select ‘ASP.NET Web Application‘ as can be seen in the screen below.

Create Empty Web Solution

Note: If you are using Visual Studio 2012 or else the step to create Blank Solution may be different. For example in Visual Studio 2012 you can navigate to ‘Visual C#’ > ‘Web’ > Select ‘ASP.NET MVC 5 Empty Project’.

Considering you have followed the Part 2 regarding Umbraco Installation and Site root folder; keep the backup of the Umbraco site root folder specifically web.config, Global.asax and ‘Views’ folder.

Then uncheck the option for “Create directory for solution”

Set the Location to the Umbraco site root folder.

Set the Solution name. Here we have created Solution with name “UmbracoMvc” and then click “OK”

Next in the “New ASP.NET Project” dialog, Select template “Empty” and tick the “MVC” check box option

Select Blank Application Type

Then click “OK”.

Step 2 – Verify the Solution Structure and Physical Files

After this you can verify the folder structure is created as below screen. Here “Umbraco” is the Solution Folder and “UmbracoMvc” is the Project Folder.

Blank Solution Directory View

After we create blank solution, Visual Studio replaces the existing Umbraco web.config and other imp. files due to this behaviour of VS; we need to restore the files and folders (shown in below screen) from the original version that we have in backup, that we took in previous step, to “UmbracoMvc” project folder.

Copy extracted source code to IIS website root directory

Now we have successfully created blank solution and recovered the files needed. So we need to verify that the Umbraco site is still working at URL ‘http://UmbracoMvc/’.

STEP 3 – Include NECESSARY files in the Solution

Open Visual Studio’s Solution Explorer and select option “Show All Files” highlighted in screen below.

Select Show All Files in Visual Studio Solution

Next include the files and folder as required but do not include the folders named “Umbraco” and “Umbraco_Client” because those part we will not work. I have shown in below screen what I have included in my solution.

Files and Folder Included as part of the Umbraco Web Application project

STEp 4 – Umbraco MVC Configurations

In Umbraco MVC, we generally not define routes. For this reason we will clean up the routes definition from “RouteConfig.cs” as shown in screen below.

Remove or Empty the Route Config

Next we will configure the Umbraco site for default rendering to MVC as shown in the screen below.

Open the “umbracoSettings.config” from “Config” folder and change the template’s default Rendering to “Mvc”.

Default Rendering Engine to MVC

Note: This will affect the creation of new Templates from Umbraco Client/Administration region. Also in new version of Umbraco default rendering is ‘Mvc’, so you can skip this part for Umbraco version 7.1.1

Conclusion

So we have completed the exercise to Create Visual Studio Solution for Umbraco Web development and we also did configurations for ASP.NET MVC 5 version. After this much you can add the source files and folders to any Source Control that works for you. Your Team will love to work in Umbraco CMS after these efforts.

In the next post we will see the how Umbraco CMS works with MVC or in other words how to cook the ASP.NET MVC recipe in Umbraco and also migration points for converting existing ASP.NET MVC sites to Umbraco MVC.

 

Keep sharing your ideas and suggestions in the comments.

Liked this post? Then spread this post to your friends.

 

Categories
.NET ASP.NET IIS MVC Setup Umbraco

Umbraco CMS with ASP.NET MVC – Part 2 Installation

In this post we will see how to start with Umbraco CMS website development with ASP.NET MVC.

In previous Introduction post here you can read the brief roadmap about posts on Umbraco MVC.

Step 1 – Download Latest Umbraco release

Download fresh installation of Umbraco CMS from Official Umbraco Site. For this post Umbraco version 7.1.1 is used and use full source code release package highlighted in bold “UmbracoCms.7.1.1.zip” in screen below.

Download Umbraco full source code release package

Step 2 – Extract the package

After downloading release package in ‘.zip’ format extract the package to temporary location.

Extract Umbraco source code to temporary location

 

Step 3 – Setup the website in IIS

After extracting the release package, the next step is to copy the extracted content to IIS web root directory by creating new folder for the Umbraco MVC website or configure the extracted folder in IIS directly in next steps.

The extracted content will look something as shown below screenshot

Copy extracted source code to IIS web root directory

Now Add a new Website in IIS. To open IIS manager you may use the cmd command ‘inetmgr.exe’.

Add a Website in IIS

Now the Add Website configuration dialog will show up. Configure the Website as below with local domain binding ‘umbracomvc’ on port ’80’

Add a Website - Configuration Dialog in IIS

Now the IIS Website is configured.

Step 4 – Create Local-only domain binding

We have configured the IIS Website with local binding definition in above steps but to correctly resolve and browse host name ‘http://umbracomvc/’ we need to configure the hosts entry in the local system with local IP address. Hosts file configuration and file path is shown in screenshot below.

Edit hosts file to point to local only domain

Note: Open the notepad or notepad++ in Administrator mode. Additionally after this configuration use the cmd command ‘ipconfig /flushdns’

Step 5 – Start Umbraco Installation

After above steps browse the website in browser at URL ‘http://umbracomvc/’ (refer ‘Host Name’ configured in IIS Website Configuration Dialog for the URL if changed in your case). When browsing for first time Umbraco will automatically initiate the Installation wizard and ask for following – Configure the licence (if any), Database connection, User credentials for Umbraco Admin, Starter Kit theme.

Few excerpts from the installation wizard are shown below:

1. Installation Welcome screen

Open browser and start umbraco installation

2. Select ‘No thanks, do not install a Starter Kit’ in Starter Kit Selection Step

Select No Starter Kit

3. Final step screen

Umbraco Installation final step

4. Verify the Umbraco Admin panel access at http://UmbracoMvc/Umbraco/ with configured user credentials in Installation wizard

Umbraco Administration

Note: Above Installation wizard screenshot were captured using Umbraco CMS version 7.0.4 but later upgraded to Umbraco CMS version 7.1.1

Conclusion

In this post we went thru steps to download & install Umbraco CMS on local system. In the next post we will see how to create Visual Studio Solution for this website.

 

I hope this post was easy to understand and screenshot images helped you to visually connect with the minimum required steps.

If you liked this kindly like or subscribe. Keep comments flowing if you have any ideas or suggestions.

Categories
.NET Introduction Umbraco

Umbraco CMS with ASP.NET MVC – Part 1 Introduction

Brief about this post

Getting Started with Umbraco MVC
Getting Started with Umbraco MVC

This post describes about agenda and upcoming articles regarding building a simple website using Umbraco CMS with ASP.NET MVC framework.

In this Series of Posts on Umbraco we will be learning about…

  1. Installation of Umbraco CMS
  2. Setup Visual Studio Solution
  3. Concept of MVC Recipe in Umbraco
  4. Information Architecture in Umbraco
  5. Presentation Architecture in Umbraco

Precap on Article Series

Installation of Umbraco CMS

Introduction & Installation of Umbraco CMS

In this post, we will see how to set up Umbraco CMS using Siteroot zip package, required configuration in IIS, and creating local-only domain name in ‘hosts’ file.

SETUP Visual Studio Solution with Umbraco CMS

Create Visual Studio Solution with Umbraco CMS

In this post, we will to see creating Visual Studio solution for Umbraco CMS. This step will help us in understanding how to version control source files of the CMS then we will be moving slowly in .NET Developer’s comfort zone which is ‘Visual Studio’.

Concept MVC Recipe in Umbraco CMS

Concept MVC Recipe in Umbraco CMS

In this post you will get the concept of how ASP.NET MVC works in Umbraco CMS. And put all Umbraco things together for better utilizing the CMS abilities in ASP.NET MVC framework. Thus this post will be more on theoretical part with some appealing pictures.

Information Architecture in Umbraco CMS

Information Architecture in Umbraco CMS

In this article we will get to know about importance of Information Architecture, also known as ‘IA’ in CMS world. We will see how to define Information Architecture based on sample HTML5 site that I have randomly picked from the Internet for simplicity.

Presentation Architecture in Umbraco CMS

Completed Website in Umbraco CMS

This article will dive into technical details of coding the website. Through this post we will complete the website building with Umbraco and MVC. And learn little something about debugging Umbraco sites in Visual Studio.

Concluding

So guys this was all about a precap on the upcoming articles on building a very simple website using Umbraco CMS with ASP.NET MVC framework.

Later on I will link all the respective articles in the series to make it easy to navigate on this topic.

Till then keep reading and if you like this post please like, comment and share.

Cheers 🙂

Categories
.NET ASP.NET Sitecore Utility

Code Generation using Sitecore Rocks and Visual Studio

Index Points

  1. Introduction
  2. Assumptions
  3. Code Generation Steps using Sitecore Rocks
  4. Image Guided Steps for Code Generation using Sitecore Rocks
  5. Conclusion
  6. Reference Links

 

Introduction

This post will guide you on how to work with code generation using Sitecore Rocks.

Assumptions

Code Generation Steps using Sitecore Rocks

For Code generation using Sitecore Rocks the steps are:

  1. Setup the Sitecore site using .exe installer or Siteroot zip – available from Sitecore SDN.
  2. Setup Sitecore site in Visual studio solution – Creating .sln file.
  3. Install Sitecore Rocks (if not already installed).
  4. Connect the Visual studio solution with Sitecore site using Hard Rock web service exposed by Sitecore.
  5. Create new StronglyTypedItems file in Sitecore visual studio solution, extension will be .scx, with appropriate name – for example “CodeGenerationFile.scx”.
  6. Right-click on created file “CodeGenerationFile.scx” and execute the command ‘Run Custom Tool’ for code generation.

Note: Check YouTube video series linked in assumption section for information on how to install and setup Sitecore Rocks and Sitecore Visual studio solution.

Image Guided Steps for Code Generation using Sitecore Rocks

The visual steps for Sitecore Rocks code generation are as below:

sitecore codegen - create strongly typed items file
Create new file for Code generation
Right click on project > Add > New Item > Visual C# > Sitecore > Code Generation > select Strongly Typed Items > click Add

sitecore codegen - run custom tool
Run custom tool command to execute and generate code files

sitecore codegen - code generated in designer file
Verify the Code generated in CodeGenerationFile.Designer.cs file (File name may differ as per added file)

Conclusion

Code generation with Sitecore Rocks is very easy to follow. After generating code using Sitecore Rocks, developers may move the classes to relatively named class files by themselves or using command ‘Move class to file’ using ReSharper tool.

Reference Links

Do comment if you like this post or have any opinions.

Categories
.NET ASP.NET C# HTML IIS Introduction JavaScript Setup SQL WCF Windows Azure Winforms WPF

Global Windows Azure Bootcamp at Ahmedabad 2013

This post is to share my experience with Global Windows Azure Boot camp event that happened in Ahmedabad.

About The Event

The event was about getting started with Windows Azure and Getting started with the Windows Azure Training Kit for any developers whether experienced or fresher and working on any programming platforms. The event was also about how real life applications can be benefited by using the power of cloud server and services.

WHAT IS WINDOWS AZURE ?

Windows Azure is Microsoft’s Cloud Platform which provides various hosting and architectural benefits along with scalability, reliability and which can scale the applications horizontal in very short time and minimum efforts. Windows Azure provides Cloud Hosting, Cloud Services, Cloud Mobile Services which enable Push notification to any platform (Really Any platform – iPhone, Android, Native application, Web applications) and many more features.

WHAT IS BOOT CAMP?

According to me, Boot camp is in other words Training Camp and in real life is much more fun. It’s an event where we, the developer, come with our tools and brains and collaborate to create and build in groups. In boot camp event people go to learn skills, usually skills involving physical or practical action rather than book subjects.

WHY IS IT GLOBAL WINDOWS AZURE EVENT?

It is because the event was happening at 90+ locations at the same time around the globe.

What was the Agenda of Event?

Start End Agenda Speaker
9:30 9:45 Registration
9:45 10:00 Welcome to GWAB!
10:00 10:45 Windows Azure – Complete Solution for Any Business Need Mahesh Devjibhai Dhola
10:45 11:00 Tea
11:00 12:00 Render Farm/Lab 1
12:00 13:00 Lab 2
13:00 14:00 Lunch/Networking
14:00 14:20 Windows Azure Real-life Application   Showcase Prabhjyot Singh Bakshi
14:20 15:00 Windows Azure for Mobiles Kaushal Bhavsar
15:00 16:00 Lab
16:00 16:15 Tea
16:15 16:45 Q&A/Giveaways
16:45 17:00 Thanks

How things went?

I think event was Awesome and I had learnt many things which I didn’t knew before. The Speakers removed the hesitation and fear of windows azure and cloud applications building that I had before the event. Event went good with the agenda and schedules although there were few examples and labs due to shortage of time, the speakers were nice and supportive to answer our questions and provided best guide they knew to clear the doubts. And they also helped in getting the Azure SDK that was +1 point to them. Initially Mahesh sir gave speech on the event agenda and introductions. Then went through the Windows Azure & its benefits, and applications that can be built with it. I must say event interactive session with him. He then introduced and made us familiar with the Windows Azure Portal to manage the sites. Then we went through the Render Lab deployment with some help. After lunch, Prabhjyot sir gave us some introduction about him and his team. He told about the cloud services and Windows 8 Application and some code examples built and already functional on the cloud. Then Kaushal Bhavsar showed us the Windows Azure Cloud Mobile Services and push notification services that Windows Azure provided using ‘Channel Url’ and that the push notification was available for use on any platform whether it is Web, native application, or mobile and on any Operating Platforms. Then some cool giveaways happened. My favorite was plural sight 1 year subscription but didn’t won it as there was only one of it but hey I got Cloud berry giveaway..

What was the cool thing about the event?

There are a couple of cool things,

  1. Alan Smith (@alansmith) who happens to be Microsoft MVP prepared something based upon his 256 worker role demo, if you want more in-depth info on the demo and the topic the check out read more from the blog post here.
  2. And we deployed the demo cloud application named renderlab on the windows azure ourselves through the labs with guidance and some efforts.
  3. Meet the Geeks – Mahesh Dhola, Jalpesh Vadgama, Kaushal Bhavsar, and Prabhjot Singh Bakshi.
  4. Meetup with other Ahmedabadi developers and learners.
  5. Lastly – Food, Giveaways (Gifts) and Windows Azure stickers.

HOW I CAME TO KNOW?

I came to know about Global Windows Azure Boot camp event going happening by Facebook post in AhmedabadDotnet Group. Go and Join the Group to get social with the Community on Facebook itself.

PS: Check the FAQ section of the event for more answers and information.

Here are few pictures from the event that I would like to share here,

Harsh Baid with Mahesh Dhola (on Right)
Harsh Baid accepting the Cloud Berry Giveaway from Mahesh Dhola (on Right)

Kaushal Bhavsar with Mahesh Dhola (on Left)
Kaushal Bhavsar accepting the Cloud Berry Giveaway from Mahesh Dhola (on Left)

Prabhjyot Singh Bakshi
Prabhjyot Singh Bakshi speaking at the event on Windows Azure Real-life Applications.

Mahesh Dhola
Mahesh Dhola speaking on Windows Azure – Complete Solution for Any Business Need.

Harsh Baid, Jalpesh Vadgama, Mahesh Dhola (left to right)
Group photo – Harsh Baid, Jalpesh Vadgama, and Mahesh Dhola (left to right)

Kaushal Bhavsar speaking on Windows Azure Cloud services
Kaushal Bhavsar speaking on Windows Azure Cloud services

The Great Handshake - Jalpesh sir and Mahesh sir (on right)
The Great Handshake – Jalpesh sir and Mahesh sir (on right) for Cloud berry giveaway

I hope you liked the post and event information. Share your experiences if you were also the part of the event Or May be some other event that you want to share with us.

 

Categories
.NET ASP.NET C# Winforms

Getting started with Multifile assembly – Part II

Some brief before we continue

Hi! In the last article on this topic here MULTIFILE ASSEMBLY part – I, I had talked conceptually about creating multi-file assembly and possible usages.

In this post we will have more insights on the implementation part regarding multi-file assembly and using MEF to apply the concept practically in the applications using Directory Catalog technique.

Table Of Contents

  • History on multiple file assembly
  • What is MEF
  • General Architecture of Extensible Application
  • Implementing Windows Forms Application using MEF

History of multiple file assembly

To implement the multiple file assembly aka plugin application approach in past was very tedious work (I believe multiple file assembly is which uses more than one assemblies). Like in .NET application programs we had to use Reflection and Dynamic assembly loading and types tactics which were not reliable i.e. In case if any exception happens in the referencing assembly while loading into main program it would result in either a minor failure of a sub program or whole program leading to crash. However today we have a very good tool at hand from Microsoft, the name is Managed Extensibility Framework i.e. MEF in short name which I would be discussing in next few paragraphs.

What is MEF?

The answer is MEF is a composition layer or class library for .NET that improves the flexibility, maintainability and testability of applications of any size. MEF is used for third-party plugin extensibility, or it can bring the benefits of a loosely-coupled plugin-like architecture to our applications. It also lets extension or plugin developers easily encapsulate code and avoid fragile hard dependencies between the applications. In the next section we would be directly going to architecture overview and implementation information.

General Architecture of Extensible Applications

Sample Architecture Overview

Here there are three major components

  • Main Assembly
  • Infrastructure Assembly
  • Plugin Repository

Main Assembly

Main Assembly is comprised of UI and Wire Line or Skeletal code to combine the building block of the application. This defines the Features and Functional limits regarding extensibility of our application. Controlling the program flow and loading plugins from the repository such as from local directory or download from global repository and so on.

Infrastructure Assembly

In Infrastructure assembly, we have interfaces and abstract classes defined which stands for two purposes:

  • Define the basic skeleton of the plugins assemblies which are to be plugged in the main application.
  • Enables the loose-coupling and balanced cohesion between the main program and plugin assemblies.

We have to design and implement the Infrastructure assembly modules step before we start implementing the plugin modules, and design decisions are based on the features and extensibility of the application. It purely depends on the Infrastructure assembly that we do not have to recompile the main application assembly, in case of any changes to accommodate any new requirement or extensibility of the plugins into the Infrastructure assembly.

Plugin Repository

In Plugin Repository, we can have many different implementations based-on the Infrastructure assembly. Each and every plugin may or may not have all the types definition that we have in the Infrastructure design. The plugin repository can be online like Nuget Gallery and Atlassian JIRA or may be offline based on the needs of the application.

Implementing Windows Application using MEF

Sample Architecture Overview from Visual StudioHere we have one visual studio solution named “DynamicAssemblyApp” and four projects in that:

  • DynamicAssembly.Infrastructure – It is Infrastructure assembly.
  • DynamicAssemblyApp – It is Main assembly.
  • DynamicAssembly.FedEx – It is an Plugin assembly for FedEx specific shipping implementations.

DynamicAssembly.USPS – It is an Plugin assembly for USPS specific shipping implementations.

So how is this application loosely coupled and how plugins work in application ?

Here the layer diagram below shows the strong-coupling between the different assemblies. On closely inspecting we can observe that the Main Assembly aka DynamicAsssemblyApp does not have connector to any of the plugins we have created. We make it possible using the MEF to load the plugin assemblies at runtime into the infrastructure instance models in the main application’s memory.

Layer Diagram

How does Sample Main Application looks ?

Main Assembly

As we click the Load Assembly button the application would lookup the plugin directory and load the different shipping methods into the main assembly and List them in the ListBox control placed on left-hand side.

Please note currently in MEF approach there is no easy way to unload the plugins once we have them loaded into memory as mentioned in one of the www.StackOverflow.com question here.

To understand the dynamism happening in the main assembly, I would like to show it in some steps as below

  1. Define the Export or ExportMany in the plugin assembly on the class definition which inherits from IShipping type (Only those classes which inherits from Interface defined in Infrastruture assembly can be marked as Export, so application would know that where the plugin instance fits).
  2. Define the location to load the dynamic parts into our application, i.e. a public variable or property of the Interface type from the Infrastructure assembly. Here is is IShipping type.
  3. Define the trigger for loading the plugins such as
    • At the start up of main application in background thread so as to not slow down the startup time (recommended).
    • On click of a button or dropdown selection (shown in the example).
    • On File Directory changes with using some File System watcher.
  4. After the trigger check the variable or property having the imports, and use in the application appropriately as per the requirements.

Please note: Import/ImportMany or Export/ExportMany can be based on three different ways

  1. String Key i.e. [Export(“MyTypeKey”)].
  2. Type Definition such as Interface i.e. [Export(typeof(IInterface))].
  3. Both from above (recommended, As this will help to uniquely identify the Import happening in the main application and we can Import the target type in different forms from one plugin assembly and in less strict manner) i.e. [Export(“MyTypeKey”, typeof(IInterface))].

Defining Export in plugin based on the type.

/// 
/// Define the FedEx method for Shipping
/// 
// Export attribute here declares that the assembly is,
// ready to provide this class to external application to use
[Export(typeof(IShipping))]
public class FedExShipping : IShipping

We import the plugin instances for FedEx and USPS Shipping Methods in Property ShippingList in the main application and declaration is decorated with ImportMany attribute which would import and instantiate all the class types inheriting from IShipping interface from the plugin assemblies into the specified property.

// Defining the imports from the plugin directory.
// Using ImportMany as we would be loading all the assemblies,
// containing the Export for the specified interface type.
[ImportMany(typeof(IShipping))]
public List<IShipping> ShippingList { get; set; }

On click of the button ‘Load Assembly’ we trigger the loading of plugins assemblies from the plugin directory in the application directory. The code for this as below

/// 
// Clean up previous Shipping Methods.
lstboxShippingMethod.Items.Clear();

// Using the directory approach for pluging/loading the assemblies dynamically.
// DirectoryCatalog constructor takes the input filepath for the plugins
// Here it is in the application directory i.e. /bin/plugin/*.dll
var catalog = new DirectoryCatalog("plugin");

// Compose container using DirectoryCatalog instance
var container = new CompositionContainer(catalog);

// Finally load the plugins
// Here we might face exceptions in loading and exception information
// is usually in the InnerException of the Exception.
container.ComposeParts(this);

// If we found no Exports from the plugins for the Shipping Methods
// then return empty handed.
if (ShippingList == null) return;

// Iterate thru each of the shipping methods and add to the ListBox Collection
// PS: We could do many other sort of things with the Imported the Shipping List.
foreach (IShipping item in ShippingList)
{
	lstboxShippingMethod.Items.Add(item.ShippingName);
}

The NameSpace for ImportMany attribute and DirectoryCatalog are as below respectively,

using System.ComponentModel.Composition
using System.ComponentModel.Composition.Hosting

So getting in action,

  1. Rebuild the solution.
  2. Rebuilding solution will copy the FedEx assembly in the main application plugin directory automatically, as it is coded in the plugin’s Post-Build commands (see in Project’s Properties) to copy it there in the plugin directory.
  3. Execute the main application.
  4. Click the ‘Load Assembly’ button.
  5. FedEx would be listed in the ListBox.
  6. Now copy manually the USPS plugin assembly (/bin directory contents) into the plugin directory.
  7. One more time click the ‘Load Assembly’ button.
  8. This time FedEx and USPS both would be listed in the ListBox.

And we are done with sample!

Download the sample application from SkyDrive here.

I hope this was pretty good to know & understandable regarding plugin applications and MEF. At the point now I think that I would publish the MEF version of the HB Code application in future.

Do comment below regarding what you think on plugin applications and using MEF.

Keep reading and keep your thoughts coming to the world out.

Some Recommended articles and questions regarding MEF and plugin applications.