Esempio n. 1
0
        /// <summary>
        /// Get the SsisTargetServerVersion of a project. See PackageHelper.SetTargetServerVersion and PackageHelper.TargetServerVersion or actual usage.
        /// </summary>
        /// <param name="project">The project to get the version of</param>
        /// <returns>The DTSTargetServerVersion of the project specified.</returns>
        /// <remarks>Do not use directly, see PackageHelper.SetTargetServerVersion and PackageHelper.TargetServerVersion for actual usage.</remarks>
        internal static SsisTargetServerVersion GetTargetServerVersion(EnvDTE.Project project)
        {
#if DENALI || SQL2014
            return(CompilationVersion);
#else
            // TODO: If this doesn't work <2016, we can just hardcode, based on conditional compiation
            Microsoft.DataWarehouse.Interfaces.IConfigurationSettings settings = (Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)((System.IServiceProvider)project).GetService(typeof(Microsoft.DataWarehouse.Interfaces.IConfigurationSettings));
            DataWarehouseProjectManager projectManager = (DataWarehouseProjectManager)PackageHelper.GetPropertyValue(settings, "ProjectManager");
            Microsoft.DataTransformationServices.Project.DataTransformationsProjectConfigurationOptions options = (Microsoft.DataTransformationServices.Project.DataTransformationsProjectConfigurationOptions)projectManager.ConfigurationManager.CurrentConfiguration.Options;
            return((SsisTargetServerVersion)options.TargetServerVersion);
#endif
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Determines whether the project users the legacy Package deployment model, as opposed to the newer Project deployment model.
        /// </summary>
        /// <param name="projectManager">The project to check.</param>
        /// <returns>true if the project uses the legacy package deployment model; otherwise else false.</returns>
        public static bool IsLegacyDeploymentMode(DataWarehouseProjectManager projectManager)
        {
#if DENALI || SQL2014
            Microsoft.DataTransformationServices.Design.Project.IObjectModelProjectManager manager = projectManager as Microsoft.DataTransformationServices.Design.Project.IObjectModelProjectManager;
            if ((manager != null) && (manager.ObjectModelProject != null))
            {
                //new project deployment mode
                return false;
            }
            else
            {
                return true;
            }
#else
            return true;
#endif
        }