Tuesday, February 7, 2017

Install node-gyp


If you're using Windows you can now install all node-gyp dependencies with single command:
 $ npm install --global --production windows-build-tools
and then install the package
 $ npm install --global node-gyp

Tuesday, November 8, 2016

Octopus update database by entityframework

Entity framework includes a tool called migrate.exe for use in deployment target to update database.
We can use that one in Octopus deployment. Here is the steps to get it working,

1. create a nuspec file in the project, make it the same name as the project name.
    make sure the id is the same package id as the Octopus package id
Add the below section in the file,
<files>
    <file src="..\packages\EntityFramework.6.1.3\tools\migrate.exe" target="tools"/>
    <file src="..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll" target="tools"/>
    <file src="..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.sqlserver.dll" target="tools"/>
    <file src="*.ps1" />
  </files>

2. Include the parameter OctoPackEnforceAddingFiles for uploading package
msbuild /t:build /p:RunOctoPack=true  /p:OctoPackEnforceAddingFiles=true .....

3. Create a new deployment step script

$installPath = $OctopusParameters['Octopus.Action[Deploy Package].Output.Package.InstallationDirectoryPath']
Write-Host "Installation Path:" $installPath

set-location "$($installPath)\tools"
Write-Host "Working Dir: "$(get-location)

.\migrate.exe <datamodel.dll> /StartUpDirectory="$($installPath)\bin" /StartUpConfigurationFile="$($installPath)\web.config"

Tuesday, November 1, 2016

Octopus msbuild cmd to publish the nuget package

Just record it here in case I will need it later,

msbuild /t:build /p:RunOctoPack=true /p:OctoPackPackageVersion=1.0.0-beta /p:OctoPackPublishPackageToHttp=http://<server>:3001/nuget/packages /p:OctoPackPublishApiKey=<apikey>

Also if the nuget is behind proxy, need to set it up with the command
  • nuget.exe config -set http_proxy=http://my.proxy.address:port
    nuget.exe config -set http_proxy.user=<domain>\<username>
    nuget.exe config -set http_proxy.password=<password>

Sunday, August 21, 2016

How to install rabbitMQ on windows

I tried to follow the rabbitMQ official guide to download and install (include Erlang) but it is still not working.

This blog finally saved my day.
http://arcware.net/installing-rabbitmq-on-windows/

Here is the summary to be done,

Firewall inbound rules setup,
Allow ports for 5672,15672
Allow program for

  • %ProgramFiles%\erl8.0\bin\erl.exe
  • %ProgramFiles%\erl8.0\erts-8.0\bin\erl.exe
  • %ProgramFiles%\erl8.0\erts-8.0\bin\epmd.exe

Set up correct home drive and reinstall the service (running cmd as administrator)
SET HOMEDRIVE=C:
rabbitmq-plugins enable rabbitmq_management
rabbitmq-service stop
rabbitmq-service install
rabbitmq-service start


Monday, May 23, 2016

Detailed guides to set up docker on windows behind a firewall

Recently just set up a docker to work under windows behind a corporate firewall

Prerequisite:
 - Enable VT-X in BIOS
 - Setup Server environment variable in the host PC
   HTTP_PROXY=http://<proxy>:<port>
   HTTPS_PROXY=http://<proxy>:<port>
   NO_PROXY=192.168.99.100

1. Download docker toolbox for windows and install it

2. Start Docker quick terminal
I removed the default image and recreate one.
docker-machine stop default
docker-machine rm default

3. Create a image named dev
docker-machine create --driver virtualbox dev

4. Set up the start environment variable
docker-machine env dev
eval $("C:\program files\docker toolbox\docker-machine.exe" env dev)
docker ps

5.Remote SSH to the image and set up proxy in it
docker-machine ssh dev
sudo -s
echo "export HTTP_PROXY=http://<proxy>:<port>" >> /var/lib/boot2docker/profile
echo "export HTTPS_PROXY=http://<proxy>:<port>" >> /var/lib/boot2docker/profile

cat /var/lib/boot2docker/profile
exit

6. Restart the image
docker-machine restart dev

7. Run hello-world to test
docker run hello-world

-----
There are also a few useful command to use
docker ps -a
docker run -p 3000:3000 -v $(pwd):/var/www -w /var/www node npm start

-----------
Updated, just found a blog talking about this as well.
http://www.netinstructions.com/how-to-install-docker-on-windows-behind-a-proxy/




Friday, April 1, 2016

Tangling with Git proxy settings in windows

To set up git proxy globally, you need to run this command

git config --global http.proxy "http://<your proxy>:<port>"

However, it returned me error,

error: could not lock config file H:\/.gitconfig: No such file or
directory error: could not lock config file
 
To fix it, need to set up the %HOME% environment variable to your user profile path

1. echo %userprofile%

2. create a new environment variable as HOME = the user profile directory

And then you can run the config http.proxy command.

Friday, February 12, 2016

Setting up Github with Visual Studio Code

Visual studio code support work with GitHub, you can reference the below link for the detailed steps,
http://michaelcrump.net/using-github-with-visualstudio-code/

The main command is the below to run in a command shell,
git remote add origin https://github.com/xinzhang/SampleProject.git
git push -u origin master
Then the config file in the .git folder will become as below,
[remote "origin"]
url = https://github.com/mbcrump/SampleProject.git
fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
remote = origin
merge = refs/heads/master
After this is done, you commit the changes but there is still the below commands to run to be able to run PUSH from Visual Studio Code,

git config --global credential.helper wincred
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL ADDRESS"


Thursday, May 21, 2015

Get Ionic framework working behind proxy

I have the error to create a new ionic project when running the command in windows 7
ionic start myproject

The solution is to set up the MAGIC environment variable in the computer settings, then it works.
http_proxy=http://username:password@hostname:port;

Wednesday, May 6, 2015

Error to download bower package in Visual studio 2015 RC when you are in corporate proxy

1. add a .bowerrc file in project,
{
"proxy": "http://192.168.11.22:8080",
"https-proxy":"http://192.168.11.22:8080"
}

2. Install Git seperately

3. go to command prompt and run the following cmd
git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
git config --global https.proxy https://proxyuser:proxypwd@proxy.server.com:8080

Tuesday, May 5, 2015

Error to download npm package in Visual studio 2015 when you are in corporate proxy

This is the command to run to set up the proxy,

npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

But where to run this command, the npm.cmd is in,
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External

Open a command prompt as administrator and run the npm config ...
Then it worked.

Custom asp.net identity 2.1 tables and primary keys

This is the codes that I use to set up the identity tables to use int as primary key.

public class User : IdentityUser<int, UserLogin, UserRole, UserClaim>



{
 
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, int> manager)



{
 
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType

var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

// Add custom user claims here

return userIdentity;



}
 
public string FirstName { get; set; }

public string LastName { get; set; }

public byte Level { get; set; }

public DateTime JoinDate { get; set; }




}
 
public class UserRole : IdentityUserRole<int> { }

public class UserLogin : IdentityUserLogin<int> { }

public class UserClaim : IdentityUserClaim<int> { }

public class Role : IdentityRole<int, UserRole>



{
 
public Role() { }

public Role(string name) { Name = name; }



}
 
public class MyUserStore : UserStore<User, Role, int, UserLogin, UserRole, UserClaim>



{
 
public MyUserStore(MyPortalContext context)

: base(context) { }



}
 
public class MyRoleStore : RoleStore<Role, int, UserRole>



{
 
public MyRoleStore(MyPortalContext context)

: base(context) { }



}

/////////////////////////////////////////////////////////

And they are customized to use different table names in MyPortalContext

protected override void OnModelCreating(DbModelBuilder modelBuilder)



{
 
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<User>().ToTable("Users");

modelBuilder.Entity<Role>().ToTable("Roles");

modelBuilder.Entity<UserLogin>().ToTable("UserLogins");

modelBuilder.Entity<UserClaim>().ToTable("UserClaims");

modelBuilder.Entity<UserRole>().ToTable("UserRoles");
}

Saturday, March 7, 2015

Angular ng-repeat scope

Need to know that angular ng-repeat directive actually create child scope for each element.
so if you want reference the parent $scope value need to use $parent

<span ng-show="item.name == currentDbName"><input type="text" name="newDbValue" ng-model="$parent.newDbValue" />{{$parent.newDbValue}}</span>

Or else if you want to update the repeating item value, you need to use $index

<div ng-repeat="name in dbnames track by $index">
        <input type="text" ng-model="dbnames[$index]" />
</div>

the "track by $index" is new since Angular1.2 to make sure the text box won't lose focus for each key stroke

Tuesday, February 3, 2015

Angular test primer in Jasmine

To test angular controller in Jasmine, need to use the angular mocks to inject module and controller
Then in the controllerSpec test js file, we can inject the controller and scope

describe('expense controller', function () {

var $controllerTestConstructor;
var scope;

beforeEach(module('app'));

beforeEach(inject(function($controller, $rootScope){



$controllerTestConstructor = $controller;

scope = $rootScope;

}));
 
it('should have three expense item', function () {
var ctrl = $controllerTestConstructor('expenseController', { $scope: scope });

expect(ctrl.expenseItems.length).toBe(3);

});

});
 

Angular module dependency injection

Angular provides the module functions to do the service injection. In this way, we can build our own service functions and inject into the controller to load it.

We can set up the module first, then call the app.js to set up the both module together, this is the example shows in the angular tutorial site.
https://docs.angularjs.org/tutorial/step_11

Here is the example for this way, there is a controller and it depends on the dataService to load the data. Each angular.module call is in its own js file.

angular.module('app', ['services', 'controllers']);

angular.module('services', [])
        .factory('expenseDataService', ['$http', expenseDataService]);

angular.module('controllers', [])
        .controller('expenseController', ['expenseDataService', expenseController]);

Also there is a simplified version. But you need to put app.js at first in the html page. In this way, all the dependency are created in the app module directly.
angular.module('app', []);

angular.module('app')
        .factory('expenseDataService', ['$http', expenseDataService]);

angular.module('app')
        .controller('expenseController', ['expenseDataService', expenseController]);

The full file is attached as a zip file.expense_app.zip

Sunday, February 1, 2015

How to install / use bower in Visual studio 2013 with proxy settings

Bower is very popular to manage client script package, here is the steps to set it up to use it in visual studio 2013.

1. Open package management console and search bower (not bower.js), install it.
    After it is installed, you should be able to open a command prompt and go to your visual studio project folder, then run "bower install <package>" from there.

2. By default, Bower installed the package into a folder called bower_components under the project folder. Usually we want to manage the packages better and put them under scripts/lib folder.

To do this, create a file named the .bowerrc and add the line,
{

"Directory":"Scripts/lib",
 
}

This will install all the packages into the scripts/lib folder. By default, windows doesn't allow you create a file starts with period (.), then you can create any temp text file and rename it in the command window.

3. If the visual studio runs internally behind a firewall, you need to set up the proxy for both Bower and Node.
   
    In the .bowerrc file, add the line,
"https-proxy": "http://<domain>%5C<user>:<passsword>@<proxy_server>:<proxy_port>/"
    Edit the node.cmd under .bin folder to add the lines,
SET HTTP_PROXY=http://1:1@192.168.11.22:8080
SET HTTPS_PROXY=http://1:1@192.168.11.22:8080

Thursday, January 22, 2015

In MVC5, How to merge the IdentityDbContext into custom db context

Here is the code as an example,

1. Add the custom user login and user role configurations

    public class IdentityUserLoginConfiguration : EntityTypeConfiguration<IdentityUserLogin>
    {
        public IdentityUserLoginConfiguration()
        {
            HasKey(iul => iul.UserId);
        }
    }
    public class IdentityUserRoleConfiguration : EntityTypeConfiguration<IdentityUserRole>
    {
        public IdentityUserRoleConfiguration()
        {
            HasKey(iur => iur.RoleId);
        }
    }

2. Inherit your custom dbcontext from IdentityDbContext,

    public class CustomDbContext : IdentityDbContext<ApplicationUser>
    { public CustomDbContext() : base("DefaultConnection")
        {
        }
        public DbSet<CustomEntity> Entities { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Configurations.Add(new IdentityUserLoginConfiguration());
            modelBuilder.Configurations.Add(new IdentityUserRoleConfiguration());
        }
    }

Wednesday, September 10, 2014

SharePoint TroubleShooting - Can not access local farm when running script in sharepoint powershell

When you run Get-SPSite or Get-SPWeb in a SharePoint powershell window and get the following error,

Can not access local farm...

It is usually the permission issue. The user execute the power shell cmd is not in the SharePoint_Shell_Access role, just run this command, Add-SPShellAdmin -UserName ... to add the user will be fine,

Here is the reference links,
http://technet.microsoft.com/en-us/library/ee806878(v=office.14).aspx#section2
http://technet.microsoft.com/en-us/library/ff607596(v=office.14).aspx

Monday, August 25, 2014

SharePoint trouble shooting - update list data without event receiver triggered in powershell

Sometimes we need to run powershell to do batch update some list items, if the event receiver is active, the update process can be very slow. In this case, we will want to turn it off before batch update, then turn it back on.

Here is the powershell script to complete this,

# disable event firing
$my = [Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
$type = $my.GetType("Microsoft.SharePoint.SPEventManager");
$prop = $type.GetProperty([string]"EventFiringDisabled",[System.Reflection.BindingFlags] ([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Static));
$prop.SetValue($null, $true, $null);
**** run times update ****

# enable event firing
$prop.SetValue($null, $false, $null);


Wednesday, August 20, 2014

SharePoint trouble shooting - error to load excel in webpart page

The ULS log shows the error as below,

Unable to create or access workbook cache at C:\Windows\TEMP\Excel Server\FileCache\46deae92-790c-4b89-86e3-3719a2edcf01\Ranges. Excel Services Application is unable to function without a workbook cache.

CachedFile.SaveFile: Threw exception: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Windows\TEMP\Excel Server\FileCache\46deae92-790c-4b89-86e3-3719a2edcf01\Ranges\5dfc1857-7543-4418-9cf1-37102e27d6fb.xlsrvrng'.
1. Run Power shell command $app = Get-SPExcelServiceApplication , $app.ApplicationPool to check if the service account has the permission to the folder
 
C:\Windows\TEMP\Excel Server

2. Just delete the excel service application folders in the cache and refresh, then it worked.

SharePoint trouble shooting - Remove orphan feature

In the ULS log, the following error message keep happening because the feature has been removed from the solution before the feature undeployed.

Feature definition missing for Feature <<feature display name>>' (Id: '2cf0c09e-157e-4d3b-aa61-fee768b489c9'; CompatibilityLevel: '15')

The following powershell script can be used to identity the orphan features,

$url = "<site url>"
$site= new-Object Microsoft.SharePoint.SPSite($url)
$site.WebApplication.Farm.FeatureDefinitions `
| where-object {$_.solutionid -ne '00000000-0000-0000-0000-000000000000'} `
| Sort-Object solutionid,displayname `
| ft -property solutionid,id, displayname,scope -auto > features.txt
$features = $site.WebApplication.Farm.FeatureDefinitions | where-object {$_.Scope -eq $null} | Sort-Object solutionid,displayname
$features | foreach {
 $id = $_.Id
}
$site.Dispose()

In codeplex, there is a good tool to remove the feature,
http://featureadmin.codeplex.com/

Just download it and use it the remove the orphan feature.