Exemplo n.º 1
0
        private void SetPackageAsDirty(IDTSSequence container, string expression, object objectChanged)
        {
            try
            {
                if (!string.IsNullOrEmpty(expression))
                {
                    shouldSkipExpressionHighlighting = true; //this flag is used by the expression highlighter to skip re-highlighting if all that's changed is the string of an existing expression... if one has been removed, then re-highlight
                }

                PropertyDescriptorCollection             properties          = TypeDescriptor.GetProperties(objectChanged);
                System.ComponentModel.PropertyDescriptor expressionsProperty = properties.Find("Expressions", false);

                // Mark package object as dirty
                IComponentChangeService changeService = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService));
                if (objectChanged == null)
                {
                    changeService.OnComponentChanging(container, null);
                    changeService.OnComponentChanged(container, null, null, null); //marks the package designer as dirty
                }
                else
                {
                    changeService.OnComponentChanging(objectChanged, expressionsProperty);
                    changeService.OnComponentChanged(objectChanged, expressionsProperty, null, null); //marks the package designer as dirty
                }
                if (container is Package)
                {
                    SSISHelpers.MarkPackageDirty((Package)container);
                }
            }
            finally
            {
                shouldSkipExpressionHighlighting = false;
            }
        }
        private void EditExpressionButtonClick(int selectedRow, int selectedCol)
        {
            try
            {
                Package package = GetCurrentPackage();
                if (package == null)
                {
                    return;
                }

                if (selectedRow < 0)
                {
                    return;
                }

                Variable variable = GetVariableForRow(selectedRow);

                if (variable == null)
                {
                    return;
                }

                DtsContainer      sourceContainer   = FindObjectForVariablePackagePath(package, variable.GetPackagePath());
                Variables         variables         = sourceContainer.Variables;
                VariableDispenser variableDispenser = sourceContainer.VariableDispenser;

                Konesans.Dts.ExpressionEditor.ExpressionEditorPublic editor = new Konesans.Dts.ExpressionEditor.ExpressionEditorPublic(variables, variableDispenser, variable);
                if (editor.ShowDialog() == DialogResult.OK)
                {
                    string expression = editor.Expression;
                    if (string.IsNullOrEmpty(expression) || string.IsNullOrEmpty(expression.Trim()))
                    {
                        expression = null;
                        variable.EvaluateAsExpression = false;
                    }
                    else
                    {
                        variable.EvaluateAsExpression = true;
                    }

                    variable.Expression = expression;
                    changesvc.OnComponentChanging(sourceContainer, null);
                    changesvc.OnComponentChanged(sourceContainer, null, null, null); //marks the package designer as dirty
                    SSISHelpers.MarkPackageDirty(package);

                    TypeDescriptor.Refresh(variable);
                    System.Windows.Forms.Application.DoEvents();

                    // Refresh the grid
                    variablesToolWindowControl.GetType().InvokeMember("FillGrid", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, variablesToolWindowControl, new object[] { });
                    SetButtonEnabled();
                    RefreshHighlights();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace, DefaultMessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        public override void Exec()
        {
            try
            {
                string propertyPath;
                string newValue;

                //Get PropertyPath values
                BatchPropertyUpdateForm frm = new BatchPropertyUpdateForm();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    propertyPath = frm.PropertyPath;
                    newValue     = frm.NewValue;
                }
                else
                {
                    return;
                }

                UIHierarchy solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer;

                foreach (UIHierarchyItem hi in ((System.Array)solExplorer.SelectedItems))
                {
                    ProjectItem pi = (ProjectItem)hi.Object;

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

                    IDesignerHost designer = w.Object as IDesignerHost;
                    if (designer == null)
                    {
                        continue;
                    }
                    changesvc = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService));


                    EditorWindow win     = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator));
                    Package      package = win.PropertiesLinkComponent as Package;
                    if (package == null)
                    {
                        continue;
                    }
                    SetPropertyValue(package, propertyPath, newValue);

                    SSISHelpers.MarkPackageDirty(package); //for now always mark it as dirty

                    //ApplicationObject.ActiveDocument.Save(null);
                    //w.Close(vsSaveChanges.vsSaveChangesYes);
                    //w.Close(vsSaveChanges.vsSaveChangesNo); //close the designer
                    //w = pi.Open(BIDSViewKinds.Designer); //opens the designer
                    w.Activate(); //that was the quick and easy way to get the expression highlighter up to date
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message + " " + ex.StackTrace);
            }
        }
Exemplo n.º 4
0
 private void RecurseExecutablesAndCaptureGuids(IDTSSequence parentExecutable)
 {
     foreach (Variable v in ((DtsContainer)parentExecutable).Variables)
     {
         //don't replace system variables since they're not in the XML
         //don't replace parameters which show as variables since they have a different ID and you won't find the variable's ID in the XML to replace
         if (!v.SystemVariable && !SSISHelpers.IsParameterVariable(v))
         {
             AddGuid(v.ID);
         }
     }
     foreach (Executable e in parentExecutable.Executables)
     {
         AddGuid(((DtsContainer)e).ID);
         if (e is IDTSSequence)
         {
             RecurseExecutablesAndCaptureGuids((IDTSSequence)e);
         }
     }
 }
        private void FindUnusedButtonClick()
        {
            try
            {
#if DENALI || SQL2014
                packageDesigner = (ComponentDesigner)variablesToolWindowControl.GetType().GetProperty("PackageDesigner", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance).GetValue(variablesToolWindowControl, null);
#else
                packageDesigner = (ComponentDesigner)variablesToolWindowControl.GetType().InvokeMember("PackageDesigner", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, variablesToolWindowControl, null);
#endif

                if (packageDesigner == null)
                {
                    return;
                }

                Package package = packageDesigner.Component as Package;
                if (package == null)
                {
                    return;
                }

                FindUnusedVariables dialog = new FindUnusedVariables(VariablesDisplayMode.Variables);
                if (dialog.Show(package) == DialogResult.OK)
                {
                    // Dialog result OK indicates we have deleted one or more variables
                    // Flag package as dirty
                    SSISHelpers.MarkPackageDirty(package);

                    // Refresh the grid
                    variablesToolWindowControl.GetType().InvokeMember("FillGrid", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, variablesToolWindowControl, new object[] { });
                    SetButtonEnabled();
                    RefreshHighlights();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace);
            }
        }
 internal static void SetTargetServerVersion(EnvDTE.Project project)
 {
     // Get target version of the package, and set on PackageHelper to ensure any ComponentInfos is for the correct info.
     PackageHelper.TargetServerVersion = SSISHelpers.GetTargetServerVersion(project);
 }
        //they asked to pop up the Package Configurations dialog, so replace the Microsoft functionality so we can control the popup form
        void cmdEvent_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
        {
            if (Enabled)
            {
                try
                {
                    if (this.ApplicationObject.ActiveWindow == null || this.ApplicationObject.ActiveWindow.ProjectItem == null)
                    {
                        return;
                    }
                    ProjectItem pi = this.ApplicationObject.ActiveWindow.ProjectItem;
                    if (!pi.Name.ToLower().EndsWith(".dtsx"))
                    {
                        return;
                    }

                    IDesignerHost designer = this.ApplicationObject.ActiveWindow.Object as IDesignerHost;
                    if (designer == null)
                    {
                        return;
                    }
                    EditorWindow win     = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator));
                    Package      package = (Package)win.PropertiesLinkComponent;
                    this.packageForFixButton        = package;
                    this.pathForPackageForFixButton = pi.get_FileNames(1);

                    DtsConfigurationsForm form = new DtsConfigurationsForm(package);
                    if (win.SelectedIndex == 0)
                    {
                        //control flow
                        EditorWindow.EditorView        view     = win.SelectedView;
                        System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance;
                        Control viewControl = (Control)view.GetType().InvokeMember("ViewControl", getflags, null, view, null);

                        IWin32Window parentWin;

                        parentWin = viewControl;

                        Button  editSelectedButton = (Button)form.Controls["editSelectedConfiguration"];
                        Control packageConfigurationsGridControl1 = form.Controls["packageConfigurationsGridControl1"];
                        Button  btnRelativePaths = new Button();
                        btnRelativePaths.Text   = "Fix All Relative Paths";
                        btnRelativePaths.Width  = 140;
                        btnRelativePaths.Left   = packageConfigurationsGridControl1.Left;
                        btnRelativePaths.Top    = editSelectedButton.Top;
                        btnRelativePaths.Height = editSelectedButton.Height;
                        btnRelativePaths.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
                        btnRelativePaths.Click += new EventHandler(btnRelativePaths_Click);
                        form.Controls.Add(btnRelativePaths);

                        if (DesignUtils.ShowDialog((Form)form, parentWin, (IServiceProvider)package.Site) == DialogResult.OK)
                        {
                            SSISHelpers.MarkPackageDirty(package);
                        }

                        CancelDefault = true;
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
                }
            }
        }
        //public override bool ShouldDisplayCommand()
        //{
        //    UIHierarchy solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer;
        //    if (((System.Array)solExplorer.SelectedItems).Length == 1)
        //    {
        //        UIHierarchyItem hierItem = ((UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0));
        //        EnvDTE.Project proj = GetSelectedProjectReference();
        //        if (proj != null)
        //        {
        //            return (proj.Kind == BIDSProjectKinds.SSIS);
        //        }
        //    }
        //    return false;
        //}

        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);

                    Cud.Transaction trans = Cud.BeginTransaction(package);

                    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;

                                trans.ChangeProperty(config, "ConfigurationString");
                            }
                        }
                    }
                    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;

                            trans.ChangeProperty(conn, "ConnectionString");
                        }
                    }
                    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;
            }
        }
        void expressionListWindow_EditExpressionSelected(object sender, EditExpressionSelectedEventArgs e)
        {
            try
            {
                Package      package   = null;
                DtsContainer container = null;

                if (win == null)
                {
                    return;
                }

                try
                {
                    package = GetCurrentPackage();
                    if (package == null)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Assert(false, ex.ToString());
                    return;
                }

                // Parameters for Expression Editor
                Variables         variables         = null;
                VariableDispenser variableDispenser = null;
                string            propertyName      = string.Empty;
                Type propertyType = null;

                // Target objects
                IDTSPropertiesProvider propertiesProvider = null;
                Variable             variable             = null;
                PrecedenceConstraint constraint           = null;

                // Get the container
                container = SSISHelpers.FindContainer(package, e.ContainerID);

                // Get the property details and variable objects for the editor
                if (e.Type == typeof(Variable))
                {
                    variable = SSISHelpers.FindVariable(container, e.ObjectID);

                    propertyName = "Value";
                    propertyType = System.Type.GetType("System." + variable.DataType.ToString());

                    variables         = container.Variables;
                    variableDispenser = container.VariableDispenser;
                }
                else if (e.Type == typeof(PrecedenceConstraint))
                {
                    constraint = SSISHelpers.FindConstraint(container, e.ObjectID);

                    propertyName = "Expression";
                    propertyType = typeof(bool);

                    variables         = container.Variables;
                    variableDispenser = container.VariableDispenser;
                }
                else
                {
                    if (e.Type == typeof(ConnectionManager))
                    {
                        propertiesProvider = SSISHelpers.FindConnectionManager(package, e.ObjectID) as IDTSPropertiesProvider;
                    }
                    else if (e.Type == typeof(ForEachEnumerator))
                    {
                        ForEachLoop forEachLoop = container as ForEachLoop;
                        propertiesProvider = forEachLoop.ForEachEnumerator as IDTSPropertiesProvider;
                    }
                    else
                    {
                        propertiesProvider = container as IDTSPropertiesProvider;
                    }

                    if (propertiesProvider != null)
                    {
                        DtsProperty property = propertiesProvider.Properties[e.Property];
                        propertyName      = property.Name;
                        propertyType      = PackageHelper.GetTypeFromTypeCode(property.Type);
                        variables         = container.Variables;
                        variableDispenser = container.VariableDispenser;
                    }
                    else
                    {
                        throw new Exception(string.Format(CultureInfo.InvariantCulture, "Expression editing not supported on this object ({0}).", e.ObjectID));
                    }
                }

                // Show the editor
                Konesans.Dts.ExpressionEditor.ExpressionEditorPublic editor = new Konesans.Dts.ExpressionEditor.ExpressionEditorPublic(variables, variableDispenser, propertyType, propertyName, e.Expression);
                editor.Editor.ExpressionFont  = ExpressionFont;
                editor.Editor.ExpressionColor = ExpressionColor;
                editor.Editor.ResultFont      = ResultFont;
                editor.Editor.ResultColor     = ResultColor;
                if (editor.ShowDialog() == DialogResult.OK)
                {
                    // Get expression
                    string expression = editor.Expression;
                    if (expression == null || string.IsNullOrEmpty(expression.Trim()))
                    {
                        expression = null;
                    }

                    // Set the new expression on the target object
                    object objectChanged = null;
                    if (variable != null)
                    {
                        if (expression == null)
                        {
                            variable.EvaluateAsExpression = false;
                        }

                        variable.Expression = expression;
                        objectChanged       = variable;
                    }
                    else if (constraint != null)
                    {
                        if (expression == null)
                        {
                            constraint.EvalOp = DTSPrecedenceEvalOp.Constraint;
                        }

                        constraint.Expression = expression;
                        objectChanged         = constraint;
                    }
                    else if (propertiesProvider != null)
                    {
                        // TaskHost, Sequence, ForLoop, ForEachLoop and ConnectionManager
                        propertiesProvider.SetExpression(e.Property, expression);
                        objectChanged = propertiesProvider;
                    }

                    expressionListWindow_RefreshExpressions(null, null);

                    // Finish displaying expressions list before you mark the package
                    // as dirty (which runs the expression highlighter)
                    System.Windows.Forms.Application.DoEvents();

                    SetPackageAsDirty(package, expression, objectChanged);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public override void Exec()
        {
            try
            {
                UIHierarchy       solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer;
                UIHierarchyItem   hierItem    = ((UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0));
                ProjectItem       pi          = (ProjectItem)hierItem.Object;
                Window            win         = pi.Document.ActiveWindow;
                IDesignerHost     designer    = (IDesignerHost)pi.Document.ActiveWindow.Object;
                Package           package     = null;
                ConnectionManager conn        = GetSelectedConnectionManager(designer, out package);

                BIDSHelper.SSIS.FixedWidthColumnsForm form = new BIDSHelper.SSIS.FixedWidthColumnsForm();
                if (conn != null && conn.Properties["Format"].GetValue(conn).ToString() == "FixedWidth")
                {
                    //hiding properties for ragged right
                    form.dataGridView1.Height            = form.dataGridView1.Height + 50 + 26;
                    form.dataGridView1.Top              -= 50;
                    form.label1.Height                  -= 50;
                    form.cboRaggedRightDelimiter.Visible = false;
                    form.lblRaggedRight.Visible          = false;
                }

                DialogResult dialogResult = form.ShowDialog();

                if (dialogResult == DialogResult.OK)
                {
                    wrap.IDTSConnectionManagerFlatFile100 ff = conn.InnerObject as wrap.IDTSConnectionManagerFlatFile100;
                    DtsConvert.GetExtendedInterface(conn);

                    while (ff.Columns.Count > 0)
                    {
                        ff.Columns.Remove(0);
                    }

                    List <string> listUsedNames = new List <string>();

                    //JCW - Added counter to identify the last column
                    int columnCount = 1;

                    foreach (DataGridViewRow row in form.dataGridView1.Rows)
                    {
                        string sName         = row.Cells[0].Value.ToString().Trim();
                        string sOriginalName = sName;
                        int    i             = 1;
                        while (listUsedNames.Contains(sName)) //find a unique name for the column
                        {
                            sName = sOriginalName + (++i);
                        }
                        listUsedNames.Add(sName);

                        wrap.IDTSConnectionManagerFlatFileColumn100 col = ff.Columns.Add();
                        wrap.IDTSName100 name = col as wrap.IDTSName100;

                        name.Name        = sName;
                        col.MaximumWidth = int.Parse(row.Cells[1].Value.ToString());
                        col.DataType     = Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_STR;

                        if (columnCount == form.dataGridView1.Rows.Count && form.cboRaggedRightDelimiter.Text != "[None]")
                        {
                            col.ColumnWidth     = 0;
                            col.ColumnType      = "Delimited";
                            col.ColumnDelimiter = DecodeDelimiter(form.cboRaggedRightDelimiter.Text);
                        }
                        else
                        {
                            col.ColumnWidth = int.Parse(row.Cells[1].Value.ToString());
                            col.ColumnType  = "FixedWidth";
                        }


                        columnCount++;
                    }

                    //mark package object as dirty
                    IComponentChangeService changesvc = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService));
                    changesvc.OnComponentChanging(package, null);
                    changesvc.OnComponentChanged(package, null, null, null); //marks the package designer as dirty
                    SSISHelpers.MarkPackageDirty(package);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 11
0
        private void CopyVariables(List <Variable> variables, bool move, DtsContainer targetContainer, Package package, System.Collections.ArrayList sourceVariableDesigners)
        {
            foreach (Variable sourceVar in variables)
            {
                if (targetContainer is IDTSPackagePath && sourceVar.GetPackagePath().StartsWith(((IDTSPackagePath)targetContainer).GetPackagePath() + ".Variables["))
                {
                    throw new VariableCopyException("You are attempting to copy the variable '" + sourceVar.QualifiedName + "' to the same scope it is already in.", null);
                }
                else if (sourceVar.SystemVariable)
                {
                    throw new VariableCopyException(sourceVar.QualifiedName + " is a system variable and cannot be copied or moved.", null);
                }
            }

            foreach (Variable sourceVar in variables)
            {
                //Variable targetVar = targetContainer.Variables.Add(sourceVar.Name, sourceVar.ReadOnly, sourceVar.Namespace, sourceVar.Value); //this is the standard way to add a variable, but it doesn't interact well with the variables tool window
                Variable targetVar = (Variable)packageDesigner.GetType().InvokeMember("CreateVariable", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, packageDesigner, new object[] { targetContainer, sourceVar.Name, sourceVar.ReadOnly, sourceVar.Namespace, sourceVar.Value });

                try
                {
                    targetVar.Name = sourceVar.Name;
                }
                catch (Exception ex)
                {
                    serviceProvider.DestroyComponent(targetVar);
                    throw new VariableCopyException("Could not copy " + sourceVar.QualifiedName + " to scope \"" + targetContainer.Name + "\" because another variable with that name already exists.", ex);
                }
                //targetVar.DataType is read only
                targetVar.Description          = sourceVar.Description;
                targetVar.EvaluateAsExpression = sourceVar.EvaluateAsExpression;
                targetVar.Expression           = sourceVar.Expression;
                targetVar.RaiseChangedEvent    = sourceVar.RaiseChangedEvent;

                if (move)
                {
                    DtsContainer sourceContainer = FindObjectForVariablePackagePath(package, sourceVar.GetPackagePath());
                    changesvc.OnComponentChanging(sourceContainer, null);
                    changesvc.OnComponentChanged(sourceContainer, null, null, null); //marks the package designer as dirty
                }
            }

            if (move)
            {
#if DENALI || SQL2014
                //terrible workaround to get the exact right parameter type for the DeleteVariables method in Denali. Guess calling InvokeMember against a function with a parameter of a generic type is tricky
                System.Collections.IList listParam = ((System.Collections.IList)System.Type.GetType("System.Collections.Generic.List`1[[" + ExpressionHighlighterPlugin.GetPrivateType(variablesToolWindowControl.GetType(), "Microsoft.DataTransformationServices.Design.VariableDesigner").AssemblyQualifiedName + "]]").GetConstructor(new Type[] { }).Invoke(new object[] { }));
                foreach (object o in sourceVariableDesigners)
                {
                    listParam.Add(o);
                }
                variablesToolWindowControl.GetType().GetMethod("DeleteVariables", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance).Invoke(variablesToolWindowControl, new object[] { listParam });
#else
                variablesToolWindowControl.GetType().InvokeMember("DeleteVariables", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, variablesToolWindowControl, new object[] { sourceVariableDesigners });
#endif
            }

            changesvc.OnComponentChanging(targetContainer, null);
            changesvc.OnComponentChanged(targetContainer, null, null, null); //marks the package designer as dirty
            SSISHelpers.MarkPackageDirty(package);

            ValidatePackage(package);
        }