public void AllPropertiesDefaultToNull() {
            // Act
            JavaScriptResult result = new JavaScriptResult();

            // Assert
            Assert.IsNull(result.Script);
        }
        public void NullScriptIsNotOutput() {
            // Arrange
            string contentType = "application/x-javascript";

            // Arrange expectations
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.ContentType = contentType).Verifiable();

            JavaScriptResult result = new JavaScriptResult();

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
        public void ExecuteResult() {
            // Arrange
            string script = "alert('foo');";
            string contentType = "application/x-javascript";

            // Arrange expectations
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
            mockControllerContext.SetupSet(c => c.HttpContext.Response.ContentType = contentType).Verifiable();
            mockControllerContext.Setup(c => c.HttpContext.Response.Write(script)).Verifiable();

            JavaScriptResult result = new JavaScriptResult {
                Script = script
            };

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
        public JavaScriptResult Javascript()
        {
            string controller = Crypto.Decrypt(Request.Params[ResourceDispatchParamControllerKey], ResourceDispatcherController.ResourceDispatchCryptoPasswordKey);
            string cacheKeyJs = this.GenerateCacheKey(controller, MediaType.javascript);

            if (!this.FileIsCached(cacheKeyJs))
            {
                StringBuilder sb = new StringBuilder();

                if (controller == ResourceDispatcherController.ResourceDispatchParamCommonKey)
                {
                    sb.Append(System.IO.File.ReadAllText(Server.MapPath(string.Format("{0}{1}",
                                                                        ApplicationConfiguration.ClientResourcesSettingsSection.CDN_JS_VirtualRoot,
                                                                        ApplicationConfiguration.ClientResourcesSettingsSection.CDN_JS_CommonFileName($customNamespace$.UI.Web.MvcApplication.UserRequest.UserProfile.Culture, MvcApplication.Version)))));
                }
                else
                {
                    sb.Append(new Template_T4_Runtime_JS_ControllerScripts()
                    {
                        Session = new Dictionary<string, object>()
                        {
                            { ResourceDispatcherController.TTSessionContext_ControllerType, Type.GetType(controller) }
                        }
                    }.TransformText());

                    foreach (var item in ApplicationConfiguration.ClientResourcesSettingsSection.WebSitePageInitScripts)
                    {
                        sb.Append(System.IO.File.ReadAllText(Server.MapPath(item)));
                    }
                }

                this.FileSetCache(sb, cacheKeyJs, MediaType.javascript);
            }

            JavaScriptResult jsResult = new JavaScriptResult();
            jsResult.Script = (string)this._objCacheManager.Get(cacheKeyJs);
            return jsResult;
        }
Esempio n. 5
0
        /// <summary>
        /// Currently not in use, but this method can be called to retrieve the javascript code, will need further time to implement
        /// </summary>
        /// <param name="searchString"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public JavaScriptResult IndexGridConfiguration(string searchString, int?page, int?pageSize)
        {
            var str = new StringBuilder();

            str.AppendLine("$(\"#grid\").kendoGrid({");
            str.AppendLine("    columns: [");
            str.AppendLine("        { field: \"Name\", title: \"Name\", width: 140 },");
            str.AppendLine("        { field: \"Description\", title: \"Description\", width: 190 },");
            str.AppendLine("        {");
            str.AppendLine("            field: \"DateCreated\", title: \"Date Created\",");
            str.AppendLine("            format: \"{0:dd-MMM-yyyy}\",");
            str.AppendLine("            parseFormats: [\"yyyy-MM-dd'T'HH:mm:ss.zz\"],");
            str.AppendLine("            filterable: false");
            str.AppendLine("        },");
            str.AppendLine("        {");
            str.AppendLine("            field: \"DateModified\", title: \"Date Modified\",");
            str.AppendLine("            format: \"{0:dd-MMM-yyyy}\",");
            str.AppendLine("            parseFormats: [\"yyyy-MM-dd'T'HH:mm:ss.zz\"],");
            str.AppendLine("            filterable: false");
            str.AppendLine("        },");
            str.AppendLine("        {");
            str.AppendLine("            title: \" \", field: 'DailyTaskItemQueueStatusId',");
            str.AppendLine("            filterable: false,");
            str.AppendLine("            template: \"<a href='/ReleaseNoteQualitative/DailyTaskItemQueueStatus/Details/${DailyTaskItemQueueStatusId}'>Details</a>\"");
            str.AppendLine("        },");
            str.AppendLine("        {");
            str.AppendLine("            title: \" \", field: 'DailyTaskItemQueueStatusId',");
            str.AppendLine("            filterable: false,");
            str.AppendLine("            template: \"<a href='/ReleaseNoteQualitative/DailyTaskItemQueueStatus/Edit/${DailyTaskItemQueueStatusId}'>Edit</a>\"");
            str.AppendLine("        },");
            str.AppendLine("        {");
            str.AppendLine("            title: \" \", field: 'DailyTaskItemQueueStatusId',");
            str.AppendLine("            filterable: false,");
            str.AppendLine("            template: \"<a href='/ReleaseNoteQualitative/DailyTaskItemQueueStatus/Delete/${DailyTaskItemQueueStatusId}'>Delete</a>\"");
            str.AppendLine("        }");
            str.AppendLine("    ],");
            str.AppendLine("    dataSource: {");
            str.AppendLine("        transport: {");
            str.AppendLine("            read: \"/DailyTaskItemQueueStatus/DailyTaskItemQueueStatus/IndexResult\"");
            str.AppendLine("        },");
            str.AppendLine("        schema: {");
            str.AppendLine("            model: {");
            str.AppendLine("                    fields: {");
            str.AppendLine("                        Name: { type: \"string\" },");
            str.AppendLine("                        Description: { type: \"string\" },");
            str.AppendLine("                        DateCreated: { type: \"date\" },");
            str.AppendLine("                        DateModified: { type: \"date\" }");
            str.AppendLine("                    }");
            str.AppendLine("            }");
            str.AppendLine("        },");
            str.AppendLine("        pageSize: 10");
            str.AppendLine("    },");
            str.AppendLine("    groupable: true,");
            str.AppendLine("    sortable: true,");
            str.AppendLine("    filterable: true,");
            str.AppendLine("    pageable: {");
            str.AppendLine("        refresh: true,");
            str.AppendLine("        pageSizes: true,");
            str.AppendLine("        buttonCount: 5");
            str.AppendLine("    }");
            str.AppendLine("});");


            var result = new JavaScriptResult();

            result.Script = str.ToString();
            return(result);
        }
		protected override void OnCreate(Bundle savedInstanceState)
		{
			base.OnCreate(savedInstanceState);

			//
			SetContentView(Resource.Layout.Main);


			//
			TxtUrl = FindViewById<EditText>(Resource.Id.txtUrl);

			_InputMethodManager =
				(InputMethodManager)GetSystemService(Context.InputMethodService);
			_InputMethodManager.HideSoftInputFromWindow(
					TxtUrl.WindowToken,
					HideSoftInputFlags.None);

			//
			var client = new ContentWebViewClient();

			client.WebViewLocaitonChanged += (sender, e) =>
			{

				WriteLine($"{ e.CommandString }");
			};

			// 
			MyWebView = FindViewById<WebView>(Resource.Id.webview);
			MyWebView.SetWebViewClient(client);
			MyWebView.Settings.JavaScriptEnabled = true;

			// 負責與頁面溝通 - Native -> WebView
			JavaScriptResult callResult = new JavaScriptResult();
			callResult.JavaScriptResultReceived += (object sender, JavaScriptResult.JavaScriptResultReceivedEventArgs e) =>
			{

				WriteLine(e.Result);

				RunOnUiThread(() =>
				{
					TxtUrl.Text = e.Result;
				});

			};

			//
			BtnGo = FindViewById<Button>(Resource.Id.btnGo);
			BtnGo.Click += (sender, e) =>
			{
				RunOnUiThread(() =>
				{
					MyWebView.EvaluateJavascript(@"msg( 1234  );", callResult);
				});

			};

			MyWebView.LoadDataWithBaseURL(
				null
				, @"<html>
						<head>
							<title>Local String</title>
							<style type='text/css'>p{font-family : Verdana; color : purple }</style>
							<script language='JavaScript'> 
								var lookup = '中文訊息'
								function msg( text ){ return text + ' received';   }
							</script>
						</head>
						<body><p>Hello World!</p><br />
							<button type='button' onclick='TP.CallFromPage(lookup)' text='Hi From Page'>Hi From Page</button>
						</body>
					</html>"
				, "text/html"
				, "utf-8"
				, null);

		}
Esempio n. 7
0
        /// <summary>
        /// Currently not in use, but this method can be called to retrieve the javascript code, will need further time to implement
        /// </summary>
        /// <param name="searchString"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public JavaScriptResult IndexGridConfiguration(string searchString, int?page, int?pageSize)
        {
            var str = new StringBuilder();

            str.AppendLine("$(\"#grid\").kendoGrid({");
            str.AppendLine("    columns: [");
            str.AppendLine("        { field: \"FunctionalityXFunctionalityDevelopmentStepId\", title: \"FunctionalityXFunctionalityDevelopmentStepId\", width: 140 },");
            str.AppendLine("        { field: \"Functionality\", title: \"Functionality\", width: 140 },");
            str.AppendLine("        { field: \"FunctionalityDevelopmentStep\", title: \"FunctionalityDevelopmentStep\", width: 190 },");
            str.AppendLine("        { field: \"SortOrder\", title: \"SortOrder\", width: 190 },");
            str.AppendLine("        { field: \"Version\", title: \"Version\", width: 190 },");
            //str.AppendLine("        {");
            //str.AppendLine("            field: \"DateCreated\", title: \"Date Created\",");
            //str.AppendLine("            format: \"{0:dd-MMM-yyyy}\",");
            //str.AppendLine("            parseFormats: [\"yyyy-MM-dd'T'HH:mm:ss.zz\"],");
            //str.AppendLine("            filterable: false");
            //str.AppendLine("        },");
            //str.AppendLine("        {");
            //str.AppendLine("            field: \"DateModified\", title: \"Date Modified\",");
            //str.AppendLine("            format: \"{0:dd-MMM-yyyy}\",");
            //str.AppendLine("            parseFormats: [\"yyyy-MM-dd'T'HH:mm:ss.zz\"],");
            //str.AppendLine("            filterable: false");
            //str.AppendLine("        },");
            str.AppendLine("        {");
            str.AppendLine("            title: \" \", field: 'FunctionalityXFunctionalityDevelopmentStepId',");
            str.AppendLine("            filterable: false,");
            str.AppendLine("            template: \"<a href='/FunctionalityDevelopmentStep/FunctionalityXFunctionalityDevelopmentStep/Details/${FunctionalityXFunctionalityDevelopmentStepId}'>Details</a>\"");
            str.AppendLine("        },");
            str.AppendLine("        {");
            str.AppendLine("            title: \" \", field: 'FunctionalityXFunctionalityDevelopmentStepId',");
            str.AppendLine("            filterable: false,");
            str.AppendLine("            template: \"<a href='/FunctionalityDevelopmentStep/FunctionalityXFunctionalityDevelopmentStep/Edit/${FunctionalityXFunctionalityDevelopmentStepId}'>Edit</a>\"");
            str.AppendLine("        },");
            str.AppendLine("        {");
            str.AppendLine("            title: \" \", field: 'FunctionalityXFunctionalityDevelopmentStepId',");
            str.AppendLine("            filterable: false,");
            str.AppendLine("            template: \"<a href='/FunctionalityDevelopmentStep/FunctionalityXFunctionalityDevelopmentStep/Delete/${FunctionalityXFunctionalityDevelopmentStepId}'>Delete</a>\"");
            str.AppendLine("        }");
            str.AppendLine("    ],");
            str.AppendLine("    dataSource: {");
            str.AppendLine("        transport: {");
            str.AppendLine("            read: \"/FunctionalityDevelopmentStep/FunctionalityXFunctionalityDevelopmentStep/IndexResult\"");
            str.AppendLine("        },");
            str.AppendLine("        schema: {");
            str.AppendLine("            model: {");
            str.AppendLine("                    fields: {");
            str.AppendLine("                        FunctionalityXFunctionalityDevelopmentStep: { type: \"number\" },");
            str.AppendLine("                        Functionality: { type: \"string\" },");
            str.AppendLine("                        FunctionalityDevelopmentStep: { type: \"string\" },");
            str.AppendLine("                        SortOrder: { type: \"number\" }");
            str.AppendLine("                        Version: { type: \"string\" }");
            str.AppendLine("                    }");
            str.AppendLine("            }");
            str.AppendLine("        },");
            str.AppendLine("        pageSize: 10");
            str.AppendLine("    },");
            str.AppendLine("    groupable: true,");
            str.AppendLine("    sortable: true,");
            str.AppendLine("    filterable: true,");
            str.AppendLine("    pageable: {");
            str.AppendLine("        refresh: true,");
            str.AppendLine("        pageSizes: true,");
            str.AppendLine("        buttonCount: 5");
            str.AppendLine("    }");
            str.AppendLine("});");


            var result = new JavaScriptResult();

            result.Script = str.ToString();
            return(result);
        }
Esempio n. 8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.web_mywebview);

            #region WebView

            var client = new ContentWebViewClient();

            client.WebViewLocaitonChanged += (object sender, ContentWebViewClient.WebViewLocaitonChangedEventArgs e) => {
                Debug.WriteLine(e.CommandString);
            };

            client.WebViewLoadCompleted += (object sender, ContentWebViewClient.WebViewLoadCompletedEventArgs e) => {
                RunOnUiThread(() => {
                    AndHUD.Shared.Dismiss(this);
                });
            };


            MyWebView = FindViewById <WebView> (Resource.Id.web_mywebview_webview);
            // NOTICE : 先換成一般的 WebViewClient
            MyWebView.SetWebViewClient(client);
            //MyWebView.SetWebViewClient(new MyWebClient());
            MyWebView.Settings.JavaScriptEnabled = true;
            MyWebView.Settings.UserAgentString   = @"Android";

            // 負責與頁面溝通 - WebView -> Native
            MyJSInterface myJSInterface = new MyJSInterface(this);

            MyWebView.AddJavascriptInterface(myJSInterface, "TP");
            myJSInterface.CallFromPageReceived += delegate(object sender, MyJSInterface.CallFromPageReceivedEventArgs e) {
                Debug.WriteLine(e.Result);
            };

            // 負責與頁面溝通 - Native -> WebView
            JavaScriptResult callResult = new JavaScriptResult();
            callResult.JavaScriptResultReceived += (object sender, JavaScriptResult.JavaScriptResultReceivedEventArgs e) => {
                Debug.WriteLine(e.Result);
            };


            // 載入一般網頁
            //MyWebView.LoadUrl ("http://stackoverflow.com/");
            // 載入以下程式碼進行互動

            /*
             * MyWebView.LoadDataWithBaseURL (
             *      null
             *      , @"<html>
             *                      <head>
             *                              <title>Local String</title>
             *                              <style type='text/css'>p{font-family : Verdana; color : purple }</style>
             *                              <script language='JavaScript'>
             *                                      var lookup = '中文訊息'
             *                                      function msg(){ window.location = 'callfrompage://Hi'  }
             *                              </script>
             *                      </head>
             *                      <body><p>Hello World!</p><br />
             *                              <button type='button' onclick='TP.CallFromPage(lookup)' text='Hi From Page'>Hi From Page</button>
             *                      </body>
             *              </html>"
             *      , "text/html"
             *      , "utf-8"
             *      , null);
             *
             */

            #endregion

            #region EditText

            _InputMethodManager =
                (InputMethodManager)GetSystemService(Context.InputMethodService);



            TxtUrl = FindViewById <EditText> (Resource.Id.web_mywebview_txtUrl);

            TxtUrl.TextChanged += (object sender,
                                   Android.Text.TextChangedEventArgs e) => {
                Debug.WriteLine(TxtUrl.Text + ":" + e.Text);
            };

            #endregion


            BtnGo        = FindViewById <Button> (Resource.Id.web_mywebview_btnGo);
            BtnGo.Click += (object sender, EventArgs e) => {
                //RunOnUiThread (() => {
                //	MyWebView.EvaluateJavascript (@"msg();", callResult);
                //});


                var url = TxtUrl.Text.Trim();

                AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.SetTitle(url);
                alert.SetMessage("");
                alert.SetNegativeButton("取消", (senderAlert, args) => {
                });
                alert.SetPositiveButton("確認", (senderAlert, args) => {
                    RunOnUiThread(
                        () => {
                        AndHUD.Shared.Show(this, "Status Message", -1, MaskType.Clear);
                    }

                        );

                    MyWebView.LoadUrl(url);
                });

                RunOnUiThread(() => {
                    alert.Show();
                });

                //
                _InputMethodManager.HideSoftInputFromWindow(
                    TxtUrl.WindowToken,
                    HideSoftInputFlags.None);
            };
        }
Esempio n. 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.webflow_mywebview);

            #region WebView

            var client = new ContentWebViewClient();

            client.WebViewLocaitonChanged += (object sender, ContentWebViewClient.WebViewLocaitonChangedEventArgs e) => {
                Debug.WriteLine(e.CommandString);
            };

            client.WebViewLoadCompleted += (object sender, ContentWebViewClient.WebViewLoadCompletedEventArgs e) => {
                RunOnUiThread(() => {
                    //AndHUD.Shared.Dismiss(this);
                    Debug.WriteLine("WebViewLoad");
                });
            };


            MyWebView = FindViewById <WebView>(Resource.Id.webflow_webview_viewweb);
            // NOTICE : 先換成一般的 WebViewClient
            //MyWebView.SetWebViewClient(client);
            MyWebView.SetWebViewClient(new MyWebClient());

            MyWebView.Settings.JavaScriptEnabled = true;
            MyWebView.Settings.UserAgentString   = @"Android";

            // 負責與頁面溝通 - WebView -> Native
            MyJSInterface myJSInterface = new MyJSInterface(this);

            MyWebView.AddJavascriptInterface(myJSInterface, "TP");
            myJSInterface.CallFromPageReceived += delegate(object sender, MyJSInterface.CallFromPageReceivedEventArgs e) {
                //MyWebView.LoadUrl("http://developer.xamarin.com");

                Debug.WriteLine(e.Result);
            };

            // 負責與頁面溝通 - Native -> WebView
            JavaScriptResult callResult = new JavaScriptResult();
            callResult.JavaScriptResultReceived += (object sender, JavaScriptResult.JavaScriptResultReceivedEventArgs e) => {
                Debug.WriteLine(e.Result);
            };


            // 載入一般網頁
            //MyWebView.LoadUrl ("http://stackoverflow.com/");
            // 載入以下程式碼進行互動

            MyWebView.LoadDataWithBaseURL(
                null
                , @"<html>
						<head>
							<title>Local String</title>
							<style type='text/css'>p{font-family : Verdana; color : purple }</style>
							<script language='JavaScript'> 
								var lookup = '中文訊息'
								function msg(){ window.location = 'callfrompage://Hi'  }
							</script>
						</head>
						<body><p>Hello World!</p><br />
							<button type='button' onclick='TP.CallFromPage(lookup)' text='Hi From Page'>Hi From Page</button>
						</body>
					</html>"
                , "text/html"
                , "utf-8"
                , null);



            #endregion

            BtnGo        = FindViewById <Button>(Resource.Id.webflow_webview_btngo);
            BtnGo.Click += (object sender, EventArgs e) => {
                RunOnUiThread(() => {
                    MyWebView.EvaluateJavascript(@"msg();", callResult);
                });

                /*
                 *              var url = TxtUrl.Text.Trim() ;
                 *
                 *              AlertDialog.Builder alert = new AlertDialog.Builder (this);
                 *              alert.SetTitle (url);
                 *              alert.SetNegativeButton( "取消", (senderAlert, args) =>{
                 *
                 *
                 *              });
                 *              alert.SetPositiveButton( "確認", (senderAlert, args) =>{
                 *
                 *                      RunOnUiThread(
                 *                              ()=>{
                 *                                      AndHUD.Shared.Show(this, "Status Message", -1, MaskType.Clear);
                 *                              }
                 *
                 *                      );
                 *
                 *                      MyWebView.LoadUrl (url);
                 *
                 *              });
                 *
                 *              RunOnUiThread (() => {
                 *                      alert.Show();
                 *              } );
                 *
                 *              //
                 *              _InputMethodManager.HideSoftInputFromWindow(
                 *                      TxtUrl.WindowToken,
                 *                      HideSoftInputFlags.None );
                 */
            };
        }
Esempio n. 10
0
 public static JavaScriptResult WithJavascriptAlert(this JavaScriptResult result, string text)
 {
     result.Script = "alert('" + text + "');" + result.Script;
     return(result);
 }
Esempio n. 11
0
 /// <summary>
 /// Creates a new <see cref="EvalCommand"/>.
 /// </summary>
 /// <param name="javaScriptResult">The <see cref="JavaScriptResult"/> to execute.</param>
 public EvalCommand(JavaScriptResult javaScriptResult)
 {
     _javaScriptResult = javaScriptResult;
 }