PersistenceParticipant.MapValues 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当宿主完成在第一个阶段中收集值的工作后,将调用此方法。 宿主会将由其在第一个阶段(CollectValues 阶段)中从所有持久性参与者中收集的值组成的两个只读字典转发给此方法用于映射。 主机会将此方法的返回的字典中的值添加到只写值的集合。
protected:
virtual System::Collections::Generic::IDictionary<System::Xml::Linq::XName ^, System::Object ^> ^ MapValues(System::Collections::Generic::IDictionary<System::Xml::Linq::XName ^, System::Object ^> ^ readWriteValues, System::Collections::Generic::IDictionary<System::Xml::Linq::XName ^, System::Object ^> ^ writeOnlyValues);
protected virtual System.Collections.Generic.IDictionary<System.Xml.Linq.XName,object> MapValues (System.Collections.Generic.IDictionary<System.Xml.Linq.XName,object> readWriteValues, System.Collections.Generic.IDictionary<System.Xml.Linq.XName,object> writeOnlyValues);
abstract member MapValues : System.Collections.Generic.IDictionary<System.Xml.Linq.XName, obj> * System.Collections.Generic.IDictionary<System.Xml.Linq.XName, obj> -> System.Collections.Generic.IDictionary<System.Xml.Linq.XName, obj>
override this.MapValues : System.Collections.Generic.IDictionary<System.Xml.Linq.XName, obj> * System.Collections.Generic.IDictionary<System.Xml.Linq.XName, obj> -> System.Collections.Generic.IDictionary<System.Xml.Linq.XName, obj>
Protected Overridable Function MapValues (readWriteValues As IDictionary(Of XName, Object), writeOnlyValues As IDictionary(Of XName, Object)) As IDictionary(Of XName, Object)
参数
- readWriteValues
- IDictionary<XName,Object>
要保持的读/写值。
- writeOnlyValues
- IDictionary<XName,Object>
要保持的只写值。
返回
包含要保留的附加只写值的字典。
示例
下面的代码示例演示如何在一个从 PersistenceParticipant 派生的类中使用 MapValues。 此示例来自 公司购买流程 示例。
class XmlPersistenceParticipant : PersistenceParticipant
{
const string propertiesNamespace = "urn:schemas-microsoft-com:System.Activities/4.0/properties";
private Guid Id;
public XmlPersistenceParticipant(Guid id)
{
Id = id;
}
//Add any additional necessary data to persist here
protected override void CollectValues(out IDictionary<XName, object> readWriteValues, out IDictionary<XName, object> writeOnlyValues)
{
base.CollectValues(out readWriteValues, out writeOnlyValues);
}
//Implementations of MapValues are given all the values collected from all participants’ implementations of CollectValues
protected override IDictionary<XName, object> MapValues(IDictionary<XName, object> readWriteValues, IDictionary<XName, object> writeOnlyValues)
{
XName statusXname = XName.Get("Status", propertiesNamespace);
IDictionary<XName, object> mappedValues = base.MapValues(readWriteValues, writeOnlyValues);
RequestForProposal requestForProposal = null;
string status = string.Empty;
object value = null;
//retrieve the status of the workflow
if (writeOnlyValues.TryGetValue(statusXname, out value))
{
status = (string)value;
}
//retrieve the RequestForProposal object
foreach (KeyValuePair<System.Xml.Linq.XName, object> item in writeOnlyValues)
{
if (item.Value is LocationInfo)
{
LocationInfo li = (LocationInfo)item.Value;
if (li.Value is RequestForProposal)
{
requestForProposal = (RequestForProposal)li.Value;
}
}
}
IOHelper.EnsureAllRfpFileExists();
// load the document
XElement doc = XElement.Load(IOHelper.GetAllRfpsFileName());
IEnumerable<XElement> current =
from r in doc.Elements("requestForProposal")
where r.Attribute("id").Value.Equals(Id.ToString())
select r;
if (status == "Closed")
{
// erase nodes for the current rfp
foreach (XElement xe in current)
{
xe.Attribute("status").Value = "finished";
}
}
else
{
// erase nodes for the current rfp
foreach (XElement xe in current)
{
xe.Remove();
}
// get the Xml version of the Rfp, add it to the document and save it
if (requestForProposal != null)
{
XElement e = SerializeRfp(requestForProposal, Id);
doc.Add(e);
}
}
doc.Save(IOHelper.GetAllRfpsFileName());
return mappedValues;
}
注解
由所有持久性参与者(包括在第一个阶段(即 CollectValues 阶段)中收集的所有值)之间的所有 MapValues 方法的实现提供的每个值均必须具有唯一的 XName。