CachedDataItem (Clase)

Representa un objeto de datos almacenado en caché en una personalización de nivel de documento que se creó usando las herramientas de desarrollo de Office incluidas en Visual Studio.

Jerarquía de herencia

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

Espacio de nombres:  Microsoft.VisualStudio.Tools.Applications
Ensamblado:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (en Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Sintaxis

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

El tipo CachedDataItem expone los siguientes miembros.

Propiedades

  Nombre Descripción
Propiedad pública DataType Obtiene o establece el nombre calificado con el nombre de ensamblado del tipo del objeto de datos almacenado en memoria caché.
Propiedad pública Id Obtiene o establece el nombre del objeto de datos almacenado en memoria caché representado por CachedDataItem.
Propiedad pública Schema Obtiene o establece un esquema que describe el objeto de datos almacenado en memoria caché representado por CachedDataItem, si el objeto de datos almacenado en memoria caché es DataSet o DataTable.
Propiedad pública Xml Obtiene o establece la representación XML del objeto de datos almacenado en memoria caché representado por CachedDataItem.

Arriba

Métodos

  Nombre Descripción
Método público Equals Determina si el objeto Object especificado es igual al objeto Object actual. (Se hereda de Object).
Método protegido Finalize Permite que un objeto intente liberar recursos y realizar otras operaciones de limpieza antes de ser reclamado por la recolección de elementos no utilizados. (Se hereda de Object).
Método público GetHashCode Actúa como función hash para un tipo concreto. (Se hereda de Object).
Método público GetType Obtiene el objeto Type de la instancia actual. (Se hereda de Object).
Método protegido MemberwiseClone Crea una copia superficial del objeto Object actual. (Se hereda de Object).
Método público SerializeDataInstance Serializa los datos en el objeto de datos almacenado en memoria caché representado por CachedDataItem.
Método público ToString Devuelve una cadena que representa el objeto actual. (Se hereda de Object).

Arriba

Comentarios

Para obtener más información sobre el almacenamiento de datos en caché para las personalizaciones de nivel de documento, vea Almacenar datos en caché e Acceso a datos de documentos en el servidor.

Ejemplos

En el ejemplo de código siguiente se examina CachedDataItem en la caché de datos de un libro de Excel y se muestra el nombre de cada objeto de datos almacenado en memoria caché.

Este ejemplo necesita:

  • Un proyecto de aplicación de consola o algún otro proyecto que no es de Office.

  • Referencias a los siguientes ensamblados:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll y Microsoft.VisualStudio.Tools.Applications.Runtime.dll (si el destino del proyecto es .NET Framework 4).

      O bien

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (si el proyecto está dirigido a .NET Framework 3.5).

  • Instrucciones Imports (para Visual Basic) o using (para C#) para los espacios de nombres Microsoft.VisualStudio.Tools.Applications y Microsoft.VisualStudio.Tools.Applications.Runtime en la parte superior de su archivo 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();
    }
}

Seguridad para subprocesos

Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Vea también

Referencia

Microsoft.VisualStudio.Tools.Applications (Espacio de nombres)

Otros recursos

Administrar documentos en un servidor mediante la clase ServerDocument

Almacenar datos en caché

Acceso a datos de documentos en el servidor