public void updateWorkoutEvent(object sender, workoutEventArgs e)
        {
            workoutStreamToClose = (cWorkout)sender;
            workoutStatus        = e;

            if (workoutStatus.running)
            {
                bWorkoutRunning = true;
            }
        }
Exemple #2
0
        private int[] segAvgPower;  //This should be a queue, probably.

        public void updateWorkoutEvent(object sender, workoutEventArgs e)
        {
            if (e.running && !e.paused && _TCXDataTimer.Enabled == false)
            {
                segAvgPower = new int[200];
                string title = "none";
                try
                {
                    cWorkout workout = (cWorkout)sender;
                    title = workout.activeWorkout.title;
                }
                catch
                { title = "idk"; }
                if (TCXFileHandler == null)
                {
                    TCXFileHandler   = new cTCXFileGenerator(firstName, lastName, title);
                    TCXDistanceCount = 0;
                }
                _TCXDataTimer.Enabled = true;
            }
            else if (e.paused && _TCXDataTimer.Enabled)
            {
                _TCXDataTimer.Enabled = false;
            }
            else if (e.finished && (_TCXDataTimer.Enabled || e.paused))
            {
                _TCXDataTimer.Enabled = false;
                //writeTCXData(e.workoutCurrentMS/1000);
                TCXFileHandler.closeTCXData();
                TCXFileHandler = null;
            }

            if (e.running && !e.paused)
            {
                if (lastSegment != e.currentSegment)
                {
                    if (lastSegment >= 0 && qPWRQue.Count > 0)
                    {
                        segAvgPower[lastSegment] = (int)qPWRQue.Average(s => s.instPwr);
                    }
                    qPWRQue.Clear();
                }
                lastSegment = e.currentSegment;
            }
        }
        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";
        }