How to set Visual Studio support C# 7 features.

  • open visual studio and click on project and choose ‘Properties’
  • in ‘Build’ tab, choose ‘Advanced…’, check screen dump
  • in language version, in dropdown list showing in screen dump, there is not ‘C#7’ and ‘C# 7.2’ for visual studio 2015
  • in visual studio 2017, same dropdown list has ‘C# 7.x’ options

Although some ways could update visual studio 2015 to support C# 7, I higly recommand to use visual studio 2017.

wp_check C# version number

wp_language_version_vs2017

Posted in Uncategorized | Comments Off on How to set Visual Studio support C# 7 features.

Typescript – tsc didn’t copy .html .css .txt to destination folder

tsc would translate .ts file to js and keep folder struction.
however, for some special file for tsc, such as .txt, .html, .css, tsc command chooses to ignore them.

we have to copy manually

for cross-platform, we are using node.js copyfiles package to do it.

but ‘copyfiles ./src/**/*.txt ./dist’ won’t work, the final result of that command is all text file would go under ‘./dist/src/path/to/file.txt’

but luckily copyfiles has options to handle and it is key reason why we uses it beside cross-platform.

in package.json add

1
2
3
4
5
  "scripts": {
    ...
    "copy-template": "copyfiles -u 1 ./src/**/*.txt ./dist"
    ...
  }

another way to is to use gulpfiles.js and gulp command line.

1
2
3
4
gulp.task('copy-template', function() {
     return gulp.src('./src/**/*.txt', {base: './src'})
            .pipe(gulp.dest('./dist'));
});

later on, add package.json to invoke this gulpfiles.js

Posted in Typescript | Comments Off on Typescript – tsc didn’t copy .html .css .txt to destination folder

Orchard 2 – Microsoft open source CMS using asp.net core

Here we assume that %Orchard% is Orchard Source code workspace folder

Orchard 2 uses autofac as DI library as well as NHibernate.

%Orchard%\src\Orchard.Web\Global.asax.cs is entry of whole website.

%Orchard%\src\Orchard.Web\Modules\Orchard.Setup\Views\Setup\Index.cshtml
%Orchard%\src\Orchard.Web\Modules\Orchard.Setup\Controllers\SetupController.cs

orchard

after filling at required field, ‘finish setup’ is clicked.
it would invoke following code

1
2
3
4
5
[HttpPost, ActionName("Index")]
public ActionResult IndexPOST(SetupViewModel model)
{
   ...
}

Orchard Init Stage Steps.
– Orchard use lots of Plugin and Module. It has complex loading and caching mechanism.
– I would write a new post for init stage source code of Orchard.

Posted in Orchard | Comments Off on Orchard 2 – Microsoft open source CMS using asp.net core

Asp.net Core publish on Ubuntu

1. Download asp.net core sdk 2 from Microsoft website
2. link ‘dotnet’ command line to ‘/usr/bin/dotnet’
3. publish project and zip all binary files including dlls, scp zip to ubuntu vps
4. export ASPNETCORE_URLS=”http://*:80″
This step is very important, because by default ‘dotnet’ command only create port for ‘localhost:5000’.
without this command, public network interface ‘eth0’ may not get listen any port.

5. run ‘dotnet Target-Project.dll’

Posted in Uncategorized | Comments Off on Asp.net Core publish on Ubuntu

.net core – create project and adding reference by command line only

dotnet new sln # new solution file
mkdir webapi
cd webapi
dotnet new webapi # new project named webapi
dotnet add package Autofac # try to add Autofac
dotnet add package Autofac.Extensions.DependencyInjection
dotnet add package MongoDB.Driver

cd ..
mkdir webapi_test ###important: dont’ name folder to be ‘xunit’, command has bugs for it
dotnet new xunit
dotnet add reference ../webapi/webapi.csproj
dotnet add package Microsoft.AspNetCore.Mvc
dotnet restore # download all references

Posted in .net core | Comments Off on .net core – create project and adding reference by command line only

Code-First EntityFramework – step by step

This is first post for code-first entity framework and how to use it.

1. add entity framework, open project, in VS Package Management
PM> Install-Package EntityFramework

2. Don’t enable migrations, if you enable migrations then, add
Enable migrations only after database is created.

3. create class inherits from DbContext

1
2
3
4
5
    public class SchoolContext : DbContext {
        public DbSet<Course> Courses { get; set; }
        public DbSet<Department> Departments { get; set; }
 
    }

add connection string in web.config with same name ‘SchoolContext’

4. enable migrations
check screen dump, it will create ‘Migrations’ folder and configuration.cs
enable-migration

5. Add-Migration
PM> Add-Migration

VS will ask you to input name and generate cs with today’s Date, check screen dump above.

Posted in entityframework | Comments Off on Code-First EntityFramework – step by step

IIS subdomain configuration

1. open ‘IIS manager’
2. right click on ‘site’ to create a new site
3.leave ip as ‘unsigned’, put all ‘host name’ to subdomain name
for example ‘tool.wudilab.com’
4. go to godaddy to add ‘core’ as subdomain

Posted in IIS | Comments Off on IIS subdomain configuration

WPF – simple wpf calculator

Here is example of WPF calculator, will add more function such as scientific calculator

https://github.com/emacslisp/wpf/tree/dev/SimpleCalculator

wpf-calc

Visual Studio 2017 enhanced the symbols token searching function which originally VS2010 has and disappear in VS2013 and VS2015.
vs2017-newfeature

Posted in WPF | Comments Off on WPF – simple wpf calculator

Azure – creating app service talking with sql server

‘app service’ and ‘sql server’ are excellent combination for creating a small website.

creating sql server on azure following step by step guide.
Even on local visual studio, it talk with sql server on azure as well.

1. open microsoft azure portal
2. select app service.
3. create app service following step by step guiding
4. one local visual studio project, click on ‘publish’
5. select microsoft azure click on publish

some excellent feature such as Api Management will be a new post to make API GATE Way talking to AZure virtual machine.

Posted in azure | Comments Off on Azure – creating app service talking with sql server

webapi – remove web api json string only

by default web api return is xml only. even return json string, but it is still embedded inside an xml file.

for example:

1
2
3
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
[{"Id":1,"Name":"Glenn Block"},{"Id":2,"Name":"Dan Roth"}]
</string>

in WebApiConfig.cs:

1
  config.Formatters.Remove(config.Formatters.XmlFormatter);

then it will be json string only.

Another sub topic is json object in C#.

add reference in visual studio that json serialization.
using System.Web.Script.Serialization;

System.Web.Script.Serialization is inside System.Web.Extensions.

Posted in Uncategorized | Comments Off on webapi – remove web api json string only