Exemplo n.º 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 button = new IHTMLButton();
            button.innerText = "Click me";
            button.WhenClicked(async b => {
                //Native.document.documentElement.style.cursor = IStyle.CursorEnum.wait;
                Native.document.documentElement.style.cursor = IStyle.CursorEnum.progress;

                await WebMethod2();
                Native.document.documentElement.style.cursor = IStyle.CursorEnum.auto;
            });
            button.AttachToDocument();
        }
Exemplo n.º 2
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 button = new IHTMLButton();

            button.innerText = "Click me";
            button.WhenClicked(async b => {
                //Native.document.documentElement.style.cursor = IStyle.CursorEnum.wait;
                Native.document.documentElement.style.cursor = IStyle.CursorEnum.progress;

                await WebMethod2();
                Native.document.documentElement.style.cursor = IStyle.CursorEnum.auto;
            });
            button.AttachToDocument();
        }
Exemplo n.º 3
0
        //public readonly ApplicationWebService service = new ApplicationWebService();

        /// <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(IDefault page)
        {
            var service = this;

            #region pre
            Func<string, IHTMLDiv, IHTMLElement> pre =
                (value, output) =>
                {
                    return new IHTMLPre { innerText = value }.AttachTo(output);
                };
            #endregion

            #region pre
            Func<string, IHTMLDiv, IHTMLElement> browse = null;

            browse =
                (path, output) =>
                {

                    var list = new IHTMLButton { innerText = path }.AttachTo(output);


                    var group = new IHTMLDiv().AttachTo(output);




                    list.onclick +=
                        delegate
                        {
                            group.style.margin = "1em";
                            group.style.paddingLeft = "1em";
                            group.style.border = "1px solid gray";

                            list.disabled = true;

                            service.File_list(path,
                                ydirectory: value =>
                                {
                                    browse(path + "/" + value, group);
                                },

                                yfile: value =>
                                {
                                    var link = new IHTMLAnchor { href = "/io" + path + "/" + value, innerText = value };

                                    link.style.display = IStyle.DisplayEnum.block;
                                    link.AttachTo(group);
                                }
                            );
                        };

                    return group;
                };
            #endregion



            #region f
            Action<string, string, Action<string, Action<string>>, Func<string, IHTMLDiv, IHTMLElement>> f =
                (text, arg1, c, y) =>
                {
                    var btn = new IHTMLButton(text).AttachToDocument();
                    var output = new IHTMLDiv().AttachToDocument();

                    btn.onclick +=
                        e =>
                        {
                            btn.style.color = JSColor.Red;

                            output.Clear();

                            c(arg1,
                                value =>
                                {
                                    btn.style.color = JSColor.Blue;


                                    y(value, output);
                                }
                            );
                        }
                    ;
                };
            #endregion

            #region ff
            Action<string, Func<Task<string>>, Func<string, IHTMLDiv, IHTMLElement>> ff =
                (text, c, y) =>
                {
                    var btn = new IHTMLButton(text).AttachToDocument();
                    var output = new IHTMLDiv().AttachToDocument();

                    btn.WhenClicked(
                        async e =>
                        {
                            btn.style.color = JSColor.Red;

                            output.Clear();

                            var value = await c();

                            btn.style.color = JSColor.Blue;


                            y(value, output);
                        }
                     );
                };
            #endregion


#if CORE_PARTIAL
            ff("Environment_getDataDirectory", () => service.Environment_getDataDirectory(), browse);
            ff("Environment_getDownloadCacheDirectory", () => service.Environment_getDownloadCacheDirectory(), browse);
            ff("Environment_getExternalStorageDirectory", () => service.Environment_getExternalStorageDirectory(), browse);
            ff("Environment_getExternalStorageState", () => service.Environment_getExternalStorageState(), pre);
            ff("Environment_getRootDirectory", () => service.Environment_getRootDirectory(), browse);

            //service.Environment_DIRECTORY("",
            //    (
            //        string DIRECTORY_MUSIC,
            //        string DIRECTORY_PODCASTS,
            //        string DIRECTORY_RINGTONES,
            //        string DIRECTORY_ALARMS,
            //        string DIRECTORY_NOTIFICATIONS,
            //        string DIRECTORY_PICTURES,
            //        string DIRECTORY_MOVIES,
            //        string DIRECTORY_DOWNLOADS,
            //        string DIRECTORY_DCIM
            //    ) =>

            f("Environment_getExternalStoragePublicDirectory DIRECTORY_MUSIC", DIRECTORY_MUSIC, service.Environment_getExternalStoragePublicDirectory, browse);
            f("Environment_getExternalStoragePublicDirectory DIRECTORY_PODCASTS", DIRECTORY_PODCASTS, service.Environment_getExternalStoragePublicDirectory, browse);
            f("Environment_getExternalStoragePublicDirectory DIRECTORY_RINGTONES", DIRECTORY_RINGTONES, service.Environment_getExternalStoragePublicDirectory, browse);
            f("Environment_getExternalStoragePublicDirectory DIRECTORY_ALARMS", DIRECTORY_ALARMS, service.Environment_getExternalStoragePublicDirectory, browse);
            f("Environment_getExternalStoragePublicDirectory DIRECTORY_NOTIFICATIONS", DIRECTORY_NOTIFICATIONS, service.Environment_getExternalStoragePublicDirectory, browse);
            f("Environment_getExternalStoragePublicDirectory DIRECTORY_PICTURES", DIRECTORY_PICTURES, service.Environment_getExternalStoragePublicDirectory, browse);
            f("Environment_getExternalStoragePublicDirectory DIRECTORY_MOVIES", DIRECTORY_MOVIES, service.Environment_getExternalStoragePublicDirectory, browse);
            f("Environment_getExternalStoragePublicDirectory DIRECTORY_DOWNLOADS", DIRECTORY_DOWNLOADS, service.Environment_getExternalStoragePublicDirectory, browse);

#endif

            f("Environment_getExternalStoragePublicDirectory DIRECTORY_DCIM", DIRECTORY_DCIM, service.Environment_getExternalStoragePublicDirectory, browse);



            new IHTMLElement(IHTMLElement.HTMLElementEnum.hr).AttachToDocument();



            // new IHTMLButton("Environment_getDownloadCacheDirectory").AttachToDocument().onclick +=
            //    e => service.Environment_getDownloadCacheDirectory("",
            //            value => new IHTMLPre { innerText = value }.AttachToDocument()
            //);
        }
Exemplo n.º 4
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(IDefault page)
        {
            @"Hello world".ToDocumentTitle();

            var output = new IHTMLTextArea().AttachToDocument();

            var gexf = new XElement("gexf");

            gexf.Add(
                new XElement("meta",
                    new XElement("creator", "jsc"),
                    new XElement("description", "NASDAQSNA")
                )
            );

            var graph = new XElement("graph",
                new XAttribute("mode", "static"),
                new XAttribute("defaultedgetype", "directed")
            );

            gexf.Add(graph);

            var nodes = new XElement("nodes");

            graph.Add(nodes);

            var edges = new XElement("edges");

            graph.Add(edges);

            output.value = gexf.ToString();
            output.onfocus +=
                delegate
                {
                    output.value = gexf.ToString();
                };
            output.onmouseover +=
             delegate
             {
                 output.value = gexf.ToString();
             };

            var NumericNodeIdLookup = new List<string>();

            Func<string, int> GetNumericNodeId =
                k =>
                {
                    if (!NumericNodeIdLookup.Contains(k))
                        NumericNodeIdLookup.Add(k);


                    return NumericNodeIdLookup.IndexOf(k);
                };

            #region AddRelatedCompanies
            Func<IHTMLDiv, string, Action, Task> AddRelatedCompanies = null;

            AddRelatedCompanies =
                (c, qid, done) =>
                {
                    var nqid = GetNumericNodeId(qid).ToString();
                    var cc = new IHTMLDiv();

                    cc.style.marginLeft = "2em";



                    var service = new ApplicationWebService
                    {
                        qid = qid,
                        yield = (id, CompanyName, Price) =>
                        {
                            var nid = GetNumericNodeId(id).ToString();

                            if (nodes.Elements().Any(k => k.Attribute("id").Name.LocalName == nid))
                            {
                            }
                            else
                            {
                                nodes.Add(
                                    new XElement("node",
                                     new XAttribute("id", nid),
                                     new XAttribute("label", CompanyName)
                                    )
                                );
                            }



                            var btn = new IHTMLButton
                            {
                                innerText = id + " " + CompanyName + " " + Price
                            };

                            btn.style.display = IStyle.DisplayEnum.block;

                            if (qid == id)
                            {
                                btn.disabled = true;

                                if (c == null)
                                {
                                    btn.AttachToDocument();
                                    cc.AttachToDocument();
                                }
                                else
                                {
                                    //btn.AttachTo(c);
                                    cc.AttachTo(c);
                                }

                                if (done != null)
                                    done();
                            }
                            else
                            {
                                edges.Add(
                                    new XElement("edge",
                                     new XAttribute("source", nqid),
                                     new XAttribute("target", nid)
                                    )
                                );

                                btn.AttachTo(cc);

                                var ccc = new IHTMLDiv();

                                ccc.AttachTo(cc);

                                int cx = 0;

                                ccc.ToggleVisible();



                                btn.WhenClicked(
                                    async delegate
                                    {
                                        if (cx == 0)
                                        {
                                            btn.style.color = JSColor.Red;

                                            await AddRelatedCompanies(ccc, id,
                                                delegate
                                                {
                                                    btn.style.color = JSColor.Blue;

                                                }
                                            );
                                        }


                                        cx++;

                                        ccc.ToggleVisible();

                                    }
                                );

                            }
                        }
                    };



                    return service.GetRelatedCompanies();
                };
            #endregion

            AddRelatedCompanies(null, "NASDAQ:FB", null);
            AddRelatedCompanies(null, "NASDAQ:GOOG", null);
        }
Exemplo n.º 5
0
        public Application(IApp page)
        {
            this.ScreenWidth = Native.window.screen.width;
            this.ScreenHeight = Native.window.screen.height;

            var now = DateTime.Now;
            this.ClientTime = now.ToString();

            //Native.document.body.querySelectorAll("script[src='view-source']").WithEach(x => x.Orphanize());

            Console.WriteLine("before notify");
            this.Notfiy().ContinueWithResult(
                data =>
                {
                    Console.WriteLine("");
                    Console.WriteLine("at notify");
                    Console.WriteLine(new { data.visit, data.DataSource.Rows.Count });

                    //                    I/chromium( 2322): ", source: http://192.168.43.7:3678/view-source (29877)
                    //I/chromium( 2322): [INFO:CONSOLE(29877)] "{ visit = 4, Count = 0 }", source: http://192.168.43.7:3678/view-source (29877)

                    var g = new DataGridView
                    {
                        ReadOnly = true,

                        SelectionMode = DataGridViewSelectionMode.FullRowSelect,

                        DataSource = data.DataSource,
                    }.AttachControlToDocument();

                    var reset = new IHTMLButton { "reset" }.AttachToDocument();

                    reset.style.position = IStyle.PositionEnum.absolute;
                    reset.style.right = "1em";
                    reset.style.top = "1em";
                    reset.style.zIndex = 100;

                    reset.WhenClicked(
                        async button =>
                        {
                            await this.Reset();

                            Native.document.documentElement.Clear();

                            Native.window.alert("reload");

                            Native.document.location.reload();
                        }
                    );

                    Console.WriteLine("before CellDoubleClick");

                    #region CellDoubleClick
                    g.CellDoubleClick +=
                        async (sender, args) =>
                        {

                            //As a service to the app, App Engine adds some headers:

                            //X-AppEngine-Country
                            //Country from which the request originated, as an ISO 3166-1 alpha-2 country code. App Engine determines this code from the client's IP address.
                            //X-AppEngine-Region
                            //Name of region from which the request originated. This value only makes sense in the context of the country in X-AppEngine-Country. For example, if the country is "US" and the region is "ca", that "ca" means "California", not Canada.
                            //X-AppEngine-City
                            //Name of the city from which the request originated. For example, a request from the city of Mountain View might have the header value mountain view.
                            //X-AppEngine-CityLatLong
                            //Latitude and longitude of the city from which the request originated. This string might look like "37.386051,-122.083851" for a request from Mountain View.

                            // script: error JSC1000: No implementation found for this native method, please implement [System.Windows.Forms.DataGridView.get_Item(System.String, System.Int32)]
                            //var Key = g["Key", args.RowIndex];

                            // is it a string, long, or signed db enum?
                            var Key = (string)g.Rows[args.RowIndex].Cells["Key"].Value;





                            var gg = new DataGridView
                            {
                                ReadOnly = true,
                                Dock = DockStyle.Fill,

                                SelectionMode = DataGridViewSelectionMode.FullRowSelect
                            };

                            gg.CellFormatting +=
                                (ggsender, e) =>
                                {
                                    if (e.RowIndex < 0)
                                        return;
                                    if (e.ColumnIndex < 0)
                                        return;

                                    if (e.Value == null)
                                        return;

                                    if (e.Value is System.DBNull)
                                        return;



                                    string stringValue = (string)e.Value;

                                    var i = 0;

                                    if (int.TryParse(stringValue, out i))
                                    {
                                        //e.CellStyle.ForeColor = Color.Gray;
                                        //e.CellStyle.ForeColor = Color.FromArgb(0x808080);
                                        //e.CellStyle.BackColor = Color.FromArgb(0xa0, 0xa0, 0xa0);
                                        //e.CellStyle.BackColor = Color.FromArgb(0xf0, 0xf0, 0xf0);
                                        e.CellStyle.BackColor = SystemColors.ButtonFace;
                                    }
                                    else
                                    {
                                        e.CellStyle.BackColor = Color.White;
                                    }
                                };

                            var ff = new Form();
                            ff.Controls.Add(gg);
                            ff.Show();

                            var headers = await this.GetVisitHeadersFor(
                                 (Design.Book1BSheet1Key)Convert.ToInt64(
                                     Key
                                 )
                             );

                            gg.DataSource = headers;


                            //g.DataSource = headers;

                            //Native.window.alert(
                            //    new { args.RowIndex, Key }
                            //    );
                        };
                    #endregion


                }
            );
        }
Exemplo n.º 6
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)
        {

            // Initialize ApplicationSprite
            sprite.AttachSpriteToDocument();


            // how did it work before?
#if v

            #region visualize
            Action<bool, byte[], Action<double, double, Action<double>, IWindow>> visualize_and_getpadding = null;

            visualize_and_getpadding =
                (allowpadding, bytes, set_padding) =>
                {
                    var r = new BinaryReader(new MemoryStream(bytes));

                    var floats = new double[bytes.Length / 4];

                    //Console.WriteLine("floats " + new { floats.Length });


                    for (int i = 0; i < floats.Length; i++)
                    {
                        // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\IO\BinaryReader.cs
                        // do we do floats?
                        floats[i] = r.ReadSingle();
                    }

                    var paddingmode_yellow = allowpadding;
                    var paddingsamples_yellow = 0;
                    var paddingmode_yellow_agg = 0.0;
                    var paddingmode_yellow_grace = 411;

                    var paddingmode_red = allowpadding;
                    var paddingsamples_red = 0;
                    var paddingmode_red_agg = 0.0;
                    var paddingmode_red_grace = 411;


            #region max
                    var min = 0.0;
                    var minset = false;

                    var max = 0.0;
                    var maxset = false;


                    for (int ix = 0; ix < floats.Length; ix += 2)
                    {
                        //                                    arg[0] is typeof System.Single
                        //script: error JSC1000: No implementation found for this native method, please implement [static System.Console.WriteLine(System.Single)]

                        var l0 = floats[ix];
                        var r0 = floats[ix + 1];

                        if (l0 != 0)
                            if (minset)
                            {
                                min = Math.Min(min, l0);
                            }
                            else
                            {
                                min = l0;
                                minset = true;
                            }

                        if (maxset)
                        {
                            max = Math.Max(max, l0);
                        }
                        else
                        {
                            max = l0;
                            maxset = true;
                        }
                    }

                    var absmax = max.Max(Math.Abs(min));

            #endregion


            #region paddingmode_yellow
                    for (int ix = 0; ix < floats.Length; ix += 2)
                    {
                        //                                    arg[0] is typeof System.Single
                        //script: error JSC1000: No implementation found for this native method, please implement [static System.Console.WriteLine(System.Single)]

                        var l0 = floats[ix];
                        var r0 = floats[ix + 1];




                        if (paddingmode_yellow)
                        {
                            // discard noise
                            if (Math.Abs(l0) > 0.08 * absmax)
                                paddingmode_yellow_agg += Math.Abs(l0);
                        }

                        if (paddingmode_yellow_agg > absmax * 2.1)
                        {
                            if (Math.Abs(l0) < 0.02 * absmax)
                            {
                                paddingmode_yellow = false;
                            }
                        }

                        if (paddingmode_yellow)
                        {
                            paddingsamples_yellow++;

                            if (paddingmode_yellow_agg > absmax * 3.2)
                            {
                                if (paddingmode_yellow_grace > 0)
                                {
                                    paddingmode_yellow_grace--;
                                }
                                else
                                {
                                    // rollback
                                    paddingsamples_yellow -= 411;
                                    paddingmode_yellow = false;
                                }
                            }
                        }

                    }
            #endregion

                    // count down while near zero, then wait for zero

            #region paddingmode_red
                    for (int ix = floats.Length - 1; ix >= 0; ix -= 2)
                    {
                        var l0 = floats[ix];
                        var r0 = floats[ix + 1];


                        if (paddingmode_red)
                        {
                            // discard noise
                            if (Math.Abs(l0) > 0.08 * absmax)
                                paddingmode_red_agg += Math.Abs(l0);
                        }

                        if (paddingmode_red_agg > absmax * 2.1)
                        {
                            if (Math.Abs(l0) < 0.02 * absmax)
                            {
                                paddingmode_red = false;
                            }
                        }

                        if (paddingmode_red)
                        {
                            paddingsamples_red++;

                            if (paddingmode_red_agg > absmax * 3.2)
                            {
                                if (paddingmode_red_grace > 0)
                                {
                                    paddingmode_red_grace--;
                                }
                                else
                                {
                                    // rollback
                                    paddingsamples_red -= 411;
                                    paddingmode_red = false;
                                }
                            }
                        }

                    }
            #endregion




                    var w = new IWindow();

                    w.onload +=
                        delegate
                        {
                            Console.WriteLine("onload");

                            try
                            {

                                //BitConverter.ToSingle(
                                w.document.body.style.margin = "0px";

                                // verbose huh. svg::svg?
                                var svg = new ISVGSVGElement().AttachTo(w.document.body);


                                var path_current = new ISVGPathElement().AttachTo(svg);
                                path_current.setAttribute("style", "stroke-width: 5; stroke: blue; fill: none;");


                                var path = new ISVGPathElement().AttachTo(svg);
                                path.setAttribute("style", "stroke: black; fill: none;");

                                var path_loop2 = new ISVGPathElement().AttachTo(svg);
                                path_loop2.setAttribute("style", "stroke: green; fill: none;");


                                var xw = new StringBuilder().Append("M0,400 ");






                                // done { min = 7.847271400218976e-44, max = 2.320612754833406e-38, paddingsamples = 1337 }

                                w.document.body.style.minHeight = 800 + "px";

                                var scalex = 4 / 44.1;

                                w.document.body.style.minWidth = floats.Length * scalex * 2 + "px";
                                w.document.body.style.overflow = IStyle.OverflowEnum.auto;

                                // we should have 4096 stereo samples
                                var samples = floats.Length;
                                var samplesperchannel = samples / 2;






            #region xw
                                for (int ix = 0; ix < floats.Length; ix += 2)
                                {
                                    //                                    arg[0] is typeof System.Single
                                    //script: error JSC1000: No implementation found for this native method, please implement [static System.Console.WriteLine(System.Single)]

                                    var l0 = floats[ix];
                                    var r0 = floats[ix + 1];








                                    // 0 is -60db
                                    // max is 0db



                                    // http://audio.tutsplus.com/articles/general/all-youll-ever-need-to-know-about-samples-and-bits/


                                    //iy = (200.0 - l0 * 1E37 * 200);
                                    var iy = (400.0 - l0 * 400.0);

                                    xw.Append(" L" + (ix * scalex) + "," + iy);


                                    //Console.WriteLine("" + ReadFloat32(i));
                                }
            #endregion

            #region xw_loop2
                                var xw_loop2 = new StringBuilder();

                                for (int ix = paddingsamples_yellow * 2; ix < floats.Length - paddingsamples_red * 2; ix += 2)
                                {
                                    //                                    arg[0] is typeof System.Single
                                    //script: error JSC1000: No implementation found for this native method, please implement [static System.Console.WriteLine(System.Single)]

                                    var l0 = floats[ix];
                                    var r0 = floats[ix + 1];

                                    var iy = (400.0 - l0 * 400.0);

                                    if (xw_loop2.ToString().Length == 0)
                                        xw_loop2.Append(" M" + ((2 * (samplesperchannel - paddingsamples_red - paddingsamples_yellow) * scalex) + ((ix + 1) * scalex)) + "," + iy);
                                    else
                                        xw_loop2.Append(" L" + ((2 * (samplesperchannel - paddingsamples_red - paddingsamples_yellow) * scalex) + ((ix + 1) * scalex)) + "," + iy);

                                }
            #endregion


                                // A frame rate of 44,100 is 44,100 samples per SECOND, or 44.1 kHz.

                                var duration_seconds = samplesperchannel / 44100;

                                w.document.title = new { samplesperchannel, paddingsamples_yellow, paddingsamples_red, duration_seconds }.ToString();

                                Console.WriteLine("done " + new { min, max, paddingsamples_yellow, paddingsamples_red });



                                //xw.Append(" L30,210");

                                path.d = xw.ToString();
                                path_loop2.d = xw_loop2.ToString();

                                var path_zero = new ISVGPathElement().AttachTo(svg);
                                path_zero.setAttribute("style", "stroke-width: 1; stroke: gray; fill: none;");
                                path_zero.d = "M0,400 L" + (2 * samplesperchannel * scalex) + ",400";



                                //var path_leftpadding = new ISVGPathElement().AttachTo(svg);
                                //path_leftpadding.setAttribute("style", "stroke-width: 5; stroke: red; fill: none;");
                                //path_leftpadding.d = "M0,400 L" + (2 * paddingsamples * scalex) + ",400";


                                var path_leftpadding_yellow = new ISVGPathElement().AttachTo(svg);
                                path_leftpadding_yellow.setAttribute("style", "stroke-width: 3; stroke: yellow; fill: none;");
                                path_leftpadding_yellow.d = "M0,400 L" + (2 * paddingsamples_yellow * scalex) + ",400";

                                var path_leftpadding_red = new ISVGPathElement().AttachTo(svg);
                                path_leftpadding_red.setAttribute("style", "stroke-width: 3; stroke: red; fill: none;");
                                path_leftpadding_red.d = "M" + (2 * (samplesperchannel - paddingsamples_red) * scalex) + ",400 L" + (2 * (samplesperchannel - 0) * scalex) + ",400";


                                Action<double> set_position =
                                     position =>
                                     {
                                         var x = (2 * position * scalex);
                                         path_current.d = "M" + x + ",50 L" + x + ",750 L" + (x + MP3PitchLoop.BLOCK_SIZE * 2 * scalex) + ",750 L" + (x + MP3PitchLoop.BLOCK_SIZE * 2 * scalex) + ",50 L" + x + ",50";

                                     };


                                set_padding(
                                    paddingsamples_yellow,
                                    paddingsamples_red,
                                    set_position,
                                    w
                                );

                                set_position(paddingsamples_yellow);

                            }
                            catch (Exception error)
                            {
                                Console.WriteLine("error " + new { error.Message, error });
                            }

                            Console.WriteLine("done");

                        };

                };
            #endregion



      

            #region f
            Func<IHTMLButton, Action<string, PlayAtAndAllowToStop>> f =
                x =>
                     (base64, playat) =>
                     {
                         var bytes = Convert.FromBase64String(base64);

                         visualize_and_getpadding(
                             true,
                             bytes,
                             (paddingleft, paddingright, set_position, w) =>
                             {
                                 var toolbar = new IHTMLDiv().AttachTo(w.document.body);

                                 toolbar.style.SetLocation(4, 4);
                                 toolbar.style.position = IStyle.PositionEnum.@fixed;

                                 new IHTMLButton { innerText = "play" }.AttachTo(toolbar).WhenClicked(
                                     delegate
                                     {
                                         playat(
                                             "" + paddingleft,
                                             "" + paddingright,
                                             yield_stop: stop =>
                                              {

                                                  var stopbtn = new IHTMLButton { innerText = "Stop" };

                                                  stopbtn.WhenClicked(
                                                      delegate
                                                      {
                                                          stop();
                                                          stopbtn.Orphanize();
                                                      }
                                                  );

                                                  stopbtn.AttachTo(toolbar);
                                              },
                                              yield_position_anddiagnostics: (position, diagnostics) =>
                                              {
                                                  set_position(Convert.ToDouble(position));

                                                  if (!string.IsNullOrEmpty(diagnostics))
                                                  {
                                                      Console.WriteLine(diagnostics);

                                                      var diagnostics_bytes = Convert.FromBase64String(diagnostics);

                                                      visualize_and_getpadding(
                                                          false,
                                                          diagnostics_bytes,
                                                          delegate
                                                          { }
                                                      );

                                                  }
                                              }


                                         );
                                     }
                                 );


                             }
                         );
                     };
            #endregion


            page.VisualizeDiesel.WhenClicked(
                delegate
                {
                    sprite.BytesForDiesel(f(page.VisualizeDiesel));
                }
            );

            page.VisualizeHelicopter.onclick += delegate
            {
                sprite.BytesForHelicopter(f(page.VisualizeHelicopter));
            };

            page.VisualizeJeep.onclick += delegate
            {
                sprite.BytesForJeep(f(page.VisualizeJeep));

            };

            page.VisualizeTone.onclick += delegate
            {

                sprite.BytesForTone(f(page.VisualizeTone));

            };

            page.VisualizeSandrun.onclick += delegate
            {

                sprite.BytesForSandrun(f(page.VisualizeSandrun));

            };
#endif

            page.PlayDiesel.onclick += delegate
            {
                sprite.PlayDiesel();
            };

            page.PlayHelicopter.onclick += delegate
            {
                sprite.Playhelicopter1();
            };



            page.PlayJeep.onclick += delegate
            {
                sprite.PlayJeep();
            };






            page.PlayTone.onclick += delegate
            {
                sprite.PlayTone();
            };




            page.PlaySandrun.onclick += delegate
            {
                sprite.PlaySandrun();
            };



        }
Exemplo n.º 7
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(IDefault page)
        {
            @"Hello world".ToDocumentTitle();

            var output = new IHTMLTextArea().AttachToDocument();

            var gexf = new XElement("gexf");

            gexf.Add(
                new XElement("meta",
                             new XElement("creator", "jsc"),
                             new XElement("description", "NASDAQSNA")
                             )
                );

            var graph = new XElement("graph",
                                     new XAttribute("mode", "static"),
                                     new XAttribute("defaultedgetype", "directed")
                                     );

            gexf.Add(graph);

            var nodes = new XElement("nodes");

            graph.Add(nodes);

            var edges = new XElement("edges");

            graph.Add(edges);

            output.value    = gexf.ToString();
            output.onfocus +=
                delegate
            {
                output.value = gexf.ToString();
            };
            output.onmouseover +=
                delegate
            {
                output.value = gexf.ToString();
            };

            var NumericNodeIdLookup = new List <string>();

            Func <string, int> GetNumericNodeId =
                k =>
            {
                if (!NumericNodeIdLookup.Contains(k))
                {
                    NumericNodeIdLookup.Add(k);
                }


                return(NumericNodeIdLookup.IndexOf(k));
            };

            #region AddRelatedCompanies
            Func <IHTMLDiv, string, Action, Task> AddRelatedCompanies = null;

            AddRelatedCompanies =
                (c, qid, done) =>
            {
                var nqid = GetNumericNodeId(qid).ToString();
                var cc   = new IHTMLDiv();

                cc.style.marginLeft = "2em";



                var service = new ApplicationWebService
                {
                    qid   = qid,
                    yield = (id, CompanyName, Price) =>
                    {
                        var nid = GetNumericNodeId(id).ToString();

                        if (nodes.Elements().Any(k => k.Attribute("id").Name.LocalName == nid))
                        {
                        }
                        else
                        {
                            nodes.Add(
                                new XElement("node",
                                             new XAttribute("id", nid),
                                             new XAttribute("label", CompanyName)
                                             )
                                );
                        }



                        var btn = new IHTMLButton
                        {
                            innerText = id + " " + CompanyName + " " + Price
                        };

                        btn.style.display = IStyle.DisplayEnum.block;

                        if (qid == id)
                        {
                            btn.disabled = true;

                            if (c == null)
                            {
                                btn.AttachToDocument();
                                cc.AttachToDocument();
                            }
                            else
                            {
                                //btn.AttachTo(c);
                                cc.AttachTo(c);
                            }

                            if (done != null)
                            {
                                done();
                            }
                        }
                        else
                        {
                            edges.Add(
                                new XElement("edge",
                                             new XAttribute("source", nqid),
                                             new XAttribute("target", nid)
                                             )
                                );

                            btn.AttachTo(cc);

                            var ccc = new IHTMLDiv();

                            ccc.AttachTo(cc);

                            int cx = 0;

                            ccc.ToggleVisible();



                            btn.WhenClicked(
                                async delegate
                            {
                                if (cx == 0)
                                {
                                    btn.style.color = JSColor.Red;

                                    await AddRelatedCompanies(ccc, id,
                                                              delegate
                                    {
                                        btn.style.color = JSColor.Blue;
                                    }
                                                              );
                                }


                                cx++;

                                ccc.ToggleVisible();
                            }
                                );
                        }
                    }
                };



                return(service.GetRelatedCompanies());
            };
            #endregion

            AddRelatedCompanies(null, "NASDAQ:FB", null);
            AddRelatedCompanies(null, "NASDAQ:GOOG", null);
        }