Ejemplo n.º 1
0
 protected override IDocument CreateDocument(ServerExplorerFacade hierarchy, string typeName, object[] objectID, bool isNew)
 {
     IDocument doc = base.CreateDocument(hierarchy, typeName, objectID, isNew);
     StoredProcDocument spDoc = (doc as StoredProcDocument);
     spDoc.IsFunction = true;
     return doc;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks accessibility of command for given items. First checks item array
        /// length – most command supports only single selection. After length is checked,
        /// process each item and if for any item command is inaccessible, returns false.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="items">Array with item’s identifiers.</param>
        /// <returns>Returns true if command should be shown and false otherwise</returns>
        public virtual bool GetIsVisible(ServerExplorerFacade hierarchy, int[] items)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            // Check length restrictions
            if (items.Length <= 0 && !IsEmptyAllowed)
            {
                return(false);
            }
            if (items.Length > 1 && !IsMultiselectAllowed)
            {
                return(false);
            }

            // Check each item using virtual method
            foreach (int i in items)
            {
                if (!CheckSingleItem(hierarchy, i))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Virtual method for formatting command text template. By default retrieves
        /// object type for first node and uses String.Format to place it in the
        /// correct place.
        /// </summary>
        /// <param name="template">Command text template.</param>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction..</param>
        /// <param name="items">Array with item’s identifiers.</param>
        /// <returns>Localized command text.</returns>
        protected virtual string FormatText(string template, ServerExplorerFacade hierarchy, int[] items)
        {
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            // Only single item format supported by default
            if (items.Length != 1)
            {
                return(template);
            }

            // Get localized object type name for the item
            string typeName = GetLocalizedItemType(hierarchy, items[0]);

            // Format comand text template with localized type name
            if (!String.IsNullOrEmpty(typeName))
            {
                return(String.Format(CultureInfo.CurrentCulture, template, typeName));
            }

            return(template);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new user defined function identifier template
        /// </summary>
        /// <param name="hierarchy">A server explorer facade object to interact with
        /// Server Explorer hierarchy</param>
        /// <param name="typeName">An object type name to create</param>
        /// <returns>Returns a new user defined function identifier template</returns>
        protected override object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            // Checking a type name
            if (!DataInterpreter.CompareInvariant(typeName, UdfDescriptor.TypeName))
            {
                throw new NotSupportedException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Resources.Error_ObjectTypeNotSupported,
                              typeName)
                          );
            }

            // Get a default schema
            string schema = hierarchy.Connection.Schema;

            if (schema == null)
            {
                return(null);
            }

            return(new object[] { null, null });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns true if given hierarchy item is object node and object descriptor
        /// supports dropping.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns true if given hierarchy item is object node and object descriptor
        /// supports dropping.
        /// </returns>
        protected override bool CheckSingleItem(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            // Extract type name
            string typeName = GetObjectType(hierarchy, item);

            if (String.IsNullOrEmpty(typeName))
            {
                return(false);
            }

            // Extract descriptor
            IObjectDescriptor descriptor = ObjectDescriptorFactory.Instance.CreateDescriptor(typeName);

            // Return true if descriptor could build drop query.
            return(descriptor != null ? descriptor.CanBeDropped : false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates new document object. Extracts creation method from the collection
        /// of registered creation methods and use it for creation.
        /// </summary>
        /// <param name="typeName">
        /// Object type name for the document
        /// </param>
        /// <param name="hierarchy">
        /// Server explorer facade object to be used for Server Explorer hierarchy interaction.
        /// Also used to extract connection.
        /// </param>
        /// <param name="isNew">
        /// Indicates if this instance represents new database object doesn’t fixed in
        /// database yet.
        /// </param>
        /// <param name="id">
        /// Array with new object identifier.
        /// </param>
        /// <returns>
        /// Instance of the new document object
        /// </returns>
        public IDocument CreateDocument(string typeName, ServerExplorerFacade hierarchy, object[] id, bool isNew)
        {
            // Check input paramaters
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            // Retrieve and invoke method
            CreateDocumentMethod createMethod = createDocumentDictionary[typeName];

            if (createMethod == null)
            {
                throw new NotSupportedException(String.Format(
                                                    CultureInfo.CurrentCulture,
                                                    Resources.Error_DocumentNotRegistered,
                                                    typeName));
            }
            return(createMethod.Invoke(hierarchy, isNew, id));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates new object identifier template without name part. Base implementation supports
        /// only 3-parts identifiers.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name to create identifier.</param>
        /// <returns>Returns new object identifier template without name part.</returns>
        protected virtual object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            // Only objects with identifier length 3 is supported
            if (ObjectDescriptor.GetIdentifierLength(typeName) != 3)
            {
                throw new NotSupportedException(String.Format(
                                                    CultureInfo.CurrentCulture,
                                                    Resources.Error_ObjectTypeNotSupported,
                                                    typeName));
            }

            // Get default schema
            string schema = hierarchy.Connection.Schema;

            Debug.Assert(!String.IsNullOrEmpty(schema), "Failed to retrive schema name!");
            if (schema == null)
            {
                return(null);
            }

            // Create template ID
            return(new object[] { null, schema, null });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates new stored function identifier template without name part.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name to create identifier.</param>
        /// <returns>Returns new stored function identifier template without name part.</returns>
        protected override object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            // Only stored procedures are supported
            if (!DataInterpreter.CompareInvariant(typeName, StoredProcDescriptor.TypeName))
            {
                throw new NotSupportedException(String.Format(
                                                    CultureInfo.CurrentCulture,
                                                    Resources.Error_ObjectTypeNotSupported,
                                                    typeName));
            }

            // Get default schema
            string schema = hierarchy.Connection.Schema;

            Debug.Assert(!String.IsNullOrEmpty(schema), "Failed to retrive schema name!");
            if (schema == null)
            {
                return(null);
            }

            return(new object[] { null, schema, null });
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Firstly creates new document as exists document and then forces it to become a clone under new name.
        /// </summary>
        /// <param name="typeName">
        /// Object type name for the document
        /// </param>
        /// <param name="hierarchy">
        /// Server explorer facade object to be used for Server Explorer hierarchy interaction.
        /// Also used to extract connection.
        /// </param>
        /// <param name="id">
        /// Array with new object identifier.
        /// </param>
        /// <param name="isNew">
        /// Indicates if this instance represents new database object doesn’t fixed in
        /// database yet.
        /// </param>
        /// <returns>
        /// Returns cloned document object.
        /// </returns>
        protected override IDocument CreateDocument(ServerExplorerFacade hierarchy, string typeName, object[] objectID, bool isNew)
        {
            // Firstly create new document object, but not as new
            IDocument result = base.CreateDocument(hierarchy, typeName, objectID, false);

            // If failed to create document, return null
            if (result == null)
            {
                return(null);
            }

            // Create new object name using current identifier as the base
            CompleteNewObjectID(
                hierarchy,
                typeName,
                ref objectID,
                (result.Name != null ? result.Name : String.Empty) + '_');

            // Check that last id part is filled
            if (objectID[objectID.Length - 1] == null)
            {
                Debug.Fail("Failed to generate cloned name!");
                return(null);
            }

            // Force object to clone
            result.CloneToName(objectID[objectID.Length - 1].ToString());

            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns identifier of the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns hierarchy item ID for editor.</returns>
        protected override int GetItemForEditor(ServerExplorerFacade hierarchy, int item)
        {
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            // Item is always the same as the given item
            return item;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates new contextless node and returns its identifier.
 /// </summary>
 /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
 /// <param name="item">Item identifier.</param>
 /// <returns>Returns hierarchy item ID for editor.</returns>
 protected override int GetItemForEditor(ServerExplorerFacade hierarchy, int item)
 {
     if (hierarchy == null)
     {
         throw new ArgumentNullException("hierarchy");
     }
     return(hierarchy.CreateObjectNode());
 }
Ejemplo n.º 12
0
        protected override IDocument CreateDocument(ServerExplorerFacade hierarchy, string typeName, object[] objectID, bool isNew)
        {
            IDocument          doc   = base.CreateDocument(hierarchy, typeName, objectID, isNew);
            StoredProcDocument spDoc = (doc as StoredProcDocument);

            spDoc.IsFunction = true;
            return(doc);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns identifier of the object for the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns array with multipart identifier for the object.</returns>
        protected override object[] GetObjectID(ServerExplorerFacade hierarchy, string typeName, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            return hierarchy.GetObjectIdentifier(item);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Generates new object identifier. For objects owned directly by schema, generates 
        /// variation of "schema.{object type}¹". For nested objects returns variation of 
        /// "{parent ID}.{object type}¹".
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <param name="typeName">Object type name.</param>
        /// <returns>Returns array with multipart identifier for the object.</returns>
        protected override object[] GetObjectID(ServerExplorerFacade hierarchy, string typeName, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");
            if (typeName == null)
                throw new ArgumentNullException("typeName");

            
            // Get identifier length
            int idLength = ObjectDescriptor.GetIdentifierLength(typeName);
            if (idLength <= 0)
                throw new NotSupportedException(String.Format(
                                CultureInfo.CurrentCulture,
                                Resources.Error_ObjectTypeNotSupported,
                                typeName));
            
            // Create object ID template
            object[] id;

            // Get parent object identifier
            object[] parentID = hierarchy.GetObjectIdentifier(item);

            // For embedded objects ID is ID of owner object with one additional slot.
            if (parentID != null && parentID.Length == idLength - 1)
            {
                // Initialize object identifier template
                id = new object[idLength];

                // Copy parent object identifier to the template
                parentID.CopyTo(id, 0);
            }
            // For root objects (objects owned directly by schema) ID has three slots with 
            // schema name in the middle
            else
            {
                id = CreateNewIDBase(hierarchy, typeName);
                if (id == null || id.Length != idLength)
                    throw new NotSupportedException(String.Format(
                                                    CultureInfo.CurrentCulture,
                                                    Resources.Error_ObjectTypeNotSupported,
                                                    typeName));
            }

            // Extract template for the new name
            string template = GetTemplate(typeName, id);
            if (template == null)
                template = typeName;

            // Generate object name (fill the last slot)
            CompleteNewObjectID(hierarchy, typeName, ref id, template);

            // Return result
            return id;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns identifier of the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns hierarchy item ID for editor.</returns>
        protected override int GetItemForEditor(ServerExplorerFacade hierarchy, int item)
        {
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            // Item is always the same as the given item
            return(item);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This function is overriden to control trigger names uniques for whole database and
        /// not for each table.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name.</param>
        /// <param name="id">Array with object identifier.</param>
        /// <param name="template">Template for the new object identifier.</param>
        protected override void CompleteNewObjectID(ServerExplorerFacade hierarchy, string typeName, ref object[] id, string template)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id.Length < 3 || id[2] == null)
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Resources.Error_InvlaidIdentifier,
                              id.Length,
                              typeName,
                              ObjectDescriptor.GetIdentifierLength(typeName)),
                          "id");
            }
            if (String.IsNullOrEmpty(template))
            {
                throw new ArgumentException(Resources.Error_EmptyString, "template");
            }

            // Initialize complete parameters
            string actualTameplate = template;
            int    counter         = 0;

            do
            {
                // Stores table id and reset it to null in template, because trigger names must be
                // unique for a whole database.
                object tableID = id[2];
                id[2] = null;

                // Use base method for completion
                base.CompleteNewObjectID(hierarchy, typeName, ref id, actualTameplate);

                // Restores table id
                id[2] = tableID;

                // Change template and add new counter
                actualTameplate = template + (++counter).ToString();
            }
            // We need to control open editors here separately, because base method will miss them
            // (it doesn't know table ID)
            while (hierarchy.HasDocument(typeName, id));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Returns object type name for the given hierarchy item.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns object type name for the given hierarchy item.
        /// </returns>
        protected override string GetObjectType(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            return(hierarchy.GetObjectType(item));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Returns identifier of the object for the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns array with multipart identifier for the object.</returns>
        protected override object[] GetObjectID(ServerExplorerFacade hierarchy, string typeName, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            return(hierarchy.GetObjectIdentifier(item));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Template method initializes editor parameters, including object type name, 
        /// object identifier, new flag and hierarchy item identifier for editor, using 
        /// virtual methods, then looks for existing editor. If existing editor is not 
        /// found, creates new document and view objects and calls OpenEditor method.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Result of execution. Typicaly null.</returns>
        protected override object ExecuteSingleItem(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            // Get object type name for editor to be open
            string typeName = GetObjectType(hierarchy, item);
            if (typeName == null)
                throw new NotSupportedException(Resources.Error_UnableToGetObjectType);

            // Get object identifier
            object[] objectID = GetObjectID(hierarchy, typeName, item);
            if (objectID == null || objectID.Length <= 0)
                throw new NotSupportedException(Resources.Error_UnableToGetObjectID);

            // Get is new flag value
            bool isNew = GetIsNewFlagForObject(hierarchy, item);

            // Get hierarchy item id for editor to be open (could differs from "item")
            int itemForEditor = GetItemForEditor(hierarchy, item);
            if (itemForEditor < 0)
                throw new NotSupportedException(Resources.Error_UnableToGetHierarchyItem);

            // Set node name for new item
            if (isNew)
            {
                hierarchy.SetName(itemForEditor, objectID[objectID.Length - 1] as string);
            }

            // Try to find if not new
            if (!isNew)
                if (hierarchy.FindAndActivateEditor(itemForEditor, typeName, objectID))
                    return null;

            // Build document and view object using factory
            IDocument document = CreateDocument(hierarchy, typeName, objectID, isNew);
            if (document == null)
                throw new NotSupportedException(Resources.Error_UnableToGetDocumentObject);
            IEditor view = CreateEditor(document);
            if (view == null)
                throw new NotSupportedException(Resources.Error_UnableToGetViewObject);

            // Open new editor instance
            hierarchy.RegisterEditor(itemForEditor, document, view);


            // Returns no result
            return null;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Enumerates child types for given node and tries to find supported
        /// by document/view factory object type.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns object type name, which should be used to create document
        /// and view objects instances.
        /// </returns>
        protected override string GetObjectType(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            // Get posible child types
            string[] childTypes = hierarchy.GetChildTypes(item);
            if (childTypes == null)
            {
                return(null);
            }

            // Extract server version
            Debug.Assert(hierarchy.Connection != null, "Hierarchy has no connection object!");
            Version serverVersion = hierarchy.Connection != null ? hierarchy.Connection.ServerVersion : null;

            // Try to find supported objct type
            foreach (string typeName in childTypes)
            {
                if (DocumentViewFactory.Instance.IsObjectTypeRegistered(typeName))
                {
                    // Extract descriptor
                    IObjectDescriptor descriptor = ObjectDescriptorFactory.Instance.CreateDescriptor(typeName);
                    if (descriptor == null)
                    {
                        Debug.Fail("Failed to get descriptor for object type " + typeName);
                        continue;
                    }

                    // Check required MySQL version for this object.
                    Version minVersion = descriptor.RequiredVersion;
                    if (serverVersion != null && minVersion != null && serverVersion < minVersion)
                    {
                        continue;
                    }

                    // This is the one. Return it.
                    return(typeName);
                }
            }

            // Type not found, command nod supported
            return(null);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Command considered as valid if object type name could be determined.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns true if command is valid for given item, otherwise returns false.</returns>
        protected override bool CheckSingleItem(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            // Get object type name
            string typeName = GetObjectType(hierarchy, item);
            if (String.IsNullOrEmpty(typeName))
                return false;
            
            // Check object type registration
            return DocumentViewFactory.Instance.IsObjectTypeRegistered(typeName);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Returns localized object type name for the given node id.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction..</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns object type name for the given node id.</returns>
        protected string GetLocalizedItemType(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            // Get object type for item
            string typeName = GetObjectType(hierarchy, item);

            return(LocalizeTypeName(typeName));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Returns identifier of the object for the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns array with multipart identifier for the object.</returns>
        protected override object[] GetObjectID(ServerExplorerFacade hierarchy, string typeName, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");
            if (typeName == null)
                throw new ArgumentNullException("typeName");

            // If this is not a table or a view, data editing is not supported.
            if (!DataInterpreter.CompareInvariant(typeName, TableDataDescriptor.TypeName))
                return null;

            // ID is the object ID of the hierarchy item
            return hierarchy.GetObjectIdentifier(item);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Creates new document object. Base implementation simply calls factory.
 /// </summary>
 /// <param name="typeName">
 /// Object type name for the document
 /// </param>
 /// <param name="hierarchy">
 /// Server explorer facade object to be used for Server Explorer hierarchy interaction.
 /// Also used to extract connection.
 /// </param>
 /// <param name="id">
 /// Array with new object identifier.
 /// </param>
 /// <param name="isNew">
 /// Indicates if this instance represents new database object doesn’t fixed in
 /// database yet.
 /// </param>
 /// <returns>
 /// Instance of the new document object
 /// </returns>
 protected virtual IDocument CreateDocument(ServerExplorerFacade hierarchy, string typeName, object[] objectID, bool isNew)
 {
     if (hierarchy == null)
     {
         throw new ArgumentNullException("hierarchy");
     }
     if (typeName == null)
     {
         throw new ArgumentNullException("typeName");
     }
     if (objectID == null)
     {
         throw new ArgumentNullException("objectID");
     }
     return(DocumentViewFactory.Instance.CreateDocument(typeName, hierarchy, objectID, isNew));
 }
Ejemplo n.º 25
0
        /// <summary>
        /// This method is overriden to display warning message before deletion. Then just calls base.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction..</param>
        /// <param name="items">Array with item’s identifiers.</param>
        /// <returns>Always returns null.</returns>
        public override object[] Execute(ServerExplorerFacade hierarchy, int[] items)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            // Build object names list
            StringBuilder list = new StringBuilder();

            foreach (int item in items)
            {
                // Extract name for item
                string name = hierarchy.GetName(item);
                if (String.IsNullOrEmpty(name))
                {
                    continue;
                }

                // If builder is not empty, add ', '
                if (list.Length > 0)
                {
                    list.Append(Resources.Comma);
                }

                // Append object name
                list.Append(name);
            }

            // Build warning message
            string message = String.Format(CultureInfo.CurrentCulture, Resources.Warning_ConfirmDelete, list.ToString());

            // First, ask user for confirmation
            if (UIHelper.ShowWarning(message, MessageBoxButtons.YesNo)
                != DialogResult.Yes)
            {
                return(null);
            }

            // Only if user confirmed delete, call to base class to execute command
            return(base.Execute(hierarchy, items));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Checks object type for the given node using document/view factory and returns 
        /// it if checking succeeds. 
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns object type name, which should be used to create document 
        /// and view objects instances.
        /// </returns>
        protected override string GetObjectType(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            // Get object type for given node
            string typeName = hierarchy.GetObjectType(item);

            // Checks object type using factory
            if (!String.IsNullOrEmpty(typeName)
                && DocumentViewFactory.Instance.IsObjectTypeRegistered(typeName))
                return typeName;

            return null;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Returns true if given hierarchy item is object node and object descriptor 
        /// supports dropping.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns true if given hierarchy item is object node and object descriptor 
        /// supports dropping.
        /// </returns>
        protected override bool CheckSingleItem(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            // Extract type name
            string typeName = GetObjectType(hierarchy, item);
            if (String.IsNullOrEmpty(typeName))
                return false;

            // Extract descriptor
            IObjectDescriptor descriptor = ObjectDescriptorFactory.Instance.CreateDescriptor(typeName);

            // Return true if descriptor could build drop query.
            return descriptor != null ? descriptor.CanBeDropped : false;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// This function is overriden to control trigger names uniques for whole database and
        /// not for each table.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name.</param>
        /// <param name="id">Array with object identifier.</param>
        /// <param name="template">Template for the new object identifier.</param>
        protected override void CompleteNewObjectID(ServerExplorerFacade hierarchy, string typeName, ref object[] id, string template)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (typeName == null)
                throw new ArgumentNullException("typeName");
            if (id == null)
                throw new ArgumentNullException("id");
            if(id.Length < 3 || id[2] == null)
                throw new ArgumentException(
                            String.Format(
                                CultureInfo.CurrentCulture,
                                Resources.Error_InvlaidIdentifier,
                                id.Length,
                                typeName,
                                ObjectDescriptor.GetIdentifierLength(typeName)),
                             "id");
            if (String.IsNullOrEmpty(template))
                throw new ArgumentException(Resources.Error_EmptyString, "template");

            // Initialize complete parameters
            string actualTameplate = template;
            int counter = 0;
            
            do
            {
                // Stores table id and reset it to null in template, because trigger names must be
                // unique for a whole database.
                object tableID = id[2];
                id[2] = null;

                // Use base method for completion
                base.CompleteNewObjectID(hierarchy, typeName, ref id, actualTameplate);

                // Restores table id
                id[2] = tableID;

                // Change template and add new counter
                actualTameplate = template + (++counter).ToString();
            }
            // We need to control open editors here separately, because base method will miss them 
            // (it doesn't know table ID)
            while (hierarchy.HasDocument(typeName, id));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Returns DROP PROCEDURE/FUNCTION statement.
        /// </summary>
        /// <param name="identifier">Database object identifier.</param>
        /// <returns>Returns DROP TABLE statement.</returns>
        public string BuildDropSql(ServerExplorerFacade hierarchy,
                                   int item, object[] identifier)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException("identifier");
            }

            int    parentId   = hierarchy.GetParent(item);
            string parentName = hierarchy.GetName(parentId);

            // Build query
            StringBuilder query = new StringBuilder("DROP ");

            query.Append(parentName == "Stored Procedures" ? "PROCEDURE" : "FUNCTION");
            query.Append(' ');

            QueryBuilder.WriteIdentifier(identifier[1] as string, identifier[2] as string, query);
            return(query.ToString());
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Completes identifier for new object and changes hierarchy item name.
        /// Last element of id array considered as the name of new object. This
        /// method sequentially generates new names in form {template}{N} and
        /// checks for existing object with same name. To check it this method
        /// tries to enumerate objects with restriction to whole id.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name.</param>
        /// <param name="id">Array with object identifier.</param>
        /// <param name="template">Template for the new object identifier.</param>
        protected virtual void CompleteNewObjectID(ServerExplorerFacade hierarchy, string typeName, ref object[] id, string template)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (String.IsNullOrEmpty(template))
            {
                throw new ArgumentException(Resources.Error_EmptyString, "template");
            }

            ObjectDescriptor.CompleteNewObjectID(hierarchy, typeName, ref id, template);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Executes command for given set of items. Calls to virtual
        /// execution method to process each item.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction..</param>
        /// <param name="items">Array with item’s identifiers.</param>
        /// <returns>Always returns null.</returns>
        public virtual object[] Execute(ServerExplorerFacade hierarchy, int[] items)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            // Creating array to store results
            object[] result = new object[items.Length];

            for (int i = 0; i < items.Length; i++)
            {
                result[i] = ExecuteSingleItem(hierarchy, items[i]);
            }

            // Always returns nothing.
            return(result);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Creates new stored function identifier template without name part.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name to create identifier.</param>
        /// <returns>Returns new stored function identifier template without name part.</returns>
        protected override object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (typeName == null)
                throw new ArgumentNullException("typeName");
            
            // Only stored procedures are supported
            if (!DataInterpreter.CompareInvariant(typeName, StoredProcDescriptor.TypeName))
                throw new NotSupportedException(String.Format(
                                CultureInfo.CurrentCulture,
                                Resources.Error_ObjectTypeNotSupported,
                                typeName));

            // Get default schema
            string schema = hierarchy.Connection.Schema;
            Debug.Assert(!String.IsNullOrEmpty(schema), "Failed to retrive schema name!");
            if (schema == null)
                return null;

            return new object[] { null, schema, null };
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Returns customized text for the command. Firstly retrieves command text
        /// template fro the resources using virtual property, then calls virtual
        /// method to format template for given items.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction..</param>
        /// <param name="items">Array with item’s identifiers.</param>
        /// <returns>Returns customized text for the command.</returns>
        public string GetText(ServerExplorerFacade hierarchy, int[] items)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            // Extract command text format template
            string template = CommandText;

            // Format command text using template and items information
            if (!String.IsNullOrEmpty(template))
            {
                return(FormatText(template, hierarchy, items));
            }

            return(String.Empty);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Command considered as valid if object type name could be determined.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns true if command is valid for given item, otherwise returns false.</returns>
        protected override bool CheckSingleItem(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            // Get object type name
            string typeName = GetObjectType(hierarchy, item);

            if (String.IsNullOrEmpty(typeName))
            {
                return(false);
            }

            // Check object type registration
            return(DocumentViewFactory.Instance.IsObjectTypeRegistered(typeName));
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Checks object type for the given node using document/view factory and returns
        /// it if checking succeeds.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns object type name, which should be used to create document
        /// and view objects instances.
        /// </returns>
        protected override string GetObjectType(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            // Get object type for given node
            string typeName = hierarchy.GetObjectType(item);

            // Checks object type using factory
            if (!String.IsNullOrEmpty(typeName) &&
                DocumentViewFactory.Instance.IsObjectTypeRegistered(typeName))
            {
                return(typeName);
            }

            return(null);
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Creates a new user defined function identifier template
        /// </summary>
        /// <param name="hierarchy">A server explorer facade object to interact with 
        /// Server Explorer hierarchy</param>
        /// <param name="typeName">An object type name to create</param>
        /// <returns>Returns a new user defined function identifier template</returns>
        protected override object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (typeName == null)
                throw new ArgumentNullException("typeName");

            // Checking a type name
            if (!DataInterpreter.CompareInvariant(typeName, UdfDescriptor.TypeName))
                throw new NotSupportedException(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        Resources.Error_ObjectTypeNotSupported,
                        typeName)
                    );

            // Get a default schema
            string schema = hierarchy.Connection.Schema;
            if (schema == null)
                return null;

            return new object[] { null, null };
        }
Ejemplo n.º 37
0
 /// <summary>
 /// This constructor initialize private variables and reads columns list.
 /// </summary>
 /// <param name="hierarchy">
 /// Server explorer facade object to be used for Server Explorer hierarchy interaction. 
 /// Also used to extract connection.
 /// </param>
 /// <param name="schemaName">Name of schema to which owns this database object.</param>
 /// <param name="objectName">Name of this database object.</param>
 /// <param name="isNew">
 /// Indicates if this instance represents new database object doesn’t fixed in 
 /// database yet.
 /// </param>
 protected BaseDocument(ServerExplorerFacade hierarchy, bool isNew, object[] id)
 {
     // Check input paramaters
     if (hierarchy == null)
         throw new ArgumentNullException("hierarchy");
     if (id == null)
         throw new ArgumentNullException("id");
     if (id.Length != ObjectDescriptor.GetIdentifierLength(TypeName))
         throw new ArgumentException(
             String.Format(
                 CultureInfo.CurrentCulture,
                 Resources.Error_InvlaidIdentifier,
                 id.Length, 
                 TypeName,
                 ObjectDescriptor.GetIdentifierLength(TypeName)),
              "id");
     
     // Storing inputs in private variables
     this.hierarchyRef = hierarchy;
     this.connectionRef = Hierarchy.Connection;
     this.schemaVal = GetSchemaFromID(id);
     this.nameVal = GetNameFromID(id);         
     this.isNewVal = isNew;
 }
Ejemplo n.º 38
0
        /// <summary>
        /// Returns identifier of the object for the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Returns array with multipart identifier for the object.</returns>
        protected override object[] GetObjectID(ServerExplorerFacade hierarchy, string typeName, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            // If this is not a table or a view, data editing is not supported.
            if (!DataInterpreter.CompareInvariant(typeName, TableDataDescriptor.TypeName))
            {
                return(null);
            }

            // ID is the object ID of the hierarchy item
            return(hierarchy.GetObjectIdentifier(item));
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Checks object type for the given node (must be Table or View) and returns TableData
        /// it if checking succeeds.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns TableData if object type name of given hierarchy item is Table or View.
        /// Otherwize returns null.
        /// </returns>
        protected override string GetObjectType(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            // Get type of the current node
            string typeName = hierarchy.GetObjectType(item);

            // If this is a table or a view, data editing is supported.
            if (DataInterpreter.CompareInvariant(typeName, TableDescriptor.TypeName) ||
                DataInterpreter.CompareInvariant(typeName, ViewDescriptor.TypeName))
            {
                return(TableDataDescriptor.TypeName);
            }

            // Else data editing is not supported
            return(null);
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Completes identifier for new object and changes hierarchy item name. 
        /// Last element of id array considered as the name of new object. This
        /// method sequentially generates new names in form {template}{N} and 
        /// checks for existing object with same name. To check it this method 
        /// tries to enumerate objects with restriction to whole id.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name.</param>
        /// <param name="id">Array with object identifier.</param>
        /// <param name="template">Template for the new object identifier.</param>
        protected virtual void CompleteNewObjectID(ServerExplorerFacade hierarchy, string typeName, ref object[] id, string template)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (typeName == null)
                throw new ArgumentNullException("typeName");
            if (id == null)
                throw new ArgumentNullException("id");
            if (String.IsNullOrEmpty(template))
                throw new ArgumentException(Resources.Error_EmptyString, "template");

            ObjectDescriptor.CompleteNewObjectID(hierarchy, typeName, ref id, template);
        } 
Ejemplo n.º 41
0
        /// <summary>
        /// Enumerates child types for given node and tries to find supported 
        /// by document/view factory object type.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns object type name, which should be used to create document 
        /// and view objects instances.
        /// </returns>
        protected override string GetObjectType(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            // Get posible child types
            string[] childTypes = hierarchy.GetChildTypes(item);
            if (childTypes == null)
                return null;

            // Extract server version
            Debug.Assert(hierarchy.Connection != null, "Hierarchy has no connection object!");
            Version serverVersion = hierarchy.Connection != null ? hierarchy.Connection.ServerVersion : null;

            // Try to find supported objct type
            foreach (string typeName in childTypes)
            {
                if (DocumentViewFactory.Instance.IsObjectTypeRegistered(typeName))
                {
                    // Extract descriptor
                    IObjectDescriptor descriptor = ObjectDescriptorFactory.Instance.CreateDescriptor(typeName);
                    if (descriptor == null)
                    {
                        Debug.Fail("Failed to get descriptor for object type " + typeName);
                        continue;
                    }

                    // Check required MySQL version for this object.
                    Version minVersion = descriptor.RequiredVersion;
                    if (serverVersion != null && minVersion != null && serverVersion < minVersion)
                        continue;

                    // This is the one. Return it.
                    return typeName;
                }
            }

            // Type not found, command nod supported
            return null;
        } 
Ejemplo n.º 42
0
 /// <summary>
 /// Initializes private variables
 /// </summary>
 /// <param name="hierarchy">A data view hierarchy accessor used to interact
 /// with Server Explorer. Also used to extract connection</param>
 /// <param name="isNew">Indicates if the instance of the class represents a
 /// new database object which hasn't yet been stored in a database</param>
 /// <param name="id">An array containing the object's identifier</param>
 public StoredProcDocument(ServerExplorerFacade hierarchy, bool isNew, object[] id)
     : base(hierarchy, isNew, id)
 {
 }
Ejemplo n.º 43
0
        /// <summary>
        /// Firstly creates new document as exists document and then forces it to become a clone under new name.
        /// </summary>
        /// <param name="typeName">
        /// Object type name for the document
        /// </param>
        /// <param name="hierarchy">
        /// Server explorer facade object to be used for Server Explorer hierarchy interaction.
        /// Also used to extract connection.
        /// </param>
        /// <param name="id">
        /// Array with new object identifier.
        /// </param>
        /// <param name="isNew">
        /// Indicates if this instance represents new database object doesn’t fixed in 
        /// database yet.
        /// </param>
        /// <returns>
        /// Returns cloned document object.
        /// </returns>
        protected override IDocument CreateDocument(ServerExplorerFacade hierarchy, string typeName, object[] objectID, bool isNew)
        {
            // Firstly create new document object, but not as new
            IDocument result = base.CreateDocument(hierarchy, typeName, objectID, false);

            // If failed to create document, return null
            if (result == null)
                return null;

            // Create new object name using current identifier as the base
            CompleteNewObjectID(
                hierarchy,
                typeName,
                ref objectID,
                (result.Name != null ? result.Name : String.Empty) + '_');

            // Check that last id part is filled
            if (objectID[objectID.Length - 1] == null)
            {
                Debug.Fail("Failed to generate cloned name!");
                return null;
            }

            // Force object to clone
            result.CloneToName(objectID[objectID.Length - 1].ToString());
            
            return result;
        }
Ejemplo n.º 44
0
 /// <summary>
 /// Always returns false.
 /// </summary>
 /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
 /// <param name="item">Item identifier.</param>
 /// <returns>Returns true, if new object will be created as a result f this command.</returns>
 protected override bool GetIsNewFlagForObject(ServerExplorerFacade hierarchy, int item)
 {
     return false;
 }
Ejemplo n.º 45
0
        /// <summary>
        /// Creates new object identifier template without name part. Base implementation supports 
        /// only 3-parts identifiers.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name to create identifier.</param>
        /// <returns>Returns new object identifier template without name part.</returns>
        protected virtual object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (typeName == null)
                throw new ArgumentNullException("typeName");

            // Only objects with identifier length 3 is supported
            if (ObjectDescriptor.GetIdentifierLength(typeName) != 3)
                throw new NotSupportedException(String.Format(
                                                CultureInfo.CurrentCulture,
                                                Resources.Error_ObjectTypeNotSupported,
                                                typeName));

            // Get default schema
            string schema = hierarchy.Connection.Schema;
            Debug.Assert(!String.IsNullOrEmpty(schema), "Failed to retrive schema name!");
            if (schema == null)
                return null;

            // Create template ID
            return new object[] { null, schema, null };
        }
Ejemplo n.º 46
0
        /// <summary>
        /// Returns object type name for the given hierarchy item.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>
        /// Returns object type name for the given hierarchy item.
        /// </returns>
        protected override string GetObjectType(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            return hierarchy.GetObjectType(item);
        }
Ejemplo n.º 47
0
 /// <summary>
 /// Returns identifier of the given node.
 /// </summary>
 /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
 /// <param name="item">Item identifier.</param>
 /// <returns>Returns hierarchy item ID for editor.</returns>
 protected override int GetItemForEditor(ServerExplorerFacade hierarchy, int item)
 {
     return item;
 }
Ejemplo n.º 48
0
 /// <summary>
 /// Creates new contextless node and returns its identifier.
 /// </summary>
 /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
 /// <param name="item">Item identifier.</param>
 /// <returns>Returns hierarchy item ID for editor.</returns>
 protected override int GetItemForEditor(ServerExplorerFacade hierarchy, int item)
 {
     if (hierarchy == null)
         throw new ArgumentNullException("hierarchy");
     return hierarchy.CreateObjectNode();
 }
Ejemplo n.º 49
0
 /// <summary>
 /// Always returns true.
 /// </summary>
 /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
 /// <param name="item">Item identifier.</param>
 /// <returns>Returns true, if new object will be created as a result f this command.</returns>
 protected override bool GetIsNewFlagForObject(ServerExplorerFacade hierarchy, int item)
 {
     return(true);
 }
Ejemplo n.º 50
0
        /// <summary>
        /// Drops single item. Uses object descriptor to build DROP statement.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Result of execution. Typicaly null.</returns>
        protected override object ExecuteSingleItem(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            // Extract type name
            string typeName = GetObjectType(hierarchy, item);
            if (String.IsNullOrEmpty(typeName))
            {
                Debug.Fail("Failed to get object type!");
                return false;
            }

            // Extract descriptor
            IObjectDescriptor descriptor = ObjectDescriptorFactory.Instance.CreateDescriptor(typeName);
            if (descriptor == null || !descriptor.CanBeDropped)
            {
                Debug.Fail("Failed to get descriptor or descriptor doesn't support dropping!");
                return null;
            }

            // Extract object identifier
            object[] identifier = hierarchy.GetObjectIdentifier(item);
            if (identifier == null)
            {
                Debug.Fail("Failed to get object identifier!");
                return null;
            }

            // TODO: Note the seconde check for TableData document. It should be replaced in the future
            // by the generic mechanism.
            
            // Check if editor is registered for the database object
            if (hierarchy.HasDocument(typeName, identifier) || hierarchy.HasDocument(TableDataDescriptor.TypeName, identifier))
            {
                UIHelper.ShowError(String.Format(
                    CultureInfo.InvariantCulture,
                    Resources.Error_CantDropBecauseOfEditor,
                    hierarchy.GetName(item)));
                return null;
            }

            // Build DROP query
			string dropQuery = String.Empty;
			if (descriptor is StoredProcDescriptor)
				dropQuery = (descriptor as StoredProcDescriptor).BuildDropSql(
					hierarchy, item, identifier);
			else
				dropQuery = descriptor.BuildDropSql(identifier);

			if (String.IsNullOrEmpty(dropQuery))
            {
                Debug.Fail("Failed to build DROP query!");
                return null;
            }

            // Extract connection
            DataConnectionWrapper connection = hierarchy.Connection;
            if (connection == null)
            {
                Debug.Fail("Failed to extract connection!");
                return null;
            }

            try
            {
                // Execute drop query
                connection.ExecuteScalar(dropQuery);

                // Drop hierarchy node
                hierarchy.DropObjectNode(item);                

                // Notify everybody about object dropping
                connection.ObjectChangeEvents.RaiseObjectRemoved(typeName, identifier);
            }
            catch (DbException e)
            {
                Trace.TraceError("Error during saving object:\n{0}", e.ToString());
                SqlErrorDialog.ShowError(e, connection.GetFullStatus());
            }
            catch (Exception e)
            {
                Trace.TraceError("Error during saving object:\n{0}", e.ToString());
                UIHelper.ShowError(e);
            }

            return null;
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Initializes private variables
 /// </summary>
 /// <param name="hierarchy">A data view hierarchy accessor used to interact 
 /// with Server Explorer. Also used to extract connection</param>
 /// <param name="isNew">Indicates if the instance of the class represents a 
 /// new database object which hasn't yet been stored in a database</param>
 /// <param name="id">An array containing the object's identifier</param>
 public UdfDocument(ServerExplorerFacade hierarchy, bool isNew, object[] id)
     : base(hierarchy, isNew, id)
 {
 }
Ejemplo n.º 52
0
        /// <summary>
        /// This method is overriden to display warning message before deletion. Then just calls base.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction..</param>
        /// <param name="items">Array with item’s identifiers.</param>
        /// <returns>Always returns null.</returns>
        public override object[] Execute(ServerExplorerFacade hierarchy, int[] items)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (items == null)
                throw new ArgumentNullException("items");

            // Build object names list
            StringBuilder list = new StringBuilder();
            foreach (int item in items)
            {
                // Extract name for item
                string name = hierarchy.GetName(item);
                if (String.IsNullOrEmpty(name))
                    continue;

                // If builder is not empty, add ', '
                if (list.Length > 0)
                    list.Append(Resources.Comma);

                // Append object name
                list.Append(name);
            }

            // Build warning message
            string message = String.Format(CultureInfo.CurrentCulture, Resources.Warning_ConfirmDelete, list.ToString());

            // First, ask user for confirmation
            if (UIHelper.ShowWarning(message, MessageBoxButtons.YesNo)
                != DialogResult.Yes)
                return null;

            // Only if user confirmed delete, call to base class to execute command
            return base.Execute(hierarchy, items);
        } 
Ejemplo n.º 53
0
        /// <summary>
        /// Generates new object identifier. For objects owned directly by schema, generates
        /// variation of "schema.{object type}¹". For nested objects returns variation of
        /// "{parent ID}.{object type}¹".
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <param name="typeName">Object type name.</param>
        /// <returns>Returns array with multipart identifier for the object.</returns>
        protected override object[] GetObjectID(ServerExplorerFacade hierarchy, string typeName, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }


            // Get identifier length
            int idLength = ObjectDescriptor.GetIdentifierLength(typeName);

            if (idLength <= 0)
            {
                throw new NotSupportedException(String.Format(
                                                    CultureInfo.CurrentCulture,
                                                    Resources.Error_ObjectTypeNotSupported,
                                                    typeName));
            }

            // Create object ID template
            object[] id;

            // Get parent object identifier
            object[] parentID = hierarchy.GetObjectIdentifier(item);

            // For embedded objects ID is ID of owner object with one additional slot.
            if (parentID != null && parentID.Length == idLength - 1)
            {
                // Initialize object identifier template
                id = new object[idLength];

                // Copy parent object identifier to the template
                parentID.CopyTo(id, 0);
            }
            // For root objects (objects owned directly by schema) ID has three slots with
            // schema name in the middle
            else
            {
                id = CreateNewIDBase(hierarchy, typeName);
                if (id == null || id.Length != idLength)
                {
                    throw new NotSupportedException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Resources.Error_ObjectTypeNotSupported,
                                                        typeName));
                }
            }

            // Extract template for the new name
            string template = GetTemplate(typeName, id);

            if (template == null)
            {
                template = typeName;
            }

            // Generate object name (fill the last slot)
            CompleteNewObjectID(hierarchy, typeName, ref id, template);

            // Return result
            return(id);
        }
Ejemplo n.º 54
0
        /// <summary>
        /// Returns DROP PROCEDURE/FUNCTION statement.
        /// </summary>
        /// <param name="identifier">Database object identifier.</param>
        /// <returns>Returns DROP TABLE statement.</returns>
        public string BuildDropSql(ServerExplorerFacade hierarchy, 
			int item, object[] identifier)
        {
            if (identifier == null)
                throw new ArgumentNullException("identifier");

			int parentId = hierarchy.GetParent(item);
			string parentName = hierarchy.GetName(parentId);

            // Build query
            StringBuilder query = new StringBuilder("DROP ");
            query.Append(parentName == "Stored Procedures" ? "PROCEDURE" : "FUNCTION");
            query.Append(' ');

            QueryBuilder.WriteIdentifier(identifier[1] as string, identifier[2] as string, query);
            return query.ToString();
        }
Ejemplo n.º 55
0
 /// <summary>
 /// Creates new document object. Base implementation simply calls factory.
 /// </summary>
 /// <param name="typeName">
 /// Object type name for the document
 /// </param>
 /// <param name="hierarchy">
 /// Server explorer facade object to be used for Server Explorer hierarchy interaction.
 /// Also used to extract connection.
 /// </param>
 /// <param name="id">
 /// Array with new object identifier.
 /// </param>
 /// <param name="isNew">
 /// Indicates if this instance represents new database object doesn’t fixed in 
 /// database yet.
 /// </param>
 /// <returns>
 /// Instance of the new document object
 /// </returns>
 protected virtual IDocument CreateDocument(ServerExplorerFacade hierarchy, string typeName, object[] objectID, bool isNew)
 {
     if (hierarchy == null)
         throw new ArgumentNullException("hierarchy");
     if (typeName == null)
         throw new ArgumentNullException("typeName");
     if (objectID == null)
         throw new ArgumentNullException("objectID");
     return DocumentViewFactory.Instance.CreateDocument(typeName, hierarchy, objectID, isNew);
 }
Ejemplo n.º 56
0
 /// <summary>
 /// Returns array with multipart identifier for the object.
 /// </summary>
 /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
 /// <param name="item">Item identifier.</param>
 /// <returns>Returns array with multipart identifier for the object.</returns>
 protected abstract object[] GetObjectID(ServerExplorerFacade hierarchy, string typeName, int item);
Ejemplo n.º 57
0
 /// <summary>
 /// This constructor initialize private identifier variables.
 /// </summary>
 /// <param name="hierarchy">
 /// Data view hierarchy accessor used to interact with Server Explorer.
 /// Also used to extract connection.
 /// </param>
 /// <param name="id">
 /// Array with the object identifier.
 /// </param>
 /// <param name="isNew">
 /// Indicates if this instance represents new database object doesn’t fixed in
 /// database yet.
 /// </param>
 public TableDataDocument(ServerExplorerFacade hierarchy, bool isNew, object[] id)
     : base(hierarchy, isNew, id)
 {
     Debug.Assert(!isNew, "Editing data in the new objects are not supported!");
 }
Ejemplo n.º 58
0
 /// <summary>
 /// Returns hierarchy item ID for editor. It can be the same item, 
 /// if the command it is changing command and it can item of new 
 /// contextless node if it is creating command.
 /// </summary>
 /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
 /// <param name="item">Item identifier.</param>
 /// <returns>Returns hierarchy item ID for editor.</returns>
 protected abstract int GetItemForEditor(ServerExplorerFacade hierarchy, int item);
Ejemplo n.º 59
0
 /// <summary>
 /// This constructor initialize private identifier variables.
 /// </summary>
 /// <param name="hierarchy">
 /// Data view hierarchy accessor used to interact with Server Explorer. 
 /// Also used to extract connection.
 /// </param>
 /// <param name="id">
 /// Array with the object identifier.
 /// </param>
 /// <param name="isNew">
 /// Indicates if this instance represents new database object doesn’t fixed in 
 /// database yet.
 /// </param>
 public TableDataDocument(ServerExplorerFacade hierarchy, bool isNew, object[] id)
     :base(hierarchy, isNew, id)
 {
     Debug.Assert(!isNew, "Editing data in the new objects are not supported!");
 }
Ejemplo n.º 60
0
 /// <summary>
 /// Returns true, if new object will be created as a result of this command.
 /// </summary>
 /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
 /// <param name="item">Item identifier.</param>
 /// <returns>Returns true, if new object will be created as a result f this command.</returns>
 protected abstract bool GetIsNewFlagForObject(ServerExplorerFacade hierarchy, int item);