Microsoft Photos App is the App that comes with Windows 10.
I turns out you can back it up or move it to another user if you copy the following directory:
C:\Users\<your_username>\AppData\Local\Packages\Microsoft.Windows.Photos_8wekyb3d8bbwe-av.zip\Microsoft.Windows.Photos_8wekyb3d8bbwe
Where <your_username> is your username. This contains things like the photos, albums, face recognition data, tags, etc.
Microsoft has conveniently placed all this information in a SQLite database which is located at:
C:\Users\<your_username>\AppData\Local\Packages\Microsoft.Windows.Photos_8wekyb3d8bbwe\LocalState\MediaDb.v1.sqlite
To view the data you can easily do so using DB Browser for SQLite.
If you are a developer this gives you a lot of information along with a pretty nice UI backed by Cognitive Services Face API (or so I assume). The difference is you don't have to pay for use of it because Microsoft is giving it to you for free with the Photos App (indirectly). All you have to do is query the SQLite database for any data you might want. Pretty nice. Thanks Microsoft.
Some tables you might find useful are:
TagVarient - the name of the tag (airplane, ocean, house, etc)
Tag - related to TagVarient and
Item - your photo or video name, size, location, duration, metadata, etc
ItemTags - joins the Tag and Item tables includes confidence score
Folder - the folders that contain your pictures and their sub folders.
Location - cities where the photos / videos were taken
Person - the people that it tagged and you grouped or it grouped. Represents the items on the People tab in the app. Includes count of people that match that face.
Face - information of where the faces are in each picture
Album - albums (generated). Not sure if self-created ones are here, but I assume they are.
Assumptions:
- Running in Visual Studio 2017
- Running an application on port 8888
- Url used to access the application is http://localhost:8888
If you want to access the web site using http://somenamehere:8888 you can do this by doing the following.
- Open your .vs/config/applicationhost.config file in a text editor
- Find the binding for your application.
<binding protocol="http" bindingInformation="*:8888:localhost" />
- In the same <bindings> section, add another <binding>
<binding protocol="http" bindingInformation="*:8888:" />
- Optional: If you are using https you will need to do the same. The key is that you match the ports.
You should be able to launch your web site in Visual Studio (Control-F5, etc). This will bring it up as it always have.
Now you need to hack your dns so that it can resolve your new made up hostname. In this example, it is somenamehere. The easiest way to do this is to open up your hosts file (C:\Windows\System32\drivers\etc\hosts) in a text editor and add the following line to the bottom of it.
127.0.0.1 somenamehere
You should now be able to ping that hostname and see that 127.0.0.1 is responding.
Now open up the browser and go to http://somenamehere:8888 and you should get your application again.
NOTE: If VS2017 gives you any issues, it may be helpful to run it as administrator.
In many email clients it will now show you the first line of the email body before you open it. If you are a developer creating this email sometimes it shows things like a url of a header image instead of something more useful. The good news is you can trick the email clients into displaying whatever you want. Just make sure the first thing in your body tag (can be after the style tag, etc) is the following:
<!-- HIDDEN PREHEADER TEXT -->
<div style="display: none; mso-hide: all; width: 0px; height: 0px; max-width: 0px; max-height: 0px; font-size: 0px; line-height: 0px;">
Whatever you want to see in the preview here
</div>
See here for Microsofts official recommendations on best practices to keep secrets out of the web config.
I am mostly concerned about appSettings and connectionStrings sections in the web.config
The Microsoft article says everything I am going to say below, but they are some important points to consider.
appSettings
To keep your appSettings secret, put them in another file that is not checked into source control. The contents of this file will be merged with what is in the web.config so this works well to allow developers to override values in appSettings.
The syntax is basically
<appSettings file="..\..\AppSettingsSecrets.config">
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
The file attribute accepts paths that are relative or absolve and the file does not have to exist. This is useful when deploying to different environments that may not use this file and instead use VSTS / replacing of tokens to manage values per environment.
connectionStrings
The connectionStrings section isn't as nice as the appSettings. The tags between connectionString tags are replaced by the contents of the external file. The file referenced MUST be in the same directory as the web.config that is referencing it. This means the secret file is per project. The other thing that makes it not work as easily is that it MUST exist otherwise you will get a build error because the project file will try to find the file. You can edit the project file and tell it to only include the file in the project for particular environments, but that is tedious and must be done on each project file.
You don't need to open up Visual Studio just to run another project. You can run IISExpress via the command line instead.
Here is the same example, once for the command prompt and again for Powershell. The name of the site can be found in the applicationhost.config file. You'll see a <site> tag and the name attribute is the siteName. This is also the name that shows up in the system tray when you launch the site in Visual Studio itself.
You can use the system tray IIS Express icon to quit instances started using Powershell or command prompt. You can also type a the letter Q at the command prompt that gets spawned.
Command Prompt
"C:\Program Files (x86)\IIS Express\iisexpress.exe" /config:"C:\dev\MyMvcApp\.vs\config\applicationhost.config" /site:"MyMvcApp"
You'll need to tweak this to match your paths, etc.
Powershell
$scriptDir = Split-Path $script:MyInvocation.MyCommand.Path
function Start-IisExpress($config, $siteName) {
Start-Process -FilePath 'C:\Program Files (x86)\IIS Express\iisexpress.exe' -ArgumentList "/config:$config /site:$siteName"
}
Start-IisExpress -config "$scriptDir\.vs\config\applicationhost.config" -siteName: "MyMvcApp"
NOTE: This assumes that you have put this in a Powershell (.ps1) file and placed it next to your solution and more importantly that the .vs directory is in the same directory as the .ps1 file. If not, you'll need to adjust the path or hard code the full path.
Install Angular CLI
If you don't have Angular CLI you will need to install it using npm
npm install -g @angular/cli
Usage
ng g c products/product-detail.component --flat
ng = Angular CLI
g = generate
c = component
--flat = no folder will be created
This will create 4 files:
src\app\products\product-detail\product-detail.component.css
src\app\products\product-detail\product-detail.component.html
src\app\products\product-detail\product-detail.component.spec.ts
src\app\products\product-detail\product-detail.component.ts
It will update the file which will register the component in the app.module.ts:
src\app\app.module.ts
It will also wire the components together putting some useful code in
src\app\products\product-detail\product-detail.component.ts
Import HttpClientModule
Add HttpClientModule to the imports array of one of the application's Angular Modules
The items in bold are the ones that are specific to adding http.
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [ AppComponent, ],
imports: [ HttpClientModule, BrowserModule, FormsModule ],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Adding Http to Service
my.service.ts
import { Injectable } from "@angular/core";
import { IProduct } from "./product";
import { HttpClient } from "@angular/common/http";
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/Observable/throw'
import 'rxjs/add/operator/catch'
import 'rxjs/add/operator/do'
import { HttpErrorResponse } from "@angular/common/http";
@Injectable()
export class ThingService {
private _thingUrl = 'www.myWebApi.com/api/myThings';
constructor (private _http: HttpClient){ }
getMyThings(): Observable<IThing[]> {
return this._http.get<IThing[]>(this._thingUrl)
.do(data => console.log('data: ' + JSON.stringify(data)))
.catch(this.handleError);
}
private handleError(err: HttpErrorResponse) {
return Observable.throw(err.message);
}
}
TIP: The url can be to a local JSON file that has the desired response. This can be useful for mocking out the web service you are calling when testing or rapidly developing.
Using Service / Subscribing
Call the subscribe method of the returned observable
In your component you could have something like this.
ngOnInit(): void {
this._productService.myThings()
.subscribe(things => {
this.things = things;
},
error => {
/// handle error here...
});
}
What is a service
Simply put it is a class with a focused purpose. Generally it is not specific to any component, and thus provides logic that can be used for different components. Useful for encapsulating external interactions such as web api calls, etc.
Dependency Injection
We can use Angular and Dependency Injection to inject the service into the component. This makes testing much easier by allowing for Mocks. Luckily, Angular has a built in injector.
In order for a component to use the service it just needs to add a parameter to the constructor of the component.
Example:
my.service.ts
import { Injectable } from '@angular/core'
@Injectable()
export class MyService {
getMyThings() : IThing[] { ... }
}
export class MyComponent {
private _myService;
constructor(myService: MyService) {
_myService = myService
}
}
Tip: Here is the same MyComponent class, but in shorter syntax
export class MyComponent {
constructor(private _myService: MyService) {
}
}
Registering the Service
A service can be registered at with different scope. Choose the right method to get the right scope.
Method 1: Registering a Provider
To make the service available to a component and its children add it to the array of providers where the component is defined.
import { MyService } from './my.service';
@Component({
selector: ...,
template: ...,
providers: [MyService]
})
export class MyComponent {
constructor(private _myService) {}
}
Common Data Types
string
number
boolean
any - when we don't care what the type is
Using Data Types
export class MyClass {
name: string = "Test";
}
Functions
export class MyClass {
doSomething(name: string) : void {
}
}
Interface
export interface IMyClass {
name: string;
code: string;
doSomething(name: string) : void
}
Class Inheriting from Interface
import { IMyClass } from './myClass';
export class MyClass implements IMyClass {
constructor(name: string, code: string) {
}
doSomething(name: string) : void { ... }
}
Now we want to extend our Display-Only nested component to take input from the user. If the user clicks the stars then notify the parent component.
In the Parent component
Using the nested component
We use it just as you would any component. To get data from the nested component we use the banana in the box [()] syntax.
<myApp-star [rating]='product.starRating'
[(notify)]='onRatingClicked($event)'></myApp-star>
$event passes along the appropriate information associated with the event.
Handle the event in the parent component
Add this to the parent component class (.ts file).
onRatingClicked(message: string) : void {
// do something with the data sent to us via the message parameter
}
Implementing the Nested Component
star.component.ts
import { Component, OnChanges, Input } from "@angular/core";
import { Component, OnChanges, Input, Output, EventEmitter } from "@angular/core";
@Component({
selector: 'pm-star',
templateUrl: './star.component.html',
styleUrls: ['./star.component.css']
})
export class StarComponent implements OnChanges {
@Input() rating: number;
starWidth: number;
@Output() ratingClicked: EventEmitter<string> = new EventEmitter<string>();
ngOnChanges(): void {
this.starWidth = this.rating * 86/5;
}
onClick() : void {
this.ratingClicked.emit('The rating ' + this.rating + ' was clicked');
}
}
Passing data from the nested container to the parent component
The only way to pass data to the parent component is using an event. It needs to be decorated with the @Output for this to work. In this example we are passing a type string, but it could be any object for more complex data.
star.component.html
<div class="crop"
[style.width.px]="starWidth"
[title]="rating"
(click)='onClick()'>
<div style="width: 86px">
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
</div>
</div>
Notice that rating is a property in the star component and so is title
Using the nested component
If we assume the source below is from some parent component html file it might look like this if we are showing a numeric value for the rating of a product.
{{product.startRating}}
If we then want to use a custom component (nested component) to show a nice graphical star rating instead of the numeric value we would use the syntax (property binding syntax) below assuming our component has a selector of myApp-star and has an input property called rating.
<myApp-star [rating]='product.starRating'></myApp-star>
Implementing the Nested Component
Typically nested components are kept in the shared directory of the project.
Use the component by adding it to the module as a declaration.
Input is sent from the parent component to the child (nested) component using a property on the nested component.
star.component.ts
import { Component, OnChanges, Input } from "@angular/core";
@Component({
selector: 'myApp-star',
templateUrl: './star.component.html',
styleUrls: ['./star.component.css']
})
export class StarComponent implements OnChanges {
@Input() rating: number;
starWidth: number;
ngOnChanges(): void {
this.starWidth = this.rating * 86/5;
}
}
Passing data from parent to nested component
Notice the @Input decorator. It is required to expose a property to a parent component in the html file. The starWidth is recalculated whenever the rating property changes.
star.component.html
<div class="crop"
[style.width.px]="starWidth"
[title]="rating">
<div style="width: 86px">
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
</div>
</div>
Notice that rating is a property in the star component and so is title
star.component.css
.crop {
overflow: hidden;
}
div {
cursor: pointer;
}
app module
Tell the module that contains the parent component where to find our star component be adding it to the declarations in the module. In the most basic of cases this is the app.modules.ts.
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { StarComponent } from './shared/star.component';
@NgModule({
declarations: [ AppComponent, StarComponent ],
imports: [ BrowserModule, FormsModule ],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Common Lifecycle Hooks
OnInit
Perform component initialization and retrieve data
import { Component, OnInit } from '@angular/core';
export class MyComponent implements OnInit {
ngOnInit(): void {
console.log('In OnInit');
}
}
OnChanges
Perform action after change to input properties
OnDestroy
Perform cleanup for the component
Sometimes we need to transform bound properties before it is displayed. Such is the case with formatting dates, currency, decimals, etc. Pipes can be chained.
Built-in Pipes
- date
- number, decimal, percent, currency
- json, slice, etc
The complete list and more information can be found
here.
Examples (no parameters):
{{ product.productCode | lowercase }}
<img [src]='product.imageUrl' [title]='product.productName | uppercase'>
{{ product.price | currency | lowercase }}
Examples (with parameters)
NOTE: Parameters are separated by colons
{{ product.price | currency: 'USD' : true : '1.2-2' }}
Custom Pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'myTransform'})
export class MyTransform implements PipeTransform {
transform(value: string, customParam1: string): string { ... }
}
Add it to your module (i.e. app.module.ts) as shown here:
@NgModule({
imports: ...
declarations: [ AppComponent, MyTransform ],
bootstrap: ...
})
Use it just like the built in pipes
Binding with Interpolation
Use {{expression}} to pull (only one way binding) in content from the component class. The expression can have many forms.
For example:
{{propertyName}}
{{'ABC' + functionName()}}
{{'Answer is ' + 3*2}}
{{showImage ? 'Hide' : 'Show'}} Image
<img src={{product.imageUrl}}>
Notice that it does not use quotes!
Property Binding
Property Binding is one way just like interpolation.
We could use interpolation to set the src url for an image using:
<img src={{product.imageUrl}}>
or
<img src='http://someUrl/{{product.imageUrl}}'>
We can use Property binding to do the first case, but not the second case.
<img [src]='product.imageUrl'>
The syntax for Property Binding has a two parts:
- Binding Target - Is always in surrounded by []
- Binding Source - Is Surrounded by '' (two single quotes).
Generally, Property Binding is preferred instead of interpolation.
Event Binding
When the user clicks something an event is generated. We can listen for these events using Event Binding. Here is the syntax.
<button (click)='doSomething()'>
The syntax for Property Binding has a two parts:
- Target Event - Is always in surrounded by ()
- Template Statement - Is Surrounded by '' (two single quotes).
In this example, when the button is clicked the doSomething() method in our component class is executed.
Two-way Binding
This is useful for having the component and dom in sync such as in the case of an input field on a form.
<input [(ngModel)]='someProperty'>
The Banana in a Box metaphor can be used to remember the order of the parenthesis. Imagine the [()] to have a banana as () in a box as [].
The class for the component would be something like this.
export class MyComponent {
someProperty: string = 'abc';
}
ngModel is a keyword defined in the FormsModule. The FormsModule will need to be added to the AppModule. To do this open your app.module.ts and add to the top of the file the following:
import { FormsModule } from '@angular/forms';
Next, in the same app.module.ts file add FormsModule to the array of imports in the @NgModule().
Built-in Structural Directives
*ngIf
This adds control flow to the page for hiding and showing content based on conditional logic.
<div *ngIf='someLogic()'>
Some content to show
</div>
*ngFor
This adds control flow to the page for looping over content like a for loop.
<div *ngFor='let obj of objects'>
<div>{{obj.PropertyHere}}</div>
</div>
Component
A Component has 3 parts
- Template
- View layout
- Created with HTML
- Includes binding and directives
- Class
- Code supporting the view
- Created with TypeScript (.ts file)
- Properties for data
- Methods for logic
- CSS
- A CSS file for the styling needed for the component
- Metadata
- Extra data for Angular
- Defined with a decorator
Example
app.component.ts file
import { Component } from '@angular/core';
@Component({
selector: 'myApp-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Hello World';
}
- The import pulls in dependency references
- @Component is the metadata / decorator that says the class is a component. This is similar to an [Attribute] in C#
- export makes the class definition available for user elsewhere.
- The selector is a unique value for this component in the application. It is suggested you prefix selectors with something that identifies it as part of your app. This is also what is used as a tag to use this component in another component. In this case it is <myApp-root><myApp-root>
- It is common to append "Component" to the name name of the class so that it is clear that it is a component.
app.component.html
<div>
<h1>
Hello{{title}}!!
</h1>
</div>
This is the HTML that defines the layout. Anything in {{...}} tags are binds to properties in the class associated with this component.
app.component.css
h1 { text-align:center }
This is a standard CSS file, except these styles will be unique to this component automatically. They will not affect other styles in the project.
Imports
Some common Angular Modules you may need to import are:
- @angular/core (as we have done above)
- @angular/animate
- @angular/http
- @angular/router
Using the Component
This is how you would use it in index.html for example:
<body>
<myApp-root></myApp-root>
</body>
Telling index.html about our Component
In app.module.ts you list what angular modules should be included in our application#
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [ AppComponent ],
imports: [ BrowserModule ],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Assumptions
Using Visual Studio Code (on Windows)
Opening Integrated Terminal
View menu -> Integrated Terminal
Install packages
Open Integrated Terminal and type:
npm install
Launching Angular Application
Open Integrated Terminal and type:
npm start
This will build app and launch in the browser.
This also launches the web server. To stop the web server type control-c at the command prompt.
The parameters to the WinRM –SQL Sever DB Deploy task in VSTS can be used do a backup using the inline sql script.It is a good idea to set the additional arguments to be -ConnectionTimeout 120 -QueryTimeout 120 (for two minutes of timeout). Set the number of seconds to a reasonable value for your system.
If you don't and your backup exceeds the default timeout (90 seconds I believe), then you will get an error like this:
##[error]Microsoft.PowerShell.Commands.WriteErrorException: Deployment on one or more machines failed.
System.Exception: The running command stopped because the preference variable "ErrorActionPreference"
or common parameter is set to Stop: Timeout expired. The timeout period elapsed prior to completion
of the operation or the server is not responding.
It is actually SQL Server complaining that the time has elapsed, but it is doing so based on wht the WinRM says is the timeout.
To set the timeout open your WinRM - SQL Sever DB Deploy task in VSTS and set the
Additional Arguments to
-ConnectionTimeout 120 -QueryTimeout 120.