コード例 #1
0
        private void CheckExpressionTask(TaskHost taskHost, TreeNode parent)
        {
            // Expression task has the Expression property which we need to treat as an expression rather than a literal value as we do for normal properties.
            // Get the Expression value and run an expression match test
            DtsProperty property   = taskHost.Properties["Expression"];
            string      expression = property.GetValue(taskHost).ToString();

            PropertyAsExpressionMatch(property, expression, parent);
        }
コード例 #2
0
        private object SetPropertyValue(DtsObject dtsObject, string propertyPath, object value)
        {
            propertyPath = propertyPath.Replace("\\", ".");
            object returnValue  = null;
            string firstPart    = propertyPath;
            string restOfString = string.Empty;

            if (propertyPath.Contains("."))
            {
                //Can have periods in object names (like connection manager names)
                //Need to verify that period is not between an index marker
                int delimiterIndex = propertyPath.IndexOf(".");
                //while (delimiterIndex > propertyPath.IndexOf("[") &&
                //    delimiterIndex < propertyPath.IndexOf("]"))
                //{
                //    delimiterIndex = propertyPath.IndexOf(".", delimiterIndex + 1 );
                //}
                if (delimiterIndex > propertyPath.IndexOf("[") &&
                    delimiterIndex < propertyPath.IndexOf("]"))
                {
                    delimiterIndex = propertyPath.IndexOf(".", propertyPath.IndexOf("]"));
                }

                if (delimiterIndex > -1)
                {
                    firstPart    = propertyPath.Substring(0, delimiterIndex);
                    restOfString = propertyPath.Substring(delimiterIndex + 1, (propertyPath.Length - (delimiterIndex + 1)));
                    if (firstPart.Length == 0)
                    {
                        return(SetPropertyValue(dtsObject, restOfString, value));
                    }
                }
            }


            if (firstPart.ToUpper().StartsWith("PACKAGE"))
            {
                if (!(dtsObject is Package))
                {
                    throw new ArgumentException("The initial object must be of type Package.", "dtsObject");
                }
                return(SetPropertyValue(dtsObject, restOfString, value));
            }

            //    \Package.Variables[User::TestVar].Properties[Value]
            if (firstPart.ToUpper().StartsWith("VARIABLES"))
            {
                if (!(dtsObject is DtsContainer))
                {
                    throw new ArgumentException("Object must be of type DtsContainer to reference variables.", "dtsObject");
                }
                Variables vars    = null;
                string    varName = GetSubStringBetween(firstPart, "[", "]");

                DtsContainer cont = (DtsContainer)dtsObject;
                cont.VariableDispenser.LockOneForRead(varName, ref vars);
                returnValue = SetPropertyValue(vars[varName], restOfString, value);
                vars.Unlock();
                return(returnValue);
            }

            //    \Package.Properties[CreationDate]
            if (firstPart.ToUpper().StartsWith("PROPERTIES"))
            {
                if (!(dtsObject is IDTSPropertiesProvider))
                {
                    throw new ArgumentException("Object must be of type IDTSPropertiesProvider to reference properties.", "dtsObject");
                }
                IDTSPropertiesProvider propProv = (IDTSPropertiesProvider)dtsObject;
                string propIndex = GetSubStringBetween(firstPart, "[", "]");

                DtsProperty prop = propProv.Properties[propIndex];
                if (dtsObject is Variable && prop.Name == "Value")
                {
                    Variable var = (Variable)dtsObject;
                    prop.SetValue(dtsObject, Convert.ChangeType(value, var.DataType));
                }
                else
                {
                    prop.SetValue(dtsObject, Convert.ChangeType(value, propProv.Properties[propIndex].Type));
                }

                //Flag value as changing
                changesvc.OnComponentChanging(prop, null);
                changesvc.OnComponentChanged(prop, null, null, null); //marks the package designer as dirty

                return(prop.GetValue(dtsObject));
            }

            //    \Package.Connections[localhost.AdventureWorksDW2008].Properties[Description]
            if (firstPart.ToUpper().StartsWith("CONNECTIONS"))
            {
                if (!(dtsObject is Package))
                {
                    throw new ArgumentException("Object must be of type Package to reference Connections.", "dtsObject");
                }
                string  connIndex = GetSubStringBetween(firstPart, "[", "]");
                Package pkg       = (Package)dtsObject;
                return(SetPropertyValue(pkg.Connections[connIndex], restOfString, value));
            }

            //    \Package.EventHandlers[OnError].Properties[Description]
            if (firstPart.ToUpper().StartsWith("EVENTHANDLERS"))
            {
                if (!(dtsObject is EventsProvider))
                {
                    throw new ArgumentException("Object must be of type EventsProvider to reference events.", "dtsObject");
                }
                EventsProvider eventProvider = (EventsProvider)dtsObject;
                string         eventIndex    = GetSubStringBetween(firstPart, "[", "]");
                return(SetPropertyValue(eventProvider.EventHandlers[eventIndex], restOfString, value));
            }

            //First Part of string is not one of the hard-coded values - it's either a task or container
            if (!(dtsObject is IDTSSequence))
            {
                throw new ArgumentException("Object must be of type IDTSSequence to reference other tasks or containers.", "dtsObject");
            }

            IDTSSequence seq = (IDTSSequence)dtsObject;

            if (seq.Executables.Contains(firstPart))
            {
                return(SetPropertyValue(seq.Executables[firstPart], restOfString, value));
            }


            //            \Package\Sequence Container\Script Task.Properties[Description]
            //    \Package\Sequence Container.Properties[Description]
            //    \Package\Execute SQL Task.Properties[Description]

            //\Package.EventHandlers[OnError].Variables[System::Cancel].Properties[Value]
            //    \Package.EventHandlers[OnError]\Script Task.Properties[Description]


            if (restOfString.Length > 0)
            {
                returnValue = SetPropertyValue(dtsObject, restOfString, value);
            }

            return(returnValue);
        }
コード例 #3
0
        private object LocatePropertyValue(object project, DtsObject dtsObject, string propertyPath, PropertyOperation operation, object value)
        {
            propertyPath = propertyPath.Replace("\\", ".");
            object returnValue  = null;
            string firstPart    = propertyPath;
            string restOfString = string.Empty;

            if (propertyPath.Contains("."))
            {
                // Can have periods in object names (like connection manager names)
                // Need to verify that period is not between an index marker
                int delimiterIndex = propertyPath.IndexOf(".", StringComparison.Ordinal);

                if (delimiterIndex > propertyPath.IndexOf("[", StringComparison.Ordinal) &&
                    delimiterIndex < propertyPath.IndexOf("]", StringComparison.Ordinal))
                {
                    delimiterIndex = propertyPath.IndexOf(".", propertyPath.IndexOf("]", StringComparison.Ordinal), StringComparison.Ordinal);
                }

                if (delimiterIndex > -1)
                {
                    firstPart    = propertyPath.Substring(0, delimiterIndex);
                    restOfString = propertyPath.Substring(delimiterIndex + 1, propertyPath.Length - (delimiterIndex + 1));
                    if (firstPart.Length == 0)
                    {
                        return(LocatePropertyValue(project, dtsObject, restOfString, operation, value));
                    }
                }
            }

            //\Project\ConnectionManagers[localhost.AdventureWorks2012.conmgr].Properties[ConnectionString]
            //\Project\Properties[ProtectionLevel]
            if (firstPart.ToUpper().StartsWith("PROJECT"))
            {
                if (!(project is Project))
                {
                    throw new ArgumentException("The initial object must be of type Project.", "project");
                }
                return(LocatePropertyValue(project, (DtsObject)project, restOfString, operation, value));
            }

            //\Project\ConnectionManagers[localhost.AdventureWorks2012.conmgr].Properties[ConnectionString]
            if (firstPart.ToUpper().StartsWith("CONNECTIONMANAGERS"))
            {
                string            connIndex = GetSubStringBetween(firstPart, "[", "]");
                ConnectionManager cm        = (((Project)project).ConnectionManagerItems[connIndex]).ConnectionManager;
                return(LocatePropertyValue(project, cm, restOfString, operation, value));
            }

            if (firstPart.ToUpper().StartsWith("PACKAGE"))
            {
                if (!(dtsObject is Package))
                {
                    throw new ArgumentException("The initial object must be of type Package.", "dtsObject");
                }
                return(LocatePropertyValue(project, dtsObject, restOfString, operation, value));
            }

            if (firstPart.ToUpper().StartsWith("VARIABLES"))
            {
                if (!(dtsObject is DtsContainer))
                {
                    throw new ArgumentException("Object must be of type DtsContainer to reference variables.", "dtsObject");
                }
                Variables vars    = null;
                string    varName = GetSubStringBetween(firstPart, "[", "]");

                DtsContainer cont = (DtsContainer)dtsObject;
                cont.VariableDispenser.LockOneForRead(varName, ref vars);
                returnValue = LocatePropertyValue(project, vars[varName], restOfString, operation, value);
                vars.Unlock();
                return(returnValue);
            }

            // \Package.Properties[CreationDate]
            if (firstPart.ToUpper().StartsWith("PROPERTIES"))
            {
                string propIndex = GetSubStringBetween(firstPart, "[", "]");

                if (!(dtsObject is IDTSPropertiesProvider))
                {
                    if (!(dtsObject is Project))
                    {
                        throw new ArgumentException("Object must be of type Project or IDTSPropertiesProvider to reference properties.", "dtsObject");
                    }
                    else
                    {
                        if (operation == PropertyOperation.Set)
                        {
                            dtsObject.GetType().GetProperty(propIndex).SetValue(dtsObject, Convert.ChangeType(value, dtsObject.GetType()));
                        }
                        return(dtsObject.GetType().GetProperty(propIndex).GetValue(dtsObject, null));
                    }
                }
                IDTSPropertiesProvider propProv = (IDTSPropertiesProvider)dtsObject;

                DtsProperty prop = propProv.Properties[propIndex];

                if (operation == PropertyOperation.Set)
                {
                    if (dtsObject is Variable)
                    {
                        Variable var = (Variable)dtsObject;
                        prop.SetValue(dtsObject, Convert.ChangeType(value, var.DataType));
                    }
                    else
                    {
                        prop.SetValue(dtsObject, Convert.ChangeType(value, propProv.Properties[propIndex].Type));
                    }
                }
                return(prop.GetValue(dtsObject));
            }

            // \Package.Connections[localhost.AdventureWorksDW2008].Properties[Description]
            if (firstPart.ToUpper().StartsWith("CONNECTIONS"))
            {
                if (!(dtsObject is Package))
                {
                    throw new ArgumentException("Object must be of type Package to reference Connections.", "dtsObject");
                }
                string  connIndex = GetSubStringBetween(firstPart, "[", "]");
                Package pkg       = (Package)dtsObject;
                return(LocatePropertyValue(project, pkg.Connections[connIndex], restOfString, operation, value));
            }

            // \Package.EventHandlers[OnError].Properties[Description]
            if (firstPart.ToUpper().StartsWith("EVENTHANDLERS"))
            {
                if (!(dtsObject is EventsProvider))
                {
                    throw new ArgumentException("Object must be of type EventsProvider to reference events.", "dtsObject");
                }
                EventsProvider eventProvider = (EventsProvider)dtsObject;
                string         eventIndex    = GetSubStringBetween(firstPart, "[", "]");
                return(LocatePropertyValue(project, eventProvider.EventHandlers[eventIndex], restOfString, operation, value));
            }

            // First Part of string is not one of the hard-coded values - it's either a task or container
            if (!(dtsObject is IDTSSequence))
            {
                throw new ArgumentException("Object must be of type IDTSSequence to reference other tasks or containers.", "dtsObject");
            }

            IDTSSequence seq = (IDTSSequence)dtsObject;

            if (seq.Executables.Contains(firstPart))
            {
                return(LocatePropertyValue(project, seq.Executables[firstPart], restOfString, operation, value));
            }

            // \Package\Sequence Container\Script Task.Properties[Description]
            // \Package\Sequence Container.Properties[Description]
            // \Package\Execute SQL Task.Properties[Description]
            // \Package.EventHandlers[OnError].Variables[System::Cancel].Properties[Value]
            // \Package.EventHandlers[OnError]\Script Task.Properties[Description]
            if (restOfString.Length > 0)
            {
                returnValue = LocatePropertyValue(project, dtsObject, restOfString, operation, value);
            }

            return(returnValue);
        }