예제 #1
0
        // Adds Users to the User List, not neccesarily opened to a Window, however.
        // this is called from the "Add User" Button
        public bool addUser(MainWindow sender, cStreamHandler StreamHandler)
        {
            cAntUsers newUser = new cAntUsers();

            newUser.firstName = sender.textBoxFirstName.Text;
            newUser.lastName  = sender.textBoxLastName.Text;

            try { newUser.ftp = Convert.ToInt32(sender.textBoxFTP.Text); }
            catch { newUser.ftp = 200; }

            if (sender.dataGridSpdCad.SelectedIndex >= 0)
            {
//                StreamHandler.spdStreams[sender.dataGridSpdCad.SelectedIndex].updateEvent += new UpdateHandler(newUser.updateSpdCadEvent);
                StreamHandler.spdStreams[sender.dataGridSpdCad.SelectedIndex].updateEvent += newUser.updateSpdCadEvent;
                newUser.activeSpeedStream = StreamHandler.spdStreams[sender.dataGridSpdCad.SelectedIndex];
            }
            if (sender.dataGridPower.SelectedIndex >= 0)
            {
                StreamHandler.pwrStreams[sender.dataGridPower.SelectedIndex].updateEvent += new UpdateHandler(newUser.updatePwrEvent);
                newUser.activePwrStream = StreamHandler.pwrStreams[sender.dataGridPower.SelectedIndex];
            }
            if (sender.dataGridHR.SelectedIndex >= 0)
            {
                StreamHandler.hbStreams[sender.dataGridHR.SelectedIndex].updateEvent += new UpdateHandler(newUser.updateHrEvent);
                newUser.activeHrStream = StreamHandler.hbStreams[sender.dataGridHR.SelectedIndex];
            }

            if ((sender.dataGridSpdCad.SelectedIndex >= 0) || (sender.dataGridPower.SelectedIndex >= 0) || (sender.dataGridHR.SelectedIndex >= 0))
            {
                l_Users.Add(newUser);
                return(true);
            }
            return(false);
        }
예제 #2
0
        public cUserHandler(cStreamHandler StreamHandler)
        {
            l_Users = new List <cAntUsers>();

            userPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CycleSoft\\Users\\");
            Directory.CreateDirectory(userPath);
            userFileArray = Directory.GetFiles(userPath, "*.xml");

            for (int i = 0; i < userFileArray.Length; i++)
            {
                cAntUsers newUser = new cAntUsers();

                Stream userContents = File.Open(userFileArray[i], FileMode.Open);
                reader = XmlReader.Create(userContents);

                while (!reader.EOF)
                {
                    /* Content Like:
                     *  <User fName = "Greg" lName = "GT" ftp = "245">
                     *          <power></power>
                     *          <wheelsize>2170</wheelsize>
                     *          <speedCad>64522</speedCad>
                     *          <heartrate>4030</heartrate>
                     *          <virtPower>16</virtPower>
                     *  </User>
                     */
                    reader.Read();
                    switch (reader.Name)
                    {
                    case "User":
                        if (reader.HasAttributes)
                        {
                            newUser.firstName = reader.GetAttribute("fName");
                            newUser.lastName  = reader.GetAttribute("lName");
                            newUser.ftp       = Convert.ToInt16(reader.GetAttribute("ftp"));
                        }
                        break;

                    case "power":
                        try
                        {
                            ushort sAddress     = (ushort)reader.ReadElementContentAsInt();
                            int    pwrStreamIdx = StreamHandler.addStream(sAddress, (byte)sensorTypes.Power);
                            if (pwrStreamIdx >= 0)
                            {
                                StreamHandler.pwrStreams[pwrStreamIdx].updateEvent += newUser.updatePwrEvent;
                                newUser.activePwrStream = StreamHandler.pwrStreams[pwrStreamIdx];
                            }
                        }
                        catch
                        { }
                        break;

                    case "speedCad":
                        try
                        {
                            ushort sAddress     = (ushort)reader.ReadElementContentAsInt();
                            int    spdStreamIdx = StreamHandler.addStream(sAddress, (byte)sensorTypes.SpeedCadence);
                            if (spdStreamIdx >= 0)
                            {
                                StreamHandler.spdStreams[spdStreamIdx].updateEvent += newUser.updateSpdCadEvent;
                                newUser.activeSpeedStream = StreamHandler.spdStreams[spdStreamIdx];
                            }
                        }
                        catch
                        { }
                        break;

                    case "heartrate":
                        try
                        {
                            ushort sAddress    = (ushort)reader.ReadElementContentAsInt();
                            int    hbStreamIdx = StreamHandler.addStream(sAddress, (byte)sensorTypes.HeartRate);
                            if (hbStreamIdx >= 0)
                            {
                                StreamHandler.hbStreams[hbStreamIdx].updateEvent += newUser.updateHrEvent;
                                newUser.activeHrStream = StreamHandler.hbStreams[hbStreamIdx];
                            }
                        }
                        catch
                        { }
                        break;

                    case "wheelsize":
                        try
                        {
                            newUser.wheelSize = reader.ReadElementContentAsInt();
                        }
                        catch
                        { newUser.wheelSize = 2100; }
                        break;

                    case "virtPower":
                        try
                        {
                            newUser.ptrSPwr = reader.ReadElementContentAsInt();
                        }
                        catch
                        { newUser.ptrSPwr = -1; }
                        break;

                    default:
                        break;
                    }
                }
                l_Users.Add(newUser);
                reader.Close();
                userContents.Close();
            }
        }
예제 #3
0
        public MainWindow()
        {
            //totally cheating, and making this hard coded for now
            b_hasVid     = false;
            b_vidPlaying = false;
            // video file is linked from xaml file, anyways.

            drawingEngine           = new cDrawingEngine();
            drawingEngine.chartZoom = 1.6;

            InitializeComponent();

            slider1.Value = 1.6;

            AntHandler     = new cAntHandler();
            StreamHandler  = new cStreamHandler();
            UserHandler    = new cUserHandler(StreamHandler);
            userWindows    = new List <UserWindow>();
            WorkoutHandler = new cWorkout();

            theServer = new cWebSocketServer();
            webServer = new MyHttpServer(8080);
            webListen = new ThreadStart(webServer.listen);
            webThread = new Thread(webListen);
            webThread.Start();


            clientCount = 0;

            // For IIS Express, this updates the applicationhost.config file, so that we know we run
            // from the same directory the program is running. What a PIA

/*
 *          string IISExpressFile = "C:\\Program Files\\IIS Express\\iisexpress.exe";
 *          if (!System.IO.File.Exists(IISExpressFile))
 *          {
 *              AutoClosingMessageBox.Show("To Use web features, install IISExpress from Microsoft", "Webservice Error", 3000);
 *          }
 *          else
 *          {
 *              string filename = "applicationhost.config";
 *              if (System.IO.File.Exists(filename))
 *              {
 *                  XmlDocument doc = new XmlDocument();
 *                  doc.Load(filename);
 *                  XmlAttribute path = (XmlAttribute)doc.SelectSingleNode("//configuration/system.applicationHost/sites/site/application/virtualDirectory/@physicalPath");
 *                  //path.InnerText = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location).Replace(@"\", @"\\") + "\\\\web";
 *                  path.InnerText = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\web";
 *                  doc.Save(filename);
 *              }
 *
 *              List<string> knownAddresses = new List<string>();
 *              IPHostEntry host;
 *              host = Dns.GetHostEntry(Dns.GetHostName());
 *              foreach (IPAddress ip in host.AddressList)
 *              {
 *                  if (ip.AddressFamily == AddressFamily.InterNetwork)
 *                  {
 *                      knownAddresses.Add("http://" + ip.ToString() + ":8080/");
 *                  }
 *              }
 *              knownAddresses.Add("http://localhost" + ":8080/");
 *
 *              StringBuilder Message = new StringBuilder("Now Accepting Web Connections at:\n");
 *              foreach (string url in knownAddresses) Message.AppendLine(url);
 *
 *
 *
 *              // Create Rules and Open Firewalls and Start IIS Express
 *              ProcessStartInfo p1 = new ProcessStartInfo("LaunchWeb.bat", System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location).Replace(@"\", @"/"));
 *              p1.UseShellExecute = true;
 *              p1.WindowStyle = ProcessWindowStyle.Minimized;
 *              p1.Verb = "runas";
 *              try
 *              {
 *                  webProcess = Process.Start(p1);
 *                  AutoClosingMessageBox.Show(Message.ToString(), "Web Server Running", 2500);
 *              }
 *              catch
 *              { MessageBox.Show("Failed to start WebProcess"); }
 *          }
 */

            for (int i = 0; i < WorkoutHandler.workOutList.Count; i++)
            {
                TimeSpan woTime = new TimeSpan(0, 0, (int)WorkoutHandler.workOutList[i].length);
                cbSelectWorkout.Items.Add(WorkoutHandler.workOutList[i].title + " " + woTime.ToString(@"h\:mm\:ss"));
                cbSelectEditWorkout.Items.Add(WorkoutHandler.workOutList[i].title);
            }

            WorkoutHandler.workoutEventStartStop += updateWorkoutEvent;
            theServer.remoteEventStartStop       += remotePlayPauseEvent;


            dataGridPower.DataContext  = StreamHandler.pwrStreams;
            dataGridHR.DataContext     = StreamHandler.hbStreams;
            dataGridSpdCad.DataContext = StreamHandler.spdStreams;

            dataGridUsers.DataContext = UserHandler.l_Users;

            System.Timers.Timer _timer = new System.Timers.Timer(500);
            _timer.Elapsed += new ElapsedEventHandler(_timerElapsed);
            _timer.Enabled  = true;


            lbl_ANTStatus.Content = "ANT Device not Found, installing or disabling Garmin Agent, then press \"Start\"";

            if (AntHandler.startUp())
            {
                AntHandler.channelMessageHandler += StreamHandler.handleAntData;
                button_Start.Background           = System.Windows.Media.Brushes.Salmon;
                button_Start.Content              = "ANT ENABLED";
                lbl_ANTStatus.Content             = "Press \"ANT ENABLED\" button to stop";
            }
            bStartWorkout.IsEnabled  = false;
            bStartWorkout2.IsEnabled = false;
            bEndWorkout.IsEnabled    = false;
            bEndWorkout2.IsEnabled   = false;
            bStartWorkout.Content    = "Select Workout";
            bStartWorkout2.Content   = "Select Workout";
            bEndWorkout.Content      = "End Workout";
            bEndWorkout2.Content     = "End Workout";
        }