Partager via


IVsDataProviderDynamicSupport.IsOperationSupported Method

Determines whether a specific operation is supported in the current environment, for the specified DDEX data source.

Namespace:  Microsoft.VisualStudio.Data.Core
Assembly:  Microsoft.VisualStudio.Data.Core (in Microsoft.VisualStudio.Data.Core.dll)

Syntax

'Déclaration
Function IsOperationSupported ( _
    source As Guid, _
    command As CommandID, _
    context As Object _
) As Boolean
bool IsOperationSupported(
    Guid source,
    CommandID command,
    Object context
)
bool IsOperationSupported(
    Guid source, 
    CommandID^ command, 
    Object^ context
)
abstract IsOperationSupported : 
        source:Guid * 
        command:CommandID * 
        context:Object -> bool 
function IsOperationSupported(
    source : Guid, 
    command : CommandID, 
    context : Object
) : boolean

Parameters

  • source
    Type: System.Guid
    A DDEX data source identifier.
  • context
    Type: System.Object
    An object representing the context in which the operation exists.

Return Value

Type: System.Boolean
true if the operation is supported by the provider in the current environment; otherwise, false.

Exceptions

Exception Condition
ArgumentNullException

The command parameter is nulla null reference (Nothing in Visual Basic).

ArgumentException

The context parameter is not an expected value for the specified operation.

Remarks

This method enables DDEX providers to dynamically alter which operations are available to the user, depending on the current environment and a particular context within that environment. In other words, the provider can adapt to the current computer configuration and to which components supporting the DDEX provider are installed. A common use of this method would be to enable or disable support for a particular operation that depends on the availability of a particular component on the computer, such as a scripting engine.

Examples

The following code demonstrates how to implement this method in such a way that it supports a Deploy command on a connection node in the data explorer only when a particular registry key exists, indicating that a specific deployment technology is installed.

using System;
using System.ComponentModel.Design;
using Microsoft.Win32;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Data.Services;

public class MyProviderDynamicSupport2 : IVsDataProviderDynamicSupport
{
    private static readonly CommandID DeployCommand =
        new CommandID(new Guid("6535F307-2083-4cbb-B2FA-11F2DCD69DAF"), 25);

    public bool IsProviderSupported
    {
        get
        {
            return true;
        }
    }

    public bool IsSourceSupported(Guid source)
    {
        return true;
    }

    public bool IsOperationSupported(
        Guid source, CommandID command, object context)
    {
        if (command == null)
        {
            throw new ArgumentNullException("command");
        }
        if (command.Equals(DeployCommand))
        {
            IVsDataExplorerConnection explorerConnection =
                context as IVsDataExplorerConnection;
            if (explorerConnection == null)
            {
                throw new ArgumentException();
            }
            RegistryKey key = Registry.LocalMachine.OpenSubKey(
                @"SOFTWARE\Company\DeployTechnology");
            if (key == null)
            {
                return false;
            }
            key.Close();
        }
        return true;
    }

    public string GetUnsupportedReason(
        Guid source, CommandID command, object context)
    {
        if (command == null)
        {
            throw new ArgumentNullException("command");
        }
        if (command.Equals(DeployCommand) &&
            !IsOperationSupported(source, command, context))
        {
            // Note: This string should be localized
            return "In order to deploy a database you need to install our deployment technology.";
        }
        return null;
    }
}

.NET Framework Security

See Also

Reference

IVsDataProviderDynamicSupport Interface

Microsoft.VisualStudio.Data.Core Namespace