Ejemplo n.º 1
0
        /// <summary>
        /// Deserializes the experiment.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="experimentFilename">The experiment filename - needed so that experiment can set all relative config paths in relation to experiment location.</param>
        /// <returns></returns>
        internal static Experiment DeserializeExperiment(XmlReader reader, TraceLab.Core.Components.IComponentsLibrary library, string experimentFilename)
        {
            Experiment loadedFlow = null;

            if (reader != null)
            {
                IXPathNavigable doc = new XPathDocument(reader);

                var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(PackageSystem.PackageReference), Type.EmptyTypes);

                var references = new ObservableCollection <IPackageReference>();
                // Get the references:
                var nav           = doc.CreateNavigator();
                var referenceIter = nav.Select("/graph/References/PackageReference");
                if (referenceIter != null)
                {
                    while (referenceIter.MoveNext())
                    {
                        var reference = (IPackageReference)serializer.Deserialize(referenceIter.Current.ReadSubtree());
                        references.Add(reference);
                    }
                }

                var graphFactory = new ExperimentFactoryReader(library, references, System.IO.Path.GetDirectoryName(experimentFilename));

                loadedFlow = QuickGraph.Serialization.SerializationExtensions.DeserializeFromXml <ExperimentNode, ExperimentNodeConnection, Experiment>(doc,
                                                                                                                                                        "/graph", "/graph/node", "/graph/edge",
                                                                                                                                                        graphFactory.GraphFactory,
                                                                                                                                                        graphFactory.NodeFactory,
                                                                                                                                                        graphFactory.EdgeFactory
                                                                                                                                                        );

                loadedFlow.References = references;

                //Update the loaded graph and sets its start and end node
                loadedFlow.ReloadStartAndEndNode();

                loadedFlow.ExperimentInfo.FilePath = experimentFilename;
            }

            return(loadedFlow);
        }
        /// <summary>
        /// Deserializes the experiment.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="experimentFilename">The experiment filename - needed so that experiment can set all relative config paths in relation to experiment location.</param>
        /// <returns></returns>
        internal static Experiment DeserializeExperiment(XmlReader reader, TraceLab.Core.Components.IComponentsLibrary library, string experimentFilename)
        {
            Experiment loadedFlow = null;

            if (reader != null)
            {
                IXPathNavigable doc = new XPathDocument(reader);

                var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(PackageSystem.PackageReference), Type.EmptyTypes);

                var references = new ObservableCollection<IPackageReference>();
                // Get the references:
                var nav = doc.CreateNavigator();
                var referenceIter = nav.Select("/graph/References/PackageReference");
                if (referenceIter != null)
                {
                    while (referenceIter.MoveNext())
                    {
                        var reference= (IPackageReference)serializer.Deserialize(referenceIter.Current.ReadSubtree());
                        references.Add(reference);
                    }
                }

                var graphFactory = new ExperimentFactoryReader(library, references, System.IO.Path.GetDirectoryName(experimentFilename));

                loadedFlow = QuickGraph.Serialization.SerializationExtensions.DeserializeFromXml<ExperimentNode, ExperimentNodeConnection, Experiment>(doc,
                    "/graph", "/graph/node", "/graph/edge",
                    graphFactory.GraphFactory,
                    graphFactory.NodeFactory,
                    graphFactory.EdgeFactory
                );

                loadedFlow.References = references;

                //Update the loaded graph and sets its start and end node
                loadedFlow.ReloadStartAndEndNode();

                loadedFlow.ExperimentInfo.FilePath = experimentFilename;
            }
            
            return loadedFlow;
        }