Esempio n. 1
0
            private NodeAndLinks ReadEditable(XElement node, IDataSource datasource, INodeFactory <ConversationNode <TNodeUI, TTransitionUI>, TTransitionUI, TUIRawData> nodeFactory)
            {
                NodeID id   = NodeID.Parse(node.Attribute("Id").Value);
                Guid   guid = Guid.Parse(node.Attribute("Guid").Value);

                Func <NodeID, ExternalFunction> nodeGenerator = datasource.GetNode(guid);
                IEditable editable = nodeGenerator(id);

                List <Tuple <Parameter, Func <bool> > > failedParameters = new List <Tuple <Parameter, Func <bool> > >();

                foreach (Parameter p in editable.Parameters)
                {
                    var         pp    = p;
                    Func <bool> retry = () =>
                    {
                        try
                        {
                            return(pp.TryDeserialiseValue(node.Elements("Parameter").Where(n => Guid.Parse(n.Attribute("guid").Value) == pp.Guid).Select(n => n.Attribute("value").Value).Single()));
                        }
                        catch
                        {
                            return(false);
                        }
                    };
                    if (!retry())
                    {
                        failedParameters.Add(Tuple.Create(pp, retry));
                    }
                }
                ConversationNode <TNodeUI, TTransitionUI> a = !failedParameters.Any() ? nodeFactory.MakeNode(editable, m_nodeUISerializer.Read(node))
                                                            : nodeFactory.MakeCorruptedNode(editable, m_nodeUISerializer.Read(node), failedParameters);

                return(MakeNodeAndLinks(a, node));
            }