/// <summary>
        /// Prepares the benchmark experiment.
        /// 1. First it deserialize the benchmark experiment
        /// 2. Secondly replaces template component node with provided composite component node
        /// </summary>
        /// <param name="selectedBenchmarkFile">The selected benchmark file.</param>
        /// <exception cref="TraceLab.Core.Exceptions.ExperimentLoadException">throws if benchmark experiment load fails</exception>
        /// <param name="experimentToBeBenchmarked">The experiment to be benchmarked.</param>
        /// <returns></returns>
        public void PrepareBenchmarkExperiment(Benchmark selectedBenchmark)
        {
            if (ExperimentToBeBenchmarked == null)
                throw new InvalidOperationException("The wizard has not been started. Benchmark cannot be run with null experiment.");

            selectedBenchmark.PrepareBenchmarkExperiment(ExperimentToBeBenchmarked, m_componentsLibrary);
        }
        /// <summary>
        /// Called when [retrieve list of benchmarks call has been completed].
        /// It adds online contests to the list of Benchmarks.
        /// The contests that has been already downloaded and thus were loaded from local directery
        /// get their link to website updated and are marked as the online contests (so that user can compete in them)
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="responseArgs">The <see cref="TraceLab.Core.WebserviceAccess.CallCompletedEventArgs&lt;TraceLab.Core.WebserviceAccess.ListOfContestsResponse&gt;"/> instance containing the event data.</param>
        private void OnRetrieveListOfBenchmarksCallCompleted(object sender, CallCompletedEventArgs<ListOfContestsResponse> responseArgs)
        {
            //local Benchmarks has been loaded already
            var localBenchmarks = BenchmarkLoader.LoadBenchmarksInfo(BenchmarksDirectory); ;
            var newOnlineBenchmarks = new List<Benchmark>();

            if (responseArgs.Response.Status == ResponseStatus.STATUS_SUCCESS)
            {
                List<Contest> contests = responseArgs.Response.ListOfContests;

                foreach (Contest contest in contests)
                {
                    //assuming the joomla com_jtracelab components is used, determine the link to contest website
                    string joomlaSiteRootUrl = m_settings.WebserviceAddress.Substring(0, m_settings.WebserviceAddress.IndexOf("administrator"));
                    string linkToContest = JoomlaLinks.GetContestWebpageLink(joomlaSiteRootUrl, contest.ContestIndex);
                    
                    //check if there is already local benchmark with the same guid
                    var benchmark = localBenchmarks.Find((b) => { return b.BenchmarkInfo.Id.Equals(contest.ContestGUID); });
                    if (benchmark == null)
                    {
                        //if benchmark has not been found create new benchmark (note, its template component is empty at this moment)
                        var newOnlineBenchmark = new Benchmark(contest, linkToContest, BenchmarksDirectory);
                        newOnlineBenchmarks.Add(newOnlineBenchmark);
                    }
                    else
                    {
                        //if found, only update the link to website
                        benchmark.BenchmarkInfo.WebPageLink = new Uri(linkToContest);
                        //mark it as online contest so that wizard now if it should give option to user to publish results
                        benchmark.IsOnlineContest = true;
                    }
                }

                //all new benchmarks add to total list of benchmarks
                localBenchmarks.AddRange(newOnlineBenchmarks);
            }
            else
            {
                //log the error, and continue
                string error = String.Format(Messages.RetrievingListOfContestsFailedWarning, responseArgs.Response.ErrorMessage);
                NLog.LogManager.GetCurrentClassLogger().Warn(error);
                ErrorMessage = error;
            }

            Benchmarks = localBenchmarks; 
        }
 public void DownloadContestPackage(IProgress progress, Benchmark benchmark)
 {
     var contestPackageResponseCallback = new BenchmarkDownloadCallback(benchmark);
     contestPackageResponseCallback.CallCompleted += OnContestPackageDownloadCompleted;
     contestPackageResponseCallback.Progress = progress;
     WebService.DownloadContestPackage(benchmark.BenchmarkInfo.Id, contestPackageResponseCallback);
 }
        private static Benchmark ReadBenchmark(string benchmarkFile)
        {
            XmlReader reader = XmlReader.Create(benchmarkFile);
            XPathDocument doc = new XPathDocument(reader);
            XPathNavigator nav = doc.CreateNavigator();

            //new version
            XPathNavigator benchmarkInfoXmlNode = nav.SelectSingleNode("/graph/BenchmarkInfo");

            BenchmarkInfo benchmarkInfo = null;
            ComponentTemplateMetadata template = null;
            
            //read the benchmark info 
            if (benchmarkInfoXmlNode != null)
            {
                XmlSerializer m_experimentInfoSerializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(BenchmarkInfo), null);
                benchmarkInfo = (BenchmarkInfo)m_experimentInfoSerializer.Deserialize(benchmarkInfoXmlNode.ReadSubtree());
            }

            //find the template
            if (benchmarkInfo != null)
            {
                template = FindTemplateComponentMetadata(nav);
            }

            Benchmark benchmark = null;
            if (benchmarkInfo != null && template != null)
            {
                //update benchmark filepath
                benchmarkInfo.FilePath = benchmarkFile;
                benchmark = new Benchmark(benchmarkInfo, template);
            }

            return benchmark;
        }