Exemplo n.º 1
0
        public void ExecutePackage()
        {
            try
            {
                if (this.projectItem.DTE.Mode == vsIDEMode.vsIDEModeDebug)
                {
                    MessageBox.Show("Please stop the debugger first.");
                    return;
                }

                lTickerCounter = 0;
                ExecutionCancelled = false;
                this.lblStatus.Text = "Status: Preparing Temporary Package";

                RefreshProjectAndPackageProperties();

                this.modifiedPackage = ssisApp.LoadPackage(projectItem.get_FileNames(0), null);
                this.modifiedPackagePath = System.IO.Path.GetTempFileName();
                this.logFilePath = System.IO.Path.GetTempFileName();

                SetupCustomLogging(this.modifiedPackage, this.logFilePath);
                ssisApp.SaveToXml(this.modifiedPackagePath, this.modifiedPackage, null);

                eventParser = new DtsPerformanceLogEventParser(this.modifiedPackage);

                //setup Process object to call the dtexec EXE
                process = new System.Diagnostics.Process();
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardError = false;
                process.StartInfo.RedirectStandardOutput = false;
                process.StartInfo.WorkingDirectory = System.IO.Directory.GetCurrentDirectory(); //inherit the working directory from the current BIDS process (so that relative dtsConfig paths will work)
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.FileName = "\"" + this.dtexecPath + "\"";
                process.StartInfo.Arguments = "/Rep N /F \"" + this.modifiedPackagePath + "\"";
                if (!string.IsNullOrEmpty(this.packagePassword))
                {
                    process.StartInfo.Arguments += " /Decrypt \"" + this.packagePassword + "\"";
                }
                process.Start();
                timer1.Enabled = true;
                timer1.Start();

                logFileLoader = new DtsTextLogFileLoader(this.logFilePath);

                //TODO: capture perfmon: SQL Server:SSISPipeline:Buffers Spooled

                this.dtsStatisticsTrendGrid1.AddNewColumnOnNextDataBinding = true;

                this.iDtsGanttGridRowDataBindingSource.DataSource = eventParser.GetAllDtsGanttGridRowDatas();
                this.ganttGrid.Refresh();

                this.StopButton.Enabled = true;
                this.StartButton.Enabled = false;
                this.lblStatus.Text = "Status: Executing";

                this.menuGantt.Visible = true;
                this.menuGrid.Visible = true;
                this.menuTrend.Visible = true;

                if (this.dtsPipelineBreakdownGrid.Visible)
                    SwitchToGanttGridMenuClicked(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        public void ExecuteTests()
        {
            this._Failed = false;
            this._ExecutionCancelled = false;
            this._TestsRunning = false;
            this._TestIndex = 0;

            CreateStartingPointPackage();

            string sNewPackagePath = null;
            Package packageToModify = null;

            this._PackageToReference = _app.LoadPackage(this._StartingPointPackagePath, null);
            Executable exe = FindExecutable(this._PackageToReference, this._DataFlowID);
            if (exe == null || !(exe is TaskHost))
            {
                this._Failed = true;
                VisualStudioHelpers.SafeShowMessageBox(this.PerformanceTab, "Couldn't find data flow task with ID " + this._DataFlowID);
                return;
            }

            TaskHost dataFlowTask = (TaskHost)exe;
            MainPipe pipelineReference = dataFlowTask.InnerObject as MainPipe;
            if (pipelineReference == null)
            {
                this._Failed = true;
                VisualStudioHelpers.SafeShowMessageBox(this.PerformanceTab, "Task ID " + this._DataFlowID + " was not a data flow task");
                return;
            }

            CreateTests(pipelineReference);
            if (_ExecutionCancelled) return;

            this._PreparingTestIterations = false;
            this._TestsRunning = true;

            try
            {
                foreach (DtsPipelineComponentTest test in this._Tests)
                {
                    _TestIndex++;
                    sNewPackagePath = this._TempDirectory + "\\Test" + _TestIndex.ToString() + "_Component" + test.ComponentToTest.ID + "_" + test.TestType.ToString() + ".dtsx";

                    if (_ExecutionCancelled) return;

                    //reload package objects so the prior test's changes don't carry forward
                    packageToModify = _app.LoadPackage(this._StartingPointPackagePath, null);
                    TaskHost taskToModify = (TaskHost)FindExecutable(packageToModify, this._DataFlowID);
                    MainPipe pipeline = (MainPipe)taskToModify.InnerObject;
                    IDTSComponentMetaDataXX component = (IDTSComponentMetaDataXX)pipeline.GetObjectByID(test.ComponentToTest.ID);
                    IDTSComponentMetaDataXX componentReference = (IDTSComponentMetaDataXX)pipelineReference.GetObjectByID(test.ComponentToTest.ID);

                    if (test.TestType == DtsPipelineComponentTestType.SourceOnly)
                    {
                        DeleteAllNonUpstreamComponents(pipeline, component);
                        foreach (IDTSOutputXX output in component.OutputCollection)
                        {
                            if (_ExecutionCancelled) return;
                            if (componentReference.OutputCollection.FindObjectByID(output.ID).IsAttached)
                            {
                                if (HasUnsupportedRawFileColumnDataTypes(componentReference))
                                    HookupRowCountTransform(taskToModify, pipeline, output);
                                else
                                    HookupRawDestination(pipeline, output);
                            }
                        }
                    }
                    else if (test.TestType == DtsPipelineComponentTestType.UpstreamOnly || test.TestType == DtsPipelineComponentTestType.UpstreamOnlyWithoutComponentItself)
                    {
                        ReplaceUpstreamDestinationOutputsWithRawFileSource(pipeline, pipelineReference, component);
                        if (_ExecutionCancelled) return;
                        DeleteAllNonUpstreamComponents(pipeline, component);
                        if (_ExecutionCancelled) return;
                        ReplaceSourcesWithRawFileSource(pipeline, pipelineReference);
                        if (test.TestType == DtsPipelineComponentTestType.UpstreamOnly)
                        {
                            foreach (IDTSOutputXX output in component.OutputCollection)
                            {
                                if (_ExecutionCancelled) return;
                                if (ContainsID(pipelineReference, output.ID) && componentReference.OutputCollection.FindObjectByID(output.ID).IsAttached)
                                {
                                    HookupRowCountTransform(taskToModify, pipeline, output);
                                }
                            }
                        }
                        else
                        {
                            int iInputIndex = 0;
                            while (iInputIndex < component.InputCollection.Count)
                            {
                                if (_ExecutionCancelled) return;
                                IDTSInputXX input = component.InputCollection[iInputIndex];
                                if (input.IsAttached)
                                {
                                    IDTSPathXX path = GetPathForInput(input, pipeline.PathCollection);
                                    IDTSOutputXX output = path.StartPoint;
                                    RemovePath(path, pipeline.PathCollection, false);
                                    HookupRowCountTransform(taskToModify, pipeline, output);
                                }
                                else
                                {
                                    iInputIndex++;
                                }
                            }
                            pipeline.ComponentMetaDataCollection.RemoveObjectByID(component.ID);
                        }
                    }
                    else if (test.TestType == DtsPipelineComponentTestType.DestinationOnlyWithoutComponentItself)
                    {
                        ReplaceUpstreamDestinationOutputsWithRawFileSource(pipeline, pipelineReference, component);
                        if (_ExecutionCancelled) return;
                        DeleteAllNonUpstreamComponents(pipeline, component);
                        if (_ExecutionCancelled) return;
                        ReplaceSourcesWithRawFileSource(pipeline, pipelineReference);
                        if (_ExecutionCancelled) return;

                        IDTSInputXX input = component.InputCollection[0]; //only one input for destinations supported
                        if (input.IsAttached)
                        {
                            IDTSPathXX path = GetPathForInput(input, pipeline.PathCollection);
                            IDTSOutputXX output = path.StartPoint;
                            RemovePath(path, pipeline.PathCollection, false);
                            HookupRawDestination(pipeline, output); //won't ever run this test type if there are unsupported raw file datatypes
                        }
                        pipeline.ComponentMetaDataCollection.RemoveObjectByID(component.ID);
                    }
                    else if (test.TestType == DtsPipelineComponentTestType.DestinationOnly)
                    {
                        bool bHasUnsupportedRawFileColumnDataTypes = HasUnsupportedRawFileColumnDataTypes(component);
                        if (!bHasUnsupportedRawFileColumnDataTypes)
                        {
                            //now use that raw file I just created as a source which goes directly to the component
                            IDTSInputXX input = component.InputCollection[0]; //only one input for destinations supported
                            if (input.IsAttached)
                            {
                                IDTSPathXX path = GetPathForInput(input, pipeline.PathCollection);
                                IDTSOutputXX output = path.StartPoint;
                                IDTSComponentMetaDataXX componentNextInPath = input.Component;
                                RemovePath(path, pipeline.PathCollection, true);
                                HookupRawSource(pipeline, pipelineReference, input, componentNextInPath, GetRawFilePathForOutput(output));
                            }
                        }
                        if (_ExecutionCancelled) return;

                        DeleteAllNonUpstreamComponents(pipeline, component);

                        if (!bHasUnsupportedRawFileColumnDataTypes)
                        {
                            foreach (IDTSOutputXX output in component.OutputCollection)
                            {
                                if (_ExecutionCancelled) return;
                                HookupRawDestination(pipeline, output);
                            }
                        }
                    }
                    if (_ExecutionCancelled) return;
                    AttachRowCountTransformToAllUnattachedOutputs(taskToModify, pipeline);
                    if (_ExecutionCancelled) return;

                    if (System.IO.File.Exists(_LogFilePath)) System.IO.File.Delete(_LogFilePath);

                    _app.SaveToXml(sNewPackagePath, packageToModify, null);

                    DtsPerformanceLogEventParser eventParser = new DtsPerformanceLogEventParser(packageToModify);

                    //setup Process object to call the dtexec EXE
                    _Process = new System.Diagnostics.Process();
                    _Process.StartInfo.UseShellExecute = false;
                    _Process.StartInfo.RedirectStandardError = false;
                    _Process.StartInfo.RedirectStandardOutput = false;
                    _Process.StartInfo.WorkingDirectory = System.IO.Directory.GetCurrentDirectory(); //inherit the working directory from the current BIDS process (so that relative dtsConfig paths will work)
                    _Process.StartInfo.CreateNoWindow = true;
                    _Process.StartInfo.FileName = "\"" + this.DtexecPath + "\"";
                    _Process.StartInfo.Arguments = "/Rep N /F \"" + sNewPackagePath + "\"";
                    if (!string.IsNullOrEmpty(this._PackagePassword))
                    {
                        _Process.StartInfo.Arguments += " /Decrypt \"" + this._PackagePassword + "\"";
                    }

                    _Process.Start();
                    _Process.WaitForExit();
                    if (_ExecutionCancelled) return;

                    System.Threading.Thread.Sleep(1000); //wait a second in case log events are still flowing

                    DtsTextLogFileLoader logFileLoader = new DtsTextLogFileLoader(_LogFilePath);
                    DtsLogEvent[] events = logFileLoader.GetEvents(true);

                    string sError = "";
                    foreach (DtsLogEvent ee in events)
                    {
                        eventParser.LoadEvent(ee);
                        if (ee.Event == BidsHelperCapturedDtsLogEvent.OnError)
                        {
                            test.IsError = true;
                            sError += ee.SourceName + " - " + ee.Message;
                            break; //first error message is really all we need
                        }
                    }

                    if (test.IsError)
                    {
                        this._TestsRunning = false;
                        this._Failed = true;
                        System.Windows.Forms.DialogResult result = VisualStudioHelpers.SafeShowMessageBox(this.PerformanceTab, "The following error occurred during test iteration " + this._TestIndex + " and package execution has been stopped.\r\n\r\nClick OK to open the temp directory with the test iteration packages to you can troubleshoot (and then delete manually when finished).\r\nClick Cancel to delete the temp directory now.\r\n\r\n" + sError, "BIDS Helper - Pipeline Component Performance Breakdown - Error", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Error);
                        if (result == System.Windows.Forms.DialogResult.OK)
                        {
                            System.Diagnostics.Process.Start(this._TempDirectory);
                        }
                        else
                        {
                            DeleteTempDirectory();
                        }
                        return;
                    }

                    foreach (IDtsGridRowData row in eventParser.GetAllDtsGanttGridRowDatas())
                    {
                        if (row.UniqueId == this._DataFlowID)
                        {
                            test.TotalSeconds = row.TotalSeconds;
                            break;
                        }
                    }
                    if (_ExecutionCancelled) return;
                }
                DeleteTempDirectory();
            }
            catch (Exception ex)
            {
                //on error, prompt asking them if they would like to save the problem package off somewhere for troubleshooting
                if (packageToModify != null && sNewPackagePath != null)
                {
                    VisualStudioHelpers.SafeShowMessageBox(this.PerformanceTab, "An unexpected error has occurred while executing test iteration " + this._TestIndex + ". The temp directory with the test iteration packages will now open. Please troubleshoot the problem.\r\n\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                    try
                    {
                        _app.SaveToXml(sNewPackagePath, packageToModify, null);
                    }
                    catch (Exception ex2)
                    {
                        VisualStudioHelpers.SafeShowMessageBox(this.PerformanceTab, "problem saving package to path " + sNewPackagePath + "\r\n" + ex2.Message + "\r\n" + ex2.StackTrace);
                    }
                }
                else
                {
                    VisualStudioHelpers.SafeShowMessageBox(this.PerformanceTab, "An unexpected error has occurred while executing test iteration " + this._TestIndex + ". The temp directory with the test iteration packages will now open. Please troubleshoot the problem.\r\n\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                }
                System.Diagnostics.Process.Start(this._TempDirectory);
            }
            finally
            {
                this._TestsRunning = false;
                if (this._ExecutionCancelled)
                    DeleteTempDirectory();
            }
        }