Thursday, 19 September 2013

PowerShell - Usefull commands


Update help definition  from online.

You need to run this command under administrator rights.

PS C:\Windows\system32> Update-Help
(I have read, that it gets updated almost every week)


PowerShell can run with wildcards : *

PS C:\Windows\system32> help *service*


Name                              Category  Module                    Synopsis                                                                                                               
----                              --------  ------                    --------                                                                                                               
Get-Service                       Cmdlet    Microsoft.PowerShell.M... Gets the services on a local or remote computer.                                                                       
New-Service                       Cmdlet    Microsoft.PowerShell.M... Creates a new Windows service.                                                                                         
New-WebServiceProxy               Cmdlet    Microsoft.PowerShell.M... Creates a Web service proxy object that lets you use and manage the Web service in Windows PowerShell.                 
Restart-Service                   Cmdlet    Microsoft.PowerShell.M... Stops and then starts one or more services.                                                                            
Resume-Service                    Cmdlet    Microsoft.PowerShell.M... Resumes one or more suspended (paused) services.                                                                       
Set-Service                       Cmdlet    Microsoft.PowerShell.M... Starts, stops, and suspends a service, and changes its properties.                                                     
Start-Service                     Cmdlet    Microsoft.PowerShell.M... Starts one or more stopped services.                                                                                   
Stop-Service                      Cmdlet    Microsoft.PowerShell.M... Stops one or more running services.                                                                                    
Suspend-Service                   Cmdlet    Microsoft.PowerShell.M... Suspends (pauses) one or more running services.         


Get full help information about command including examples


PS C:\Windows\system32> help Get-Service -full

What version of PowerShell do I have Installed

  1. $PSVersionTable
  2. $host.version

Get gui for command

PS C:\Windows\system32> Show-Command Start-Process

Get members of commands:

This command shows all information what all I can get get.

PS D:\Scripts> get-service | get-member

PowerShell function parameters
If you are using parameters use param definition in function instead in bracets of the function name:

function WebConfig-SetAppConfigValueForKey{
    param(
         [Parameter(Mandatory=$true)]
         [xml]$doc,
         [Parameter(Mandatory=$true)]
         [string]$key,
         [Parameter(Mandatory=$true)]
         [string]$value
    )


Executing script path

If you are executing script you will be able to get path of the script which gets executed.

function Test(){
    $scriptpath = $MyInvocation.MyCommand.Path
    write-host $scriptpath
}

Test

If you execute the script without file you will get null




Tuesday, 10 September 2013

Could not open Source file: Could not find a part of the path Web.config; \umbraco\Xslt\Web.config'


I am using Team city as my build server, and web deploy in order to create my deploy package.

I have received error message:

My error message that is on Build server


[09:31:02]Step 1/1: Publish & Deploy (MSBuild) (47s)
[09:31:05][Step 1/1] Website.Web.UI\Website.Web.UI.csproj.teamcity: Build targets: Build;Package (45s)
[09:31:50][Website.Web.UI\Website.Web.UI.csproj.teamcity] AutoParameterizationWebConfigConnectionStringsCore
[09:31:50][AutoParameterizationWebConfigConnectionStringsCore] ParameterizeTransformXml
[09:31:50][ParameterizeTransformXml] D:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(2352, 5): Could not open Source file: Could not find a part of the path 'D:\41fe9571fcaca9a1\Website.Web.UI\umbraco\Xslt\Web.config;
\umbraco\Xslt\Web.config'.

[09:31:50][Website.Web.UI\Website.Web.UI.csproj.teamcity] Project Website.Web.UI\Website.Web.UI.csproj.teamcity failed.
[09:31:50][Step 1/1] Step Publish & Deploy (MSBuild) failed

I have found 2 cases which cause this error.

This happens because of web.deploy is running web.config transformation changes. By default the web.config is set to build as content.

Solution 1 - Svn issue


Issue has been that I have had 2 sources loading data.
One:Source check out from repository
Second:Artefacts used from previous steps.

Use only one source for build and error goes away.

Solution 2 - Web.config transform


Find the file in your solution(project). in my case it is:"D:\41fe9571fcaca9a1\Website.Web.UI\umbraco\Xslt\Web.config".
Go to the properties of the file (Alt + Enter)

Update your configuration.

Set your "Build Action" to  None or Content

This means that there will be no transform on this config, usual configuration is compile.




 

Saturday, 7 September 2013

AngularJS Chrome Disable same origin policy

I case you have problem loading template files in chrome: 
open your console.
Make sure you have closed chrome before running following command.

Command:
Chrome.exe --allow-file-access-from-files
Now open your chrome again and your scripts should work.



Wednesday, 4 September 2013

Rendering from variable html using jquery template

I started to use template for rendering my code from json responses.
Everything work great if you do not have html in the variables.

Supposed documentation should be here: http://api.jquery.com/category/plugins/templates

I could not find it.

Modifying example from github:

I have found example how to achieve this here.

I have not been able to make this work.
Finally I have  found out that the correct syntax is:


${Name} =>{{html Name}}
 Note that there is no longer: $.

Source for this example:


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-2.0.3.js"></script>
    <script src="Scripts/jQuery.tmpl.js"></script>
    <style>
        table { border-collapse:collapse; margin:8px; background-color:#f8f8f8; }
        table td { border:1px solid blue; padding:3px; }
    </style>
    <script type="text/javascript">
        $(document).ready(function() {

            var movies = [
                { Name: "The Red Violin<strong>test</strong>", ReleaseYear: "1998", Director: "François Girard" },
                { Name: "Eyes Wide Shut", ReleaseYear: "1999", Director: "Stanley Kubrick" },
                { Name: "The Inheritance", ReleaseYear: "1976", Director: "Mauro Bolognini" }
            ];

            var markup = "<tr><td colspan='2'>{{html Name}}</td><td>Released: ${ReleaseYear}</td><td>Director: ${Director}</td></tr>";

            /* Compile markup string as a named template */
            $.template("movieTemplate", markup);

            /* Render the named template */
            $("#showBtn").click(function () {
                $("#movieList").empty();
                $.tmpl("movieTemplate", movies).appendTo("#movieList");
            });
        });
       

    </script>
</head>
    <body>
       
        <button id="showBtn">Show movies</button><br/>
        <table><tbody id="movieList"></tbody></table>

    </body>
</html>

Friday, 16 August 2013

NUnit using data source

I am using NUnit to run unit test.
I have been using  test cases for a while but I needed to use multiple tests with date time.
I did not wanted to write a parsing string into date time.
My code generates html as you can see from code below.


My solution after while of reading documentation:








 [Test, TestCaseSource(typeof(NewsHtmlHelperTests), "DisplayRelatedUpdateLinkTestSources")]
        public void DisplayRelatedUpdateLinkTests(string sourcePath, string articlePath, string name, DateTime createdDate, MvcHtmlString expected)
        {
            var actual = NewsHelper.DisplayRelatedUpdateLink(null, sourcePath, articlePath, name, createdDate);
            Assert.AreEqual(expected.ToString(),actual.ToString());
        }

        public static IEnumerable DisplayRelatedUpdateLinkTestSources
        {
            get
            {
                yield return new TestCaseData("/test", "/test", "Test Article", new DateTime(2012, 05, 28), 
                                            new MvcHtmlString("
  • 28 May Test Article
  • ")); yield return new TestCaseData("/test", "/test/Different", "Test Article Name", new DateTime(2012, 10, 21), new MvcHtmlString("
  • 21 Oct Test Article Name
  • ")); yield return new TestCaseData("/testing", "/test", "Test Article", new DateTime(2012, 09, 18), new MvcHtmlString("
  • 18 Sep Test Article
  • ")); yield return new TestCaseData("/News/Article1", "/News/Article1", "Test Article", new DateTime(2012, 06, 05), new MvcHtmlString("
  • 5 Jun Test Article
  • ")); yield return new TestCaseData("/", "/Hello", "Test Article", new DateTime(2013, 08, 25), new MvcHtmlString("
  • 25 Aug Test Article
  • ")); yield return new TestCaseData("/Snipe", "/Snipe", "Sniper in London", new DateTime(2011, 05, 15), new MvcHtmlString("
  • 15 May Sniper in London
  • ")); } }