Aracılığıyla paylaş


ServerDocument.IsCacheEnabled Yöntem

Belirtilen belge veri önbelleği olup olmadığını gösteren bir değeri alır.

Ad alanı:  Microsoft.VisualStudio.Tools.Applications
Derleme:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll içinde)

Sözdizimi

'Bildirim
Public Shared Function IsCacheEnabled ( _
    documentPath As String _
) As Boolean
public static bool IsCacheEnabled(
    string documentPath
)

Parametreler

  • documentPath
    Tür: System.String
    Denetlemek istediğiniz belgenin tam yolu.

Dönüş Değeri

Tür: System.Boolean
true Belirtilen belge veri önbelleği varsa; Aksi takdirde, false.

Özel Durumlar

Exception Koşul
ArgumentNullException

documentPath Parametresi nullnull başvuru (Visual Basic'te Nothing) veya boş ya da tamamen boşluk karakterlerinden oluşur.

FileNotFoundException

Tarafından belirtilen dosya documentPath yok.

DocumentCustomizedWithPreviousRuntimeException

Tarafından belirtilen dosya documentPath ile Visual Studio 2010 Araçları Office çalışma zamanı veya Microsoft Office sistemi için Visual Studio Araçları için oluşturulmamış bir özelleştirme vardır (sürüm 3.0 çalışma zamanı).

Notlar

Veri önbelleğine gerçekte verileri içeren değil mi Bu yöntem yalnızca belge veri önbelleği olup olmadığını gösterir.Belge içindeki veri içeren veri önbelleği olup olmadığını, hala döner true.

Örnekler

Aşağıdaki kod örneği oluşturur Yeni bir ServerDocument, sonra kullanır CachedData özelliği veri önbelleğinin içeriğini görüntülemek için.İlk örnekte IsCacheEnabled çalışma kitabı veri önbelleğine sahip olduğunu doğrulamak için yöntem.

Bu örnek aşağıdakileri gerektirir:

  • Konsol uygulama projesi veya başka bir Office dışı proje.

  • Aşağıdaki derlemelere başvurular:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.dll (durumunda proje hedefleri .NET Framework 4 veya .NET Framework 4.5).

      veya

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (proje .NET Framework 3.5 hedefliyorsa).

  • Imports(Visual Basic için) veya using için (C#) deyimleri için Microsoft.VisualStudio.Tools.Applications ve Microsoft.VisualStudio.Tools.Applications.Runtime kod dosyanın üst ad.

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

.NET Framework Güvenliği

Ayrıca bkz.

Başvuru

ServerDocument Sınıf

Microsoft.VisualStudio.Tools.Applications Ad Alanı