Compartilhar via


Método ServerDocument.IsCacheEnabled

Obtém um valor que indica se o documento especificado tem um cache de dados.

Namespace:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (em Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Sintaxe

'Declaração
Public Shared Function IsCacheEnabled ( _
    documentPath As String _
) As Boolean
public static bool IsCacheEnabled(
    string documentPath
)

Parâmetros

  • documentPath
    Tipo: System.String
    O caminho completo de documento que você deseja verificar.

Valor de retorno

Tipo: System.Boolean
true se o documento especificado tem um cache de dados; caso contrário, false.

Exceções

Exceção Condição
ArgumentNullException

O parâmetro de documentPath é nulluma referência nula (Nothing no Visual Basic) ou vazio ou consiste inteiramente em caracteres de espaço em branco.

FileNotFoundException

O arquivo especificado por documentPath não existe.

DocumentCustomizedWithPreviousRuntimeException

O arquivo especificado por documentPath tem uma personalização que não é criada no 2010 Visual Studio Tools for Office Runtime ou Visual Studio para o Microsoft Office system (tempo de execução de versão 3,0).

Comentários

Este método indica somente se o documento tem um cache de dados, não se o cache de dados realmente contém dados. Se o documento tem um cache de dados que não contém nenhum dados nele, esse método ainda retorna true.

Exemplos

O exemplo de código a seguir cria um novo ServerDocumentem seguida, usa a propriedade de CachedData para exibir o conteúdo da cache de dados. O primeiro exemplo usa o método de IsCacheEnabled para verificar que a pasta de trabalho tem um cache de dados.

Este exemplo requer:

  • Um projeto de aplicativo do console ou qualquer outro projeto do Office não.

  • Referências para os seguintes conjuntos:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.dll (se o projeto utiliza .NET Framework 4 ou .NET Framework 4.5).

      ou

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (se o projeto utiliza o .NET Framework 3.5).

  • Imports (Visual Basic) ou instruções de using (para C#) para Microsoft.VisualStudio.Tools.Applications e namespaces de Microsoft.VisualStudio.Tools.Applications.Runtime na parte superior do arquivo de código.

Private Sub DisplayDataCacheContents(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion <> 3 Then
            MessageBox.Show("This document does not have a Visual Studio Tools for Office " & _
                "customization, or it has a customization that was created with a version of " & _
                "the runtime that is incompatible with this version of the ServerDocument class.")
            Return
        End If

        If ServerDocument.IsCacheEnabled(documentPath) Then
            serverDocument1 = New ServerDocument(documentPath)
            Dim stringBuilder1 As New System.Text.StringBuilder()

            ' Display all of the cached data items 
            ' in the document.
            Dim hostItem1 As CachedDataHostItem
            For Each hostItem1 In serverDocument1.CachedData.HostItems
                stringBuilder1.Append(vbLf & "Namespace and class: ")
                stringBuilder1.Append(hostItem1.Id & vbLf)
                Dim dataItem1 As CachedDataItem
                For Each dataItem1 In hostItem1.CachedData
                    stringBuilder1.Append("     Data item: ")
                    stringBuilder1.Append(dataItem1.Id & vbLf)
                Next dataItem1
            Next hostItem1
            MessageBox.Show(stringBuilder1.ToString())
        Else
            MessageBox.Show("The specified document does not have cached data.")
        End If

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As UnknownCustomizationFileException
        System.Windows.Forms.MessageBox.Show("The specified document has a file " & _
            "extension that is not supported by Visual Studio Tools for Office.")
    Finally
        If Not (serverDocument1 Is Nothing) Then
            serverDocument1.Close()
        End If
    End Try
End Sub
private void DisplayDataCacheContents(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);

        if (runtimeVersion != 3)
        {
            MessageBox.Show("This document does not have a Visual Studio Tools for " +
                "Office customization, or it has a customization that was created with " +
                "a version of the runtime that is incompatible with this version of the " +
                "ServerDocument class.");
            return;
        }

        if (ServerDocument.IsCacheEnabled(documentPath))
        {
            serverDocument1 = new ServerDocument(documentPath);
            System.Text.StringBuilder stringBuilder1 =
                new System.Text.StringBuilder();

            // Display all of the cached data items 
            // in the document.
            foreach (CachedDataHostItem hostItem1 in
                serverDocument1.CachedData.HostItems)
            {
                stringBuilder1.Append("\nNamespace and class: ");
                stringBuilder1.Append(hostItem1.Id + "\n");
                foreach (CachedDataItem dataItem1 in
                    hostItem1.CachedData)
                {
                    stringBuilder1.Append("     Data item: ");
                    stringBuilder1.Append(dataItem1.Id + "\n");
                }
            }
            MessageBox.Show(stringBuilder1.ToString());
        }
        else
        {
            MessageBox.Show("The specified document does not have cached data.");
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (UnknownCustomizationFileException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document has a file " +
            "extension that is not supported by Visual Studio Tools for Office.");
    }
    finally
    {
        if (serverDocument1 != null)
            serverDocument1.Close();
    }
}

Segurança do .NET Framework

Consulte também

Referência

ServerDocument Classe

Namespace Microsoft.VisualStudio.Tools.Applications