Exemplo n.º 1
0
        /// <summary>
        /// Extracts type name of supported value using reflection
        /// </summary>
        /// <param name="ObjectType"></param>
        /// <returns></returns>
        public static string GetNameOfType(int ObjectType)
        {
            DBObjectType o = new DBObjectType();

            string result = "Not a known object type!";
            Type   t      = typeof(DBObjectType);

            FieldInfo[] fi = t.GetFields();

            foreach (FieldInfo i in fi)
            {
                try
                {
                    object value = i.GetValue(o);
                    if (null != value && (int)value == ObjectType)
                    {
                        result = i.Name;
                    }
                }
                catch
                {
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private void LoadFromObjectExplorer()
        {
            if (HostServicesSingleton.HostServices == null || HostServicesSingleton.HostServices.ObjectExplorerService == null)
            {
                throw new InvalidOperationException("ObjectExplorer is not active or visible!");
            }

            IList <ObjectExplorerNode> selNodes = HostServicesSingleton.HostServices.ObjectExplorerService.SelNodes;
            StringBuilder sb       = new StringBuilder();
            string        template = "{0}=[{1}].[{2}]";
            string        objType  = String.Empty;

            foreach (ObjectExplorerNode node in selNodes)
            {
                if (!DBObjectType.CanTypeBeDumpedForScriptingWizardUsage(node.Type) || node.ConnParams == null)
                {
                    continue;
                }

                if (node.ConnParams.Server != _cp.Server || !node.DatabaseName.Equals(_cp.Database, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                objType = DbObjectListUtils.EncodeObjectExplorerNodeType(node.Type);
                sb.AppendLine(String.Format(template, objType, node.Owner, node.Name));
            }

            PrepareObjectFromContent(sb.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Extracts field name,value structure for constants with reflection
        /// </summary>
        /// <returns></returns>
        public static IList <DBObjectTypeDesc> GetTypeDescriptions()
        {
            DBObjectType o = new DBObjectType();

            IList <DBObjectTypeDesc> result = new List <DBObjectTypeDesc>();
            Type t = typeof(DBObjectType);

            FieldInfo[] fi = t.GetFields();

            foreach (FieldInfo i in fi)
            {
                try
                {
                    if (null != i.GetValue(o))
                    {
                        result.Add(new DBObjectTypeDesc((int)i.GetValue(o), i.Name));
                    }
                }
                catch
                {
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Try to replace procedure, function, view and trigger script
        /// create portion with alter in a single source line
        /// </summary>
        /// <param name="ObjectType">DBObjectType</param>
        /// <param name="sourceLine">Source line</param>
        /// <param name="result">Replaced line text </param>
        /// <returns></returns>
        private static bool TryToReplaceCreateWithAlter(int ObjectType, string sourceLine, ref string result)
        {
            string createCommand = String.Empty;
            string alterCommand  = String.Empty;

            result = sourceLine;

            DetermineCommandConstants(ObjectType, ref createCommand, ref alterCommand);
            if (String.IsNullOrEmpty(createCommand) || String.IsNullOrEmpty(alterCommand))
            {
                throw new ObjectTypeNotSupportedByOperation(String.Format("Object type \"{0}\"is not supported by this operation.", DBObjectType.GetNameOfType(ObjectType)));
            }

            int    x               = 0;
            string command         = String.Empty;
            bool   isCreateCommand = false;
            bool   isCreate        = false;

            int createEndPos = -1;

            while (x < sourceLine.Length)
            {
                if (IsValidChar(sourceLine[x]))
                {
                    command += sourceLine[x];
                }
                else if (!String.IsNullOrEmpty(command))
                {
                    if (!isCreate)
                    {
                        isCreate = (command.Trim().ToLowerInvariant() == "create");
                        if (isCreate)
                        {
                            createEndPos = x;
                        }
                    }

                    isCreateCommand = (command.Trim().ToLowerInvariant() == createCommand);
                    if (isCreateCommand)
                    {
                        command = String.Empty;
                        break;
                    }
                    else if (command[command.Length - 1] == ' ')
                    {
                        command += " ";
                    }
                }
                x++;
            }

            if (isCreateCommand || (command.Trim().ToLowerInvariant() == createCommand))
            {
                string tmp = sourceLine.Substring(0, createEndPos - 6);
                if (tmp.Length > 0 && !Char.IsSeparator(tmp[tmp.Length - 1]))
                {
                    tmp += " ";
                }
                tmp            += alterCommand;
                tmp            += sourceLine.Substring(x, sourceLine.Length - x);
                result          = tmp;
                isCreateCommand = true;
            }

            return(isCreateCommand);
        }