One day Play – Create a TFS 2017 Instance On Azure Virtual Machine

Prerequisite

  • Azure account
  • TFS 2017 (Trial)
  • SQL Server 2012 and above (SQL Express is fine for demo and self play)
  • Domain Name (there are many free domain register provider nowadays, see more details later)

Step 1 – Spin up VM

Sign up a free Azure account, then spin up a VM with Windows 2016 Data Centre image

Step 2 – Configure NSG (Network Security Group)

Make sure you add both HTTP and HTTPS in the Inbound security rules, so we can later access from external.

Step 3 – SQL Server and TFS Installation

Download SQL Server 2016 Express installer (5MB) from the link below, then follow the instruction and install with default settings.

https://www.microsoft.com/en-us/sql-server/sql-server-downloads

Download TFS 2017 installer (2MB) from the link below, then follow the instruction and install with default settings

https://www.visualstudio.com/en-us/news/releasenotes/tfs2017-relnotes

By default, TFS will be running on port 8080. In this example, my TFS web url is

http://tfsdemo:8080/tfs

Open you your TFS site in IE, make sure you can see the TFS homepage 

Step 4 – Register a free domain name

In this step, we’ll register a DNS, and in the next few steps we can configure the TFS to be accessible from external.

After a quick search, I found http://www.freenom.com/ that seems good enough and satisfy me need, so I registered a few free domain names from this site. Registration process is quite straightforward and only took me a few minutes to get my free domain name. 🙂

Once you logged in to the site, you can access to your domain management from Services menu.



Before set up your DNS, you will need to get the virtual machine public IP from Azure portal

In the DNS management screen, put the public IP in the target for A record.

 

Step 5 – Bind the domain name on TFS site

Open the IIS, first disable the Default Website,then locate to Team Foundation Server site, add a new binding

Port: 80

Host Name:  <The one your registered in step 4>

 

Step 6 – Update the TFS public url

You can change the TFS public url via TFS Admin console.

TIPS: If you try to test the new public url from TFS server, you will be prompted to enter username and password, but I couldn’t manage to log in successfully. I can’t figure out what caused this.  If you want to access the TFS on its server, you’ll need to continue using your the local url with port 8080.

Congratulation, you have completed everything, and your TFS server is now publicly available.

It’s a tough day, but finally I get it working 🙂 Hopefully, this might help you.

Advertisements

Sitecore UnitTest with FakeDb

When you are working on the CMS solution, the solution design and architecture can be very different, that caused writing and maintaining the uint tests be even more difficult than bespoke solution.

A typical example of this is at some point your code calls the Sitecore API, how do you ensure your code is working when the code has related to external dependencies that you can’t remove?

Thanks for Sitecore FakeDb, it makes that happen and a lot simpler to write the unit tests on this CMS plateform. In the following sections, I will assume you are a Sitecore developer with passion of writing the unit tests.

Dependencies

In order to use FakeDb for the unit tests, you need the following dlls within your Tests project

  1. Sitecore.FakeDb – You can install this via the nuget package
  2. Lucene.Net
  3. Sitecore.Analytics
  4. Sitecore.Kernel
  5. Sitecore.Logging
  6. Sitecore.Nexus

NOTES: All above Sitecore related packages can be either reference from dll or via Sitecore nuget server.

Lastly, you also need to copy your Sitecore license.xml file into the root of your Test project.

NOTE: When you install the Sitecore.FakeDb package, it will automatically update the app.config file by including the license file location (see screenshot below)

Sample Test (MSTest)

NCrunch Configuration

In order to run unit tests with NCrunch, in the NCrunch Configuration window, select the tests project and configure the following settings:

References

NCrunch

https://github.com/sergeyshushlyapin/Sitecore.FakeDb/wiki/Configuration

AutoFixture with Sitecore.FakeDb

https://github.com/sergeyshushlyapin/Sitecore.FakeDb/wiki/AutoFixture-Samples

7 Zip exclude multiple files and directories

Adds to the archive.7z all files from Folder1 and its subfolders, except *.png files.

7z a archive.7z Folder1\ -xr!*.png

To exclude the list of directories and files, you can first store the items in a text file separated by new line for each, then run the following command

7z.exe a -t7z archive.7z C:\Project\Solution1 -xr@exclusionList.txt

a – Add to archive

-t7z – type of archive, in this example, it uses 7z

-xr@ – specify the exclusion list.

Happy Coding!

Sitecore – Add missing icons for specific media types

Recently, I was trying to save the PDF file in the media library and found this issue. The PDF file used empty icon instead.

Luckily, this seems a common issue and solution can be easily googling out.

Sitecore has official document in its knowledge base about this issue.

Missing icons for specific media types

What I want to point out is if you search this issue from google, you will be very likely found some other blog posts provide the similar approach, the only difference comparing to Sitecore official document is the type specified in the generator.

<generator type="Sitecore.Resources.Media.MediaThumbnailGenerator, Sitecore.Kernel">

The type seems redundant or causing icon failed to be displayed in my current Sitecore v8.0 update 3.

Below is my patch config instead of modifying the web.config

<mediaLibrary>
<mediaTypes>
<mediaType name="PDF file" extensions="pdf" patch:before="*[@name='AVI video']" >
<mimeType>application/pdf</mimeType>
<forceDownload>false</forceDownload>
<sharedTemplate>system/media/unversioned/pdf</sharedTemplate>
<versionedTemplate>system/media/versioned/pdf</versionedTemplate>
<thumbnails>
<staticFile>/sitecore/shell/Themes/standard/images/pdf_icon.png</staticFile>
</thumbnails>
</mediaType>
</mediaTypes>
</mediaLibrary>

Happy coding 🙂

 

 

Sitecore – Reader is in incorrect state

My demo app came up with this issue after making some changes to patch config file today.

Reader is in incorrect state
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.Exception: Reader is in incorrect state

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[Exception: Reader is in incorrect state]
Sitecore.Xml.Patch.XmlReaderSource..ctor(XmlReader reader, String sourceName) +123
Sitecore.Configuration.ConfigPatcher.GetXmlElement(XmlReader reader, String sourceName) +45
Sitecore.Configuration.ConfigPatcher.ApplyPatch(TextReader patch, String sourceName) +138
Sitecore.Configuration.ConfigPatcher.ApplyPatch(String filename) +93
Sitecore.Configuration.ConfigReader.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder) +177

This is a weird issue at the first glance, I still have no idea what happened under the hood, though I solved the problem.

I added a comment in my patch config which is in between and section, this is the fundamental cause.

To fix this YSOD, simply move the comment anywhere within section.

Happy coding 🙂

Jenkins 2.0 Set Up on OSX

Prerequisite

  • JAVA JDK 7 or above
  • GIT
  • MAVEN 3 or above

Install Jenkins

  • Install jenkins via homebrew
  • brew update &amp;&amp; brew install jenkins

Starting Jenkins

After Jenkins is installed successfully, follow the instructions to start Jenkins on login

ln -sfv /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents

If you want to configure Jenkins to launch on system startup, for all users on OS X, then copy the plist file to the system Launchd location instead

$ sudo cp -fv /usr/local/opt/jenkins/*.plist /Library/LaunchDaemons

$ sudo chown `whoami` /Library/LaunchDaemons/homebrew.mxcl.jenkins.plist

You can always start Jenkins manually with

$ /usr/local/bin/jenkins

or if you have set up your PATH correctly when installing Homebrew, simply

$ jenkins

Starting Jenkins as service

Start service

brew services start jenkins

Stop service

brew services stop jenkins

Restart service

brew services restart jenkins

Restarting Jenkins

If you have an older version of Jenkins and you are upgrading it, then you can restart it this way:

$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist

Install Jenkins Plugins

  • Git
  • Maven
  • Parameterized Trigger Plugin (This plugin will simplify the maven profile configuration)
  • JUnit
  • PMD / FindBugs / Checkstyle (For quality analysis)
  • Greenball

Configure Jenkins

Go to Manage Jenkins -&gt; Global Tool Configuration, configure the following sections

JDK

  • Deselect Intall automatically as we will use the installed JDK
  • Fill the JDK Name E.g. JDK 1.7
  • Specify the JAVA_HOME path. E.g. /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

Maven

  • Deselect Intall automatically as we will use the installed Maven
  • Fill the Maven Name E.g. Maven 3
  • Specify the MAVEN_HOME path. E.g. /usr/local/opt/maven31/libexec

Git

Git intallation should be picked up by default, unless you install GIT after Jekins.

Set Up Job

  1. Create new maven project by giving a new.
  2. Go to Source Code Management sections, add repositories link.
  3. If you want to use SSH, click Add button in Credentials section. In the dialog, choose SSH Username with private key option, then select From the jenkins master ./ssh, Note: Dont put any value into Username
  4. Click Build Now to test the job.

Reference

Homebrew

http://brew.sh/

Installing Jenkins OS X Homebrew

http://flummox-engineering.blogspot.com/2016/01/installing-jenkins-os-x-homebrew.html

Maven doesn’t have a ‘lib’ subdirectory in Jenkins

http://flummox-engineering.blogspot.com/2016/01/maven-doesnt-have-a-lib-subdirectory-jenkins.html

Solution:

The ‘lib’ folder should be linking to libexec subdirectory.

If you install your maven via homebrew, your maven home should /usr/local/opt/maven31/libexec. (Note: maven31 is the version I installed on my mac, change this according to your local setting.)

Jenkins CI on OSX

Link

Uninstall Jenkins

Execute uninstall script from terminal:

'/Library/Application Support/Jenkins/Uninstall.command'

Set up EPiServer CMS + Commerce in 11 steps

Believe or not, it’s super easy to set up an empty CMS site with Commerce package in version 9. Thanks for the EPi team awesome work.

Prerequisites

  • Visual Studio 2013/2015
  • Windows 8 above (At least, you will need to have localdb installed.)
  • EPiServer CMS VSIX. (You can install within Visual Studio Extension Manager or download from here)

Let’s start

CMS

  1. Use EPiServer VSIX template to set up an empty CMS project.
    12
  2. Install package “EPiServer.Commerce.UI.ManagerIntegration”  via nuget package console.
  3. UPDATE ALL EPiServer packages.
  4. Install package “EPiServer.Commerce”
  5. Run cmdlet “update-epidatabase”  via nuget package console.
  6. Change local database location – Move database to db folders.
    In this demo, I placed the db out side of the CMS directory, and put it in the solution root directory.

    static EPiServerApplication()
    {
    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + @"\..\db\");
    AppDomain.CurrentDomain.SetData("DataDirectory", dir.FullName);
    }
  7. Login to CMS administrative interface with default username : admin and password : store, then “execute all remaining steps” to run the migration

Commerce

  1. Create an empty Mvc application with Visual Studio (Framework > 4.5.2)
  2. Install the nuget package “Episerver.CommerceManager”.
  3. Run cmdlet update-epidatabase
  4. Show all files and include App_Data,App_GlobalResources,Apps, NotificationTemplates folders and Default,Global.asax files.
  5. Make sure “CommerceManagerLink” in CMS is pointing to commerce manager url.
    <add key="CommerceManagerLink" value="http://localhost:{port}/" />

It’s the end, and that’s all you need to do for the setup. Enjoy your EPi development.