public void Init(EditorWindow parentWin, EditorWindow.EditorView view, ProjectItem pi, string DataFlowGUID)
        {
            this.parentWin   = parentWin;
            this.parentView  = view;
            this.projectItem = pi;

            //capture the project manager object
            sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings settings = (sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)((System.IServiceProvider)pi.ContainingProject).GetService(typeof(sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings));
            this.projectManager = (Microsoft.DataWarehouse.Project.DataWarehouseProjectManager)settings.GetType().InvokeMember("ProjectManager", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy, null, settings, null);

            //capture the output window object
            IOutputWindowFactory service = ((System.IServiceProvider)pi.ContainingProject).GetService(typeof(IOutputWindowFactory)) as IOutputWindowFactory;

            this.standardOutputWindow = service.GetStandardOutputWindow(StandardOutputWindow.Debug);

            //run the package immediately
            if (DataFlowGUID == null)
            {
                ExecutePackage();
            }
            else
            {
                BreakdownPipelinePerformance(DataFlowGUID);
            }
        }
        private void ShowValidationItems(List <string> bimlScriptPaths, Project project, string projectDirectory)
        {
            var tempTargetDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            try
            {
                Directory.CreateDirectory(tempTargetDirectory);

                // Get the General output window, we use it to write out our BIML "compilation" messages
                this.ApplicationObject.ToolWindows.OutputWindow.Parent.SetFocus();
                IOutputWindowFactory service      = ((System.IServiceProvider)project).GetService(typeof(IOutputWindowFactory)) as IOutputWindowFactory;
                IOutputWindow        outputWindow = service.GetStandardOutputWindow(StandardOutputWindow.Build);
                outputWindow.Clear();
                outputWindow.ReportStatusMessage("Validating BIML");

                ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
                ApplicationObject.StatusBar.Progress(true, "Checking Biml for Errors", 1, 2);

                ValidationReporter validationReporter = BimlUtility.GetValidationReporter(bimlScriptPaths, project, projectDirectory, tempTargetDirectory);

                ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                ApplicationObject.StatusBar.Progress(false, "Checking Biml for Errors", 2, 2);

                // If we have no errors and no warnings, say so
                if (!validationReporter.HasErrors && !validationReporter.HasWarnings)
                {
                    // Write a closing message to the output window
                    outputWindow.ReportStatusMessage("No errors or warnings were found.");
                    outputWindow.ReportStatusMessage("BIML validation completed.");

                    // Show message to user
                    MessageBox.Show("No errors or warnings were found.", DefaultMessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    // We have errors and/or warnings. Show both.
                    BimlUtility.ProcessValidationReport(outputWindow, validationReporter, true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                // Clean up the temporary directory and files, but supress any errors encountered
                try
                {
                    if (Directory.Exists(tempTargetDirectory))
                    {
                        Directory.Delete(tempTargetDirectory);
                    }
                }
                catch (Exception)
                {
                }

                try
                {
                    ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                    ApplicationObject.StatusBar.Progress(false, "Checking Biml for Errors", 2, 2);
                }
                catch { }
            }
        }
Ejemplo n.º 3
0
        public override void Exec()
        {
            if (MessageBox.Show("Are you sure you want to change any hardcoded paths pointing to files in the packages directory to relative paths?\r\n\r\nThis command impacts configurations and connection managers.", "BIDS Helper - Fix Relative Paths", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            try
            {
                this.ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationFind);
                this.ApplicationObject.StatusBar.Text = "Fixing relative paths...";

                EnvDTE.Project proj = GetSelectedProjectReference();
                Microsoft.DataWarehouse.Interfaces.IConfigurationSettings settings = (Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)((System.IServiceProvider)proj).GetService(typeof(Microsoft.DataWarehouse.Interfaces.IConfigurationSettings));
                DataWarehouseProjectManager projectManager = (DataWarehouseProjectManager)settings.GetType().InvokeMember("ProjectManager", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy, null, settings, null);

                this.ApplicationObject.ToolWindows.OutputWindow.Parent.SetFocus();
                IOutputWindowFactory service      = ((System.IServiceProvider)proj).GetService(typeof(IOutputWindowFactory)) as IOutputWindowFactory;
                IOutputWindow        outputWindow = service.GetStandardOutputWindow(StandardOutputWindow.Deploy);
                outputWindow.Activate();
                outputWindow.Clear();
                outputWindow.ReportStatusMessage("BIDS Helper is fixing relative paths in all open packages...\r\n");

                bool          bFoundOpenPackage = false;
                StringBuilder sb = new StringBuilder();
                string        sPackageDirectory = string.Empty;
                foreach (ProjectItem item in proj.ProjectItems)
                {
                    try
                    {
                        if (!item.get_IsOpen(BIDSViewKinds.Designer))
                        {
                            continue;
                        }
                    }
                    catch
                    {
                        continue;
                    }
                    if (!bFoundOpenPackage)
                    {
                        bFoundOpenPackage = true;

                        sPackageDirectory = System.IO.Path.GetDirectoryName(item.get_FileNames(0));
                        outputWindow.ReportStatusMessage("The current working directory is:");
                        outputWindow.ReportStatusMessage(System.IO.Directory.GetCurrentDirectory());
                        outputWindow.ReportStatusMessage(string.Empty);
                        outputWindow.ReportStatusMessage("The directory for the packages is:");
                        outputWindow.ReportStatusMessage(sPackageDirectory);
                        outputWindow.ReportStatusMessage(string.Empty);

                        if (string.Compare(sPackageDirectory, System.IO.Directory.GetCurrentDirectory(), true) != 0)
                        {
                            outputWindow.ReportStatusMessage("PROBLEM:");
                            outputWindow.ReportStatusMessage("Since the packages are not in the current working directory, no changes to configurations will be made. Please start Visual Studio by double clicking on the .sln file for the project, and make sure the .sln file is in the same directory as the packages.");
                            return;
                        }
                    }

                    Window w = item.Open(BIDSViewKinds.Designer); //opens the designer
                    w.Activate();

                    IDesignerHost designer = w.Object as IDesignerHost;
                    if (designer == null)
                    {
                        continue;
                    }
                    EditorWindow win     = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator));
                    Package      package = win.PropertiesLinkComponent as Package;
                    if (package == null)
                    {
                        continue;
                    }

                    outputWindow.ReportStatusMessage("Package " + item.Name);

                    #if DENALI || SQL2014
                    Cud.Transaction trans = Cud.BeginTransaction(package);
                    #endif

                    bool bChanged = false;
                    foreach (Microsoft.SqlServer.Dts.Runtime.Configuration config in package.Configurations)
                    {
                        if (config.ConfigurationType == DTSConfigurationType.ConfigFile)
                        {
                            if (string.Compare(System.IO.Path.GetDirectoryName(config.ConfigurationString), System.IO.Directory.GetCurrentDirectory(), true) == 0)
                            {
                                config.ConfigurationString = System.IO.Path.GetFileName(config.ConfigurationString);
                                outputWindow.ReportStatusMessage("  Configuration " + config.Name + " changed to relative path");
                                bChanged = true;

                                #if DENALI || SQL2014
                                trans.ChangeProperty(config, "ConfigurationString");
                                #endif
                            }
                        }
                    }
                    foreach (ConnectionManager conn in package.Connections)
                    {
                        if (string.IsNullOrEmpty(conn.GetExpression("ConnectionString")) && string.Compare(System.IO.Path.GetDirectoryName(conn.ConnectionString), System.IO.Directory.GetCurrentDirectory(), true) == 0)
                        {
                            conn.ConnectionString = System.IO.Path.GetFileName(conn.ConnectionString);
                            outputWindow.ReportStatusMessage("  Connection " + conn.Name + " changed to relative path");
                            bChanged = true;

                            #if DENALI || SQL2014
                            trans.ChangeProperty(conn, "ConnectionString");
                            #endif
                        }
                    }
                    if (bChanged)
                    {
                        SSISHelpers.MarkPackageDirty(package);
                    }
                    else
                    {
                        outputWindow.ReportStatusMessage("  No changes");
                    }
                }

                if (!bFoundOpenPackage)
                {
                    outputWindow.ReportStatusMessage("PROBLEM:");
                    outputWindow.ReportStatusMessage("No packages in this project were open.");
                    return;
                }

                outputWindow.Activate();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
            finally
            {
                this.ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationFind);
                this.ApplicationObject.StatusBar.Text = string.Empty;
            }
        }
Ejemplo n.º 4
0
        private void Expand(List <string> bimlScriptPaths, Project project, string projectDirectory)
        {
            var tempTargetDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            try
            {
                Directory.CreateDirectory(tempTargetDirectory);

                // Get the General output window, and use that to write out our BIML "compilation" messages
                this.ApplicationObject.ToolWindows.OutputWindow.Parent.SetFocus();
                IOutputWindowFactory service      = ((System.IServiceProvider)project).GetService(typeof(IOutputWindowFactory)) as IOutputWindowFactory;
                IOutputWindow        outputWindow = service.GetStandardOutputWindow(StandardOutputWindow.Build);
                outputWindow.Clear();
                outputWindow.ReportStatusMessage("Expanding BIML");

                // Set status here as well as calling method, as that wasn't showing - Check and cleanup later
                ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
                ApplicationObject.StatusBar.Progress(true, "Generating SSIS Packages", 1, 3);

                ValidationReporter validationReporter = BimlUtility.GetValidationReporter(bimlScriptPaths, project, projectDirectory, tempTargetDirectory);

                // If we have errors show them, and finish
                if (validationReporter.HasErrors)
                {
                    ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                    ApplicationObject.StatusBar.Progress(false, "Generating SSIS Packages", 3, 3);
                    BimlUtility.ProcessValidationReport(outputWindow, validationReporter, false);
                }
                else
                {
                    // We can compile OK, but show warnings if we have them
                    if (validationReporter.HasWarnings)
                    {
                        BimlUtility.ProcessValidationReport(outputWindow, validationReporter, true);
                    }

                    // Write a closing message to the output window, since we have completed OK
                    outputWindow.ReportStatusMessage("BIML expansion completed.");
                    ApplicationObject.StatusBar.Progress(true, "Generating SSIS Packages", 2, 3);


                    List <string> newProjectFiles = new List <string>();
                    string[]      newPackageFiles = Directory.GetFiles(tempTargetDirectory, "*.dtsx", SearchOption.AllDirectories);
                    newProjectFiles.AddRange(newPackageFiles);

#if (!YUKON && !KATMAI)
                    //IF DENALI or later...
                    // Read packages AND project connection managers
                    string[] newConnFiles = Directory.GetFiles(tempTargetDirectory, "*.conmgr", SearchOption.AllDirectories);
                    newProjectFiles.AddRange(newConnFiles);
#endif
                    var safePackageFilePaths        = new List <string>();
                    var conflictingPackageFilePaths = new List <string>();
                    foreach (var tempFilePath in newProjectFiles)
                    {
                        string tempFileName        = Path.GetFileName(tempFilePath);
                        string projectItemFileName = Path.Combine(projectDirectory, tempFileName);
                        if (File.Exists(projectItemFileName))
                        {
                            conflictingPackageFilePaths.Add(tempFilePath);
                        }
                        else
                        {
                            safePackageFilePaths.Add(tempFilePath);
                        }
                    }

                    if (conflictingPackageFilePaths.Count > 0)
                    {
                        var dialog = new MultipleSelectionConfirmationDialog(conflictingPackageFilePaths, projectDirectory, safePackageFilePaths.Count);
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            foreach (var filePath in dialog.SelectedFilePaths)
                            {
                                safePackageFilePaths.Add(filePath);
                            }
                        }
                        else
                        {
                            return;
                        }
                    }

#if (DENALI || SQL2014)
                    /*
                     * Make sure that the package correctly references the Project connection manager, if used
                     */
                    List <ProjectConnectionManagerInfo> prjConnInfoList = new List <ProjectConnectionManagerInfo>();

                    // STEP 1 - Store all existing Project Connection Managers
                    foreach (ProjectItem item in project.ProjectItems)
                    {
                        if (item.Name.EndsWith(".conmgr"))
                        {
                            string fileFullPath = item.FileNames[0];

                            XmlReader   r   = new XmlTextReader(fileFullPath);
                            XmlDocument doc = new XmlDocument();
                            doc.Load(r);

                            //XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(doc.NameTable);
                            //xmlnsManager.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts");

                            XmlElement node = doc.DocumentElement;

                            string prefix = node.GetPrefixOfNamespace("www.microsoft.com/SqlServer/Dts");

                            XmlAttribute xaObjectName = node.Attributes[prefix + ":ObjectName"];
                            XmlAttribute xaDTSID      = node.Attributes[prefix + ":DTSID"];

                            if (xaObjectName == null)
                            {
                                throw new ApplicationException("ObjectName attribute cannot found.");
                            }
                            if (xaDTSID == null)
                            {
                                throw new ApplicationException("DTSID attribute cannot found.");
                            }

                            prjConnInfoList.Add(new ProjectConnectionManagerInfo(fileFullPath, xaObjectName.Value, xaDTSID.Value));

                            r.Close();
                        }
                    }

                    // STEP 2 - For all the Connection Managers that have to be inserted in the solution,
                    //          if a connection manager with the same name alread exists, use the existing GUID
                    //          to avoid corrupting the package that will be inserted
                    foreach (var tempFilePath in safePackageFilePaths)
                    {
                        if (tempFilePath.EndsWith(".conmgr"))
                        {
                            string fileFullPath = tempFilePath;

                            XmlReader   r   = new XmlTextReader(fileFullPath);
                            XmlDocument doc = new XmlDocument();
                            doc.Load(r);

                            //XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(doc.NameTable);
                            //xmlnsManager.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts");

                            XmlElement node = doc.DocumentElement;

                            string prefix = node.GetPrefixOfNamespace("www.microsoft.com/SqlServer/Dts");

                            bool saveRequired = false;
                            ProjectConnectionManagerInfo pcmi = prjConnInfoList.Find(x => System.IO.Path.GetFileName(x.FileFullPath) == System.IO.Path.GetFileName(fileFullPath));
                            if (pcmi != null)
                            {
                                XmlAttribute xaDTSID = node.Attributes[prefix + ":DTSID"];
                                if (xaDTSID == null)
                                {
                                    throw new ApplicationException("DTSID attribute cannot found.");
                                }

                                xaDTSID.Value = pcmi.DTSID;
                                saveRequired  = true;
                            }
                            else
                            {
                                XmlAttribute xaObjectName = node.Attributes[prefix + ":ObjectName"];
                                XmlAttribute xaDTSID      = node.Attributes[prefix + ":DTSID"];

                                if (xaObjectName == null)
                                {
                                    throw new ApplicationException("ObjectName attribute cannot found.");
                                }
                                if (xaDTSID == null)
                                {
                                    throw new ApplicationException("DTSID attribute cannot found.");
                                }

                                prjConnInfoList.Add(new ProjectConnectionManagerInfo(fileFullPath, xaObjectName.Value, xaDTSID.Value));
                            }

                            r.Close();

                            if (saveRequired)
                            {
                                doc.Save(fileFullPath);
                            }
                        }
                    }

                    // STEP 3 - For Each NEW package make sure that the Project Connection Manager
                    //          points to the correct GUID
                    foreach (var tempFilePath in safePackageFilePaths)
                    {
                        if (tempFilePath.EndsWith(".dtsx"))
                        {
                            string fileFullPath = tempFilePath;

                            XmlReader   r   = new XmlTextReader(fileFullPath);
                            XmlDocument doc = new XmlDocument();
                            doc.Load(r);

                            XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(doc.NameTable);
                            xmlnsManager.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts");

                            XmlElement root = doc.DocumentElement;

                            XmlNodeList nodes = root.SelectNodes("//connection", xmlnsManager);
                            foreach (XmlNode n in nodes)
                            {
                                string refID = n.Attributes["connectionManagerRefId"].Value;
                                ProjectConnectionManagerInfo pcmi = prjConnInfoList.Find(x => "Package.ConnectionManagers[" + x.ObjectName + "]" == refID);
                                if (pcmi == null)
                                {
                                    pcmi = prjConnInfoList.Find(x => "Project.ConnectionManagers[" + x.ObjectName + "]" == refID);
                                }

                                if (pcmi != null)
                                {
                                    // If a local connection manager does NOT exists, then point to the project connection manager
                                    XmlNode node = root.SelectSingleNode("/DTS:Executable/DTS:ConnectionManagers/DTS:ConnectionManager[@DTS:refId=\"" + pcmi.ObjectName + "\"]", xmlnsManager);
                                    if (node == null)
                                    {
                                        n.Attributes["connectionManagerID"].Value    = pcmi.DTSID + ":external";
                                        n.Attributes["connectionManagerRefId"].Value = "Project.ConnectionManagers[" + pcmi.ObjectName + "]";
                                    }
                                }
                            }

                            r.Close();

                            doc.Save(fileFullPath);
                        }
                    }
#endif

                    // Add files to VS Project
                    foreach (var tempFilePath in safePackageFilePaths)
                    {
                        string projectItemFilePath = Path.Combine(projectDirectory, Path.GetFileName(tempFilePath));
                        File.Copy(tempFilePath, projectItemFilePath, true);
                        project.ProjectItems.AddFromFile(projectItemFilePath);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                try
                {
                    if (Directory.Exists(tempTargetDirectory))
                    {
                        Directory.Delete(tempTargetDirectory);
                    }
                }
                catch (Exception)
                {
                }
            }
        }