public Benchmark(ExperimentInfo experimentInfo, ComponentTemplateMetadata componentTemplate) { if (experimentInfo == null) { throw new ArgumentNullException("benchmarkInfo"); } if (String.IsNullOrEmpty(experimentInfo.FilePath)) { throw new ArgumentException("Benchmark file path cannot be null or empty."); } if (componentTemplate == null) { throw new ArgumentNullException("componentTemplate"); } BenchmarkInfo = new BenchmarkInfo(experimentInfo); ComponentTemplate = componentTemplate; IsOnlineContest = false; }
private static ComponentTemplateMetadata FindTemplateComponentMetadata(XPathNavigator nav) { ComponentTemplateMetadata template = null; //search for all references for template components metadata string templateType = typeof(ComponentTemplateMetadata).ToString(); XPathExpression expression = nav.Compile("//Metadata[starts-with(@type, '" + templateType + "')]"); XPathNavigator templateXmlNode = nav.SelectSingleNode(expression); if (templateXmlNode != null) { string label = templateXmlNode.GetAttribute("Label", String.Empty); IOSpec ioSpec = new IOSpec(); XPathNavigator ioSpecNav = templateXmlNode.SelectSingleNode("IOSpec"); ioSpec.ReadXml(ioSpecNav.ReadSubtree()); template = new ComponentTemplateMetadata(ioSpec, label); } return(template); }
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); }
internal void OnContestPackageDownloadCompleted(object sender, CallCompletedEventArgs <ContestPackageResponse> responseArgs) { BenchmarkDownloadCallback callback = sender as BenchmarkDownloadCallback; var benchmark = callback.Benchmark; if (responseArgs.Response.Status == ResponseStatus.STATUS_SUCCESS) { //do error handling of file writing and deserialization try { //save the file to benchmark directory into its filepath File.WriteAllBytes(benchmark.BenchmarkInfo.FilePath, Convert.FromBase64String(responseArgs.Response.ContestPackage)); //load benchmark info to update its experiment results unitname string resultsUnitname = BenchmarkLoader.ReadExperimentResultsUnitname(benchmark.BenchmarkInfo.FilePath); if (resultsUnitname != null) { benchmark.BenchmarkInfo.ExperimentResultsUnitname = resultsUnitname; //read the file to determine ComponentTemplate ComponentTemplateMetadata template = BenchmarkLoader.FindTemplateComponentMetadata(benchmark.BenchmarkInfo.FilePath); //set the benchmark if (template != null) { benchmark.ComponentTemplate = template; } else { callback.Progress.Reset(); callback.Progress.SetError(true); callback.Progress.CurrentStatus = "Error!"; benchmark.ErrorMessage = Messages.ComponentTemplateNotFoundInContestError; } } else { callback.Progress.Reset(); callback.Progress.SetError(true); callback.Progress.CurrentStatus = "Error!"; benchmark.ErrorMessage = Messages.ExperimentResultsUnitnameNotDefined; } } catch (System.Xml.XmlException) { callback.Progress.Reset(); callback.Progress.SetError(true); callback.Progress.CurrentStatus = "Error!"; benchmark.ErrorMessage = Messages.ContestFileDeserializationError; } catch (UnauthorizedAccessException ex) { callback.Progress.Reset(); callback.Progress.SetError(true); callback.Progress.CurrentStatus = "Error!"; benchmark.ErrorMessage = String.Format(Messages.ContestFileSaveError, ex.Message); } catch (IOException ex) { callback.Progress.Reset(); callback.Progress.SetError(true); callback.Progress.CurrentStatus = "Error!"; benchmark.ErrorMessage = String.Format(Messages.ContestFileSaveError, ex.Message); } catch (System.Security.SecurityException ex) { callback.Progress.Reset(); callback.Progress.SetError(true); callback.Progress.CurrentStatus = "Error!"; benchmark.ErrorMessage = String.Format(Messages.ContestFileSaveError, ex.Message); } catch (System.Exception ex) { callback.Progress.Reset(); callback.Progress.SetError(true); callback.Progress.CurrentStatus = "Error!"; benchmark.ErrorMessage = String.Format(Messages.ContestDownloadError, ex.Message); } } else //response status different than SUCCESS { //propagate error from the response args callback.Progress.Reset(); callback.Progress.SetError(true); callback.Progress.CurrentStatus = "Error!"; benchmark.ErrorMessage = responseArgs.Response.ErrorMessage; } }