Udostępnij za pośrednictwem


Klasa CachedDataItem

Reprezentuje obiekt buforowane dane w dostosowania poziomu dokumentu, który został utworzony za pomocą narzędzia programowania pakietu Office w programie Visual Studio.

Hierarchia dziedziczenia

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

Przestrzeń nazw:  Microsoft.VisualStudio.Tools.Applications
Zestaw:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (w Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Składnia

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

Typ CachedDataItem uwidacznia następujące elementy członkowskie.

Właściwości

  Nazwa Opis
Właściwość publiczna DataType Zwraca lub ustawia nazwa kwalifikowana zestawu typu obiektu danych buforowanych.
Właściwość publiczna Id Zwraca lub ustawia nazwę obiektu buforowanych danych, która jest reprezentowana przez CachedDataItem.
Właściwość publiczna Schema Zwraca lub ustawia schemat opisujący obiekt buforowanych danych, która jest reprezentowana przez CachedDataItem, jeśli obiekt buforowanych danych jest DataSet lub DataTable.
Właściwość publiczna Xml Zwraca lub ustawia reprezentacji XML obiektu buforowanych danych, która jest reprezentowana przez CachedDataItem.

Początek

Metody

  Nazwa Opis
Metoda publiczna Equals Określa, czy określony obiekt jest równy bieżącemu obiektowi. (Odziedziczone z Object).
Metoda publiczna GetHashCode Służy jako domyślnej funkcji mieszania. (Odziedziczone z Object).
Metoda publiczna GetType Pobiera Type bieżącego wystąpienia. (Odziedziczone z Object).
Metoda publiczna SerializeDataInstance Szereguje danych do obiektu buforowanych danych, który jest reprezentowany przez CachedDataItem.
Metoda publiczna ToString Zwraca ciąg, który reprezentuje bieżący obiekt. (Odziedziczone z Object).

Początek

Uwagi

Aby uzyskać więcej informacji na temat buforowania danych w dokumencie poziom dostosowania, zobacz Buforowanie danych i Uzyskiwanie dostępu do danych w dokumentach na serwerze.

Przykłady

Poniższy przykład kodu sprawdza każdy CachedDataItem w pamięci podręcznej danych skoroszytu programu Excel i wyświetla nazwę każdego buforowane dane obiektu.

W tym przykładzie wymaga:

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();
    }
}

Bezpieczeństwo wątku

Wszystkie publiczne static (Shared w języku Visual Basic) elementy członkowskie tego typu są bezpieczne dla wątków. Wystąpienia elementów członkowskich nie dają gwarancji bezpieczeństwa wątków.

Zobacz też

Informacje

Przestrzeń nazw Microsoft.VisualStudio.Tools.Applications

Inne zasoby

Zarządzanie dokumentami na serwerze za pomocą klasy ServerDocument

Buforowanie danych

Uzyskiwanie dostępu do danych w dokumentach na serwerze