private void fillInConfig(MyroConfigFiles myroConfig) { if (myroConfig == null) { IconBox.Source = null; IconRectangle.Visibility = Visibility.Visible; FriendlyNameBox.Text = ""; HttpPortBox.Text = Params.DefaultHttpPort.ToString(); DsspPortBox.Text = Params.DefaultDsspPort.ToString(); } else { if (myroConfig.IconFilePath != null) { setIcon(new BitmapImage(new Uri("file://" + myroConfig.IconFilePath))); } else { setIcon(null); } ManifestBox.Text = myroConfig.ManifestFilePath; FriendlyNameBox.Text = myroConfig.MyroConfiguration.FriendlyName; HttpPortBox.Text = myroConfig.MyroConfiguration.HttpPort.ToString(); DsspPortBox.Text = myroConfig.MyroConfiguration.DsspPort.ToString(); } }
/// <summary> /// Copy the image to the proper location and name, i.e. make it the robot's icon. /// </summary> /// <param name="config"></param> /// <param name="imagePath"></param> public void WriteImage(MyroConfigFiles config, string imagePath) { string iconPath = Path.Combine(configPath, (config.BaseName + IconSuffix + Path.GetExtension(imagePath))); File.Copy(imagePath, iconPath); config.IconFilePath = iconPath; }
/// <summary> /// Store the MyroRobotConfiguration member of the MyroConfigFiles parameter. /// The GUI calls this when the user modifies a robot configuration. /// </summary> /// <param name="config"></param> public void WriteConfig(MyroConfigFiles config) { using (var writer = new StreamWriter(config.ConfigFilePath)) { new XmlSerializer(typeof(MyroRobotConfiguration)) .Serialize(writer, config.MyroConfiguration); config.MyroConfigExisted = true; } }
/// <summary> /// Look for a robot configuration matching the base name, ignoring case. Throws /// BaseNameNotFoundException. /// </summary> /// <param name="baseName"></param> /// <returns></returns> public MyroConfigFiles FindFromBaseName(string baseName) { MyroConfigFiles config = FindConfigFiles().Find( c => c.BaseName.Equals(baseName, StringComparison.InvariantCultureIgnoreCase)); if (config == null) { throw new BaseNameNotFoundException(); } else { return(config); } }
public static UIElement MakeListItem(MyroConfigFiles myroConfig) { Grid s1 = new Grid() { HorizontalAlignment = HorizontalAlignment.Stretch }; s1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); s1.ColumnDefinitions.Add(new ColumnDefinition()); StackPanel s2 = new StackPanel() { VerticalAlignment = VerticalAlignment.Center, Orientation = Orientation.Vertical }; s2.SetValue(Grid.ColumnProperty, 1); Label l1 = new Label() { Content = myroConfig.BaseName, Padding = new Thickness(0, 0, 5, 0) }; Label l2 = new Label() { Content = myroConfig.MyroConfigExisted ? myroConfig.MyroConfiguration.FriendlyName : "No Myro configuration", Padding = new Thickness(0, 0, 5, 0) }; Image i = new Image() { VerticalAlignment = VerticalAlignment.Center, Width = 64, Height = 64, Margin = new Thickness(2, 2, 3, 2), Stretch = Stretch.Uniform }; i.SetValue(Grid.ColumnProperty, 0); if (myroConfig.IconFilePath != null) i.Source = new BitmapImage(new Uri("file://" + myroConfig.IconFilePath)); s2.Children.Add(l1); s2.Children.Add(l2); s1.Children.Add(i); s1.Children.Add(s2); return s1; }
private void OnSelectConfig(object sender, SelectionChangedEventArgs e) { try { bool cancelled; if (currentModified && ConfigList.SelectedIndex != configFiles.IndexOf(currentConfigFiles)) { if (promptApplyChanges() == true) cancelled = false; else { ConfigList.SelectedIndex = configFiles.IndexOf(currentConfigFiles); cancelled = true; } } else cancelled = false; if (!currentModified && !cancelled) if (ConfigList.SelectedIndex >= 0 && ConfigList.SelectedIndex < configFiles.Count) { currentConfigFiles = configFiles[ConfigList.SelectedIndex]; fillInConfig(currentConfigFiles); } else { currentConfigFiles = null; fillInConfig(null); } } catch (Exception err) { GUIUtilities.ReportUnexpectedException(err); this.Close(); } }
//private void disconnect() //{ // Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, // new ThreadStart(delegate() // { // manifestBox.Text = "Disconnecting from robot..."; // })); // controlPanel.SetRobot(null); // if (robot != null) // robot.Shutdown(); // robot = null; // Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, // new ThreadStart(delegate() // { // controlPanel.IsEnabled = false; // try // { // ((Image)connectButton.Content).Source = new BitmapImage(new Uri("disconnect.png", UriKind.Relative)); // manifestBox.Text = (curManifest == null ? "Disconnected" : curManifest + " (disconnected)"); // } // catch (Exception e) { Console.WriteLine(e); } // })); //} private void connect(MyroConfigFiles config) { try { if (connected == false) { //Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, // new ThreadStart(delegate() // { //manifestBox.Text = "Connecting to robot..."; commandWindow.ExecuteCommandInteractive("from myro import *"); commandWindow.LogText("> init('" + config.BaseName + "')\n", Colors.MediumBlue); //})); Robot.Init(config); } } catch (Exception e) { Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new ThreadStart(delegate() { GUIUtilities.ReportUnexpectedException(e); MessageBox.Show(this, Strings.TrySpecifyCOMPort, "Myro"); })); } }
/// <summary> /// This version of Init is generally not called by the end-user. It /// uses a configuation that is already found by a MyroConfigFinder class. /// </summary> /// <param name="config"></param> public static void Init(MyroConfigFiles config) { Init(config, null); }
/// <summary> /// This is an internal helper method that starts the DSS environment, /// using the manifest file specified in the MyroConfigFiles argument. /// </summary> /// <param name="config"></param> private static void startDSS(MyroConfigFiles config) { string manifestFile = Path.Combine(Path.Combine(Params.ConfigPath, config.BaseName + ".manifest"), config.BaseName + ".manifest.xml"); Robot.httpPort = config.MyroConfiguration.HttpPort; Robot.dsspPort = config.MyroConfiguration.DsspPort; FileAttributes att = File.GetAttributes(manifestFile); if ((att & (FileAttributes.Device | FileAttributes.Directory | FileAttributes.Offline)) != 0) throw new IOException("Manifest file is not a normal file"); Console.Write("Starting DSS environment..."); DssEnvironment.Initialize(httpPort, dsspPort, "file://" + manifestFile); Console.WriteLine("Done"); }
/// <summary> /// This is another init method that is generally not called by the end-user. /// The purpose of the comPort argument is the same as with the string version, /// init(string baseName, string comPort). /// </summary> /// <param name="config"></param> /// <param name="comPort"></param> public static void Init(MyroConfigFiles config, string comPort) { bool isScribbler = config.BaseName.ToLower().Equals("scribbler"); // If this is a Scribbler, wait for it to start if (isScribbler) { CurrentConfig = config; LastStateChange = RobotStateChange.CONNECTING; try { // Start DSS if not started if (bank == null) { startDSS(config); createAdapters(); } connectWaitForScribbler(comPort); } catch (Exception) { LastStateChange = RobotStateChange.CONNECTING_FAILED; CurrentConfig = null; throw; } LastStateChange = RobotStateChange.CONNECTING_SUCCEEDED; } else { if (bank == null) { CurrentConfig = config; LastStateChange = RobotStateChange.CONNECTING; try { startDSS(config); createAdapters(); } catch (Exception) { LastStateChange = RobotStateChange.CONNECTING_FAILED; CurrentConfig = null; throw; } LastStateChange = RobotStateChange.CONNECTING_SUCCEEDED; } else { throw new MyroInitException("Myro is already initialized"); } } }