当前位置: 首页>>代码示例>>C#>>正文


C# PersistenceParticipant.MapValues方法代码示例

本文整理汇总了C#中System.Activities.Persistence.PersistenceParticipant.MapValues方法的典型用法代码示例。如果您正苦于以下问题:C# PersistenceParticipant.MapValues方法的具体用法?C# PersistenceParticipant.MapValues怎么用?C# PersistenceParticipant.MapValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Activities.Persistence.PersistenceParticipant的用法示例。


在下文中一共展示了PersistenceParticipant.MapValues方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: XmlPersistenceParticipant

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;
    }
开发者ID:.NET开发者,项目名称:System.Activities.Persistence,代码行数:84,代码来源:PersistenceParticipant.MapValues


注:本文中的System.Activities.Persistence.PersistenceParticipant.MapValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。