Skip to content

Commit

Permalink
Merge pull request #546 from warrenbuckley/feature/better-logging
Browse files Browse the repository at this point in the history
Output window for extension logging in Crednetials & Sponsorware files
  • Loading branch information
Warren Buckley authored Dec 6, 2021
2 parents 24c3231 + d91a56a commit 2e716cf
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "iis-express",
"displayName": "IIS Express",
"description": "This allows you to run the current folder as a website using the IIS Express web server",
"version": "1.4.0",
"version": "1.5.0",
"publisher": "warren-buckley",
"icon": "images/iis-icon.png",
"galleryBanner": {
Expand All @@ -24,7 +24,7 @@
"url": "https://github.com/warrenbuckley/IIS-Express-Code.git"
},
"engines": {
"vscode": "^1.51.0"
"vscode": "^1.62.0"
},
"categories": [
"Other"
Expand Down
8 changes: 4 additions & 4 deletions src/IISExpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class IISExpress {

// Create output channel & show it
this._output = this._output || vscode.window.createOutputChannel('IIS Express');
this._output.show(vscode.ViewColumn.Three);
this._output.show();

// Site name is the name of the workspace folder & GUID/UUID
// Need to append a UUID as could have two folders/sites with same name
Expand All @@ -107,7 +107,7 @@ export class IISExpress {
// Not done as async - so we wait until this command completes
try {
process.execFileSync(this._iisAppCmdPath, ['add', 'site', `-name:${siteName}`, `-bindings:${this._args.protocol}://localhost:${this._args.port}`, `-physicalPath:${this._args.path}`]);
} catch (error) {
} catch (error:any) {
console.log(error);
this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath, "appCmd": `add site -name:${siteName} -bindings:${this._args.protocol}://localhost:${this._args.port} -physicalPath:${this._args.path}`});
}
Expand All @@ -119,7 +119,7 @@ export class IISExpress {
// appcmd set app /app.name:Site-Staging-201ec232-2906-4052-a431-727ec57b5b2e/ /applicationPool:Clr2IntegratedAppPool
try {
process.execFileSync(this._iisAppCmdPath, ['set', 'app', `/app.name:${siteName}/`, `/applicationPool:${appPool}`]);
} catch (error) {
} catch (error:any) {
console.log(error);
this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath});
}
Expand Down Expand Up @@ -181,7 +181,7 @@ export class IISExpress {
// Not done as async - so we wait until this command completes
try {
process.execFileSync(this._iisAppCmdPath, ['delete', 'site', `${siteName}`]);
} catch (error) {
} catch (error:any) {
console.log(error);
this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath, "appCmd": `delete site ${siteName}`});
}
Expand Down
13 changes: 12 additions & 1 deletion src/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export class Credentials {
public authSession: vscode.AuthenticationSession | undefined;
private reporter: TelemetryReporter | undefined;
private context: vscode.ExtensionContext;
private outputWindow: vscode.OutputChannel;

constructor(context: vscode.ExtensionContext, reporter:TelemetryReporter) {
constructor(context: vscode.ExtensionContext, reporter:TelemetryReporter, outputWindow:vscode.OutputChannel) {
this.context = context;
this.reporter = reporter;
this.outputWindow = outputWindow;

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

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

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

Expand Down Expand Up @@ -75,11 +79,16 @@ export class Credentials {
let isValidSponsor = false;

if(accessToken){

const accountLabel = this.authSession?.account.label;
this.outputWindow.appendLine(`[Credentials] Checking sponsorship for ${accountLabel}`);

// Make a request to Azure Function to check if they are a sponsor
// Do request - pass back JSON response bool from this func
await axios.post(AZURE_FUNCTION_URL, {token: accessToken})
.then(response => {
isValidSponsor = response.data.validSponsor ? response.data.validSponsor : false;
this.outputWindow.appendLine(`[Credentials] Is ${accountLabel} a valid sponsor from Azure Function? ${isValidSponsor}`);
})
.catch(error => {

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

this.reporter?.sendTelemetryException(error);
isValidSponsor = false;
this.outputWindow.appendLine(`[Credentials] Error determining if user ${accountLabel} is a valid sponsor`);
this.outputWindow.appendLine(`[ERROR] ${error}`);
});
}

Expand Down
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const key = 'e0cc903f-73ec-4216-92cd-3479696785b2';
// create telemetry reporter on extension activation
const reporter:TelemetryReporter = new TelemetryReporter(extensionId, extensionVersion, key);

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

let vsCodeFolderToRun:vscode.Uri | undefined = undefined;

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

// Init credentials class with event listener & prompt/get token from GitHub auth
const credentials = new Credentials(context, reporter);
const sponsorware = new Sponsorware(context, credentials, reporter);
const credentials = new Credentials(context, reporter, iisOutputWindow);
const sponsorware = new Sponsorware(context, credentials, reporter, iisOutputWindow);

// Register tree provider to put our custom commands into the tree
// Start, Stop, Restart, Support etc...
Expand Down
12 changes: 10 additions & 2 deletions src/sponsorware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ export class Sponsorware {
private totalCount:number = 0;
private credentials: Credentials;
private reporter: TelemetryReporter;
private outputWindow: vscode.OutputChannel;

constructor(context: vscode.ExtensionContext, credentials:Credentials, reporter:TelemetryReporter) {
constructor(context: vscode.ExtensionContext, credentials:Credentials, reporter:TelemetryReporter, outputWindow:vscode.OutputChannel) {
this.context = context;
this.credentials = credentials;
this.reporter = reporter;
this.outputWindow = outputWindow;
}

private async doWeShowSponsorMessagePanel():Promise<boolean> {
// Exit out early if they are a sponsor
// Don't show them the sponsorware message

const isSponsor = await this.credentials.isUserSponsor();
if(isSponsor){
const githubUsername = this.credentials.authSession?.account?.label;
this.outputWindow.appendLine(`[Sponsorware] User ${githubUsername} is a valid sponsor`);
return false;
}

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

this.outputWindow.appendLine(`[Sponsorware] Total count ${this.totalCount}`);
this.outputWindow.appendLine(`[Sponsorware] Sponsorware count ${sponsorwareCount}`);
this.outputWindow.appendLine(`[Sponsorware] Sponsorware display count ${sponsorwareDisplayCount}`);

// Decide if we met the threshold yet
if(sponsorwareCount >= sponsorwareDisplayCount){
// Each activation of extension (ie when VSCode boots)
Expand All @@ -38,6 +45,7 @@ export class Sponsorware {

// If we have met the threshold - reset the sponsor counter back to 0
this.context.globalState.update('iisexpress.sponsorware.count', 0);
this.outputWindow.appendLine(`[Sponsorware] Sponsorware threshold met - display the friendly message`);
return true;
}
else {
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const config = {
},
devtool: 'source-map',
externals: {
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/
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/
'applicationinsights-native-metrics': 'commonjs applicationinsights-native-metrics' // ignored because we don't ship native module
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
Expand Down

0 comments on commit 2e716cf

Please sign in to comment.