Condividi tramite


Classe CachedDataItem

Rappresenta un oggetto dati memorizzato nella cache in una personalizzazione a livello di documento creato tramite gli Strumenti di sviluppo di Microsoft Office per Visual Studio.

Gerarchia di ereditarietà

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

Spazio dei nomi:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Sintassi

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

Il tipo CachedDataItem espone i seguenti membri.

Proprietà

  Nome Descrizione
Proprietà pubblica DataType Ottiene o imposta il nome qualificato dall'assembly del tipo di oggetto dati memorizzato.
Proprietà pubblica Id Ottiene o imposta il nome dell'oggetto dati memorizzato nella cache rappresentato da CachedDataItem.
Proprietà pubblica Schema Ottiene o imposta uno schema che descrive l'oggetto dati memorizzato nella cache rappresentato da CachedDataItem, se tale oggetto dati è un oggetto DataSet o DataTable.
Proprietà pubblica Xml Ottiene o imposta la rappresentazione XML dell'oggetto dati memorizzato rappresentato dalla proprietà CachedDataItem.

In alto

Metodi

  Nome Descrizione
Metodo pubblico Equals Determina se l'oggetto Object specificato è uguale all'oggetto Object corrente. (Ereditato da Object)
Metodo protetto Finalize Consente a un oggetto di provare a liberare risorse ed eseguire altre operazioni di pulitura prima che l'oggetto stesso venga recuperato dalla procedura di Garbage Collection. (Ereditato da Object)
Metodo pubblico GetHashCode Funge da funzione hash per un determinato tipo. (Ereditato da Object)
Metodo pubblico GetType Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object)
Metodo protetto MemberwiseClone Consente di creare una copia dei riferimenti dell'oggetto Object corrente. (Ereditato da Object)
Metodo pubblico SerializeDataInstance Serializza i dati nell'oggetto dati memorizzato nella cache che è rappresentato da CachedDataItem.
Metodo pubblico ToString Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object)

In alto

Note

Per ulteriori informazioni sulla memorizzazione di dati nella cache nelle personalizzazioni a livello di documento, vedere Memorizzazione di dati nella cache e Accesso ai dati dei documenti sul server.

Esempi

Nell'esempio di codice seguente viene esaminato ogni oggetto CachedDataItem nella cache di dati di una cartella di lavoro di Excel e viene visualizzato il nome di ogni oggetto dati memorizzato nella cache.

Per questo esempio sono necessari i seguenti requisiti:

  • Progetto di applicazione console o qualche altro progetto non-Office.

  • Riferimenti ai seguenti assembly:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.dll (se il progetto è destinato a .NET Framework 4).

      oppure

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (se il progetto è destinato a .NET Framework 3.5).

  • Istruzioni Imports (per Visual Basic) o using (per C#) per gli spazi dei nomi Microsoft.VisualStudio.Tools.Applications e Microsoft.VisualStudio.Tools.Applications.Runtime all'inizio del file di codice

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

Codice thread safe

Qualsiasi membro static (Shared in Visual Basic) pubblico di questo tipo è thread-safe. I membri di istanza non sono garantiti come thread-safe.

Vedere anche

Riferimenti

Spazio dei nomi Microsoft.VisualStudio.Tools.Applications

Altre risorse

Gestione dei documenti di un server utilizzando la classe ServerDocument

Memorizzazione di dati nella cache

Accesso ai dati dei documenti sul server