WebSocket上のJSON-RPCの結果を非同期で受け取るコード(typescript)

暇な時に解説書きます。

class JSONRPCWebSocket {
    
    private resultDic: { [key: number]: any; } = {};
    private ws: WebSocket = null;
    private idCounter: number = 0;

    public interval: number = 100;
    public timeout: number = 3000;
    

    public closeWebSocket() {
        this.ws.close();
    }

    /*
    結果が戻ってきたら連想配列に格納する。
    */
    private onMessage = (args) => {
        var json = JSON.parse(args.data);
        console.log(this.interval);
        this.resultDic[json["id"]] = json["result"];
    }

    /*
    実行結果待ち
    */
    private wait(id: number, time: number, resolve) {
        if (id in this.resultDic) {
            var result = this.resultDic[id];
            delete this.resultDic[id];
            resolve(result);
        } else if (time > this.timeout) {
            resolve("timeout");
        } else {
            setTimeout(() => {
                this.wait(id, time + this.interval, resolve);
            }, this.interval);
        }
    }

    public openWebSocket(url : string) {
        this.ws = new WebSocket(url);
        //受信
        this.ws.onmessage = this.onMessage;
        //接続成功時
        this.ws.onopen = function (args) {
            console.log("open");
        }
        this.ws.onclose = function (args) {
            console.log("close");
        }
        this.ws.onerror = function (args) {
            console.log("error");
        }
    }

    /*
    メソッドをJSON RPCの形にして投げて、結果を待つ。
    */
    public invoke(method: string, params: any[]): any {
        var id = this.idCounter++;
        var hash: { [key: number]: any; } = {};
        hash["method"] = method;
        hash["params"] = params;
        hash["id"] = id;
        hash["type"] = "get";
        var json = JSON.stringify(hash);
        this.ws.send(json);

        return new Promise((resolve, reject) => {
            this.wait(id, 0, resolve);
        });
    }
}

参考サイト

Powerpoint VBAの情報は少ないから集める価値はあるのです。

VBAの文法などの情報

見つけ次第載せる。

Powerpointのオブジェクト関係などの情報

seesaawiki.jp

https://msdn.microsoft.com/ja-jp/library/office/ff862770.aspx

MsoShapeType 列挙 (Office)

MsoAutoShapeType 列挙 (Office)

MsoConnectorType Enumeration (Microsoft.Office.Core)

ConnectorFormat オブジェクト (PowerPoint)

その他

mint-s.jp

現在のページのオブジェクトの名前を全て出力する

Sub 現在のスライドのオブジェクトのNameを出力する()

Dim page As Slide
Set page = ActivePresentation.Slides(ActiveWindow.Selection.SlideRange.SlideNumber)

Dim shp As Object
For Each shp In page.Shapes
    MsgBox (shp.Name)
Next shp

End Sub

参考

www.relief.jp tonari-it.com

Powerpoint VBAはじめました

始めます。 環境はPowerpoint 2016。

何はともあれHello world。 表示→マクロ→適当に名前入力→作成でマクロエディタが開きます。

Sub Hello()
   MsgBox ("Hello world")
End Sub

これで実行ボタンを押すとHello worldと書かれたメッセージボックスが開きます。 簡単ですね。

プロジェクトテンプレートのインポート(Visual Studio 2017)

VS2015にはTypescriptの空テンプレートが付属していたんですが、VS2017には無いんですよね(多分)。

じゃあ2015から持ってくればいいじゃんってことでテンプレートを探してインポートしました。

このサイトの仕方に従ってやったら簡単にできたので報告。

方法 : プロジェクト テンプレートと項目テンプレートを配置して整理する

該当フォルダにテンプレート突っ込むだけじゃ駄目で、cmdでdevenv.exeを実行しないといけないのは盲点でした。