├── FirebaseAndAngularAndDotnetCore
├── keys
│ ├── .gitkeep
│ └── firebase_admin_sdk.json
├── wwwroot
│ └── .gitkeep
├── client-app
│ ├── README.md
│ ├── src
│ │ ├── assets
│ │ │ └── .gitkeep
│ │ ├── app
│ │ │ ├── app.component.scss
│ │ │ ├── home
│ │ │ │ ├── home.component.scss
│ │ │ │ ├── home.component.html
│ │ │ │ ├── home.component.spec.ts
│ │ │ │ └── home.component.ts
│ │ │ ├── login
│ │ │ │ ├── login.component.scss
│ │ │ │ ├── login.component.html
│ │ │ │ ├── login.component.spec.ts
│ │ │ │ └── login.component.ts
│ │ │ ├── secret
│ │ │ │ ├── secret.component.scss
│ │ │ │ ├── secret.component.html
│ │ │ │ ├── secret.component.ts
│ │ │ │ └── secret.component.spec.ts
│ │ │ ├── models
│ │ │ │ ├── current-user.ts
│ │ │ │ └── current-user.spec.ts
│ │ │ ├── security
│ │ │ │ ├── auth-interceptor.spec.ts
│ │ │ │ ├── auth-guard.guard.spec.ts
│ │ │ │ ├── auth-guard.guard.ts
│ │ │ │ └── auth-interceptor.ts
│ │ │ ├── app.component.html
│ │ │ ├── services
│ │ │ │ ├── auth-service.service.spec.ts
│ │ │ │ └── auth-service.service.ts
│ │ │ ├── app-routing.module.ts
│ │ │ ├── app.component.ts
│ │ │ ├── app.component.spec.ts
│ │ │ └── app.module.ts
│ │ ├── environments
│ │ │ ├── environment.prod.ts
│ │ │ └── environment.ts
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── styles.scss
│ │ ├── main.ts
│ │ ├── test.ts
│ │ └── polyfills.ts
│ ├── e2e
│ │ ├── tsconfig.json
│ │ ├── src
│ │ │ ├── app.po.ts
│ │ │ └── app.e2e-spec.ts
│ │ └── protractor.conf.js
│ ├── .editorconfig
│ ├── tsconfig.app.json
│ ├── tsconfig.spec.json
│ ├── browserslist
│ ├── tsconfig.json
│ ├── .gitignore
│ ├── karma.conf.js
│ ├── package.json
│ ├── tslint.json
│ └── angular.json
├── appsettings.Development.json
├── appsettings.json
├── Models
│ └── tokenVerifyRequest.cs
├── FirebaseAndAngular.Web.csproj
├── Program.cs
├── Properties
│ └── launchSettings.json
├── Controllers
│ └── UsersController.cs
├── FirebaseAndAngular.sln
└── Startup.cs
├── WebSocketAndNetCore
├── client-app
│ ├── README.md
│ ├── src
│ │ ├── assets
│ │ │ └── .gitkeep
│ │ ├── app
│ │ │ ├── app.component.scss
│ │ │ ├── models
│ │ │ │ ├── square.ts
│ │ │ │ ├── socket-message.ts
│ │ │ │ ├── square-change-request.ts
│ │ │ │ ├── square.spec.ts
│ │ │ │ ├── socket-message.spec.ts
│ │ │ │ └── square-change-request.spec.ts
│ │ │ ├── app-routing.module.ts
│ │ │ ├── web-socket.service.spec.ts
│ │ │ ├── app.module.ts
│ │ │ ├── app.component.spec.ts
│ │ │ ├── app.component.html
│ │ │ ├── app.component.ts
│ │ │ └── web-socket.service.ts
│ │ ├── environments
│ │ │ ├── environment.prod.ts
│ │ │ └── environment.ts
│ │ ├── styles.scss
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── main.ts
│ │ ├── test.ts
│ │ └── polyfills.ts
│ ├── e2e
│ │ ├── tsconfig.json
│ │ ├── src
│ │ │ ├── app.po.ts
│ │ │ └── app.e2e-spec.ts
│ │ └── protractor.conf.js
│ ├── .editorconfig
│ ├── tsconfig.app.json
│ ├── tsconfig.spec.json
│ ├── browserslist
│ ├── tsconfig.json
│ ├── .gitignore
│ ├── karma.conf.js
│ ├── package.json
│ ├── tslint.json
│ └── angular.json
├── appsettings.Development.json
├── appsettings.json
├── WebSocketAndNetCore.Web.csproj
├── SocketMessage.cs
├── Program.cs
├── Properties
│ └── launchSettings.json
├── Square.cs
├── WebSocketsAndNetCore.sln
├── Startup.cs
└── SquareService.cs
├── README.md
├── HealthCheckPeek
├── appsettings.Development.json
├── appsettings.json
├── WeatherForecast.cs
├── MyDatabaseContext.cs
├── HealthCheckPeek.csproj
├── Program.cs
├── Properties
│ └── launchSettings.json
├── HealthCheckPeek.sln
├── Controllers
│ └── WeatherForecastController.cs
├── HealthChecks
│ └── HealthCheckHelpers.cs
└── Startup.cs
├── LICENSE
└── .gitignore
/FirebaseAndAngularAndDotnetCore/keys/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/wwwroot/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/app.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/app.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/home/home.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/login/login.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/secret/secret.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NetCoreTutes
2 | Tutorials and example code for the .Net Core platform
3 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/models/square.ts:
--------------------------------------------------------------------------------
1 | export class Square {
2 | Id: number;
3 | Color: string;
4 | }
5 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/styles.scss:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/models/socket-message.ts:
--------------------------------------------------------------------------------
1 | export class SocketMessage {
2 | MessageType: string;
3 | Payload: any
4 | }
5 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SleepyCrat/NetCoreTutes/HEAD/WebSocketAndNetCore/client-app/src/favicon.ico
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SleepyCrat/NetCoreTutes/HEAD/FirebaseAndAngularAndDotnetCore/client-app/src/favicon.ico
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/models/square-change-request.ts:
--------------------------------------------------------------------------------
1 | export class SquareChangeRequest {
2 | Id: number;
3 | Color: string;
4 | Name: string;
5 | }
6 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/models/current-user.ts:
--------------------------------------------------------------------------------
1 | export class CurrentUser {
2 | isSignedIn: boolean;
3 | displayName: string;
4 | email: string;
5 | }
6 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/secret/secret.component.html:
--------------------------------------------------------------------------------
1 |
Welcome to the secret area
2 |
3 |
6 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/models/square.spec.ts:
--------------------------------------------------------------------------------
1 | import { Square } from './square';
2 |
3 | describe('Square', () => {
4 | it('should create an instance', () => {
5 | expect(new Square()).toBeTruthy();
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/HealthCheckPeek/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/login/login.component.html:
--------------------------------------------------------------------------------
1 |
2 | Go back home
3 |
--------------------------------------------------------------------------------
/HealthCheckPeek/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/home/home.component.html:
--------------------------------------------------------------------------------
1 | Welcome to the Firebase example application. Please log in
2 | Welcome {{currentUser.displayName}}. Thank you for loggin in
3 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/models/current-user.spec.ts:
--------------------------------------------------------------------------------
1 | import { CurrentUser } from './current-user';
2 |
3 | describe('CurrentUser', () => {
4 | it('should create an instance', () => {
5 | expect(new CurrentUser()).toBeTruthy();
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/models/socket-message.spec.ts:
--------------------------------------------------------------------------------
1 | import { SocketMessage } from './socket-message';
2 |
3 | describe('SocketMessage', () => {
4 | it('should create an instance', () => {
5 | expect(new SocketMessage()).toBeTruthy();
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/security/auth-interceptor.spec.ts:
--------------------------------------------------------------------------------
1 | import { AuthInterceptor } from './auth-interceptor';
2 |
3 | describe('AuthInterceptor', () => {
4 | it('should create an instance', () => {
5 | expect(new AuthInterceptor()).toBeTruthy();
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/models/square-change-request.spec.ts:
--------------------------------------------------------------------------------
1 | import { SquareChangeRequest } from './square-change-request';
2 |
3 | describe('SquareChangeRequest', () => {
4 | it('should create an instance', () => {
5 | expect(new SquareChangeRequest()).toBeTruthy();
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*",
10 | "FirebaseProjectName": "[YOUR FIREBASE PROEJCT NAME]"
11 | }
12 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/keys/firebase_admin_sdk.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": "",
3 | "project_id": "",
4 | "private_key_id": "",
5 | "private_key": "",
6 | "client_email": "",
7 | "client_id": "",
8 | "auth_uri": "",
9 | "token_uri": "",
10 | "auth_provider_x509_cert_url": "",
11 | "client_x509_cert_url": ""
12 | }
13 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/Models/tokenVerifyRequest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace FirebaseAndAngular.Web.Models
7 | {
8 | public class TokenVerifyRequest
9 | {
10 | public string Token { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 |
4 | const routes: Routes = [];
5 |
6 | @NgModule({
7 | imports: [RouterModule.forRoot(routes)],
8 | exports: [RouterModule]
9 | })
10 | export class AppRoutingModule { }
11 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get(browser.baseUrl) as Promise;
6 | }
7 |
8 | getTitleText() {
9 | return element(by.css('app-root .content span')).getText() as Promise;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get(browser.baseUrl) as Promise;
6 | }
7 |
8 | getTitleText() {
9 | return element(by.css('app-root .content span')).getText() as Promise;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/HealthCheckPeek/WeatherForecast.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace HealthCheckPeek
4 | {
5 | public class WeatherForecast
6 | {
7 | public DateTime Date { get; set; }
8 |
9 | public int TemperatureC { get; set; }
10 |
11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12 |
13 | public string Summary { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ClientApp
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/app",
5 | "types": []
6 | },
7 | "files": [
8 | "src/main.ts",
9 | "src/polyfills.ts"
10 | ],
11 | "include": [
12 | "src/**/*.ts"
13 | ],
14 | "exclude": [
15 | "src/test.ts",
16 | "src/**/*.spec.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts",
12 | "src/polyfills.ts"
13 | ],
14 | "include": [
15 | "src/**/*.spec.ts",
16 | "src/**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ClientApp
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/app",
5 | "types": []
6 | },
7 | "files": [
8 | "src/main.ts",
9 | "src/polyfills.ts"
10 | ],
11 | "include": [
12 | "src/**/*.ts"
13 | ],
14 | "exclude": [
15 | "src/test.ts",
16 | "src/**/*.spec.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts",
12 | "src/polyfills.ts"
13 | ],
14 | "include": [
15 | "src/**/*.spec.ts",
16 | "src/**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/app.component.html:
--------------------------------------------------------------------------------
1 | Firebase Example Application
2 |
8 |
9 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/styles.scss:
--------------------------------------------------------------------------------
1 | body{
2 | font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
3 | }
4 |
5 | .navbar {
6 | display: flex;
7 | justify-content: flex-start;
8 | }
9 |
10 | .navbar a {
11 | margin: 0.5em;
12 | }
13 |
14 | .googleButton {
15 | background-color: red;
16 | color: white;
17 | font-size: 22px;
18 | }
19 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/WebSocketAndNetCore.Web.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/web-socket.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 |
3 | import { WebSocketService } from './web-socket.service';
4 |
5 | describe('WebSocketService', () => {
6 | beforeEach(() => TestBed.configureTestingModule({}));
7 |
8 | it('should be created', () => {
9 | const service: WebSocketService = TestBed.get(WebSocketService);
10 | expect(service).toBeTruthy();
11 | });
12 | });
13 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/services/auth-service.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 |
3 | import { AuthServiceService } from './auth-service.service';
4 |
5 | describe('AuthServiceService', () => {
6 | beforeEach(() => TestBed.configureTestingModule({}));
7 |
8 | it('should be created', () => {
9 | const service: AuthServiceService = TestBed.get(AuthServiceService);
10 | expect(service).toBeTruthy();
11 | });
12 | });
13 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/browserslist:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # You can see what browsers were selected by your queries by running:
6 | # npx browserslist
7 |
8 | > 0.5%
9 | last 2 versions
10 | Firefox ESR
11 | not dead
12 | not IE 9-11 # For IE 9-11 support, remove 'not'.
--------------------------------------------------------------------------------
/WebSocketAndNetCore/SocketMessage.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace WebSocketAndNetCore.Web
8 | {
9 | public class SocketMessage
10 | {
11 | public string MessageType { get; set; }
12 | public T Payload { get; set; }
13 |
14 | public string ToJson()
15 | {
16 | return JsonConvert.SerializeObject(this);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/security/auth-guard.guard.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async, inject } from '@angular/core/testing';
2 |
3 | import { AuthGuardGuard } from './auth-guard.guard';
4 |
5 | describe('AuthGuardGuard', () => {
6 | beforeEach(() => {
7 | TestBed.configureTestingModule({
8 | providers: [AuthGuardGuard]
9 | });
10 | });
11 |
12 | it('should ...', inject([AuthGuardGuard], (guard: AuthGuardGuard) => {
13 | expect(guard).toBeTruthy();
14 | }));
15 | });
16 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/browserslist:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # You can see what browsers were selected by your queries by running:
6 | # npx browserslist
7 |
8 | > 0.5%
9 | last 2 versions
10 | Firefox ESR
11 | not dead
12 | not IE 9-11 # For IE 9-11 support, remove 'not'.
--------------------------------------------------------------------------------
/HealthCheckPeek/MyDatabaseContext.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace HealthCheckPeek
8 | {
9 | public class MyDatabaseContext : DbContext
10 | {
11 | public MyDatabaseContext(DbContextOptions options) : base(options)
12 | {
13 |
14 | }
15 |
16 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
17 | { }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/HealthCheckPeek/HealthCheckPeek.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/secret/secret.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AuthServiceService } from '../services/auth-service.service';
3 |
4 | @Component({
5 | selector: 'app-secret',
6 | templateUrl: './secret.component.html',
7 | styleUrls: ['./secret.component.scss']
8 | })
9 | export class SecretComponent implements OnInit {
10 |
11 | secrets: string[] = [];
12 | constructor(private authService: AuthServiceService) { }
13 |
14 | ngOnInit() {
15 | this.authService.getUserSecrets().subscribe(secretData => { this.secrets = secretData });
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 | import { FormsModule } from '@angular/forms';
4 | import { AppRoutingModule } from './app-routing.module';
5 | import { AppComponent } from './app.component';
6 | import { WebSocketService } from './web-socket.service';
7 |
8 | @NgModule({
9 | declarations: [
10 | AppComponent
11 | ],
12 | imports: [
13 | BrowserModule,
14 | AppRoutingModule,
15 | FormsModule
16 | ],
17 | providers: [
18 | WebSocketService
19 | ],
20 | bootstrap: [AppComponent]
21 | })
22 | export class AppModule { }
23 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "downlevelIteration": true,
9 | "experimentalDecorators": true,
10 | "module": "esnext",
11 | "moduleResolution": "node",
12 | "importHelpers": true,
13 | "target": "es2015",
14 | "typeRoots": [
15 | "node_modules/@types"
16 | ],
17 | "lib": [
18 | "es2018",
19 | "dom"
20 | ]
21 | },
22 | "angularCompilerOptions": {
23 | "fullTemplateTypeCheck": true,
24 | "strictInjectionParameters": true
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "downlevelIteration": true,
9 | "experimentalDecorators": true,
10 | "module": "esnext",
11 | "moduleResolution": "node",
12 | "importHelpers": true,
13 | "target": "es2015",
14 | "typeRoots": [
15 | "node_modules/@types"
16 | ],
17 | "lib": [
18 | "es2018",
19 | "dom"
20 | ],
21 | "skipLibCheck": true
22 | },
23 | "angularCompilerOptions": {
24 | "fullTemplateTypeCheck": true,
25 | "strictInjectionParameters": true
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: any;
11 |
12 | // First, initialize the Angular testing environment.
13 | getTestBed().initTestEnvironment(
14 | BrowserDynamicTestingModule,
15 | platformBrowserDynamicTesting()
16 | );
17 | // Then we find all the tests.
18 | const context = require.context('./', true, /\.spec\.ts$/);
19 | // And load the modules.
20 | context.keys().map(context);
21 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: any;
11 |
12 | // First, initialize the Angular testing environment.
13 | getTestBed().initTestEnvironment(
14 | BrowserDynamicTestingModule,
15 | platformBrowserDynamicTesting()
16 | );
17 | // Then we find all the tests.
18 | const context = require.context('./', true, /\.spec\.ts$/);
19 | // And load the modules.
20 | context.keys().map(context);
21 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false
7 | };
8 |
9 | /*
10 | * For easier debugging in development mode, you can import the following file
11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
12 | *
13 | * This import should be commented out in production mode because it will have a negative impact
14 | * on performance if an error is thrown.
15 | */
16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
17 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 | import { browser, logging } from 'protractor';
3 |
4 | describe('workspace-project App', () => {
5 | let page: AppPage;
6 |
7 | beforeEach(() => {
8 | page = new AppPage();
9 | });
10 |
11 | it('should display welcome message', () => {
12 | page.navigateTo();
13 | expect(page.getTitleText()).toEqual('client-app app is running!');
14 | });
15 |
16 | afterEach(async () => {
17 | // Assert that there are no errors emitted from the browser
18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19 | expect(logs).not.toContain(jasmine.objectContaining({
20 | level: logging.Level.SEVERE,
21 | } as logging.Entry));
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/home/home.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { HomeComponent } from './home.component';
4 |
5 | describe('HomeComponent', () => {
6 | let component: HomeComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ HomeComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(HomeComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 | import { browser, logging } from 'protractor';
3 |
4 | describe('workspace-project App', () => {
5 | let page: AppPage;
6 |
7 | beforeEach(() => {
8 | page = new AppPage();
9 | });
10 |
11 | it('should display welcome message', () => {
12 | page.navigateTo();
13 | expect(page.getTitleText()).toEqual('client-app app is running!');
14 | });
15 |
16 | afterEach(async () => {
17 | // Assert that there are no errors emitted from the browser
18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19 | expect(logs).not.toContain(jasmine.objectContaining({
20 | level: logging.Level.SEVERE,
21 | } as logging.Entry));
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/login/login.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { LoginComponent } from './login.component';
4 |
5 | describe('LoginComponent', () => {
6 | let component: LoginComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ LoginComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(LoginComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/secret/secret.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { SecretComponent } from './secret.component';
4 |
5 | describe('SecretComponent', () => {
6 | let component: SecretComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ SecretComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(SecretComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/FirebaseAndAngular.Web.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/HealthCheckPeek/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.Hosting;
8 | using Microsoft.Extensions.Logging;
9 |
10 | namespace HealthCheckPeek
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | CreateHostBuilder(args).Build().Run();
17 | }
18 |
19 | public static IHostBuilder CreateHostBuilder(string[] args) =>
20 | Host.CreateDefaultBuilder(args)
21 | .ConfigureWebHostDefaults(webBuilder =>
22 | {
23 | webBuilder.UseStartup();
24 | });
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.Hosting;
8 | using Microsoft.Extensions.Logging;
9 |
10 | namespace WebSocketAndNetCore.Web
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | CreateHostBuilder(args).Build().Run();
17 | }
18 |
19 | public static IHostBuilder CreateHostBuilder(string[] args) =>
20 | Host.CreateDefaultBuilder(args)
21 | .ConfigureWebHostDefaults(webBuilder =>
22 | {
23 | webBuilder.UseStartup();
24 | });
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { HomeComponent } from './home/home.component';
4 | import { LoginComponent } from './login/login.component';
5 | import { SecretComponent } from './secret/secret.component';
6 | import { AuthGuardGuard } from './security/auth-guard.guard';
7 |
8 |
9 | const routes: Routes = [
10 | { path: '', component: HomeComponent },
11 | { path: 'login', component: LoginComponent },
12 | { path: 'secret', component: SecretComponent, canActivate: [AuthGuardGuard] },
13 | { path: '**', component: SecretComponent }
14 | ];
15 |
16 | @NgModule({
17 | imports: [RouterModule.forRoot(routes)],
18 | exports: [RouterModule]
19 | })
20 | export class AppRoutingModule { }
21 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.Hosting;
8 | using Microsoft.Extensions.Logging;
9 |
10 | namespace FirebaseAndAngular.Web
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | CreateHostBuilder(args).Build().Run();
17 | }
18 |
19 | public static IHostBuilder CreateHostBuilder(string[] args) =>
20 | Host.CreateDefaultBuilder(args)
21 | .ConfigureWebHostDefaults(webBuilder =>
22 | {
23 | webBuilder.UseStartup();
24 | });
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | # Only exists if Bazel was run
8 | /bazel-out
9 |
10 | # dependencies
11 | /node_modules
12 |
13 | # profiling files
14 | chrome-profiler-events*.json
15 | speed-measure-plugin*.json
16 |
17 | # IDEs and editors
18 | /.idea
19 | .project
20 | .classpath
21 | .c9/
22 | *.launch
23 | .settings/
24 | *.sublime-workspace
25 |
26 | # IDE - VSCode
27 | .vscode/*
28 | !.vscode/settings.json
29 | !.vscode/tasks.json
30 | !.vscode/launch.json
31 | !.vscode/extensions.json
32 | .history/*
33 |
34 | # misc
35 | /.sass-cache
36 | /connect.lock
37 | /coverage
38 | /libpeerconnection.log
39 | npm-debug.log
40 | yarn-error.log
41 | testem.log
42 | /typings
43 |
44 | # System Files
45 | .DS_Store
46 | Thumbs.db
47 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/home/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { CurrentUser } from '../models/current-user';
3 | import { Subscription } from 'rxjs';
4 | import { AuthServiceService } from '../services/auth-service.service';
5 | import { Router } from '@angular/router';
6 |
7 | @Component({
8 | selector: 'app-home',
9 | templateUrl: './home.component.html',
10 | styleUrls: ['./home.component.scss']
11 | })
12 | export class HomeComponent implements OnInit {
13 | currentUser: CurrentUser = new CurrentUser();
14 | $authSubscription: Subscription;
15 |
16 | constructor(private authService: AuthServiceService, private router: Router) {
17 | this.$authSubscription = this.authService.user$.subscribe(u => {
18 | this.currentUser = u;
19 | });
20 | }
21 |
22 | ngOnInit() {
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/security/auth-guard.guard.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
3 | import { Observable } from 'rxjs';
4 | import { AuthServiceService } from '../services/auth-service.service';
5 | import { take, tap } from 'rxjs/operators';
6 | import { map } from 'rxjs/operators';
7 | @Injectable({
8 | providedIn: 'root'
9 | })
10 | export class AuthGuardGuard implements CanActivate {
11 | constructor(private authservice: AuthServiceService, private router: Router) {
12 |
13 | }
14 |
15 | canActivate(
16 | next: ActivatedRouteSnapshot,
17 | state: RouterStateSnapshot): Observable {
18 | return this.authservice
19 | .getUserobservable()
20 | .pipe(map(u => u != null && u.isSignedIn));
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { AuthServiceService } from './services/auth-service.service';
3 | import { Subscription } from 'rxjs';
4 | import { CurrentUser } from './models/current-user';
5 | import { Router } from '@angular/router';
6 |
7 | @Component({
8 | selector: 'app-root',
9 | templateUrl: './app.component.html',
10 | styleUrls: ['./app.component.scss']
11 | })
12 | export class AppComponent {
13 | currentUser: CurrentUser = new CurrentUser();
14 | $authSubscription: Subscription;
15 | constructor(private authService: AuthServiceService, private router: Router) {
16 | this.$authSubscription = this.authService.user$.subscribe(u => {
17 | this.currentUser = u;
18 | });
19 | }
20 |
21 | logTheUserOut() {
22 | this.authService.logout().then(() => {
23 | });
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:32951",
8 | "sslPort": 44301
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "WebSocketAndNetCore.Web": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "",
24 | "applicationUrl": "https://localhost:5001",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/security/auth-interceptor.ts:
--------------------------------------------------------------------------------
1 | import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
2 | import { Observable } from 'rxjs';
3 | import { AuthServiceService } from '../services/auth-service.service';
4 | import { Injectable } from '@angular/core';
5 |
6 | @Injectable({
7 | providedIn: 'root'
8 | })
9 | export class AuthInterceptor implements HttpInterceptor {
10 | constructor(private authService: AuthServiceService) {
11 |
12 | }
13 |
14 | intercept(req: HttpRequest, next: HttpHandler): Observable> {
15 | var token = this.authService.getToken();
16 | if (token) {
17 | var header = "Bearer " + token;
18 | var reqWithAuth = req.clone({ headers: req.headers.set("Authorization", header) });
19 | return next.handle(reqWithAuth);
20 | }
21 |
22 | return next.handle(req);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | # Only exists if Bazel was run
8 | /bazel-out
9 |
10 | # dependencies
11 | /node_modules
12 |
13 | # profiling files
14 | chrome-profiler-events*.json
15 | speed-measure-plugin*.json
16 |
17 | # IDEs and editors
18 | /.idea
19 | .project
20 | .classpath
21 | .c9/
22 | *.launch
23 | .settings/
24 | *.sublime-workspace
25 |
26 | # IDE - VSCode
27 | .vscode/*
28 | !.vscode/settings.json
29 | !.vscode/tasks.json
30 | !.vscode/launch.json
31 | !.vscode/extensions.json
32 | .history/*
33 |
34 | # misc
35 | /.sass-cache
36 | /connect.lock
37 | /coverage
38 | /libpeerconnection.log
39 | npm-debug.log
40 | yarn-error.log
41 | testem.log
42 | /typings
43 |
44 | # System Files
45 | .DS_Store
46 | Thumbs.db
47 |
48 | src/environments/environment.local.ts
49 | /wwwroot
50 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:1404",
8 | "sslPort": 44313
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "FirebaseAndAngular.Web": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "",
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/HealthCheckPeek/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:64391",
8 | "sslPort": 44320
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "health",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "HealthCheckPeek": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "weatherforecast",
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 | // Protractor configuration file, see link for more information
3 | // https://github.com/angular/protractor/blob/master/lib/config.ts
4 |
5 | const { SpecReporter } = require('jasmine-spec-reporter');
6 |
7 | /**
8 | * @type { import("protractor").Config }
9 | */
10 | exports.config = {
11 | allScriptsTimeout: 11000,
12 | specs: [
13 | './src/**/*.e2e-spec.ts'
14 | ],
15 | capabilities: {
16 | browserName: 'chrome'
17 | },
18 | directConnect: true,
19 | baseUrl: 'http://localhost:4200/',
20 | framework: 'jasmine',
21 | jasmineNodeOpts: {
22 | showColors: true,
23 | defaultTimeoutInterval: 30000,
24 | print: function() {}
25 | },
26 | onPrepare() {
27 | require('ts-node').register({
28 | project: require('path').join(__dirname, './tsconfig.json')
29 | });
30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
31 | }
32 | };
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false,
7 | firebaseConfig : {
8 | apiKey: "",
9 | authDomain: "",
10 | databaseURL: "",
11 | projectId: "",
12 | storageBucket: "",
13 | messagingSenderId: "",
14 | appId: ""
15 | }
16 | };
17 |
18 | /*
19 | * For easier debugging in development mode, you can import the following file
20 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
21 | *
22 | * This import should be commented out in production mode because it will have a negative impact
23 | * on performance if an error is thrown.
24 | */
25 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
26 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 | // Protractor configuration file, see link for more information
3 | // https://github.com/angular/protractor/blob/master/lib/config.ts
4 |
5 | const { SpecReporter } = require('jasmine-spec-reporter');
6 |
7 | /**
8 | * @type { import("protractor").Config }
9 | */
10 | exports.config = {
11 | allScriptsTimeout: 11000,
12 | specs: [
13 | './src/**/*.e2e-spec.ts'
14 | ],
15 | capabilities: {
16 | browserName: 'chrome'
17 | },
18 | directConnect: true,
19 | baseUrl: 'http://localhost:4200/',
20 | framework: 'jasmine',
21 | jasmineNodeOpts: {
22 | showColors: true,
23 | defaultTimeoutInterval: 30000,
24 | print: function() {}
25 | },
26 | onPrepare() {
27 | require('ts-node').register({
28 | project: require('path').join(__dirname, './tsconfig.json')
29 | });
30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
31 | }
32 | };
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/login/login.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AuthServiceService } from '../services/auth-service.service';
3 | import { Router } from '@angular/router';
4 | import { CurrentUser } from '../models/current-user';
5 | import { Subscription } from 'rxjs';
6 |
7 | @Component({
8 | selector: 'app-login',
9 | templateUrl: './login.component.html',
10 | styleUrls: ['./login.component.scss']
11 | })
12 | export class LoginComponent implements OnInit {
13 | currentUser: CurrentUser = new CurrentUser();
14 | $authSubscription: Subscription;
15 | constructor(private authService: AuthServiceService, private router: Router) {
16 | this.$authSubscription = this.authService.user$.subscribe(u => {
17 | this.currentUser = u;
18 | });
19 | }
20 |
21 | ngOnInit() {
22 | }
23 |
24 | loginWithGoogle() {
25 | this.authService.doGoogleSignIn().then(() => {
26 | this.router.navigate(['']);
27 | });
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Frank Jones
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, './coverage/client-app'),
20 | reports: ['html', 'lcovonly', 'text-summary'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false,
30 | restartOnFileChange: true
31 | });
32 | };
33 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, './coverage/client-app'),
20 | reports: ['html', 'lcovonly', 'text-summary'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false,
30 | restartOnFileChange: true
31 | });
32 | };
33 |
--------------------------------------------------------------------------------
/HealthCheckPeek/HealthCheckPeek.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29613.14
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthCheckPeek", "HealthCheckPeek.csproj", "{273D691F-62E2-4FFB-BAC5-137102F70E1E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {273D691F-62E2-4FFB-BAC5-137102F70E1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {273D691F-62E2-4FFB-BAC5-137102F70E1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {273D691F-62E2-4FFB-BAC5-137102F70E1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {273D691F-62E2-4FFB-BAC5-137102F70E1E}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {42E0774D-2B04-41BA-B4F3-1EE9E7590478}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/Square.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace WebSocketAndNetCore.Web
8 | {
9 | public class Square
10 | {
11 | public int Id { get; set; }
12 | public string Color { get; set; }
13 |
14 | public static IEnumerable GetInitialSquares()
15 | {
16 | var colors = new string[] { "red", "green", "blue" };
17 | var squares = new List();
18 | for (int i = 0; i < 10; i++)
19 | {
20 | var random = new Random();
21 | squares.Add(new Square()
22 | {
23 | Id = i,
24 | Color = colors[(random.Next(1, 3)) - 1]
25 | });
26 | }
27 | return squares;
28 | }
29 | }
30 |
31 | public class SquareChangeRequest
32 | {
33 | public int Id { get; set; }
34 | public string Color { get; set; }
35 | public string Name { get; set; }
36 |
37 | public static SquareChangeRequest FromJson(string json)
38 | {
39 | return JsonConvert.DeserializeObject(json);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { RouterTestingModule } from '@angular/router/testing';
3 | import { AppComponent } from './app.component';
4 |
5 | describe('AppComponent', () => {
6 | beforeEach(async(() => {
7 | TestBed.configureTestingModule({
8 | imports: [
9 | RouterTestingModule
10 | ],
11 | declarations: [
12 | AppComponent
13 | ],
14 | }).compileComponents();
15 | }));
16 |
17 | it('should create the app', () => {
18 | const fixture = TestBed.createComponent(AppComponent);
19 | const app = fixture.debugElement.componentInstance;
20 | expect(app).toBeTruthy();
21 | });
22 |
23 | it(`should have as title 'client-app'`, () => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | const app = fixture.debugElement.componentInstance;
26 | expect(app.title).toEqual('client-app');
27 | });
28 |
29 | it('should render title', () => {
30 | const fixture = TestBed.createComponent(AppComponent);
31 | fixture.detectChanges();
32 | const compiled = fixture.debugElement.nativeElement;
33 | expect(compiled.querySelector('.content span').textContent).toContain('client-app app is running!');
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { RouterTestingModule } from '@angular/router/testing';
3 | import { AppComponent } from './app.component';
4 |
5 | describe('AppComponent', () => {
6 | beforeEach(async(() => {
7 | TestBed.configureTestingModule({
8 | imports: [
9 | RouterTestingModule
10 | ],
11 | declarations: [
12 | AppComponent
13 | ],
14 | }).compileComponents();
15 | }));
16 |
17 | it('should create the app', () => {
18 | const fixture = TestBed.createComponent(AppComponent);
19 | const app = fixture.debugElement.componentInstance;
20 | expect(app).toBeTruthy();
21 | });
22 |
23 | it(`should have as title 'client-app'`, () => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | const app = fixture.debugElement.componentInstance;
26 | expect(app.title).toEqual('client-app');
27 | });
28 |
29 | it('should render title', () => {
30 | const fixture = TestBed.createComponent(AppComponent);
31 | fixture.detectChanges();
32 | const compiled = fixture.debugElement.nativeElement;
33 | expect(compiled.querySelector('.content span').textContent).toContain('client-app app is running!');
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
28 |
29 |
30 | Current Color:
31 |
34 |
35 |
36 |
37 |
38 | {{square.Id}}
39 |
40 |
41 |
42 |
47 |
48 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 |
4 | import { AppRoutingModule } from './app-routing.module';
5 | import { AppComponent } from './app.component';
6 | import { HomeComponent } from './home/home.component';
7 | import { LoginComponent } from './login/login.component';
8 | import { SecretComponent } from './secret/secret.component';
9 | import { AngularFireModule } from '@angular/fire';
10 | import { AngularFireAuthModule } from '@angular/fire/auth';
11 | import { environment } from '../environments/environment';
12 | import { AuthGuardGuard } from './security/auth-guard.guard';
13 | import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
14 | import { AuthInterceptor } from './security/auth-interceptor';
15 |
16 | @NgModule({
17 | declarations: [
18 | AppComponent,
19 | HomeComponent,
20 | LoginComponent,
21 | SecretComponent
22 | ],
23 | imports: [
24 | BrowserModule,
25 | AppRoutingModule,
26 | AngularFireModule.initializeApp(environment.firebaseConfig),
27 | AngularFireAuthModule,
28 | HttpClientModule
29 | ],
30 | providers: [
31 | AuthGuardGuard,
32 | { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }
33 | ],
34 | bootstrap: [AppComponent]
35 | })
36 | export class AppModule { }
37 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { WebSocketService } from './web-socket.service';
3 | import { Square } from './models/square';
4 | import { SquareChangeRequest } from './models/square-change-request';
5 |
6 | @Component({
7 | selector: 'app-root',
8 | templateUrl: './app.component.html',
9 | styleUrls: ['./app.component.scss']
10 | })
11 | export class AppComponent {
12 | announcementSub;
13 | messages: string[] = [];
14 | squares: Square[] = [];
15 | colors: string[] = ["red", "green", "blue"];
16 | currentColor: string = "red";
17 | name: string = "";
18 | constructor(private socketService: WebSocketService) {
19 | this.socketService.announcement$.subscribe(announcement => {
20 | if (announcement) {
21 | this.messages.unshift(announcement);
22 | }
23 | });
24 | this.socketService.squares$.subscribe(sq => {
25 | this.squares = sq;
26 | });
27 | this.socketService.name$.subscribe(n => {
28 | this.name = n;
29 | });
30 | }
31 |
32 | ngOnInit() {
33 | this.socketService.startSocket();
34 |
35 | }
36 |
37 | squareClick(event, square: Square) {
38 | if (square.Color === this.currentColor)
39 | return;
40 | var req = new SquareChangeRequest();
41 | req.Id = square.Id;
42 | req.Color = this.currentColor;
43 | this.socketService.sendSquareChangeRequest(req);
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/HealthCheckPeek/Controllers/WeatherForecastController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 | using Microsoft.Extensions.Logging;
7 |
8 | namespace HealthCheckPeek.Controllers
9 | {
10 | [ApiController]
11 | [Route("[controller]")]
12 | public class WeatherForecastController : ControllerBase
13 | {
14 | private static readonly string[] Summaries = new[]
15 | {
16 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
17 | };
18 |
19 | private readonly ILogger _logger;
20 |
21 | public WeatherForecastController(ILogger logger)
22 | {
23 | _logger = logger;
24 | }
25 |
26 | [HttpGet]
27 | public IEnumerable Get()
28 | {
29 | var rng = new Random();
30 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast
31 | {
32 | Date = DateTime.Now.AddDays(index),
33 | TemperatureC = rng.Next(-20, 55),
34 | Summary = Summaries[rng.Next(Summaries.Length)]
35 | })
36 | .ToArray();
37 | }
38 |
39 | [HttpGet("slow")]
40 | public async Task Slow()
41 | {
42 | await Task.Delay(3000);
43 | return "slow";
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client-app",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e"
11 | },
12 | "private": true,
13 | "dependencies": {
14 | "@angular/animations": "~8.2.14",
15 | "@angular/common": "~8.2.14",
16 | "@angular/compiler": "~8.2.14",
17 | "@angular/core": "~8.2.14",
18 | "@angular/forms": "~8.2.14",
19 | "@angular/platform-browser": "~8.2.14",
20 | "@angular/platform-browser-dynamic": "~8.2.14",
21 | "@angular/router": "~8.2.14",
22 | "@types/socket.io-client": "^1.4.32",
23 | "rxjs": "~6.4.0",
24 | "socket.io-client": "^2.3.0",
25 | "tslib": "^1.10.0",
26 | "zone.js": "~0.9.1"
27 | },
28 | "devDependencies": {
29 | "@angular-devkit/build-angular": "~0.803.24",
30 | "@angular/cli": "~8.3.24",
31 | "@angular/compiler-cli": "~8.2.14",
32 | "@angular/language-service": "~8.2.14",
33 | "@types/node": "~8.9.4",
34 | "@types/jasmine": "~3.3.8",
35 | "@types/jasminewd2": "~2.0.3",
36 | "codelyzer": "^5.0.0",
37 | "jasmine-core": "~3.4.0",
38 | "jasmine-spec-reporter": "~4.2.1",
39 | "karma": "~4.1.0",
40 | "karma-chrome-launcher": "~2.2.0",
41 | "karma-coverage-istanbul-reporter": "~2.0.1",
42 | "karma-jasmine": "~2.0.1",
43 | "karma-jasmine-html-reporter": "^1.4.0",
44 | "protractor": "~5.4.0",
45 | "ts-node": "~7.0.0",
46 | "tslint": "~5.15.0",
47 | "typescript": "~3.5.3"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/Controllers/UsersController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using FirebaseAdmin;
6 | using FirebaseAndAngular.Web.Models;
7 | using Microsoft.AspNetCore.Authorization;
8 | using Microsoft.AspNetCore.Http;
9 | using Microsoft.AspNetCore.Mvc;
10 |
11 | namespace FirebaseAndAngular.Web.Controllers
12 | {
13 | [Route("api/[controller]")]
14 | [ApiController]
15 | public class UsersController : ControllerBase
16 | {
17 | [HttpPost("verify")]
18 | public async Task VerifyToken(TokenVerifyRequest request)
19 | {
20 | var auth = FirebaseAdmin.Auth.FirebaseAuth.DefaultInstance;
21 |
22 | try
23 | {
24 | var response = await auth.VerifyIdTokenAsync(request.Token);
25 | if (response != null)
26 | return Accepted();
27 | }
28 | catch (FirebaseException ex)
29 | {
30 | return BadRequest();
31 | }
32 |
33 | return BadRequest();
34 | }
35 |
36 | [HttpGet("secrets")]
37 | [Authorize]
38 | public IEnumerable GetSecrets()
39 | {
40 | return new List()
41 | {
42 | "This is from the secret controller",
43 | "Seeing this means you are authenticated",
44 | "You have logged in using your google account from firebase",
45 | "Have a nice day!!"
46 | };
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client-app",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "start-local": "ng serve -c local",
8 | "build": "ng build",
9 | "test": "ng test",
10 | "lint": "ng lint",
11 | "e2e": "ng e2e"
12 | },
13 | "private": true,
14 | "dependencies": {
15 | "@angular/animations": "~8.2.14",
16 | "@angular/common": "~8.2.14",
17 | "@angular/compiler": "~8.2.14",
18 | "@angular/core": "~8.2.14",
19 | "@angular/fire": "^5.4.0",
20 | "@angular/forms": "~8.2.14",
21 | "@angular/platform-browser": "~8.2.14",
22 | "@angular/platform-browser-dynamic": "~8.2.14",
23 | "@angular/router": "~8.2.14",
24 | "firebase": "^7.8.0",
25 | "rxjs": "~6.4.0",
26 | "tslib": "^1.10.0",
27 | "zone.js": "~0.9.1"
28 | },
29 | "devDependencies": {
30 | "@angular-devkit/build-angular": "~0.803.24",
31 | "@angular/cli": "~8.3.24",
32 | "@angular/compiler-cli": "~8.2.14",
33 | "@angular/language-service": "~8.2.14",
34 | "@types/node": "~8.9.4",
35 | "@types/jasmine": "~3.3.8",
36 | "@types/jasminewd2": "~2.0.3",
37 | "codelyzer": "^5.0.0",
38 | "jasmine-core": "~3.4.0",
39 | "jasmine-spec-reporter": "~4.2.1",
40 | "karma": "~4.1.0",
41 | "karma-chrome-launcher": "~2.2.0",
42 | "karma-coverage-istanbul-reporter": "~2.0.1",
43 | "karma-jasmine": "~2.0.1",
44 | "karma-jasmine-html-reporter": "^1.4.0",
45 | "protractor": "~5.4.0",
46 | "ts-node": "~7.0.0",
47 | "tslint": "~5.15.0",
48 | "typescript": "~3.5.3"
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/app/web-socket.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { SocketMessage } from './models/socket-message';
3 | import { BehaviorSubject } from 'rxjs';
4 | import { Square } from './models/square';
5 | import { SquareChangeRequest } from './models/square-change-request';
6 |
7 | @Injectable({
8 | providedIn: 'root'
9 | })
10 | export class WebSocketService {
11 | private socket: WebSocket;
12 | squares$: BehaviorSubject = new BehaviorSubject([]);
13 | announcement$: BehaviorSubject = new BehaviorSubject('');
14 | name$: BehaviorSubject = new BehaviorSubject('');
15 | private name: string;
16 | constructor() { }
17 |
18 | startSocket() {
19 | this.socket = new WebSocket('wss://localhost:5001/ws');
20 | this.socket.addEventListener("open", (ev => {
21 | console.log('opened')
22 | }));
23 | this.socket.addEventListener("message", (ev => {
24 | var messageBox: SocketMessage = JSON.parse(ev.data);
25 | console.log('message object', messageBox);
26 | switch (messageBox.MessageType) {
27 | case "name":
28 | this.name = messageBox.Payload;
29 | this.name$.next(this.name);
30 | break;
31 | case "announce":
32 | this.announcement$.next(messageBox.Payload);
33 | break;
34 | case "squares":
35 | this.squares$.next(messageBox.Payload);
36 | break;
37 | default:
38 | break;
39 | }
40 | }));
41 | }
42 |
43 | sendSquareChangeRequest(req: SquareChangeRequest) {
44 | req.Name = this.name;
45 | var requestAsJson = JSON.stringify(req);
46 | this.socket.send(requestAsJson);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/WebSocketsAndNetCore.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26124.0
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSocketAndNetCore.Web", "WebSocketAndNetCore.Web.csproj", "{DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|Any CPU = Release|Any CPU
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Debug|x64.ActiveCfg = Debug|Any CPU
24 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Debug|x64.Build.0 = Debug|Any CPU
25 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Debug|x86.ActiveCfg = Debug|Any CPU
26 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Debug|x86.Build.0 = Debug|Any CPU
27 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Release|x64.ActiveCfg = Release|Any CPU
30 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Release|x64.Build.0 = Release|Any CPU
31 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Release|x86.ActiveCfg = Release|Any CPU
32 | {DAE0B415-F656-45BB-B285-F3E3F3ACF6FE}.Release|x86.Build.0 = Release|Any CPU
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/FirebaseAndAngular.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26124.0
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FirebaseAndAngular.Web", "FirebaseAndAngular.Web.csproj", "{F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|Any CPU = Release|Any CPU
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Debug|x64.ActiveCfg = Debug|Any CPU
24 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Debug|x64.Build.0 = Debug|Any CPU
25 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Debug|x86.ActiveCfg = Debug|Any CPU
26 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Debug|x86.Build.0 = Debug|Any CPU
27 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Release|x64.ActiveCfg = Release|Any CPU
30 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Release|x64.Build.0 = Release|Any CPU
31 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Release|x86.ActiveCfg = Release|Any CPU
32 | {F4FA2442-D84A-48E1-A3D3-4D9B308C9F28}.Release|x86.Build.0 = Release|Any CPU
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tslint:recommended",
3 | "rules": {
4 | "array-type": false,
5 | "arrow-parens": false,
6 | "deprecation": {
7 | "severity": "warning"
8 | },
9 | "component-class-suffix": true,
10 | "contextual-lifecycle": true,
11 | "directive-class-suffix": true,
12 | "directive-selector": [
13 | true,
14 | "attribute",
15 | "app",
16 | "camelCase"
17 | ],
18 | "component-selector": [
19 | true,
20 | "element",
21 | "app",
22 | "kebab-case"
23 | ],
24 | "import-blacklist": [
25 | true,
26 | "rxjs/Rx"
27 | ],
28 | "interface-name": false,
29 | "max-classes-per-file": false,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": false,
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-consecutive-blank-lines": false,
47 | "no-console": [
48 | true,
49 | "debug",
50 | "info",
51 | "time",
52 | "timeEnd",
53 | "trace"
54 | ],
55 | "no-empty": false,
56 | "no-inferrable-types": [
57 | true,
58 | "ignore-params"
59 | ],
60 | "no-non-null-assertion": true,
61 | "no-redundant-jsdoc": true,
62 | "no-switch-case-fall-through": true,
63 | "no-var-requires": false,
64 | "object-literal-key-quotes": [
65 | true,
66 | "as-needed"
67 | ],
68 | "object-literal-sort-keys": false,
69 | "ordered-imports": false,
70 | "quotemark": [
71 | true,
72 | "single"
73 | ],
74 | "trailing-comma": false,
75 | "no-conflicting-lifecycle": true,
76 | "no-host-metadata-property": true,
77 | "no-input-rename": true,
78 | "no-inputs-metadata-property": true,
79 | "no-output-native": true,
80 | "no-output-on-prefix": true,
81 | "no-output-rename": true,
82 | "no-outputs-metadata-property": true,
83 | "template-banana-in-box": true,
84 | "template-no-negated-async": true,
85 | "use-lifecycle-interface": true,
86 | "use-pipe-transform-interface": true
87 | },
88 | "rulesDirectory": [
89 | "codelyzer"
90 | ]
91 | }
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tslint:recommended",
3 | "rules": {
4 | "array-type": false,
5 | "arrow-parens": false,
6 | "deprecation": {
7 | "severity": "warning"
8 | },
9 | "component-class-suffix": true,
10 | "contextual-lifecycle": true,
11 | "directive-class-suffix": true,
12 | "directive-selector": [
13 | true,
14 | "attribute",
15 | "app",
16 | "camelCase"
17 | ],
18 | "component-selector": [
19 | true,
20 | "element",
21 | "app",
22 | "kebab-case"
23 | ],
24 | "import-blacklist": [
25 | true,
26 | "rxjs/Rx"
27 | ],
28 | "interface-name": false,
29 | "max-classes-per-file": false,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": false,
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-consecutive-blank-lines": false,
47 | "no-console": [
48 | true,
49 | "debug",
50 | "info",
51 | "time",
52 | "timeEnd",
53 | "trace"
54 | ],
55 | "no-empty": false,
56 | "no-inferrable-types": [
57 | true,
58 | "ignore-params"
59 | ],
60 | "no-non-null-assertion": true,
61 | "no-redundant-jsdoc": true,
62 | "no-switch-case-fall-through": true,
63 | "no-var-requires": false,
64 | "object-literal-key-quotes": [
65 | true,
66 | "as-needed"
67 | ],
68 | "object-literal-sort-keys": false,
69 | "ordered-imports": false,
70 | "quotemark": [
71 | true,
72 | "single"
73 | ],
74 | "trailing-comma": false,
75 | "no-conflicting-lifecycle": true,
76 | "no-host-metadata-property": true,
77 | "no-input-rename": true,
78 | "no-inputs-metadata-property": true,
79 | "no-output-native": true,
80 | "no-output-on-prefix": true,
81 | "no-output-rename": true,
82 | "no-outputs-metadata-property": true,
83 | "template-banana-in-box": true,
84 | "template-no-negated-async": true,
85 | "use-lifecycle-interface": true,
86 | "use-pipe-transform-interface": true
87 | },
88 | "rulesDirectory": [
89 | "codelyzer"
90 | ]
91 | }
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/app/services/auth-service.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { AngularFireAuth } from '@angular/fire/auth'
3 | import * as firebase from 'firebase/app';
4 | import { BehaviorSubject, Observable } from 'rxjs';
5 | import { CurrentUser } from '../models/current-user';
6 | import { HttpClient } from '@angular/common/http';
7 | import { map } from 'rxjs/operators';
8 |
9 |
10 | @Injectable({
11 | providedIn: 'root'
12 | })
13 | export class AuthServiceService {
14 |
15 | user$: BehaviorSubject = new BehaviorSubject(new CurrentUser());
16 |
17 | constructor(private angularAuth: AngularFireAuth, private httpclient: HttpClient) {
18 | this.angularAuth.authState.subscribe((firebaseUser) => {
19 | this.configureAuthState(firebaseUser);
20 | });
21 | }
22 |
23 | doGoogleSignIn(): Promise {
24 | var googleProvider = new firebase.auth.GoogleAuthProvider();
25 | googleProvider.addScope('email');
26 | googleProvider.addScope('profile');
27 | return this.angularAuth.auth.signInWithPopup(googleProvider).then((auth) => {});
28 | }
29 |
30 | configureAuthState(firebaseUser: firebase.User): void {
31 | if (firebaseUser) {
32 | firebaseUser.getIdToken().then((theToken) => {
33 | console.log('we have a token');
34 | this.httpclient.post('/api/users/verify', { token: theToken }).subscribe({
35 | next: () => {
36 | let theUser = new CurrentUser();
37 | theUser.displayName = firebaseUser.displayName;
38 | theUser.email = firebaseUser.email;
39 | theUser.isSignedIn = true;
40 | localStorage.setItem("jwt", theToken);
41 | this.user$.next(theUser);
42 | },
43 | error: (err) => {
44 | console.log('inside the error from server', err);
45 | this.doSignedOutUser()
46 | }
47 | });
48 | }, (failReason) => {
49 | this.doSignedOutUser();
50 | });
51 | } else {
52 | this.doSignedOutUser();
53 | }
54 | }
55 |
56 | private doSignedOutUser() {
57 | let theUser = new CurrentUser();
58 | theUser.displayName = null;
59 | theUser.email = null;
60 | theUser.isSignedIn = false;
61 | localStorage.removeItem("jwt");
62 | this.user$.next(theUser);
63 | }
64 |
65 | logout(): Promise {
66 | return this.angularAuth.auth.signOut();
67 | }
68 |
69 | getUserobservable(): Observable {
70 | return this.user$.asObservable();
71 | }
72 |
73 | getToken(): string {
74 | return localStorage.getItem("jwt");
75 | }
76 |
77 | getUserSecrets(): Observable {
78 | return this.httpclient.get("/api/users/secrets").pipe(map((resp: string[]) => resp));
79 | }
80 | }
81 |
82 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
22 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
23 |
24 | /**
25 | * Web Animations `@angular/platform-browser/animations`
26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
28 | */
29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
30 |
31 | /**
32 | * By default, zone.js will patch all possible macroTask and DomEvents
33 | * user can disable parts of macroTask/DomEvents patch by setting following flags
34 | * because those flags need to be set before `zone.js` being loaded, and webpack
35 | * will put import in the top of bundle, so user need to create a separate file
36 | * in this directory (for example: zone-flags.ts), and put the following flags
37 | * into that file, and then add the following code before importing zone.js.
38 | * import './zone-flags.ts';
39 | *
40 | * The flags allowed in zone-flags.ts are listed here.
41 | *
42 | * The following flags will work for all browsers.
43 | *
44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
47 | *
48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
50 | *
51 | * (window as any).__Zone_enable_cross_context_check = true;
52 | *
53 | */
54 |
55 | /***************************************************************************************************
56 | * Zone JS is required by default for Angular itself.
57 | */
58 | import 'zone.js/dist/zone'; // Included with Angular CLI.
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
22 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
23 |
24 | /**
25 | * Web Animations `@angular/platform-browser/animations`
26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
28 | */
29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
30 |
31 | /**
32 | * By default, zone.js will patch all possible macroTask and DomEvents
33 | * user can disable parts of macroTask/DomEvents patch by setting following flags
34 | * because those flags need to be set before `zone.js` being loaded, and webpack
35 | * will put import in the top of bundle, so user need to create a separate file
36 | * in this directory (for example: zone-flags.ts), and put the following flags
37 | * into that file, and then add the following code before importing zone.js.
38 | * import './zone-flags.ts';
39 | *
40 | * The flags allowed in zone-flags.ts are listed here.
41 | *
42 | * The following flags will work for all browsers.
43 | *
44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
47 | *
48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
50 | *
51 | * (window as any).__Zone_enable_cross_context_check = true;
52 | *
53 | */
54 |
55 | /***************************************************************************************************
56 | * Zone JS is required by default for Angular itself.
57 | */
58 | import 'zone.js/dist/zone'; // Included with Angular CLI.
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.HttpsPolicy;
8 | using Microsoft.AspNetCore.Mvc;
9 | using Microsoft.Extensions.Configuration;
10 | using Microsoft.Extensions.DependencyInjection;
11 | using Microsoft.Extensions.Hosting;
12 | using Microsoft.Extensions.Logging;
13 | using Microsoft.AspNetCore.SpaServices.AngularCli;
14 | using System.Net.WebSockets;
15 |
16 | namespace WebSocketAndNetCore.Web
17 | {
18 | public class Startup
19 | {
20 | public Startup(IConfiguration configuration)
21 | {
22 | Configuration = configuration;
23 | }
24 |
25 | public IConfiguration Configuration { get; }
26 |
27 | // This method gets called by the runtime. Use this method to add services to the container.
28 | public void ConfigureServices(IServiceCollection services)
29 | {
30 | services.AddControllers();
31 | services.AddSpaStaticFiles(config => config.RootPath = "wwwroot");
32 | services.AddSingleton(typeof(SquareService), new SquareService());
33 | }
34 |
35 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
36 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
37 | {
38 | if (env.IsDevelopment())
39 | {
40 | app.UseDeveloperExceptionPage();
41 | }
42 |
43 | app.UseStaticFiles();
44 | app.UseSpaStaticFiles();
45 |
46 | app.UseHttpsRedirection();
47 |
48 | app.UseRouting();
49 |
50 | app.UseAuthorization();
51 |
52 | app.UseEndpoints(endpoints =>
53 | {
54 | endpoints.MapControllers();
55 | });
56 |
57 | app.UseWebSockets();
58 | app.Use(async (context, next) =>
59 | {
60 | if (context.Request.Path == "/ws")
61 | {
62 | if (context.WebSockets.IsWebSocketRequest)
63 | {
64 | var socket = await context.WebSockets.AcceptWebSocketAsync();
65 | var squareService = (SquareService)app.ApplicationServices.GetService(typeof(SquareService));
66 | await squareService.AddUser(socket);
67 | }
68 | else
69 | {
70 | context.Response.StatusCode = 400;
71 | }
72 | }
73 | else
74 | {
75 | await next();
76 | }
77 | });
78 | app.UseSpa(config =>
79 | {
80 | config.Options.SourcePath = "client-app";
81 | if (env.IsDevelopment())
82 | {
83 | config.UseAngularCliServer("start");
84 | }
85 | });
86 |
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/HealthCheckPeek/HealthChecks/HealthCheckHelpers.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Http;
2 | using Microsoft.Extensions.Diagnostics.HealthChecks;
3 | using Newtonsoft.Json;
4 | using Newtonsoft.Json.Linq;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Diagnostics;
8 | using System.Linq;
9 | using System.Net.Mime;
10 | using System.Net.NetworkInformation;
11 | using System.Threading;
12 | using System.Threading.Tasks;
13 |
14 | namespace HealthCheckPeek
15 | {
16 | public class HealthCheckHelpers
17 | {
18 | public static async Task GenerateHealthCheckResultFromPIngRequest(string hostName)
19 | {
20 | using (var thePing = new Ping())
21 | {
22 | var pingResult = await thePing.SendPingAsync(hostName);
23 | var description = $"A ping of the {hostName} website";
24 | var healthCheckData = new Dictionary();
25 | healthCheckData.Add("RoundTripMS", pingResult.RoundtripTime);
26 | healthCheckData.Add("ActualIPAddress", pingResult.Address.ToString());
27 | if (pingResult.Status == IPStatus.Success)
28 | {
29 | return HealthCheckResult.Healthy(description, healthCheckData);
30 | }
31 |
32 | return HealthCheckResult.Unhealthy(description, null, healthCheckData);
33 | }
34 | }
35 |
36 | public static async Task RouteTimingHealthCheck(string routePath)
37 | {
38 | using (var client = new System.Net.WebClient())
39 | {
40 | var watch = new Stopwatch();
41 | watch.Start();
42 | var url = $"{BaseUrl}{routePath}";
43 | var result = await client.DownloadStringTaskAsync(url);
44 | watch.Stop();
45 | var milliseconds = watch.ElapsedMilliseconds;
46 | var healthCheckData = new Dictionary();
47 | healthCheckData.Add("TimeInMS", milliseconds);
48 | if (milliseconds <= 1000)
49 | return HealthCheckResult.Healthy($"call to the route {routePath}", healthCheckData);
50 | else if (milliseconds >= 1001 && milliseconds <= 2000)
51 | return HealthCheckResult.Degraded($"call to the route {routePath}", null, healthCheckData);
52 | else
53 | return HealthCheckResult.Unhealthy($"call to the route {routePath}", null, healthCheckData);
54 | }
55 | }
56 |
57 | public static async Task WriteResponses(HttpContext context, HealthReport result)
58 | {
59 | var json = new JObject(
60 | new JProperty("status", result.Status.ToString()),
61 | new JProperty("results", new JObject(result.Entries.Select(pair =>
62 | new JProperty(pair.Key, new JObject(
63 | new JProperty("status", pair.Value.Status.ToString()),
64 | new JProperty("description", pair.Value.Description),
65 | new JProperty("data", new JObject(pair.Value.Data.Select(
66 | p => new JProperty(p.Key, p.Value))))))))));
67 |
68 | context.Response.ContentType = MediaTypeNames.Application.Json;
69 | await context.Response.WriteAsync(json.ToString(Formatting.Indented));
70 | }
71 |
72 | public static string BaseUrl { get; set; }
73 | }
74 | }
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using FirebaseAdmin;
7 | using Google.Apis.Auth.OAuth2;
8 | using Microsoft.AspNetCore.Authentication.JwtBearer;
9 | using Microsoft.AspNetCore.Builder;
10 | using Microsoft.AspNetCore.Hosting;
11 | using Microsoft.AspNetCore.HttpsPolicy;
12 | using Microsoft.AspNetCore.Mvc;
13 | using Microsoft.AspNetCore.SpaServices.AngularCli;
14 | using Microsoft.Extensions.Configuration;
15 | using Microsoft.Extensions.DependencyInjection;
16 | using Microsoft.Extensions.Hosting;
17 | using Microsoft.Extensions.Logging;
18 | using Microsoft.IdentityModel.Tokens;
19 |
20 | namespace FirebaseAndAngular.Web
21 | {
22 | public class Startup
23 | {
24 | public Startup(IConfiguration configuration,IWebHostEnvironment env)
25 | {
26 | Configuration = configuration;
27 | HostingEnvironment = env;
28 | }
29 |
30 | public IConfiguration Configuration { get; }
31 | public IWebHostEnvironment HostingEnvironment { get; set; }
32 | // This method gets called by the runtime. Use this method to add services to the container.
33 | public void ConfigureServices(IServiceCollection services)
34 | {
35 | services.AddSpaStaticFiles(config =>
36 | {
37 | config.RootPath = "wwwroot";
38 | });
39 |
40 | services.AddControllers();
41 |
42 | var pathToKey = Path.Combine(Directory.GetCurrentDirectory(), "keys", "firebase_admin_sdk.json");
43 |
44 | if (HostingEnvironment.IsEnvironment("local"))
45 | pathToKey = Path.Combine(Directory.GetCurrentDirectory(), "keys", "firebase_admin_sdk.local.json");
46 |
47 | FirebaseApp.Create(new AppOptions
48 | {
49 | Credential = GoogleCredential.FromFile(pathToKey)
50 | });
51 |
52 | services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
53 | .AddJwtBearer(options =>
54 | {
55 | var firebaseProjectName = Configuration["FirebaseProjectName"];
56 | options.Authority = "https://securetoken.google.com/" + firebaseProjectName;
57 | options.TokenValidationParameters = new TokenValidationParameters
58 | {
59 | ValidateIssuer = true,
60 | ValidIssuer = "https://securetoken.google.com/" + firebaseProjectName,
61 | ValidateAudience = true,
62 | ValidAudience = firebaseProjectName,
63 | ValidateLifetime = true
64 | };
65 | });
66 | }
67 |
68 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
69 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
70 | {
71 | if (env.IsDevelopment())
72 | {
73 | app.UseDeveloperExceptionPage();
74 | }
75 |
76 | app.UseStaticFiles();
77 | app.UseSpaStaticFiles();
78 | app.UseHttpsRedirection();
79 |
80 | app.UseRouting();
81 |
82 | app.UseAuthentication();
83 | app.UseAuthorization();
84 |
85 | app.UseEndpoints(endpoints =>
86 | {
87 | endpoints.MapControllers();
88 | });
89 | app.UseSpa(spa =>
90 | {
91 | spa.Options.SourcePath = "client-app";
92 | if (env.IsDevelopment() || env.IsEnvironment("local"))
93 | {
94 | var startScript = env.IsEnvironment("local") ? "start-local" : "start";
95 | spa.UseAngularCliServer(npmScript: startScript);
96 | }
97 |
98 | });
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/HealthCheckPeek/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Net.Mime;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Builder;
7 | using Microsoft.AspNetCore.Diagnostics.HealthChecks;
8 | using Microsoft.AspNetCore.Hosting;
9 | using Microsoft.AspNetCore.Http;
10 | using Microsoft.AspNetCore.HttpsPolicy;
11 | using Microsoft.AspNetCore.Mvc;
12 | using Microsoft.Extensions.Configuration;
13 | using Microsoft.Extensions.DependencyInjection;
14 | using Microsoft.Extensions.Diagnostics.HealthChecks;
15 | using Microsoft.Extensions.Hosting;
16 | using Microsoft.Extensions.Logging;
17 | using Newtonsoft.Json;
18 | using Newtonsoft.Json.Linq;
19 | using Microsoft.EntityFrameworkCore;
20 |
21 | namespace HealthCheckPeek
22 | {
23 | public class Startup
24 | {
25 | public Startup(IConfiguration configuration)
26 | {
27 | Configuration = configuration;
28 | }
29 |
30 | public IConfiguration Configuration { get; }
31 |
32 | // This method gets called by the runtime. Use this method to add services to the container.
33 | public void ConfigureServices(IServiceCollection services)
34 | {
35 | services.AddControllers();
36 | services.AddHealthChecks()
37 | .AddAsyncCheck("google_ping_check", () => HealthCheckHelpers.GenerateHealthCheckResultFromPIngRequest("google.com"))
38 | .AddAsyncCheck("microsoft_ping_check", () => HealthCheckHelpers.GenerateHealthCheckResultFromPIngRequest("microsoft.com"))
39 | .AddAsyncCheck("yahoo_ping_check", () => HealthCheckHelpers.GenerateHealthCheckResultFromPIngRequest("yahoo.com"))
40 | .AddAsyncCheck("localhost_ping_check", () => HealthCheckHelpers.GenerateHealthCheckResultFromPIngRequest("localhost"))
41 | .AddAsyncCheck("forecast_time_check", () => HealthCheckHelpers.RouteTimingHealthCheck("/weatherforecast"))
42 | .AddAsyncCheck("forecast_time_check_slow", () => HealthCheckHelpers.RouteTimingHealthCheck("/weatherforecast/slow"))
43 | .AddDbContextCheck("database_check", tags: new[] { "database" });
44 | services.AddHttpContextAccessor();
45 |
46 | services.AddDbContext(options =>
47 | {
48 | options.UseSqlServer(@"Connection_string_here");
49 | });
50 | }
51 |
52 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
53 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
54 | {
55 | app.Use(async (context, next) =>
56 | {
57 | HealthCheckHelpers.BaseUrl = $"{ context.Request.Scheme}://{context.Request.Host}";
58 | await next();
59 | });
60 |
61 | app.UseHealthChecks("/health",
62 | new HealthCheckOptions
63 | {
64 | ResponseWriter = HealthCheckHelpers.WriteResponses
65 | });
66 |
67 | if (env.IsDevelopment())
68 | {
69 | app.UseDeveloperExceptionPage();
70 | }
71 |
72 | app.UseHttpsRedirection();
73 |
74 | app.UseRouting();
75 |
76 | app.UseAuthorization();
77 |
78 | app.UseEndpoints(endpoints =>
79 | {
80 | endpoints.MapHealthChecks("/health/database", new HealthCheckOptions
81 | {
82 | Predicate = (check) => check.Tags.Contains("database"),
83 | ResponseWriter = HealthCheckHelpers.WriteResponses
84 | });
85 |
86 | endpoints.MapHealthChecks("/health/websites", new HealthCheckOptions
87 | {
88 | Predicate = (check) => check.Tags.Contains("websites"),
89 | ResponseWriter = HealthCheckHelpers.WriteResponses
90 | });
91 |
92 | endpoints.MapControllers();
93 | });
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/client-app/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "client-app": {
7 | "projectType": "application",
8 | "schematics": {
9 | "@schematics/angular:component": {
10 | "style": "scss"
11 | }
12 | },
13 | "root": "",
14 | "sourceRoot": "src",
15 | "prefix": "app",
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-devkit/build-angular:browser",
19 | "options": {
20 | "outputPath": "wwwroot",
21 | "index": "src/index.html",
22 | "main": "src/main.ts",
23 | "polyfills": "src/polyfills.ts",
24 | "tsConfig": "tsconfig.app.json",
25 | "aot": false,
26 | "assets": [
27 | "src/favicon.ico",
28 | "src/assets"
29 | ],
30 | "styles": [
31 | "src/styles.scss"
32 | ],
33 | "scripts": []
34 | },
35 | "configurations": {
36 | "production": {
37 | "fileReplacements": [
38 | {
39 | "replace": "src/environments/environment.ts",
40 | "with": "src/environments/environment.prod.ts"
41 | }
42 | ],
43 | "optimization": true,
44 | "outputHashing": "all",
45 | "sourceMap": false,
46 | "extractCss": true,
47 | "namedChunks": false,
48 | "aot": true,
49 | "extractLicenses": true,
50 | "vendorChunk": false,
51 | "buildOptimizer": true,
52 | "budgets": [
53 | {
54 | "type": "initial",
55 | "maximumWarning": "2mb",
56 | "maximumError": "5mb"
57 | },
58 | {
59 | "type": "anyComponentStyle",
60 | "maximumWarning": "6kb",
61 | "maximumError": "10kb"
62 | }
63 | ]
64 | }
65 | }
66 | },
67 | "serve": {
68 | "builder": "@angular-devkit/build-angular:dev-server",
69 | "options": {
70 | "browserTarget": "client-app:build"
71 | },
72 | "configurations": {
73 | "production": {
74 | "browserTarget": "client-app:build:production"
75 | }
76 | }
77 | },
78 | "extract-i18n": {
79 | "builder": "@angular-devkit/build-angular:extract-i18n",
80 | "options": {
81 | "browserTarget": "client-app:build"
82 | }
83 | },
84 | "test": {
85 | "builder": "@angular-devkit/build-angular:karma",
86 | "options": {
87 | "main": "src/test.ts",
88 | "polyfills": "src/polyfills.ts",
89 | "tsConfig": "tsconfig.spec.json",
90 | "karmaConfig": "karma.conf.js",
91 | "assets": [
92 | "src/favicon.ico",
93 | "src/assets"
94 | ],
95 | "styles": [
96 | "src/styles.scss"
97 | ],
98 | "scripts": []
99 | }
100 | },
101 | "lint": {
102 | "builder": "@angular-devkit/build-angular:tslint",
103 | "options": {
104 | "tsConfig": [
105 | "tsconfig.app.json",
106 | "tsconfig.spec.json",
107 | "e2e/tsconfig.json"
108 | ],
109 | "exclude": [
110 | "**/node_modules/**"
111 | ]
112 | }
113 | },
114 | "e2e": {
115 | "builder": "@angular-devkit/build-angular:protractor",
116 | "options": {
117 | "protractorConfig": "e2e/protractor.conf.js",
118 | "devServerTarget": "client-app:serve"
119 | },
120 | "configurations": {
121 | "production": {
122 | "devServerTarget": "client-app:serve:production"
123 | }
124 | }
125 | }
126 | }
127 | }},
128 | "defaultProject": "client-app"
129 | }
130 |
--------------------------------------------------------------------------------
/FirebaseAndAngularAndDotnetCore/client-app/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "client-app": {
7 | "projectType": "application",
8 | "schematics": {
9 | "@schematics/angular:component": {
10 | "style": "scss"
11 | }
12 | },
13 | "root": "",
14 | "sourceRoot": "src",
15 | "prefix": "app",
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-devkit/build-angular:browser",
19 | "options": {
20 | "outputPath": "wwwroot",
21 | "index": "src/index.html",
22 | "main": "src/main.ts",
23 | "polyfills": "src/polyfills.ts",
24 | "tsConfig": "tsconfig.app.json",
25 | "aot": false,
26 | "assets": [
27 | "src/favicon.ico",
28 | "src/assets"
29 | ],
30 | "styles": [
31 | "src/styles.scss"
32 | ],
33 | "scripts": []
34 | },
35 | "configurations": {
36 | "local": {
37 | "fileReplacements": [
38 | {
39 | "replace": "src/environments/environment.ts",
40 | "with": "src/environments/environment.local.ts"
41 | }
42 | ]
43 | },
44 | "production": {
45 | "fileReplacements": [
46 | {
47 | "replace": "src/environments/environment.ts",
48 | "with": "src/environments/environment.prod.ts"
49 | }
50 | ],
51 | "optimization": true,
52 | "outputHashing": "all",
53 | "sourceMap": false,
54 | "extractCss": true,
55 | "namedChunks": false,
56 | "aot": true,
57 | "extractLicenses": true,
58 | "vendorChunk": false,
59 | "buildOptimizer": true,
60 | "budgets": [
61 | {
62 | "type": "initial",
63 | "maximumWarning": "2mb",
64 | "maximumError": "5mb"
65 | },
66 | {
67 | "type": "anyComponentStyle",
68 | "maximumWarning": "6kb",
69 | "maximumError": "10kb"
70 | }
71 | ]
72 | }
73 | }
74 | },
75 | "serve": {
76 | "builder": "@angular-devkit/build-angular:dev-server",
77 | "options": {
78 | "browserTarget": "client-app:build"
79 | },
80 | "configurations": {
81 | "production": {
82 | "browserTarget": "client-app:build:production"
83 | },
84 | "local": {
85 | "browserTarget": "client-app:build:local"
86 | }
87 | }
88 | },
89 | "extract-i18n": {
90 | "builder": "@angular-devkit/build-angular:extract-i18n",
91 | "options": {
92 | "browserTarget": "client-app:build"
93 | }
94 | },
95 | "test": {
96 | "builder": "@angular-devkit/build-angular:karma",
97 | "options": {
98 | "main": "src/test.ts",
99 | "polyfills": "src/polyfills.ts",
100 | "tsConfig": "tsconfig.spec.json",
101 | "karmaConfig": "karma.conf.js",
102 | "assets": [
103 | "src/favicon.ico",
104 | "src/assets"
105 | ],
106 | "styles": [
107 | "src/styles.scss"
108 | ],
109 | "scripts": []
110 | }
111 | },
112 | "lint": {
113 | "builder": "@angular-devkit/build-angular:tslint",
114 | "options": {
115 | "tsConfig": [
116 | "tsconfig.app.json",
117 | "tsconfig.spec.json",
118 | "e2e/tsconfig.json"
119 | ],
120 | "exclude": [
121 | "**/node_modules/**"
122 | ]
123 | }
124 | },
125 | "e2e": {
126 | "builder": "@angular-devkit/build-angular:protractor",
127 | "options": {
128 | "protractorConfig": "e2e/protractor.conf.js",
129 | "devServerTarget": "client-app:serve"
130 | },
131 | "configurations": {
132 | "production": {
133 | "devServerTarget": "client-app:serve:production"
134 | }
135 | }
136 | }
137 | }
138 | }},
139 | "defaultProject": "client-app"
140 | }
141 |
--------------------------------------------------------------------------------
/WebSocketAndNetCore/SquareService.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Concurrent;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Net.WebSockets;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 |
10 | namespace WebSocketAndNetCore.Web
11 | {
12 | public class SquareService
13 | {
14 | private ConcurrentDictionary _users = new ConcurrentDictionary();
15 | private List _squares = new List(Square.GetInitialSquares());
16 | public async Task AddUser(WebSocket socket)
17 | {
18 | try
19 | {
20 | var name = GenerateName();
21 | var userAddedSuccessfully = _users.TryAdd(name, socket);
22 | while (!userAddedSuccessfully)
23 | {
24 | name = GenerateName();
25 | userAddedSuccessfully = _users.TryAdd(name, socket);
26 | }
27 |
28 | GiveUserTheirName(name, socket).Wait();
29 | AnnounceNewUser(name).Wait();
30 | SendSquares(socket).Wait();
31 | while (socket.State == WebSocketState.Open)
32 | {
33 | var buffer = new byte[1024 * 4];
34 | WebSocketReceiveResult socketResponse;
35 | var package = new List();
36 | do
37 | {
38 | socketResponse = await socket.ReceiveAsync(new ArraySegment(buffer), CancellationToken.None);
39 | package.AddRange(new ArraySegment(buffer, 0, socketResponse.Count));
40 | } while (!socketResponse.EndOfMessage);
41 | var bufferAsString = System.Text.Encoding.ASCII.GetString(package.ToArray());
42 | if (!string.IsNullOrEmpty(bufferAsString))
43 | {
44 | var changeRequest = SquareChangeRequest.FromJson(bufferAsString);
45 | await HandleSquareChangeRequest(changeRequest);
46 | }
47 | }
48 | await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);
49 | }
50 | catch (Exception ex)
51 | { }
52 | }
53 |
54 | private string GenerateName()
55 | {
56 | var prefix = "WebUser";
57 | Random ran = new Random();
58 | var name = prefix + ran.Next(1, 1000);
59 | while (_users.ContainsKey(name))
60 | {
61 | name = prefix + ran.Next(1, 1000);
62 | }
63 | return name;
64 | }
65 |
66 | private async Task SendSquares(WebSocket socket)
67 | {
68 | var message = new SocketMessage>()
69 | {
70 | MessageType = "squares",
71 | Payload = _squares
72 | };
73 |
74 | await Send(message.ToJson(), socket);
75 | }
76 |
77 | private async Task SendAll(string message)
78 | {
79 | await Send(message, _users.Values.ToArray());
80 | }
81 |
82 | private async Task Send(string message, params WebSocket[] socketsToSendTo)
83 | {
84 | var sockets = socketsToSendTo.Where(s => s.State == WebSocketState.Open);
85 | foreach (var theSocket in sockets)
86 | {
87 | var stringAsBytes = System.Text.Encoding.ASCII.GetBytes(message);
88 | var byteArraySegment = new ArraySegment(stringAsBytes, 0, stringAsBytes.Length);
89 | await theSocket.SendAsync(byteArraySegment, WebSocketMessageType.Text, true, CancellationToken.None);
90 | }
91 | }
92 |
93 | private async Task GiveUserTheirName(string name, WebSocket socket)
94 | {
95 | var message = new SocketMessage
96 | {
97 | MessageType = "name",
98 | Payload = name
99 | };
100 | await Send(message.ToJson(), socket);
101 | }
102 |
103 | private async Task AnnounceNewUser(string name)
104 | {
105 | var message = new SocketMessage
106 | {
107 | MessageType = "announce",
108 | Payload = $"{name} has joined"
109 | };
110 | await SendAll(message.ToJson());
111 | }
112 |
113 | private async Task AnnounceSquareChange(SquareChangeRequest request)
114 | {
115 | var message = new SocketMessage
116 | {
117 | MessageType = "announce",
118 | Payload = $"{request.Name} has changed square #{request.Id} to {request.Color}"
119 | };
120 | await SendAll(message.ToJson());
121 | }
122 |
123 | private async Task HandleSquareChangeRequest(SquareChangeRequest request)
124 | {
125 | var theSquare = _squares.First(sq => sq.Id == request.Id);
126 | theSquare.Color = request.Color;
127 | await SendSquaresToAll();
128 | await AnnounceSquareChange(request);
129 | }
130 |
131 | private async Task SendSquaresToAll()
132 | {
133 | var message = new SocketMessage>()
134 | {
135 | MessageType = "squares",
136 | Payload = _squares
137 | };
138 |
139 | await SendAll(message.ToJson());
140 | }
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 | /FirebaseAndAngularAndDotnetCore/keys/firebase_admin_sdk.local.json
352 | /FirebaseAndAngularAndDotnetCore/appsettings.local.json
353 |
--------------------------------------------------------------------------------