Ejemplo n.º 1
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            // Create database
            using (WorkoutContext db = new WorkoutContext(WorkoutContext.DBConnectionString))
            {
                if (db.DatabaseExists())
                {
                    db.DeleteDatabase();
                }

                //Create the database
                db.CreateDatabase();
            }
        }
Ejemplo n.º 2
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            XDocument xdoc = XDocument.Load("days.xml");
            XElement root = xdoc.Root;

            //Database
            this.workoutDB = new WorkoutContext(WorkoutContext.DBConnectionString);

            // Gather all exercises only
            // For each day
            foreach (XElement element in root.Nodes())
            {
                int num = Convert.ToInt32((element.Descendants("num").Single() as XElement).Value);

                Day day = new Day();
                day.Workout = (element.Descendants("workout").Single() as XElement).Value.ToString();
                day.Num = num;
                day.VideoKey = ((element.Descendants("video").Single() as XElement).Descendants("video_key").Single() as XElement).Value;
                day.ThumbnailUrl = ((element.Descendants("video").Single() as XElement).Descendants("thumbnail_url").Single() as XElement).Value;

                this.workoutDB.Days.InsertOnSubmit(day);
                this.workoutDB.SubmitChanges();

                if (element.Elements().Count() == 4)
                {
                    XElement exerciseRoot = element.Descendants("exercises").Single() as XElement;

                    // For each exercise
                    foreach (XElement exec in exerciseRoot.Nodes())
                    {
                        Exercise exercise = new Exercise();
                        exercise.Name = (exec.Descendants("name").Single() as XElement).Value.ToString();

                        try
                        {
                            this.workoutDB.Exercises.First(ex => ex.Name == exercise.Name);
                        }
                        catch (Exception ex)
                        {
                            this.workoutDB.Exercises.InsertOnSubmit(exercise);
                            Console.WriteLine(ex);
                        }

                        this.workoutDB.SubmitChanges();
                    }
                }
            }

            List<Exercise> exercisesInDB = (from Exercise exercise in workoutDB.Exercises
                                            select exercise).ToList();

            List<Day> daysInDB = (from Day day in workoutDB.Days
                                  select day).ToList();

            // Days
            foreach (XElement element in root.Nodes())
            {
                int num = Convert.ToInt32((element.Descendants("num").Single() as XElement).Value);

                // Exercises are also present
                if (element.Elements().Count() == 4)
                {
                    XElement exerciseRoot = element.Descendants("exercises").Single() as XElement;

                    foreach (XElement exec in exerciseRoot.Nodes())
                    {
                        DayExercise dayExercise = new DayExercise();

                        string exerciseName = (exec.Descendants("name").Single() as XElement).Value.ToString();
                        string type = (exec.Descendants("type").Single() as XElement).Value.ToString();
                        Exercise exercise =  exercisesInDB.Single(ex => ex.Name == exerciseName);
                        Day day = daysInDB.Single(d => d.Num == num);

                        dayExercise.ExerciseId = exercise.ExerciseId;
                        dayExercise.DayId = day.DayId;
                        dayExercise.ExerciseSetType = decodeSetType(type);
                        dayExercise.Description = (exec.Descendants("description").Single() as XElement).Value.ToString().Trim(new char[] { '\n', ' ' }); ;
                        Regex rgx = new Regex("\n\\s*");
                        dayExercise.Description = rgx.Replace(dayExercise.Description, "\n");
                        this.workoutDB.DayExercises.InsertOnSubmit(dayExercise);
                    }
                }
            }

            this.workoutDB.SubmitChanges();
            // Call the base method.
            base.OnNavigatedTo(e);
        }
Ejemplo n.º 3
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            XDocument xdoc = XDocument.Load("days.xml");
            XElement  root = xdoc.Root;

            //Database
            this.workoutDB = new WorkoutContext(WorkoutContext.DBConnectionString);

            // Gather all exercises only
            // For each day
            foreach (XElement element in root.Nodes())
            {
                int num = Convert.ToInt32((element.Descendants("num").Single() as XElement).Value);

                Day day = new Day();
                day.Workout      = (element.Descendants("workout").Single() as XElement).Value.ToString();
                day.Num          = num;
                day.VideoKey     = ((element.Descendants("video").Single() as XElement).Descendants("video_key").Single() as XElement).Value;
                day.ThumbnailUrl = ((element.Descendants("video").Single() as XElement).Descendants("thumbnail_url").Single() as XElement).Value;

                this.workoutDB.Days.InsertOnSubmit(day);
                this.workoutDB.SubmitChanges();

                if (element.Elements().Count() == 4)
                {
                    XElement exerciseRoot = element.Descendants("exercises").Single() as XElement;

                    // For each exercise
                    foreach (XElement exec in exerciseRoot.Nodes())
                    {
                        Exercise exercise = new Exercise();
                        exercise.Name = (exec.Descendants("name").Single() as XElement).Value.ToString();

                        try
                        {
                            this.workoutDB.Exercises.First(ex => ex.Name == exercise.Name);
                        }
                        catch (Exception ex)
                        {
                            this.workoutDB.Exercises.InsertOnSubmit(exercise);
                            Console.WriteLine(ex);
                        }

                        this.workoutDB.SubmitChanges();
                    }
                }
            }


            List <Exercise> exercisesInDB = (from Exercise exercise in workoutDB.Exercises
                                             select exercise).ToList();

            List <Day> daysInDB = (from Day day in workoutDB.Days
                                   select day).ToList();

            // Days
            foreach (XElement element in root.Nodes())
            {
                int num = Convert.ToInt32((element.Descendants("num").Single() as XElement).Value);

                // Exercises are also present
                if (element.Elements().Count() == 4)
                {
                    XElement exerciseRoot = element.Descendants("exercises").Single() as XElement;

                    foreach (XElement exec in exerciseRoot.Nodes())
                    {
                        DayExercise dayExercise = new DayExercise();

                        string   exerciseName = (exec.Descendants("name").Single() as XElement).Value.ToString();
                        string   type         = (exec.Descendants("type").Single() as XElement).Value.ToString();
                        Exercise exercise     = exercisesInDB.Single(ex => ex.Name == exerciseName);
                        Day      day          = daysInDB.Single(d => d.Num == num);

                        dayExercise.ExerciseId      = exercise.ExerciseId;
                        dayExercise.DayId           = day.DayId;
                        dayExercise.ExerciseSetType = decodeSetType(type);
                        dayExercise.Description     = (exec.Descendants("description").Single() as XElement).Value.ToString().Trim(new char[] { '\n', ' ' });;
                        Regex rgx = new Regex("\n\\s*");
                        dayExercise.Description = rgx.Replace(dayExercise.Description, "\n");
                        this.workoutDB.DayExercises.InsertOnSubmit(dayExercise);
                    }
                }
            }

            this.workoutDB.SubmitChanges();
            // Call the base method.
            base.OnNavigatedTo(e);
        }