コード例 #1
0
        private async void GetReportsResponse(HttpResponseMessage restResponse)
        {
            if (restResponse != null && restResponse.StatusCode == System.Net.HttpStatusCode.OK && restResponse.Content != null)
            {
                Log.Debug(TAG, restResponse.Content.ToString());
                string strContent = await restResponse.Content.ReadAsStringAsync();

                reports = JsonConvert.DeserializeObject <GlobalReportsModel>(strContent);

                if (reports != null)
                {
                    GetAccessToken();
                }
                else
                {
                    Log.Debug(TAG, "GetReportsResponse() Failed");
                    Utils.Utils.ShowToast(this, "Reports are not available");
                    String body = "<html><body>Failed to load reports.</b></body></html>";
                    showContentOnWebView(body);
                }
            }
            else
            {
                Log.Debug(TAG, "GetReportsResponse() Failed");
                Utils.Utils.ShowToast(this, "Failed to load reports");
                String body = "<html><body>Failed to load reports.</b></body></html>";
                showContentOnWebView(body);
            }
        }
コード例 #2
0
        private void LoadReports(GlobalReportsModel reports, String token)
        {
            string html = "<html> Reports\n" +
                          "\n\n<script type=\"text/javascript\"> " +
                          "var ReportUrl1 = \"" + reports.MonthlyConsumptionKWh + "\"; " +
                          "var ReportUrl2 = \"" + reports.MonthlyConsumptionCost + "\"; " +
                          "\n\nvar iframe; " +
                          "\n\nvar accessToken = " + "\'" + token + "\'" + " ; " +
                          "\n\nvar height=200;" +
                          "\n\nvar width=300; " +

                          "function loadEmbededTiles() \n\n{ " +
                          "embedReportTile1(); " +
                          "embedReportTile2();" +
                          "} " +

                          //Tile 1----------------------------------------

                          "function embedReportTile1() { " +
                          "var embedTileUrl = ReportUrl1; " +
                          "if (\"\" === embedTileUrl) { " +
                          "console.log(\"No embed URL found\"); " +
                          "document.getElementById('IFrame1').style.display = 'none'; " +
                          "return; " +
                          "} " +
                          "iframe = document.getElementById('IFrame1'); " +
                          "iframe.src = embedTileUrl + \"&width=\" + width + \"&height=\" + height; " +
                          "iframe.onload = postActionLoadTile1; " +
                          "} " +

                          "function postActionLoadTile1() { " +
                          "if (\"\" === accessToken) { " +
                          "console.log(\"Access token not found\"); " +
                          "return; " +
                          "} " +
                          "var h = height; " +
                          "var w = width; " +
                          "var m = { action: \"loadTile\", accessToken: accessToken, height: h, width: w }; " +
                          "var message = JSON.stringify(m); " +
                          "iframe = document.getElementById('IFrame1'); " +
                          "iframe.contentWindow.postMessage(message, \"*\");; " +
                          "} " +

                          //Tile 2----------------------------------------

                          "function embedReportTile2() { " +
                          "var embedTileUrl = ReportUrl2; " +
                          "if (\"\" === embedTileUrl) { " +
                          "console.log(\"No embed URL found\"); " +
                          "document.getElementById('IFrame2').style.display = 'none'; " +
                          "return; " +
                          "} " +
                          "iframe = document.getElementById('IFrame2'); " +
                          "iframe.src = embedTileUrl + \"&width=\" + width + \"&height=\" + height; " +
                          "iframe.onload = postActionLoadTile2; " +
                          "} " +

                          "function postActionLoadTile2() { " +
                          "if (\"\" === accessToken) { " +
                          "console.log(\"Access token not found\"); " +
                          "return; " +
                          "} " +
                          "var h = height; " +
                          "var w = width; " +
                          "var m = { action: \"loadTile\", accessToken: accessToken, height: h, width: w }; " +
                          "var message = JSON.stringify(m); " +
                          "iframe = document.getElementById('IFrame2'); " +
                          "iframe.contentWindow.postMessage(message, \"*\");; " +
                          "} " +

                          //----------------------------------------

                          "</script> " +

                          "<body " + "onload=\"loadEmbededTiles()\">" +
                          "<iframe id=\"IFrame1\" src=\"\" style=\"height:40vh;width:300px;\" frameborder=\"0\" seamless></iframe> " +
                          "<iframe id=\"IFrame2\" src=\"\" style=\"height:40vh;width:300px;\" frameborder=\"0\" seamless></iframe> " +
                          "</body> " +
                          "\n\n</html>\n";

            //Debug.WriteLine("Html Content : " + html);

            showContentOnWebView(html);
        }