예제 #1
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {

            var s = new StringBuilder();

            s.AppendLine("alert('hi');");


            //script: error JSC1000: You tried to instance a class which seems to be marked as native.
            //script: error JSC1000: type has no callable constructor: [ScriptCoreLib.JavaScript.DOM.Blob] Void .ctor(System.String[])

            var blob = new Blob(new[] { s.ToString() });
            //var url = URL.createObjectURL(blob);

            //<script src="blob:http%3A//192.168.43.252%3A28384/6a37d088-4403-4eb2-b45e-1d19083b304e"></script>

            new IHTMLScript { src = blob.ToObjectURL() }.AttachToDocument();

        }
예제 #2
0
		public Application(IApp page)
		{
			// GetScriptApplicationSourceForInlineWorker { value = view-source#worker }

			//Native.document.curr
			new IHTMLPre { new { Native.document.currentScript } }.AttachToDocument();
			//{ { currentScript = null } }

			// we could jump to encrypted secondary app here...
			new IHTMLButton { "prefetch source (edit and continue can update code?)" }.AttachToDocument().WhenClicked(
					//async 
					button =>
					{
						//Request URL:http://192.168.43.252:17858/view-source
						//Request Method:0

						new IXMLHttpRequest(
							ScriptCoreLib.Shared.HTTPMethodEnum.GET,
							"view-source",
							r =>
							{
								//new IHTMLPre { new { r.responseType } }.AttachToDocument();
								new IHTMLPre { new { r.responseText.Length } }.AttachToDocument();

								var aFileParts = new[] { r.responseText };
								var oMyBlob = new Blob(aFileParts, new { type = "text/html" });	// the blob


								var url = oMyBlob.ToObjectURL();

								InternalInlineWorker.ScriptApplicationSourceForInlineWorker = url;

								new IHTMLPre { new { InternalInlineWorker.ScriptApplicationSourceForInlineWorker } }.AttachToDocument();
							}

						);



					}
			);

			new IHTMLButton { "work" }.AttachToDocument().WhenClicked(
				async button =>
				{
					var state = new
					{
						input_for_other_thread = new { Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsBackground }
					};

					// X:\jsc.svn\core\ScriptCoreLib.Extensions\ScriptCoreLib.Extensions\Extensions\TaskExtensions.cs

					//var x = await Task<string>.Factory.StartNew(
					var x = await Task.Factory.StartNew(
						state,
						scope =>
						{
							// Console is special. { scope = [object Object] }

							Console.WriteLine(
								//"Console is special. " + new { scope }
								"Console is special. " + new { scope.input_for_other_thread.ManagedThreadId }
							);



							return new
							{
								output = "who is serializing this? only the browser API? jsc not helping here yet?",

								scope,

								inside = new
								{
									Thread.CurrentThread.ManagedThreadId,
									Thread.CurrentThread.IsBackground
								}
							};
							//return "who is serializing this? only the browser API? jsc not helping here yet?";
						}
					//, state
					);


					new IHTMLPre { new { x.output, x.scope, x.inside } }.AttachToDocument();

				}
			);

		}
예제 #3
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            // see also
            // X:\jsc.svn\examples\javascript\DragIntoCRX\DragIntoCRX\Application.cs

            page.Data.WhenClicked(
                async button =>
                {
                    var DataTable = await this.DoEnterData();
                    var DataTable_xml = StringConversionsForDataTable.ConvertToString(
                                        DataTable
                                    );


                    var grid = new DataGridView { DataSource = DataTable };


                    grid.AttachControlTo(page.output);

                    var csv = WriteCSV(DataTable);


                    // http://www.w3.org/TR/file-writer-api/

                    page.x.title = "special.csv";
                    page.x.style.textDecoration = "underline";

                    page.x.css.hover.style.color = "red";


                    // http://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link
                    var blob = new Blob(new[] { csv.ToString() }, new { type = "octet/stream" });

                    var href = blob.ToObjectURL();



                    page.x.href = href;

                    // we can now click on the link
                    page.x.download = page.x.title;

                    // hide the fact, we are actually using <a>
                    //page.x.Hide();

                    //var iframe = new IHTMLIFrame { name = "y" }.AttachToDocument();
                    //page.x.target = iframe.name;

                    // http://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side
                    // http://msdn.microsoft.com/en-us/library/ie/hh779016(v=vs.85).aspx
                    // http://stackoverflow.com/questions/4309958/can-i-write-files-with-html5-js




                    page.Csv.disabled = false;
                    page.Csv.onclick +=
                        delegate
                        {
                            page.x.click();

                        };

                    page.Csv.ondragstart +=
                          e =>
                          {
                              Console.WriteLine("ondragstart");

                              // public void addElement(IHTMLElement element);
                              //e.dataTransfer.addElement(
                              // http://help.dottoro.com/ljxfefku.php

                              // X:\jsc.svn\examples\javascript\DropFileIntoSQLite\DropFileIntoSQLite\Application.cs
                              e.dataTransfer.effectAllowed = "copy";

                              e.dataTransfer.setData(

                                   typeof(DataTable).Name
                                    //"jsc/datatable"
                                    ,
                                    DataTable_xml

                              );

                              //                              ondragover: { types = 1, items = 1, files = 0 }
                              // view-source:29615
                              //{ type = jsc/datatable } 

                              Console.WriteLine("setDownloadURL");
                              // http://www.thecssninja.com/html5/gmail-dragout
                              // Unfortunately it doesn’t work anymore in any browser, not also in chrome

                              // https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer#setData.28.29
                              e.dataTransfer.setDownloadURL(
                                 page.x.title,
                                  Encoding.UTF8.GetBytes(csv.ToString())
                              );
                          };


                }
            );

        }