Compartilhar via


CachedDataItem Classe (sistema de 2007)

Representa um objeto de dados em cache em uma personalização em nível de documento que foi criado usando Visual Studio Tools for Office.

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

Sintaxe

<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class CachedDataItem _
    Inherits CachedDataNodeBase

Dim instance As CachedDataItem
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class CachedDataItem : CachedDataNodeBase

Comentários

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

Observação:

Essa classe pode ser usada somente com soluções para Microsoft Office palavra 2007 e Microsoft Office Excel 2007.Para acesso os dados armazenados em cache em soluções para palavra 2003 e Excel 2003, use o CachedDataItem classe na Microsoft.VisualStudio.Tools.Applications.Runtime namespace do runtime do Visual Studio 2005 Tools for Microsoft Office Second Edition. Para obter mais informações, consulte Gerenciando documentos em um servidor usando a classe do ServerDocument.

Exemplos

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

Este exemplo requer uma referência aos assemblies Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll e Microsoft.VisualStudio.Tools.Applications.tempo de execução.v9.0.dll e Imports (para Visual Basic) ou using (para translation from VPE for Csharp) instruções para Microsoft.VisualStudio.Tools.Applications e Microsoft.VisualStudio.Tools.Applications.Runtime espaços para nome na parte superior do seu arquivo de código.

PrivateSub DisplayDataCacheContents(ByVal documentPath AsString)
    Dim runtimeVersion AsInteger = 0
    Dim serverDocument1 As ServerDocument = NothingTry
        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.")
            ReturnEndIfIf ServerDocument.IsCacheEnabled(documentPath) Then
            serverDocument1 = New ServerDocument(documentPath)
            Dim stringBuilder1 AsNew System.Text.StringBuilder()

            ' Display all of the cached data items             ' in the document.Dim hostItem1 As CachedDataHostItem
            ForEach hostItem1 In serverDocument1.CachedData.HostItems
                stringBuilder1.Append(vbLf & "Namespace and class: ")
                stringBuilder1.Append(hostItem1.Id & vbLf)
                Dim dataItem1 As CachedDataItem
                ForEach 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.")
        EndIfCatch 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.")
    FinallyIfNot (serverDocument1 IsNothing) Then
            serverDocument1.Close()
        EndIfEndTryEndSub
privatevoid 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();
    }
}

Hierarquia de herança

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

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

Membros CachedDataItem

Namespace Microsoft.VisualStudio.Tools.Applications

Outros recursos

Cache de dados

Acessando dados em documentos no servidor