Friday, January 24, 2020

New Preview Features is available in Azure Database

Microsoft had integrate some new features in Azure Database

when i play with the Azure Database today, I spotted that there a new section called Power platform

the new features will allow the user build reports, PowerApp and workflow against the database.


 







here is list of flow template for free trial









these new features will definitely increase the productivity in the azure database.

Wednesday, January 22, 2020

Tricky C# interview question

I had been asked to trace the following code for the output

  class Program
    {
        public delegate void Iterator();
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            List<Iterator> interators = new List<Iterator>();
            for (int i = 0; i < 15; i++)
            {
                interators.Add(delegate { Console.WriteLine(i); });
            }

            foreach (var interator in interators)
            {
                interator();
            }
            Console.Read();
        }
    }

Do you like to try it?
 


Monday, January 20, 2020

how to fix "error NG8001: "your selector'' is not a known element" in Angular Development

after i run npm build to compile my angular project

i got the following error

C:\DanAngular\triathlon-app>ng build

ERROR in src/app/results/results/results.component.html:2:1 - error NG8001: 'results-list' is not a known element:
1. If 'results-list' is an Angular component, then verify that it is part of this module.
2. If 'results-list' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

2 <results-list (selected)=showDetails($event)>Loading athelete list ...</results-list>


when i go inside my project and locate the results-list.component.ts

the selector had been defined as app-results-list

@Component({
  selector: 'app-results-list',
  templateUrl: './results-list.component.html',
  styleUrls: ['./results-list.component.scss']
})
export class ResultsListComponent implements OnInit {
  athletesAthlete[];
  timingPointsTimingPoint[];
  @Output() selected=new EventEmitter<Athlete>();

  constructor(private athleteServiceAthleteServiceService) { }



 <results-list (selected)=showDetails($event)>Loading athelete list ...</results-list>

should use app-results-list as the selector.

 <app-results-list (selected)=showDetails($event)>Loading athelete list ...</app-results-list>



how to fix "Property 'map' does not exist on type 'Observable'" in Angular Development

1. first install the latest ReactJS compact package

     npm install --save rxjs-compat@6

2. reference to the rxjs/rx

import 'rxjs/Rx';





Angular Development Quick Tips 2


1. Import {Http, Response} from '@angular/http' will cause a not error if you do not expressively install the libary.

npm install @angular/http@latest.

for the latest angular/CLI, the library had been moved to @angular/common/http.

we should use the correct path

Import {Http, Response} from '@angular/common/http'

2. how to generate a component inside the specific folder without a folder

npm g c specifiFolder/mycomponent --flat -d

the  --flat instructed the npm command to generate a component without a folder.

-d will force a dry run and show you the output in the windows only. you can verify the output before generating them.



 



Saturday, January 18, 2020

how to fix the tricky component or function 'is not defined react/jsx-no-undef' error in React Development

here is the code for customsection.js

import React, { Component } from "react"


class CustomSection extends Component{
    render(){ 
        return (
        <h1>Hello Custom Section</h1>
        );
    }
}

export default CustomSection;

then i have the code from the App.js will have the CustomerSection component

import React, { Component } from 'react';

import  './CustomSection'
class App extends Component {
  render(){
  return (
    <div> 
      <h1>Hello World</h1>
      <CustomSection />
    </div>
  );
  }
}

export default App;


it looks simple and straight, however when i compile the code in the visual studio terminal

npm run-script build

PS C:\DanAngular\dan-react\my-first-react> npm run-script build

> my-first-react@0.1.0 build C:\DanAngular\dan-react\my-first-react
> react-scripts build

Creating an optimized production build...
Failed to compile.

./src/App.js
  Line 28:8:  'CustomSection' is not defined  react/jsx-no-undef

Search for the keywords to learn more about each error.





the error stems from this line

import  './CustomSection'

we must specific the component name in the import. that is very practice, i really like this checking on the compile time. it will enforce the proper component being reference and will be called.

import CustomSection from './CustomSection'

after i fixed this line, then the project compiled and ran,








my first try on the react is good and running


Happy programming, Cheers





Thursday, January 16, 2020

how to quickly setup a swagger in asp.net core Web API project with visual studio

1. Create a ASP.Net web project with Visual studio

2. Install the Swagger package in the Package Manager window

              Install-Package Swashbuckle.AspNetCore

 3. add swagger generator to services collection which is the dependency injection container

        services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
            });

4. setup the swagger in the configure method
         // enable the swagger middleware
           app.UseSwagger();

            // Enable middleware to serve swagger-ui
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

5. launch the app and view the swagger ui from the link below, please note the port will be different

  https://localhost:{port}/swagger/index.html

   for my local development i had the following

     https://localhost:44392/swagger/index.html



Tuesday, January 14, 2020

Interview Question 1.

I am actively looking for new opportunties now. i will keep posting the interview question that had been asked in each interview. i hope you can learn from the interview questions.

1.if the element is not found, but it showed in the inspector what reason


A: the function had been called, before the DOM is ready

1.how to generate a token in .net?

2. can two same class in the stylesheet.

3. what is cause that style border is black, but show red in the browser?

4. how to trouble the slow sql dynamic query?

5. how do you do the eblast for marketing?

6. how do you send a link to a customer, that will automatically redirect to the customer account?

7. SQL injection

8. customerError in web config file, how do you enable the error message with customError="RemoteOnly"?

9. static variable vs normal variable

A: static variable can be access with instantiate the class, out of class scope if the access modifier is public
normal variable can not be access without instantiate the class.


Friday, January 10, 2020

A new tool App Service Editor is currently under preview in Azure Portal

I just found a new feature in the Azure Portal today. it is a web based tool for Azure Web App in the Development Tool section of App Service.












after you click on the App Service Editor item. it will popup a new page.









if you want to learn more information about this new tool, please check on the link below

Understanding the Azure App Service Editor

How to troubleshoot the sync failed issue in DevOps deployment?

After i push the change from local to Github, then i click on the sync button in the deployment center.






How the status indicated that the sync result is failed. we can check the issue by click on the Log button to expand the log section.











Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
D:\Program Files (x86)\dotnet\sdk\2.2.109\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\home\site\repository\DanCoreWebApp\DanCoreWebApp.csproj]
D:\Program Files (x86)\dotnet\sdk\2.2.109\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\home\site\repository\WebApp2\WebApp2.csproj]
Failed exitCode=1, command=dotnet restore "D:\home\site\repository\DanCoreWebApp.sln"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\85.11214.4277\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

the error log showed that .Net Core version issue. Currently Azure does not support the .Net Core 3.0 in the production.





Sunday, January 5, 2020

Angular Development Quick Tip 1

1. Augury is the great chrome add in to visualize data for Angular Development

you can give it here

https://chrome.google.com/webstore/detail/augury/elgalmkoelokbchhkhacckoklkejnhcd/related?hl=en










2. run ng generate command with -d flag to verify the location, name etc before it really create them.
 since dry run mode will not make any change in the current solution

ng generate service myService -d








C:\DanAngular\dan-app>ng generate service myService -d
CREATE src/app/my-service.service.spec.ts (349 bytes)
CREATE src/app/my-service.service.ts (138 bytes)

NOTE: The "dryRun" flag means no changes were made.

from the above output, I should be able to find that i do not need to use myService as the service name

i tweak my command to ng generate serivce my -d








C:\DanAngular\dan-app>ng generate service my -d
CREATE src/app/my.service.spec.ts (313 bytes)
CREATE src/app/my.service.ts (131 bytes)

NOTE: The "dryRun" flag means no changes were made.





Thursday, January 2, 2020

Handy Tool to Manipulate JSON Data

1. Andrew Friedman create an online tool to convert C# data object to JSON format Data.

it will really help in generate JSON data to Test Web API

https://csharp2json.io/

2. Jonathan Keith launched a web site for converting JSON Data to C# Class

it will reduce the time to code the Business Object for Web API consumption. Since we can get the sample JSON Data from web api portal or web api swagger. we just have to copy the sample JSON data and paste input the textbox, then click generate.

we can copy the output and add them to your project. it can save time and avoid the typo error.

http://json2csharp.com/