Classe CachedDataItem

Representa um objeto de dados em cache uma personalização de nível de documento foi criado usando as ferramentas de desenvolvimento do Office em Visual Studio.

Hierarquia de herança

System.Object
  Microsoft.VisualStudio.Tools.Applications.CachedDataNodeBase
    Microsoft.VisualStudio.Tools.Applications.CachedDataItem

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

Sintaxe

'Declaração
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class CachedDataItem _
    Inherits CachedDataNodeBase
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class CachedDataItem : CachedDataNodeBase

O tipo CachedDataItem expõe os membros a seguir.

Propriedades

  Nome Descrição
Propriedade pública DataType Obtém ou define o nome qualificado por conjunto do tipo de objeto de dados em cache.
Propriedade pública Id Obtém ou define o nome do objeto de dados em cache que é representado pela CachedDataItem.
Propriedade pública Schema Obtém ou define um esquema que descreve o objeto de dados em cache é representado pela CachedDataItem, se o objeto de dados em cache é um DataSet ou DataTable.
Propriedade pública Xml Obtém ou define a representação XML do objeto de dados em cache que é representado pela CachedDataItem.

Início

Métodos

  Nome Descrição
Método público Equals Determina se o especificado Object é igual a atual Object. (Herdado de Object.)
Método protegido Finalize Permite que um objeto tentar liberar recursos e executar outras operações de limpeza antes que ele é recuperado pela coleta de lixo. (Herdado de Object.)
Método público GetHashCode Serves as a hash function for a particular type. (Herdado de Object.)
Método público GetType Obtém o Type da instância atual. (Herdado de Object.)
Método protegido MemberwiseClone Cria uma cópia superficial do atual Object. (Herdado de Object.)
Método público SerializeDataInstance Serializa os dados para o objeto de dados em cache é representado pela CachedDataItem.
Método público ToString Retorna um string que representa o objeto atual. (Herdado de Object.)

Início

Comentários

Para obter mais informações sobre o cache de dados no nível do documento personalizações, consulte Cache de dados e Acesso a dados em documentos no servidor.

Exemplos

O exemplo de código a seguir examina cada CachedDataItem no cache de dados de uma pasta de trabalho do Excel e o exibe em cache o nome de cada objeto de dados.

This example requires:

  • Um projeto de aplicativo de console ou algum outro projeto de não-Office.

  • Referências aos assemblies seguintes:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.dll (se os destinos do projeto de .NET Framework 4).

      or

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (se os destinos do projeto a.NET Framework 3.5).

  • Imports(para Visual Basic) ou using (para C#) instruções para Microsoft.VisualStudio.Tools.Applications e Microsoft.VisualStudio.Tools.Applications.Runtime namespaces no topo do seu 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();
    }
}

Acesso thread-safe

Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Consulte também

Referência

Namespace Microsoft.VisualStudio.Tools.Applications

Outros recursos

Gerenciamento de documentos em um servidor usando a classe ServerDocument

Cache de dados

Acesso a dados em documentos no servidor