예제 #1
0
        private void DrawGanttBar(DataGridViewCellPaintingEventArgs e, int RowIndex)
        {
            Graphics graphics = e.Graphics;

            if (listRowBitmaps == null)
            {
                return;
            }
            if (listRowBitmaps.Count > RowIndex && listRowBitmaps[RowIndex] != null)
            {
                RectangleF clipRectangle = base.GetCellDisplayRectangle(1, RowIndex, false);
                graphics.DrawImage(listRowBitmaps[RowIndex], e.CellBounds.X, e.CellBounds.Y);
                return;
            }

            IDtsGridRowData dataPackage = (IDtsGridRowData)((BindingSource)DataSource)[0];

            if (dataPackage.DateRanges.Count > 0)
            {
                TimeSpan tsTotal;
                if (dataPackage.DateRanges[0].EndDate > DateTime.MinValue)
                {
                    tsTotal = dataPackage.DateRanges[0].EndDate.Subtract(dataPackage.DateRanges[0].StartDate);
                }
                else
                {
                    tsTotal = _DataBindingDate.Subtract(dataPackage.DateRanges[0].StartDate);
                }
                if (Columns[1].Width != ((int)(tsTotal.TotalSeconds * PIXELS_PER_SECOND + 2)))
                {
                    Columns[1].Width = ((int)(tsTotal.TotalSeconds * PIXELS_PER_SECOND + 2));
                }

                RectangleF clipRectangle = base.GetCellDisplayRectangle(1, RowIndex, false);
                graphics.SetClip(clipRectangle);
                float height = clipRectangle.Height;
                int   num4   = this.Columns[1].Width - (int)clipRectangle.Width;

                if (this.IsRowVisible(RowIndex))
                {
                    int iRowHeight = Rows[RowIndex].Height;
                    int iBarHeight = iRowHeight - 6;

                    Bitmap   canvas  = new Bitmap((int)clipRectangle.Width, (int)clipRectangle.Height, e.Graphics);
                    Graphics gBitmap = Graphics.FromImage(canvas);
                    gBitmap.SmoothingMode     = SmoothingMode.AntiAlias;
                    gBitmap.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                    IDtsGridRowData data                 = (IDtsGridRowData)((BindingSource)DataSource)[RowIndex];
                    DateRange       rangePrev            = null;
                    int             iOverlappingDiamonds = 1;
                    for (int iRange = 0; iRange < data.DateRanges.Count; iRange++)
                    {
                        DateRange range  = data.DateRanges[iRange];
                        TimeSpan  tsLeft = range.StartDate.Subtract(dataPackage.DateRanges[0].StartDate);
                        if (data.Type == typeof(PipelinePath))
                        {
                            int x = (int)(PIXELS_PER_SECOND * tsLeft.TotalSeconds);
                            if (x > 0)
                            {
                                x -= BIDSHelper.Resources.Common.SmallBlueDiamond.Width / 2;
                            }
                            else
                            {
                                x -= 4;
                            }

                            if (rangePrev != null && rangePrev.StartDate == range.StartDate)
                            {
                                iOverlappingDiamonds++;
                                PointF pointDot = new PointF(x, 0);
                                if (iRange == data.DateRanges.Count - 1 || data.DateRanges[iRange + 1].StartDate != range.StartDate)
                                {
                                    string s = (iOverlappingDiamonds > 9 ? "+" : iOverlappingDiamonds.ToString());
                                    gBitmap.DrawString(s, FONT_DIAMOND_SUPERSCRIPT, Brushes.DarkBlue, new PointF(x + 7F, -1F));
                                    gBitmap.DrawIcon(BIDSHelper.Resources.Common.SmallBlueDiamond, x, (int)3);
                                }
                            }
                            else
                            {
                                iOverlappingDiamonds = 1;
                                gBitmap.DrawIcon(BIDSHelper.Resources.Common.SmallBlueDiamond, x, (int)3);
                            }
                        }
                        else
                        {
                            TimeSpan tsBar;
                            if (range.EndDate > DateTime.MinValue)
                            {
                                tsBar = range.EndDate.Subtract(range.StartDate);
                            }
                            else
                            {
                                tsBar = _DataBindingDate.Subtract(range.StartDate);
                            }
                            float x     = (float)(PIXELS_PER_SECOND * tsLeft.TotalSeconds);
                            float width = (float)(PIXELS_PER_SECOND * tsBar.TotalSeconds);
                            if (width < (float)(iBarHeight) / 2f)
                            {
                                width = (float)(iBarHeight) / 2f;
                                if (x > 0)
                                {
                                    x -= width / 2f;
                                }
                            }

                            GraphicsPath path       = GetRoundedRectanglePath(x, 2, width, (float)(iBarHeight), (float)((iBarHeight) / 5f));
                            Color        colorDark  = (data.IsError ? Color.DarkRed : Color.DarkBlue);
                            Color        colorLight = (data.IsError ? Color.Red : Color.Blue);
                            gBitmap.FillPath(new LinearGradientBrush(new Point(0, 2), new Point(0, 2 + iBarHeight), Color.FromArgb(0x80, colorLight), Color.FromArgb(0xe0, colorDark)), path);
                            gBitmap.DrawPath(Pens.Black, path);
                        }
                        rangePrev = range;
                    }

                    //cache the bitmap so the expense of recreating it won't have to happen on scroll of the grid
                    if (listRowBitmaps.Count > RowIndex)
                    {
                        listRowBitmaps[RowIndex] = canvas;
                        clipRectangle            = base.GetCellDisplayRectangle(1, RowIndex, false);
                        graphics.DrawImage(listRowBitmaps[RowIndex], e.CellBounds.X, e.CellBounds.Y);
                    }
                }
            }
            graphics.ResetClip();
        }
        public void LoadEvent(DtsLogEvent e)
        {
            if (!listComponentsPerformanceLookup.ContainsKey(e.SourceId))
            {
                return;
            }
            DtsObjectPerformance perf = listComponentsPerformanceLookup[e.SourceId];

            if (e.Event == BidsHelperCapturedDtsLogEvent.OnPipelineRowsSent)
            {
                //<ignore> : <ignore> : PathID : PathName : TransformID : TransformName : InputID : InputName : RowsSent
                //Denali includes the following at the end... DestinationTransformName : Paths[SourceName.SourceOutputName] : DestinationTransformName.Inputs[InputName]
                DtsPipelinePerformance pipePerf = (DtsPipelinePerformance)perf;
                string[] parts    = e.Message.Split(new string[] { " : " }, StringSplitOptions.None);
                int      iPathID  = int.Parse(parts[2]);
                int      iInputID = int.Parse(parts[6]);
                if (pipePerf.InputOutputLookup.ContainsKey(iInputID))
                {
                    PipelinePath path = pipePerf.InputOutputLookup[iInputID];
                    path.DateRanges.Add(new DateRange(e.StartTime, e.EndTime));
                    path.RowCount += int.Parse(parts[8]);
                    path.BufferCount++;
                }
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.OnPipelinePrePrimeOutput)
            {
                //PrimeOutput will be called on a component. : 28490 : Flat File Source 1
                //<ignore> : TransformID : TransformName
                DtsPipelinePerformance pipePerf = (DtsPipelinePerformance)perf;
                string[] parts        = e.Message.Split(new string[] { " : " }, StringSplitOptions.None);
                int      iTransformID = int.Parse(parts[1]);
                foreach (ExecutionTree tree in pipePerf.ExecutionTrees)
                {
                    if (tree.Paths.Count > 0)
                    {
                        PipelinePath path = tree.Paths[0]; //only look for the component on the output of the first path
                        if (path.OutputTransformID == iTransformID)
                        {
                            tree.DateRanges.Add(new DateRange(e.StartTime));
                            //break; //there could be multiple execution trees started by the same component?
                        }
                    }
                }
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.OnPipelinePostEndOfRowset)
            {
                //A component has finished processing all of its rows. : 30341 : Multicast : 30342 : Multicast Input 1
                //<ignore> : TransformID : TransformName : InputID : InputName
                DtsPipelinePerformance pipePerf = (DtsPipelinePerformance)perf;
                string[] parts    = e.Message.Split(new string[] { " : " }, StringSplitOptions.None);
                int      iInputID = int.Parse(parts[3]);

                foreach (ExecutionTree tree in pipePerf.ExecutionTrees)
                {
                    foreach (PipelinePath path in tree.Paths)
                    {
                        if (path.InputID == iInputID)
                        {
                            if (tree.DateRanges.Count > 0) //this is to avoid an error on issue 31275 where OnPipelinePrePrimeOutput wasn't ever called so we didn't start a date range
                            {
                                DateRange lastDateRange = tree.DateRanges[tree.DateRanges.Count - 1];
                                if (lastDateRange.EndDate == DateTime.MinValue)
                                {
                                    lastDateRange.EndDate = e.EndTime;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.OnPreExecute)
            {
                perf.DateRanges.Add(new DateRange(e.StartTime));
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.OnPostExecute)
            {
                if (perf.DateRanges.Count > 0)
                {
                    DateRange lastDateRange = perf.DateRanges[perf.DateRanges.Count - 1];
                    if (lastDateRange.EndDate == DateTime.MinValue)
                    {
                        lastDateRange.EndDate = e.EndTime;
                    }
                }
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.PipelineExecutionTrees)
            {
                DtsPipelinePerformance pipePerf = (DtsPipelinePerformance)perf;
                ExecutionTree          tree     = null;
                foreach (string line in e.Message.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (line.StartsWith(EXECUTION_TREE_START_PHRASE))
                    {
                        int iTreeID = int.Parse(line.Substring(EXECUTION_TREE_START_PHRASE.Length));
                        tree          = new ExecutionTree();
                        tree.ID       = iTreeID;
                        tree.UniqueId = pipePerf.ID + "ExecutionTree" + iTreeID;
                        tree.Name     = "Execution Tree " + iTreeID;

                        bool bFoundTree = false;
                        foreach (ExecutionTree t in pipePerf.ExecutionTrees)
                        {
                            if (t.ID == tree.ID)
                            {
                                bFoundTree = true;
                                break;
                            }
                        }
                        if (!bFoundTree)
                        {
                            pipePerf.ExecutionTrees.Add(tree);
                        }
                    }
                    else if (line.StartsWith(EXECUTION_TREE_END_PHRASE))
                    {
                        //skip line
                    }
                    else
                    {
                        Match match = regexExecutionTreeOutput.Match(line);

#if DENALI || SQL2014
                        if (match.Groups.Count == 3)
                        {
                            string sComponent = match.Groups[1].Value;
                            string sOutput    = match.Groups[2].Value;
                            foreach (PipelinePath path in pipePerf.InputOutputLookup.Values)
                            {
                                if (path.OutputName == sOutput && path.OutputTransformName == sComponent && !tree.Paths.Contains(path))
                                {
                                    tree.Paths.Add(path);
                                }
                            }
                        }
#else
                        if (match.Groups.Count == 2)
                        {
                            int iOutputID = int.Parse(match.Groups[1].Value);
                            if (pipePerf.InputOutputLookup.ContainsKey(iOutputID) && !tree.Paths.Contains(pipePerf.InputOutputLookup[iOutputID]))
                            {
                                tree.Paths.Add(pipePerf.InputOutputLookup[iOutputID]);
                            }
                        }
#endif
                    }
                }
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.PipelineExecutionPlan)
            {
                DtsPipelinePerformance pipePerf = (DtsPipelinePerformance)perf;
                foreach (string line in e.Message.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                {
                    Match match = regexCreateBuffer.Match(line);
                    if (match.Groups.Count == 3)
                    {
                        int iBufferID       = int.Parse(match.Groups[1].Value) - 1;
                        int iBufferRowCount = pipePerf.GetBufferRowCount(iBufferID);
                        int iOutputID       = int.Parse(match.Groups[2].Value);
                        foreach (ExecutionTree tree in pipePerf.ExecutionTrees)
                        {
                            foreach (PipelinePath path in tree.Paths)
                            {
                                if (path.OutputID == iOutputID)
                                {
                                    tree.BufferRowCount = iBufferRowCount;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.BufferSizeTuning)
            {
                DtsPipelinePerformance pipePerf = (DtsPipelinePerformance)perf;
                Match match = regexBufferSizeTuning.Match(e.Message);
                if (match.Groups.Count == 3)
                {
                    int iBufferID       = int.Parse(match.Groups[1].Value);
                    int iBufferRowCount = int.Parse(match.Groups[2].Value);
                    pipePerf.SetBufferRowCount(iBufferID, iBufferRowCount);
                }
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.OnError)
            {
                perf.IsError = true;
                this.Errors.Add(e.Message);
            }
            else if (e.Event == BidsHelperCapturedDtsLogEvent.PackageEnd)
            {
                this.PackageEndReceived = true;
            }
        }