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;
}
備註
透過跨所有持續性參與者實作 MapValues 方法所提供的每個值,包括在第一個階段收集到的所有值 (CollectValues stage),都必須有唯一的 XName。