<commit_before>import * as vscode from 'vscode';
import * as ews from './lib/ews-soap/exchangeClient';

var Promise = require('promise');

export class ManifestUploader {
    constructor() {
    }
    
    private showUserBox():Thenable<string>{
        var config = vscode.workspace.getConfiguration("officeManifestUploader");
        var userName = config.get<string>("userName");
        
        if (userName)
        {
            return new Promise((f,r)=>{
               f(userName);
            });
        }
        
        return vscode.window.showInputBox({
                placeHolder: "<EMAIL>",
                prompt: "Enter your username"
            });
    }
    
    private showPwdBox():Thenable<string>
    {
        var config = vscode.workspace.getConfiguration("officeManifestUploader");
        var password = config.get<string>("password");
        
        if (password)
        {
            return new Promise((f,r)=>{
               f(password);
            });
        }
        
        return vscode.window.showInputBox({
                password: true,
                placeHolder: "password",
                prompt: "Enter your password"
            });
    }
    
    private showServerBox():Thenable<string>
    {
       var config = vscode.workspace.getConfiguration("officeManifestUploader");
        var serverUrl = config.get<string>("serverUrl");
                
        if (serverUrl)
        {
            return new Promise((f,r)=>{
               f(serverUrl);
            });
        }
        
       return vscode.window.showInputBox({
           password: false,
           placeHolder: "mail.office365.com",
           prompt: "Server name:"
        });
    }
    
    public upload(manifest:string) {  
        this.showUserBox().then((user) => {
            this.showPwdBox().then((pwd) => {
                this.showServerBox().then((server)=>{
                    this.uploadInternal(manifest, user, pwd, server);                        
                });
            });
        });
        
    }
    private uploadInternal(manifest:string, userName:string, password:string, serverUrl:string){
        vscode.window.showInformationMessage("Starting manifest upload...");
            
        ews.initialize({ url: serverUrl, 
            username:userName, password:password},
            function(err: any) {
                ews.installApp(manifest, function(err: any) {
                    if (err)
                    {
                        vscode.window.showErrorMessage('An error occurred: ' + err);<commit_msg>Changed uploader<commit_after>import * as vscode from "vscode";
import * as fs from "fs";
import * as ews from "./lib/ews-soap/exchangeClient";

let Promise = require("promise");

export class ManifestUploader {
    constructor() {
    }

    private showUserBox(): Thenable<string> {
        let config = vscode.workspace.getConfiguration("officeManifestUploader");
        let userName = config.get<string>("userName");

        if (userName)
        {
            return new Promise((f, r) => {
               f(userName);
            });
        }

        return vscode.window.showInputBox({
                placeHolder: "<EMAIL>",
                prompt: "Enter your username"
            });
    }

    private showPwdBox(): Thenable<string>
    {
        let config = vscode.workspace.getConfiguration("officeManifestUploader");
        let password = config.get<string>("password");

        if (password)
        {
            return new Promise((f, r) => {
               f(password);
            });
        }

        return vscode.window.showInputBox({
                password: true,
                placeHolder: "password",
                prompt: "Enter your password"
            });
    }

    private showServerBox(): Thenable<string>
    {
        let config = vscode.workspace.getConfiguration("officeManifestUploader");
        let serverUrl = config.get<string>("serverUrl");

        if (serverUrl)
        {
            return new Promise((f, r) => {
                f(serverUrl);
            });
        }

        return vscode.window.showInputBox({
            password: false,
            placeHolder: "mail.office365.com",
            prompt: "Server name:"
        });
    }

    public upload() {
        vscode.workspace.findFiles("manifest.xml", "").then((uris) => {
            if (!uris) {
                vscode.window.showErrorMessage("No manifest.xml file found in the workspace!");
                return;
            }

            if (uris.length > 1) {
                vscode.window.showErrorMessage("More than one manifest.xml file found in the workspace!");
                return;
            }

            vscode.workspace.openTextDocument(uris[0])
            .then((file) => {
               let truePath = file.fileName;

               let data = fs.readFileSync(truePath).toString();
               let manifest = new Buffer(data).toString("base64");

               this.showUserBox().then((user) => {
                    this.showPwdBox().then((pwd) => {
                        this.showServerBox().then((server) => {
                            this.uploadInternal(manifest, user, pwd, server);
                        });
                    });
                });
            }, (reason) => {
                vscode.window.showErrorMessage("Couldn't open file " + uris[0]);
            });
        }, (reason) => {
            vscode.window.showErrorMessage("An error occurred: " + reason);
        });
    }
    private uploadInternal(manifest: string, userName: string, password: string, serverUrl: string){
        vscode.window.showInformationMessage("Starting manifest upload...");

        ews.initialize({ url: serverUrl,
            username: userName, password: password},
            function(err: any) {
                ews.installApp(manifest, function(err: any) {
                    if (err)
                    {
                        vscode.window.showErrorMessage("An error occurred while uploading: " + err);
{'fraction_non_alphanumeric': 0.12090265195190249, 'fraction_numerical': 0.0018118926041838248, 'mean_word_length': 1.6104901117798796, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4003315', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1565, 'n_words': 304}