Skip to content

Commit dde9e6f

Browse files
committed
Added telemetry for starting app
1 parent 607755a commit dde9e6f

File tree

6 files changed

+454
-10
lines changed

6 files changed

+454
-10
lines changed

TelemetryClient/telemetryClient.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const appInsights = require('applicationinsights');
2+
3+
class TelemetryClient {
4+
constructor() {
5+
let connectionString = 'InstrumentationKey=c764f176-19a5-4949-825d-9f30db2f14e8;IngestionEndpoint=https://germanywestcentral-1.in.applicationinsights.azure.com/';
6+
appInsights.setup(connectionString).start();
7+
}
8+
9+
trackevent(eventName, properties, callback) {
10+
appInsights.defaultClient.trackEvent({name: eventName, properties: properties});
11+
appInsights.defaultClient.flush({callback: callback});
12+
}
13+
}
14+
15+
module.exports = TelemetryClient;

ai.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const readline = require('readline-sync');
2+
let appInsights = require("applicationinsights");
3+
let connectionString = 'InstrumentationKey=c764f176-19a5-4949-825d-9f30db2f14e8;IngestionEndpoint=https://germanywestcentral-1.in.applicationinsights.azure.com';
4+
5+
class questions {
6+
constructor () {
7+
this.askAge = this.askAge.bind(this)
8+
}
9+
10+
askAge() {
11+
var age = readline.question("What is your age? ");
12+
client.trackEvent({name: "age entered", properties: {age: age}});
13+
}
14+
15+
askName() {
16+
var name = readline.question("What is your name? ");
17+
client.trackEvent({name: "name entered", properties: {name: name}});
18+
client.flush({callback: this.askAge});
19+
}
20+
21+
}
22+
23+
let q = new questions()
24+
25+
appInsights.setup(connectionString).setAutoCollectConsole(true).start();
26+
let client = appInsights.defaultClient;
27+
client.trackEvent({name: "my custom event", properties: {myProp: "custom property value 2"}});
28+
29+
client.flush({callback: q.askName()});

battleship.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@ const cliColor = require('cli-color');
44
const beep = require('beepbeep');
55
const position = require("./GameController/position.js");
66
const letters = require("./GameController/letters.js");
7+
const telemetryClient = require("./TelemetryClient/telemetryClient.js");
8+
const appInsights = require('applicationinsights');
9+
10+
let telemetry = new telemetryClient();
711

812
class Battleship {
13+
constructor () {
14+
this.start = this.start.bind(this);
15+
this.printWelcomeScreen = this.printWelcomeScreen.bind(this);
16+
}
917

1018
start() {
19+
console.log("Starting...");
20+
telemetry.trackevent("ApplicationStarted", {Technolog: "Node.js"}, this.printWelcomeScreen);
21+
};
22+
23+
printWelcomeScreen() {
1124
console.log(cliColor.magenta(" |__"));
1225
console.log(cliColor.magenta(" |\\/"));
1326
console.log(cliColor.magenta(" ---"));
@@ -46,6 +59,7 @@ class Battleship {
4659
console.log("Enter coordinates for your shot :");
4760
var position = Battleship.ParsePosition(readline.question());
4861
var isHit = gameController.CheckIsHit(this.enemyFleet, position);
62+
4963
if (isHit) {
5064
beep();
5165

@@ -111,9 +125,9 @@ class Battleship {
111125
console.log();
112126
console.log(`Please enter the positions for the ${ship.name} (size: ${ship.size})`);
113127
for (var i = 1; i < ship.size + 1; i++) {
114-
console.log(`Enter position ${i} of ${ship.size} (i.e A3):`);
115-
const position = readline.question();
116-
ship.addPosition(Battleship.ParsePosition(position));
128+
console.log(`Enter position ${i} of ${ship.size} (i.e A3):`);
129+
const position = readline.question();
130+
ship.addPosition(Battleship.ParsePosition(position));
117131
}
118132
})
119133
}

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
battleship = require("./battleship.js");
1+
const battleship = require("./battleship.js");
22

33
new battleship().start();

0 commit comments

Comments
 (0)