예제 #1
0
        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();
            }
        }
예제 #2
0
        /// <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;
        }
예제 #3
0
 /// <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;
     }
 }
예제 #4
0
        /// <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);
            }
        }
예제 #5
0
        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;
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
        //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");
                    }));
            }
        }
예제 #8
0
 /// <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;
 }
예제 #9
0
 /// <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;
     }
 }
예제 #10
0
파일: Robot.cs 프로젝트: SamLin95/cs3630
 /// <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);
 }
예제 #11
0
파일: Robot.cs 프로젝트: SamLin95/cs3630
 /// <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");
 }
예제 #12
0
파일: Robot.cs 프로젝트: SamLin95/cs3630
        /// <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");
                }
            }
        }