コード例 #1
0
        public ApplicationPerformanceForm(IExploreApplicationPerformance service)
        {
            var f = this;



            f.Text = "GetApplicationPerformance";

            var g = new DataGridView
            {
                ScrollBars = System.Windows.Forms.ScrollBars.Vertical,

                AllowUserToAddRows = false,

                Dock = DockStyle.Fill,
                SelectionMode = DataGridViewSelectionMode.FullRowSelect,
                ReadOnly = true,
            }.AttachTo(f);

            #region CellFormatting
            g.CellFormatting +=
                (sender, e) =>
                {
                    var SourceCell = g[e.ColumnIndex, e.RowIndex];
                    var IsSelected = SourceCell.Selected;


                    if (SourceCell.OwningColumn.Name == "Timestamp" && !SourceCell.IsInEditMode)
                    {
                        e.FormattingApplied = true;

                        var t = ScriptCoreLib.Library.StringConversionsForStopwatch.DateTimeConvertFromObject(SourceCell.Value);

                        e.Value = t.ToString();
                        //e.CellStyle.BackColor = g.RowHeadersDefaultCellStyle.BackColor;
                        e.CellStyle.ForeColor = Color.Gray;

                        return;
                    }
                };
            #endregion

            CSSDataGridView.__ContentTable_css_tr.hover.style.textDecoration = "underline";
            CSSDataGridView.__ContentTable_css_tr.hover.style.cursor = IStyle.CursorEnum.pointer;
            CSSDataGridView.__ContentTable_css_tr.hover.style.color = "blue";

            #region Load
            f.Load +=
                async delegate
                {
                    Console.WriteLine("enter f.Load");

                    //await Native.window.requestAnimationFrameAsync;
                    //await Native.window.requestAnimationFrameAsync;
                    var s = Stopwatch.StartNew();
                    var data0 = await service.GetApplicationPerformance();
                    Console.WriteLine("got data0 at f.Load");
                    f.Text += " " + s.ElapsedMilliseconds + "ms";

                    g.DataSourceChanged +=
                        delegate
                        {
                            var p = g.PreferredSize;

                            if (p.Height > 400)
                                p.Height = 400;

                            f.ClientSize = p;
                            f.Left = (Native.window.Width - f.Width) / 2;
                        };

                    g.DataSource = data0;





                };
            #endregion



            // script: error JSC1000: No implementation found for this native method, please implement [System.Windows.Forms.DataGridView.add_CellContentDoubleClick(System.Windows.Forms.DataGridViewCellEventHandler)]
            // script: error JSC1000: No implementation found for this native method, please implement [System.Windows.Forms.DataGridViewCellMouseEventArgs.get_RowIndex()]

            //g.CellContentClick +=
            //g.CellContentDoubleClick +=
            //g.CellMouseClick +=

            #region CellClick
            g.CellClick +=
                async delegate
                {

                    PerformanceResourceTimingData2ApplicationPerformanceRow x = g.SelectedRows.AsEnumerable().Select(
                                row => (PerformanceResourceTimingData2ApplicationPerformanceRow)((DataRowView)row.DataBoundItem).Row
                            ).FirstOrDefault();




                    var kf = new Form
                    {
                        Owner = f,
                        Text = "/GetApplicationResourcePerformance",

                        StartPosition = FormStartPosition.Manual,
                        Left = f.Left,
                        Top = f.Top,
                        Width = f.Width
                    };

                    var kg = new DataGridView
                    {

                        ScrollBars = System.Windows.Forms.ScrollBars.Vertical, // while not maximized

                        AllowUserToAddRows = false,

                        Dock = DockStyle.Fill,
                        SelectionMode = DataGridViewSelectionMode.FullRowSelect,
                        ReadOnly = true,



                    }.AttachTo(kf);


                    #region CellFormatting
                    kg.CellFormatting +=
                        (sender, e) =>
                        {
                            var SourceCell = kg[e.ColumnIndex, e.RowIndex];
                            var IsSelected = SourceCell.Selected;


                            if (SourceCell.OwningColumn.Name == "Timestamp" && !SourceCell.IsInEditMode)
                            {
                                e.FormattingApplied = true;

                                var t = ScriptCoreLib.Library.StringConversionsForStopwatch.DateTimeConvertFromObject(SourceCell.Value);

                                e.Value = t.ToString();
                                //e.CellStyle.BackColor = kkg.RowHeadersDefaultCellStyle.BackColor;
                                e.CellStyle.ForeColor = Color.Gray;

                                return;
                            }

                            #region duration
                            if (SourceCell.OwningColumn.Name == "duration" && !SourceCell.IsInEditMode)
                            {
                                e.FormattingApplied = true;

                                var crow = (PerformanceResourceTimingData2ApplicationResourcePerformanceRow)((DataRowView)SourceCell.OwningRow.DataBoundItem).Row;
                                e.Value = crow.duration + "ms";

                                var rows =
                                    kg.Rows.AsEnumerable().Where(xx => xx.DataBoundItem != null).Select(
                                         xrow => ((PerformanceResourceTimingData2ApplicationResourcePerformanceRow)((DataRowView)xrow.DataBoundItem).Row)
                                    );

                                var min = rows.Min(
                                    xx => xx.duration
                                    );
                                var max = rows.Max(
                                    xx => xx.duration
                                    );
                                SourceCell.ToolTipText = new { crow.duration, min, max }.ToString();

                                var red = (int)(((crow.duration - min) * 255) / (max - min));

                                e.CellStyle.ForeColor = Color.FromArgb(
                                    red: red,
                                    green: 0,
                                    blue: 255 - red
                                );
                                e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

                                return;
                            }
                            #endregion

                            #region path
                            if (SourceCell.OwningColumn.Name == "path" && !SourceCell.IsInEditMode)
                            {
                                var crow = (PerformanceResourceTimingData2ApplicationResourcePerformanceRow)((DataRowView)SourceCell.OwningRow.DataBoundItem).Row;

                                var red = crow.path.Contains("xml/") ? 255 : 0;

                                e.CellStyle.ForeColor = Color.FromArgb(
                                    red: red,
                                    green: 0,
                                    blue: 255 - red
                                );

                                return;
                            }
                            #endregion
                        };
                    #endregion


                    kf.Load +=
                      async delegate
                      {
                          Console.WriteLine("enter kf.Load");

                          var s = Stopwatch.StartNew();
                          var kdata = await service.GetApplicationResourcePerformance(x);
                          Console.WriteLine("got kdata at kf.Load");
                          kf.Text += " " + s.ElapsedMilliseconds + "ms";

                          kg.DataSourceChanged +=
                              delegate
                              {


                                  kf.ClientSize = kg.PreferredSize;

                                  // script: error JSC1000: No implementation found for this native method, please implement [System.Windows.Forms.DataGridViewColumnCollection.get_Item(System.String)]

                                  // when is it ready?

                                  //await Task.Delay(2);
                                  //kg.Columns["name"].Width = 8;
                                  kg.Columns["name"].Visible = false;

                              };

                          kg.DataSource = kdata.AsDataTable();
                      };


                    kg.CellClick +=
                        delegate
                        {
                            kg.SelectedRows.AsEnumerable().Select(
                                row => (PerformanceResourceTimingData2ApplicationResourcePerformanceRow)((DataRowView)row.DataBoundItem).Row
                            ).FirstOrDefault().With(
                                async row =>
                                {
                                    var kkf = new Form
                                    {
                                        Owner = kf,
                                        Text = "GetSimilarApplicationResourcePerformance",
                                        StartPosition = FormStartPosition.Manual,

                                        // centerparent!
                                        Left = kf.Left,
                                        Top = kf.Top,
                                        Width = kf.Width
                                    };

                                    var kkg = new DataGridView
                                    {
                                        ScrollBars = System.Windows.Forms.ScrollBars.Vertical,
                                        AllowUserToAddRows = false,

                                        //DataSource = kdata,
                                        Dock = DockStyle.Fill,
                                        SelectionMode = DataGridViewSelectionMode.FullRowSelect,
                                        ReadOnly = true
                                    }.AttachTo(kkf);


                                    #region CellFormatting
                                    kkg.CellFormatting +=
                                        (sender, e) =>
                                        {
                                            var SourceCell = kkg[e.ColumnIndex, e.RowIndex];
                                            var IsSelected = SourceCell.Selected;


                                            if (SourceCell.OwningColumn.Name == "Timestamp" && !SourceCell.IsInEditMode)
                                            {
                                                e.FormattingApplied = true;

                                                var t = ScriptCoreLib.Library.StringConversionsForStopwatch.DateTimeConvertFromObject(SourceCell.Value);

                                                e.Value = t.ToString();
                                                //e.CellStyle.BackColor = kkg.RowHeadersDefaultCellStyle.BackColor;
                                                e.CellStyle.ForeColor = Color.Gray;

                                                return;
                                            }

                                            #region duration
                                            if (SourceCell.OwningColumn.Name == "duration" && !SourceCell.IsInEditMode)
                                            {
                                                e.FormattingApplied = true;

                                                var crow = (PerformanceResourceTimingData2ApplicationResourcePerformanceRow)((DataRowView)SourceCell.OwningRow.DataBoundItem).Row;
                                                e.Value = crow.duration + "ms";

                                                var rows =
                                                    kkg.Rows.AsEnumerable().Where(xx => xx.DataBoundItem != null).Select(
                                                         xrow => ((PerformanceResourceTimingData2ApplicationResourcePerformanceRow)((DataRowView)xrow.DataBoundItem).Row)
                                                    );

                                                var min = rows.Min(
                                                    xx => xx.duration
                                                    );
                                                var max = rows.Max(
                                                    xx => xx.duration
                                                    );

                                                SourceCell.ToolTipText = new { crow.duration, min, max }.ToString();


                                                var red = (int)(((crow.duration - min) * 255) / (max - min));

                                                e.CellStyle.ForeColor = Color.FromArgb(
                                                    red: red,
                                                    green: 0,
                                                    blue: 255 - red
                                                );
                                                e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;


                                                return;
                                            }
                                            #endregion


                                            #region path
                                            if (SourceCell.OwningColumn.Name == "path" && !SourceCell.IsInEditMode)
                                            {
                                                var crow = (PerformanceResourceTimingData2ApplicationResourcePerformanceRow)((DataRowView)SourceCell.OwningRow.DataBoundItem).Row;

                                                var red = crow.path.Contains("xml?") ? 255 : 0;

                                                e.CellStyle.ForeColor = Color.FromArgb(
                                                    red: red,
                                                    green: 0,
                                                    blue: 255 - red
                                                );

                                                return;
                                            }
                                            #endregion
                                        };
                                    #endregion


                                    #region Load
                                    kkf.Load +=
                                        async delegate
                                        {
                                            Console.WriteLine("enter kkf.Load");
                                            //kkg.DataSource = await this.GetSimilarApplicationResourcePerformance(row);

                                            var s = Stopwatch.StartNew();

                                            var xdata = await service.GetSimilarApplicationResourcePerformance(row);
                                            Console.WriteLine("got xdata at kkf.Load");
                                            kkf.Text += " " + s.ElapsedMilliseconds + "ms";

                                            kkg.DataSourceChanged +=
                                                delegate
                                                {
                                                    var p = kkg.PreferredSize;
                                                    p.Height = p.Height.Min(400);

                                                    kkf.ClientSize = p;
                                                };

                                            kkg.DataSource = xdata;


                                        };
                                    #endregion

                                    //kf.Hide();

                                    //Native.document.title = "kkf";
                                    await kkf.ShowAsync(hideOwner: true);

                                    //kf.Show();

                                    //Native.document.title = "kf";

                                }
                            );
                        };

                    //Native.document.title = "kf";
                    await kf.ShowAsync(hideOwner: true);
                    //Native.document.title = "f";


                };
            #endregion
        }