private async Task <MissionSpec> loadMission(string path) { using (StreamReader reader = new StreamReader(path)) { try { string xml = await reader.ReadToEndAsync(); xml = xml.Replace("__SEED__", _rand.Next().ToString()); MissionSpec mission = new MissionSpec(xml, true); if (!mission.isVideoRequested(0)) { mission.requestVideo(Settings.Default.VideoWidth, Settings.Default.VideoHeight); } mission.removeAllCommandHandlers(); mission.allowAllContinuousMovementCommands(); mission.allowAllDiscreteMovementCommands(); XDocument xdoc = XDocument.Parse(xml); XNamespace malmo = "http://ProjectMalmo.microsoft.com"; var timeUpNode = xdoc.Descendants(malmo + "ServerQuitFromTimeUp").FirstOrDefault(); if (timeUpNode != null) { _missionDuration = TimeSpan.FromMilliseconds(double.Parse(timeUpNode.Attribute("timeLimitMs").Value)); } else { _missionDuration = TimeSpan.Zero; } if (_recordWindow != null && _recordWindow.IsVisible) { _recordWindow.MissionPath = path; } return(mission); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Parsing Mission", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } } }
private async Task<MissionSpec> loadMission(string path) { using (StreamReader reader = new StreamReader(path)) { try { string xml = await reader.ReadToEndAsync(); xml = xml.Replace("__SEED__", _rand.Next().ToString()); MissionSpec mission = new MissionSpec(xml, true); if (!mission.isVideoRequested(0)) { mission.requestVideo(Settings.Default.VideoWidth, Settings.Default.VideoHeight); } mission.removeAllCommandHandlers(); mission.allowAllContinuousMovementCommands(); mission.allowAllDiscreteMovementCommands(); XDocument xdoc = XDocument.Parse(xml); XNamespace malmo = "http://ProjectMalmo.microsoft.com"; var timeUpNode = xdoc.Descendants(malmo + "ServerQuitFromTimeUp").FirstOrDefault(); if(timeUpNode != null) { _missionDuration = TimeSpan.FromMilliseconds(double.Parse(timeUpNode.Attribute("timeLimitMs").Value)); } else { _missionDuration = TimeSpan.Zero; } if (_recordWindow != null && _recordWindow.IsVisible) { _recordWindow.MissionPath = path; } return mission; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Parsing Mission", MessageBoxButton.OK, MessageBoxImage.Error); return null; } } }