[英]How can I read a workflow instance property promoted as binary?
就我而言,我提升了UInt64值。 UInt64无法升级为变体,因此我使用了promoteAsBinary。
这是我必须阅读的代码:
String sql =
@"Select Value33, InstanceId from
[System.Activities.DurableInstancing].[InstancePromotedProperties]
where PromotionName = 'MyUInt64'";
try
{
string connectionString = ConfigurationManager.ConnectionStrings
["InstanceStore"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
using (SqlDataReader reader = cmd.ExecuteReader())
{
Console.WriteLine("Promoted values:");
while (reader.Read())
{
byte[] result = (byte[])reader["Value33"];
// How do I turn this byte[] into an UInt64??
}
}
}
}
catch (Exception exception)
{
Console.WriteLine("Query Unhandled exception: {0}",
exception.Message);
}
我尝试将byte []传递给MemoryStream,然后将BinaryReader与Default编码,ASCI和UTF-8一起使用,但是它不起作用。 我得到一个垃圾值。 我将实例设置为none。
storeBehavior.InstanceEncodingOption = InstanceEncodingOption.None;
我遇到了您遇到的相同问题。
我做了以下方法。 您可以使用gzip保存工作流程数据。 如果使用此选项,则将其设置为true。 通用类型是数据要进行消毒的类型。
顺便说一句:抱歉使用嵌套的使用结构。 您应该避免这种类型的构造,这是处置的不良做法。 请参阅: http : //msdn.microsoft.com/en-us/library/ms182334.aspx
public T DeserializeBinaryData<T>(byte[] serializedBinaryData)
{
using (var memoryStream = new MemoryStream())
{
memoryStream.Write(serializedBinaryData, 0, serializedBinaryData.Length);
memoryStream.Position = 0;
if (compressed)
{
using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
{
using (
var dictionaryReader = XmlDictionaryReader.CreateBinaryReader(gZipStream,
XmlDictionaryReaderQuotas
.Max))
{
var netDataContractSerializer = new NetDataContractSerializer();
var deserializedData = netDataContractSerializer.ReadObject(dictionaryReader);
return (T)deserializedData;
}
}
}
using (
var dictionaryReader = XmlDictionaryReader.CreateBinaryReader(memoryStream,
XmlDictionaryReaderQuotas
.Max))
{
var deserializedData = new NetDataContractSerializer().ReadObject(dictionaryReader);
return (T)deserializedData;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.