Skip to content

Commit 2e716cf

Browse files
author
Warren Buckley
authored
Merge pull request #546 from warrenbuckley/feature/better-logging
Output window for extension logging in Crednetials & Sponsorware files
2 parents 24c3231 + d91a56a commit 2e716cf

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "iis-express",
33
"displayName": "IIS Express",
44
"description": "This allows you to run the current folder as a website using the IIS Express web server",
5-
"version": "1.4.0",
5+
"version": "1.5.0",
66
"publisher": "warren-buckley",
77
"icon": "images/iis-icon.png",
88
"galleryBanner": {
@@ -24,7 +24,7 @@
2424
"url": "https://github.com/warrenbuckley/IIS-Express-Code.git"
2525
},
2626
"engines": {
27-
"vscode": "^1.51.0"
27+
"vscode": "^1.62.0"
2828
},
2929
"categories": [
3030
"Other"

src/IISExpress.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class IISExpress {
8787

8888
// Create output channel & show it
8989
this._output = this._output || vscode.window.createOutputChannel('IIS Express');
90-
this._output.show(vscode.ViewColumn.Three);
90+
this._output.show();
9191

9292
// Site name is the name of the workspace folder & GUID/UUID
9393
// Need to append a UUID as could have two folders/sites with same name
@@ -107,7 +107,7 @@ export class IISExpress {
107107
// Not done as async - so we wait until this command completes
108108
try {
109109
process.execFileSync(this._iisAppCmdPath, ['add', 'site', `-name:${siteName}`, `-bindings:${this._args.protocol}://localhost:${this._args.port}`, `-physicalPath:${this._args.path}`]);
110-
} catch (error) {
110+
} catch (error:any) {
111111
console.log(error);
112112
this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath, "appCmd": `add site -name:${siteName} -bindings:${this._args.protocol}://localhost:${this._args.port} -physicalPath:${this._args.path}`});
113113
}
@@ -119,7 +119,7 @@ export class IISExpress {
119119
// appcmd set app /app.name:Site-Staging-201ec232-2906-4052-a431-727ec57b5b2e/ /applicationPool:Clr2IntegratedAppPool
120120
try {
121121
process.execFileSync(this._iisAppCmdPath, ['set', 'app', `/app.name:${siteName}/`, `/applicationPool:${appPool}`]);
122-
} catch (error) {
122+
} catch (error:any) {
123123
console.log(error);
124124
this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath});
125125
}
@@ -181,7 +181,7 @@ export class IISExpress {
181181
// Not done as async - so we wait until this command completes
182182
try {
183183
process.execFileSync(this._iisAppCmdPath, ['delete', 'site', `${siteName}`]);
184-
} catch (error) {
184+
} catch (error:any) {
185185
console.log(error);
186186
this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath, "appCmd": `delete site ${siteName}`});
187187
}

src/credentials.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export class Credentials {
1313
public authSession: vscode.AuthenticationSession | undefined;
1414
private reporter: TelemetryReporter | undefined;
1515
private context: vscode.ExtensionContext;
16+
private outputWindow: vscode.OutputChannel;
1617

17-
constructor(context: vscode.ExtensionContext, reporter:TelemetryReporter) {
18+
constructor(context: vscode.ExtensionContext, reporter:TelemetryReporter, outputWindow:vscode.OutputChannel) {
1819
this.context = context;
1920
this.reporter = reporter;
21+
this.outputWindow = outputWindow;
2022

2123
this.initialize();
2224
}
@@ -40,6 +42,7 @@ export class Credentials {
4042
// Used to enable/disable the GitHub Login command & to know when user has auth'd
4143
vscode.commands.executeCommand('setContext', 'iisexpress:userIsLoggedIn', true);
4244
this.reporter?.sendTelemetryEvent('github.loggedin');
45+
this.outputWindow.appendLine(`[Credentials] Logged in as ${session.account.label}`);
4346
return;
4447
}
4548

@@ -48,6 +51,7 @@ export class Credentials {
4851

4952
// Used to enable/disable the GitHub Login command & to know when user has auth'd
5053
vscode.commands.executeCommand('setContext', 'iisexpress:userIsLoggedIn', false);
54+
this.outputWindow.appendLine(`[Credentials] Logged out`);
5155
this.reporter?.sendTelemetryEvent('github.loggedout');
5256
}
5357

@@ -75,11 +79,16 @@ export class Credentials {
7579
let isValidSponsor = false;
7680

7781
if(accessToken){
82+
83+
const accountLabel = this.authSession?.account.label;
84+
this.outputWindow.appendLine(`[Credentials] Checking sponsorship for ${accountLabel}`);
85+
7886
// Make a request to Azure Function to check if they are a sponsor
7987
// Do request - pass back JSON response bool from this func
8088
await axios.post(AZURE_FUNCTION_URL, {token: accessToken})
8189
.then(response => {
8290
isValidSponsor = response.data.validSponsor ? response.data.validSponsor : false;
91+
this.outputWindow.appendLine(`[Credentials] Is ${accountLabel} a valid sponsor from Azure Function? ${isValidSponsor}`);
8392
})
8493
.catch(error => {
8594

@@ -100,6 +109,8 @@ export class Credentials {
100109

101110
this.reporter?.sendTelemetryException(error);
102111
isValidSponsor = false;
112+
this.outputWindow.appendLine(`[Credentials] Error determining if user ${accountLabel} is a valid sponsor`);
113+
this.outputWindow.appendLine(`[ERROR] ${error}`);
103114
});
104115
}
105116

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const key = 'e0cc903f-73ec-4216-92cd-3479696785b2';
2929
// create telemetry reporter on extension activation
3030
const reporter:TelemetryReporter = new TelemetryReporter(extensionId, extensionVersion, key);
3131

32+
const iisOutputWindow = vscode.window.createOutputChannel('IIS Express (Logs)');
3233

3334
let vsCodeFolderToRun:vscode.Uri | undefined = undefined;
3435

@@ -46,8 +47,8 @@ export async function activate(context: vscode.ExtensionContext) {
4647
let liveShareServer:vscode.Disposable;
4748

4849
// Init credentials class with event listener & prompt/get token from GitHub auth
49-
const credentials = new Credentials(context, reporter);
50-
const sponsorware = new Sponsorware(context, credentials, reporter);
50+
const credentials = new Credentials(context, reporter, iisOutputWindow);
51+
const sponsorware = new Sponsorware(context, credentials, reporter, iisOutputWindow);
5152

5253
// Register tree provider to put our custom commands into the tree
5354
// Start, Stop, Restart, Support etc...

src/sponsorware.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ export class Sponsorware {
99
private totalCount:number = 0;
1010
private credentials: Credentials;
1111
private reporter: TelemetryReporter;
12+
private outputWindow: vscode.OutputChannel;
1213

13-
constructor(context: vscode.ExtensionContext, credentials:Credentials, reporter:TelemetryReporter) {
14+
constructor(context: vscode.ExtensionContext, credentials:Credentials, reporter:TelemetryReporter, outputWindow:vscode.OutputChannel) {
1415
this.context = context;
1516
this.credentials = credentials;
1617
this.reporter = reporter;
18+
this.outputWindow = outputWindow;
1719
}
1820

1921
private async doWeShowSponsorMessagePanel():Promise<boolean> {
2022
// Exit out early if they are a sponsor
2123
// Don't show them the sponsorware message
22-
2324
const isSponsor = await this.credentials.isUserSponsor();
2425
if(isSponsor){
26+
const githubUsername = this.credentials.authSession?.account?.label;
27+
this.outputWindow.appendLine(`[Sponsorware] User ${githubUsername} is a valid sponsor`);
2528
return false;
2629
}
2730

@@ -30,6 +33,10 @@ export class Sponsorware {
3033
const sponsorwareCount = this.context.globalState.get<number>('iisexpress.sponsorware.count', 0);
3134
const sponsorwareDisplayCount = this.context.globalState.get<number>('iisexpress.sponsorware.display.count', 10); // Default to 10 if the random number not been set
3235

36+
this.outputWindow.appendLine(`[Sponsorware] Total count ${this.totalCount}`);
37+
this.outputWindow.appendLine(`[Sponsorware] Sponsorware count ${sponsorwareCount}`);
38+
this.outputWindow.appendLine(`[Sponsorware] Sponsorware display count ${sponsorwareDisplayCount}`);
39+
3340
// Decide if we met the threshold yet
3441
if(sponsorwareCount >= sponsorwareDisplayCount){
3542
// Each activation of extension (ie when VSCode boots)
@@ -38,6 +45,7 @@ export class Sponsorware {
3845

3946
// If we have met the threshold - reset the sponsor counter back to 0
4047
this.context.globalState.update('iisexpress.sponsorware.count', 0);
48+
this.outputWindow.appendLine(`[Sponsorware] Sponsorware threshold met - display the friendly message`);
4149
return true;
4250
}
4351
else {

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const config = {
1818
},
1919
devtool: 'source-map',
2020
externals: {
21-
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
21+
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
22+
'applicationinsights-native-metrics': 'commonjs applicationinsights-native-metrics' // ignored because we don't ship native module
2223
},
2324
resolve: {
2425
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader

0 commit comments

Comments
 (0)