Aracılığıyla paylaş


CachedDataItem.SerializeDataInstance Yöntem

Tarafından temsil edilen önbelleğe alınmış veri nesnesine veri serileştirildiğini CachedDataItem.

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

Sözdizimi

'Bildirim
Public Sub SerializeDataInstance ( _
    value As Object _
)
public void SerializeDataInstance(
    Object value
)

Parametreler

  • value
    Tür: System.Object
    Veri önbelleği alanındaki bir nesneye kaydetmek istediğiniz verileri içeren nesne.

Notlar

Use SerializeDataInstance başlatmak veya önbelleğe alınmış verileri nesnesinin değerini değiştirmek için yöntem.Bu yöntem serileştirildiğini value parametresi önbelleğe alınmış verileri içine nesne CachedDataItem temsil eder.Karmaşık önbelleğe alınmış veri nesnesindeki belirli veri değerlerini gibi değişiklik yapmak için bir DataSet veya DataTable, önbelleğe alınan nesnenin yeni bir örneğini xml gösterimine önbelleğe alınmış veri serisini bu kopyaya değişiklikleri yapın ve daha sonra SerializeDataInstance yöntemi değişiklikleri seri hale getirmek için veri önbelleğine yedekleyin.Daha fazla bilgi için, bkz. Sunucu Üzerindeki Belgelerin İçerisindeki Verilere Erişim ve İzlenecek yol: Bir çalışma kitabını bir sunucuda önbelleğe alınmış verileri değiştirme.

Bu yöntem DiffGram biçiminde seri hale getirilirken için kullandığı DataSet, DataTableve typed dataset nesneleri veri önbelleğine.Bu veri önbelleği çevrimdışı bir belgede yapılan değişiklikler sunucuya doğru gönderilmelerini sağlar.

Örnekler

Aşağıdaki kod örneği SerializeDataInstance bir çalışma sayfasında bir Excel çalışma kitabını, önbelleğe alınmış bir dize değerini değiştirmek için yöntem.

Bu örnek aşağıdakileri gerektirir:

  • Belge düzeyinde özelleştirme içeren Excel için bir Sheet1 , sınıf ExcelWorkbook1 ad ve önbelleğe alınmış dizede Sheet1 adında bir sınıfı CachedString.

  • Bir konsol uygulaması projesi veya başka bir Office proje.

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

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll

    • Microsoft.VisualStudio.Tools.Applications.Runtime.dll

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

Private Sub ModifyCachedString(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 hostItem1 As CachedDataHostItem = _
                serverDocument1.CachedData.HostItems("ExcelWorkbook1.Sheet1")
            Dim dataItem1 As CachedDataItem = hostItem1.CachedData("CachedString")

            If dataItem1 IsNot Nothing AndAlso _
                Type.GetType(dataItem1.DataType).Equals(GetType(String)) Then

                dataItem1.SerializeDataInstance("This is the new cached string value.")
                serverDocument1.Save()
            End If
        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 ModifyCachedString(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);
            CachedDataHostItem hostItem1 = 
                serverDocument1.CachedData.HostItems["ExcelWorkbook1.Sheet1"];
            CachedDataItem dataItem1 = hostItem1.CachedData["CachedString"];

            if (dataItem1 != null &&
                Type.GetType(dataItem1.DataType) == typeof(string))
            {
                dataItem1.SerializeDataInstance("This is the new cached string value.");
                serverDocument1.Save();
            }
        }
        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

CachedDataItem Sınıf

Microsoft.VisualStudio.Tools.Applications Ad Alanı

Diğer Kaynaklar

Sunucu Üzerindeki Belgelerin İçerisindeki Verilere Erişim