<commit_before>"use strict";
import * as vscode from 'vscode';
import {Environment} from './environmentPath';
import {File, FileManager} from './fileManager';
import {LocalSetting} from './setting';
import {PluginService, ExtensionInformation} from './pluginService';
import * as fs from 'fs';

var watch = require('node-watch');
var openurl = require('open');


export class Commons {

    public ERROR_MESSAGE: string = "Error Logged In Console (Help menu > Toggle Developer Tools). You may open an issue using 'Sync : Open Issue' from advance setting command.";

    private static watcher = null;

    constructor(private en: Environment) {

    }

    public LogException(error: any, message: string, msgBox: boolean): void {

        if (error) {
            console.error(error);
        }
        if (msgBox == true) {
            vscode.window.showErrorMessage(message);
        }
        else {
            vscode.window.setStatusBarMessage("");
            vscode.window.setStatusBarMessage(message,5000);
        }
    }

    public async InternetConnected(): Promise<boolean> {
        return new Promise<boolean>(async (resolve, reject) => {
            resolve(true);
        });
    }

    public StartWatch(): void {
        var appSetting : string = this.en.APP_SETTINGS;
        var appSummary : string = this.en.APP_SUMMARY;
        while (appSetting.indexOf("/") > -1) {
            appSetting = appSetting.replace("/", "\\");
        }

        while (appSummary.indexOf("/") > -1) {
            appSummary = appSummary.replace("/", "\\");
        }

        Commons.watcher = watch(this.en.PATH + "/User/");

        let updateCompleted: boolean = true;

        Commons.watcher.on('change', (path) => {

            if ((path != appSetting) && (path != appSummary)) {

                if (updateCompleted) {

                    updateCompleted = false;
                    vscode.window.setStatusBarMessage("Updating Process Starting On File Change.");

                    setTimeout(function () {

                        vscode.commands.executeCommand('extension.updateSettings', "forceUpdate").then((res) => {
                            updateCompleted = true;
                        });
                    }, 3000);
                }
                else {
                    vscode.window.setStatusBarMessage("Upload already in process. Please wait...", 3000);
                }
                //return;
            }

        });
    }
    public CloseWatch(): void {
        if (Commons.watcher != null) {
            Commons.watcher.close();
        }

    }

    public InitializeSettings(askInformation: boolean, askGIST: boolean): Promise<any> {
        var self = this;
        var localSettings: any;
        vscode.window.setStatusBarMessage("Sync : Checking for Github Token and GIST.", 2000);

        return new Promise<any>(async (resolve, reject) => {
            await FileManager.FileExists(self.en.APP_SETTINGS).then(async function (fileExist: boolean) {
                if (fileExist) {
                    await FileManager.ReadFile(self.en.APP_SETTINGS).then(async function (settin: string) {

                        vscode.window.setStatusBarMessage("");
                        if (settin) {
                            var set: any;
                            set = JSON.parse(settin);
                            vscode.window.setStatusBarMessage("");

                            if (!askInformation) {
                                resolve(set);
                            }
                            else {
                                if (set.Token == null || set.Token == "") {
                                    openurl("https://github.com/settings/tokens");

                                    await self.GetTokenAndSave(set).then(function (token: string) {
                                        if (!token) {
                                            vscode.window.showErrorMessage("TOKEN NOT SAVED");
                                            reject(false);
                                        }
                                        else {
                                            set.Token = token;
                                        }
                                    }, function (err: any) {
                                        self.LogException(err, self.ERROR_MESSAGE, true);
                                        reject(err);
                                    });
                                }
<commit_msg>Internet not connected exception handled<commit_after>"use strict";
import * as vscode from 'vscode';
import {Environment} from './environmentPath';
import {File, FileManager} from './fileManager';
import {LocalSetting} from './setting';
import {PluginService, ExtensionInformation} from './pluginService';
import * as fs from 'fs';

var watch = require('node-watch');
var openurl = require('open');


export class Commons {

    public ERROR_MESSAGE: string = "Error Logged In Console (Help menu > Toggle Developer Tools). You may open an issue using 'Sync : Open Issue' from advance setting command.";

    private static watcher = null;

    constructor(private en: Environment) {

    }

    public LogException(error: any, message: string, msgBox: boolean): void {

        if (error) {
            console.error(error);
            if(error.code== 500){
                 message = "Sync : Internet Not Connected or Unable to Connect to Github. Exception Logged in Console";
                 msgBox = false;
            }
        }
        
        if (msgBox == true) {
            vscode.window.showErrorMessage(message);
        }
        else {
            vscode.window.setStatusBarMessage("");
            vscode.window.setStatusBarMessage(message,5000);
        }
    }

    public async InternetConnected(): Promise<boolean> {
        return new Promise<boolean>(async (resolve, reject) => {
            resolve(true);
        });
    }

    public StartWatch(): void {
        var appSetting : string = this.en.APP_SETTINGS;
        var appSummary : string = this.en.APP_SUMMARY;
        while (appSetting.indexOf("/") > -1) {
            appSetting = appSetting.replace("/", "\\");
        }

        while (appSummary.indexOf("/") > -1) {
            appSummary = appSummary.replace("/", "\\");
        }

        Commons.watcher = watch(this.en.PATH + "/User/");

        let updateCompleted: boolean = true;

        Commons.watcher.on('change', (path) => {

            if ((path != appSetting) && (path != appSummary)) {

                if (updateCompleted) {

                    updateCompleted = false;
                    vscode.window.setStatusBarMessage("Updating Process Starting On File Change.");

                    setTimeout(function () {

                        vscode.commands.executeCommand('extension.updateSettings', "forceUpdate").then((res) => {
                            updateCompleted = true;
                        });
                    }, 3000);
                }
                else {
                    vscode.window.setStatusBarMessage("Upload already in process. Please wait...", 3000);
                }
                //return;
            }

        });
    }
    public CloseWatch(): void {
        if (Commons.watcher != null) {
            Commons.watcher.close();
        }

    }

    public InitializeSettings(askInformation: boolean, askGIST: boolean): Promise<any> {
        var self = this;
        var localSettings: any;
        

        return new Promise<any>(async (resolve, reject) => {
            await FileManager.FileExists(self.en.APP_SETTINGS).then(async function (fileExist: boolean) {
                if (fileExist) {
                    await FileManager.ReadFile(self.en.APP_SETTINGS).then(async function (settin: string) {
                        
                        vscode.window.setStatusBarMessage("");
                        vscode.window.setStatusBarMessage("Sync : Checking for Github Token and GIST.", 2000);
                        
                        if (settin) {
                            var set: any;
                            set = JSON.parse(settin);
                            vscode.window.setStatusBarMessage("");

                            if (!askInformation) {
                                resolve(set);
                            }
                            else {
                                if (set.Token == null || set.Token == "") {
                                    openurl("https://github.com/settings/tokens");

                                    await self.GetTokenAndSave(set).then(function (token: string) {
                                        if (!token) {
                                            vscode.window.showErrorMessage("TOKEN NOT SAVED");
                                            reject(false);
                                        }
                                        else {
                                            set.Token = token;
                                        }
                                    }, function (err: any) {
                                        self.LogException(err, self.ERROR_MESSAGE, true);
                                        reject(err);
                                    });
                                }

{'fraction_non_alphanumeric': 0.10684171202903191, 'fraction_numerical': 0.004162664105027218, 'mean_word_length': 1.2993865030674847, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2043270', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2119, 'n_words': 505}