Exemplo n.º 1
0
        public override void Exec()
        {
            if (!BimlUtility.CheckRequiredFrameworkVersion())
            {
                return;
            }

            UIHierarchy solExplorer        = this.ApplicationObject.ToolWindows.SolutionExplorer;
            var         emittableFilePaths = new List <string>();
            Project     containingProject  = null;
            string      projectDirectory   = null;
            bool        sameProject        = false;

            foreach (object selected in ((System.Array)solExplorer.SelectedItems))
            {
                UIHierarchyItem hierItem    = (UIHierarchyItem)selected;
                ProjectItem     projectItem = hierItem.Object as ProjectItem;
                if (projectItem != null && projectItem.Name.ToLower().EndsWith(".biml"))
                {
                    if (projectItem.Document != null && !projectItem.Document.Saved)
                    {
                        projectItem.Document.Save(null);
                    }

                    Project newContainingProject = projectItem.ContainingProject;
                    sameProject       = containingProject == null || containingProject == newContainingProject;
                    containingProject = projectItem.ContainingProject;
                    projectDirectory  = Path.GetDirectoryName(containingProject.FullName);
                    string filePath = Path.Combine(projectDirectory, projectItem.Name);
                    emittableFilePaths.Add(filePath);
                }
            }

            if (sameProject && containingProject != null && projectDirectory != null)
            {
                try
                {
                    ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
                    ApplicationObject.StatusBar.Progress(true, "Generating SSIS Packages", 1, 3);

                    Expand(emittableFilePaths, containingProject, projectDirectory);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    try
                    {
                        ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationDeploy);
                        ApplicationObject.StatusBar.Progress(false, "Generating SSIS Packages", 3, 3);
                    }
                    catch { }
                }
            }
        }
        public override void Exec()
        {
            if (Biml.BimlUtility.ShowDisabledMessage())
            {
                return;
            }

            if (!BimlUtility.CheckRequiredFrameworkVersion())
            {
                return;
            }

            UIHierarchy solExplorer        = this.ApplicationObject.ToolWindows.SolutionExplorer;
            var         emittableFilePaths = new List <string>();
            Project     containingProject  = null;
            string      projectDirectory   = null;
            bool        sameProject        = false;

            foreach (object selected in ((System.Array)solExplorer.SelectedItems))
            {
                UIHierarchyItem hierItem    = (UIHierarchyItem)selected;
                ProjectItem     projectItem = hierItem.Object as ProjectItem;
                if (projectItem != null && projectItem.Name.ToLower().EndsWith(".biml"))
                {
                    if (projectItem.Document != null && !projectItem.Document.Saved)
                    {
                        projectItem.Document.Save(null);
                    }

                    Project newContainingProject = projectItem.ContainingProject;
                    sameProject       = containingProject == null || containingProject == newContainingProject;
                    containingProject = projectItem.ContainingProject;
                    projectDirectory  = Path.GetDirectoryName(containingProject.FullName);
                    string filePath = Path.Combine(projectDirectory, projectItem.Name);
                    emittableFilePaths.Add(filePath);
                }
            }

            if (sameProject && containingProject != null && projectDirectory != null)
            {
                try
                {
                    ShowValidationItems(emittableFilePaths, containingProject, projectDirectory);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        internal static ValidationReporter GetValidationReporter(List <string> bimlScriptPaths, Project project, string projectDirectory, string tempTargetDirectory)
        {
            // ArgumentNullException - Value cannot be null. Parameter: input - Caused when using the 1.6 BIML engine version but 1.7 code, BidsHelperPhaseWorkflows xml file name mismatched. Biml vs Hadron
#if KATMAI
            SsisVersion        ssisVersion        = BimlUtility.GetSsisVersion2008Variant();
            ValidationReporter validationReporter = BidsHelper.CompileBiml(typeof(AstNode).Assembly, "Varigence.Biml.BidsHelperPhaseWorkflows.xml", "Compile", bimlScriptPaths, new List <string>(), tempTargetDirectory, projectDirectory, SqlServerVersion.SqlServer2008, ssisVersion, SsasVersion.Ssas2008, SsisDeploymentModel.Package);
#elif DENALI
            ValidationReporter validationReporter = BidsHelper.CompileBiml(typeof(AstNode).Assembly, "Varigence.Biml.BidsHelperPhaseWorkflows.xml", "Compile", bimlScriptPaths, new List <string>(), tempTargetDirectory, projectDirectory, SqlServerVersion.SqlServer2008, SsisVersion.Ssis2012, SsasVersion.Ssas2008, DeployPackagesPlugin.IsLegacyDeploymentMode(project) ? SsisDeploymentModel.Package : SsisDeploymentModel.Project);
#elif SQL2014
            SsisVersion        version            = (SSISHelpers.GetProjectTargetVersion(project) == SSISHelpers.ProjectTargetVersion.SQLServer2012 ? SsisVersion.Ssis2012 : SsisVersion.Ssis2014);
            ValidationReporter validationReporter = BidsHelper.CompileBiml(typeof(AstNode).Assembly, "Varigence.Biml.BidsHelperPhaseWorkflows.xml", "Compile", bimlScriptPaths, new List <string>(), tempTargetDirectory, projectDirectory, SqlServerVersion.SqlServer2008, version, SsasVersion.Ssas2008, DeployPackagesPlugin.IsLegacyDeploymentMode(project) ? SsisDeploymentModel.Package : SsisDeploymentModel.Project);
#else
            ValidationReporter validationReporter = BidsHelper.CompileBiml(typeof(AstNode).Assembly, "Varigence.Biml.BidsHelperPhaseWorkflows.xml", "Compile", bimlScriptPaths, new List <string>(), tempTargetDirectory, projectDirectory, SqlServerVersion.SqlServer2005, SsisVersion.Ssis2005, SsasVersion.Ssas2005, SsisDeploymentModel.Package);
#endif
            return(validationReporter);
        }
        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 { }
            }
        }
Exemplo n.º 5
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)
                {
                }
            }
        }