ServerDocument.IsCacheEnabled – metoda
Získá hodnotu, která označuje, zda má zadaný dokument v mezipaměti data.
Obor názvů: Microsoft.VisualStudio.Tools.Applications
Sestavení: Microsoft.VisualStudio.Tools.Applications.ServerDocument (v Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
Syntaxe
'Deklarace
Public Shared Function IsCacheEnabled ( _
documentPath As String _
) As Boolean
public static bool IsCacheEnabled(
string documentPath
)
Parametry
- documentPath
Typ: System.String
Úplná cesta dokumentu, který chcete zkontrolovat.
Vrácená hodnota
Typ: System.Boolean
true Pokud zadaný dokument obsahuje mezipaměť dat; jinak false.
Výjimky
Výjimka | Podmínka |
---|---|
ArgumentNullException | documentPath Parametr je nullodkaz null (Nothing v jazyce Visual Basic) nebo prázdné nebo je celá tvořena znaky pro prázdné místo. |
FileNotFoundException | Do souboru určeného parametrem documentPath neexistuje. |
DocumentCustomizedWithPreviousRuntimeException | Do souboru určeného parametrem documentPath má vlastní nastavení, která nebyla vytvořena pomocí nástroje sady Visual Studio 2010 pro Office Runtime nebo Visual Studio Tools pro systém Microsoft Office (verze 3.0 Runtime). |
Poznámky
Tato metoda označuje pouze zda dokument obsahuje mezipaměť dat, ne to, zda obsahuje mezipaměť dat ve skutečnosti data.Pokud dokument obsahuje mezipaměť dat, který neobsahuje žádná data v něm, vrátí tato metoda stále true.
Příklady
Následující příklad kódu vytvoří nový ServerDocumenta potom použije CachedData k zobrazení obsahu mezipaměti data.V prvním příkladu IsCacheEnabled metodu k ověření, že sešit obsahuje data mezipaměti.
Tento příklad vyžaduje:
Projekt aplikace konzoly nebo jiného projektu mimo sadu Office.
Odkazy na následující sestavení:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (Pokud projekt cílen .NET Framework 4 nebo .NET Framework 4.5).
nebo
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (Pokud je projekt cílen na rozhraní.NET Framework 3.5).
Imports(pro Visual Basic) nebo using (pro jazyk C#) příkazy pro Microsoft.VisualStudio.Tools.Applications a Microsoft.VisualStudio.Tools.Applications.Runtime obory názvů v horní části souboru kódu.
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();
}
}
Zabezpečení rozhraní .NET Framework
- Plná důvěra přímému volajícímu. Částečně zabezpečený kód nemůže tento člen použít. Další informace naleznete v tématu Používání knihoven z částečně důvěryhodného kódu.