示例#1
0
        /// <summary>
        /// Loads a experiment from the specified file.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <exception cref="TraceLab.Core.Exceptions.ExperimentLoadException">throws if experiment load fails</exception>
        /// <returns>
        /// Returns loaded m_experiment. If loading failed it returns null.
        /// </returns>
        public static Experiment Load(string fileName, TraceLab.Core.Components.ComponentsLibrary library)
        {
            Experiment experiment = null;

            try
            {
                using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(fileName))
                {
                    experiment = ExperimentSerializer.DeserializeExperiment(reader, library, fileName);
                }

                if (experiment != null)
                {
                    experiment.ResetModifiedFlag();
                }
            }
            catch (ArgumentException e)
            {
                throw new ExperimentLoadException("The experiment file could not be loaded. Filename cannot be empty. ", e);
            }
            catch (System.Security.SecurityException e)
            {
                throw new ExperimentLoadException("The experiment file could not be loaded.", e);
            }
            catch (System.IO.FileNotFoundException e)
            {
                throw new ExperimentLoadException("The experiment file has not been found.", e);
            }
            catch (System.IO.DirectoryNotFoundException e)
            {
                throw new ExperimentLoadException("The directory has not been found.", e);
            }
            catch (UriFormatException e)
            {
                throw new ExperimentLoadException("The experiment is corrupted and could not be loaded.", e);
            }
            catch (System.Xml.XmlException e)
            {
                throw new ExperimentLoadException("The experiment is corrupted and could not be loaded.", e);
            }

            return(experiment);
        }