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

visual studio – how to format whole project files

formatting one single file is simple, find Edit.FormatDocument command in visual studio and click to apply for it. or Ctrl+K Ctrl+D.

customizing C# indent, for example, going Tools | Options | Text Editor | C# | Tabs, on UI user could customize formatting style they want.

However, it is not easy to indent whole project.

In visual studio 2010, before VS macro is removed. we could use following script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text
 
Public Module Formatting
 
 Dim allowed As List(Of String) = New List(Of String)
 Dim processed As Integer = 0
 Dim ignored As Integer = 0
 Dim errors As StringBuilder = New StringBuilder()
 Dim skippedExtensions As List(Of String) = New List(Of String)
 
 Public Sub FormatProject()
  allowed.Add(".master")
  allowed.Add(".aspx")
  allowed.Add(".ascx")
  allowed.Add(".asmx")
  allowed.Add(".cs")
  allowed.Add(".vb")
  allowed.Add(".config")
  allowed.Add(".css")
  allowed.Add(".htm")
  allowed.Add(".html")
  allowed.Add(".js")
  Try
   recurseSolution(AddressOf processItem)
  Catch ex As Exception
   Debug.Print("error in main loop: " + ex.ToString())
  End Try
  Debug.Print("processed items: " + processed.ToString())
  Debug.Print("ignored items: " + ignored.ToString())
  Debug.Print("ignored extensions: " + String.Join(" ", skippedExtensions.ToArray()))
  Debug.Print(errors.ToString())
 End Sub
 
 Private Sub processItem(ByVal Item As ProjectItem)
  If Not Item.Name.Contains(".") Then
   'Debug.Print("no file extension. ignoring.")
   ignored += 1
   Return
  End If
  Dim ext As String
  ext = Item.Name.Substring(Item.Name.LastIndexOf(".")) 'get file extension
  If allowed.Contains(ext) Then
   formatItem(Item)
   processed += 1
  Else
   'Debug.Print("ignoring file with extension: " + ext)
   If Not skippedExtensions.Contains(ext) Then
    skippedExtensions.Add(ext)
   End If
   ignored += 1
  End If
 End Sub
 
 Private Sub formatItem(ByVal Item As ProjectItem)
  Debug.Print("processing file " + Item.Name)
  Try
   Dim window As EnvDTE.Window
   window = Item.Open()
   window.Activate()
   DTE.ExecuteCommand("Edit.FormatDocument", "")
   window.Document.Save()
   window.Close()
  Catch ex As Exception
   Debug.Print("error processing file." + ex.ToString())
   errors.Append("error processing file " + Item.Name + "  " + ex.ToString())
  End Try
 End Sub
 
 Private Delegate Sub task(ByVal Item As ProjectItem)
 
 Private Sub recurseSolution(ByVal taskRoutine As task)
  For Each Proj As Project In DTE.Solution.Projects
   Debug.Print("project " + Proj.Name)
   For Each Item As ProjectItem In Proj.ProjectItems
    recurseItems(Item, 0, taskRoutine)
   Next
  Next
 End Sub
 
 Private Sub recurseItems(ByVal Item As ProjectItem, ByVal depth As Integer, ByVal taskRoutine As task)
  Dim indent As String = New String("-", depth)
  Debug.Print(indent + " " + Item.Name)
  If Not Item.ProjectItems Is Nothing Then
   For Each Child As ProjectItem In Item.ProjectItems
    taskRoutine(Child)
    recurseItems(Child, depth + 1, taskRoutine)
   Next
  End If
 End Sub
 
End Module

for visual studio 2015, I recommend plugin
https://visualstudiogallery.msdn.microsoft.com/68076712-aea1-4317-ba71-ecf987da415f/view/Reviews

Posted in Uncategorized | Comments Off on visual studio – how to format whole project files