private void SaveExpressionsInDatabase(UsersContext db, Dictionary <DateTime, List <string> > data)
        {
            const int id = 1;

            foreach (var date in data)
            {
                var session = new TrainingSession {
                    Date = date.Key, UserId = id
                };
                db.TrainingSessions.Add(session);
                foreach (var expression in date.Value)
                {
                    var list = new List <LoggedExercise>();
                    foreach (var log in PowerLogParser.ParseInput(expression).ToList())
                    {
                        foreach (var set in log.Sets)
                        {
                            for (int i = 0; i < set.Sets; i++)
                            {
                                list.Add(new LoggedExercise
                                {
                                    UserId       = id,
                                    Reps         = set.Reps,
                                    WeightValue  = set.Weight,
                                    Date         = date.Key,
                                    FailedToLift = set.FailedToLift,
                                    ForcedReps   = set.ForcedReps,
                                    MaxEffort    = set.MaxEffort,
                                    ToFailure    = set.ToFailure,
                                    Comment      = set.Comment,
                                    Exercise     = new Exercise {
                                        Name = log.Name
                                    }
                                });
                            }
                        }
                    }

                    foreach (var log in list)
                    {
                        log.Date     = date.Key;
                        log.Exercise = db.Exercises.FirstOrDefault(x => x.Name.Equals(log.Exercise.Name, StringComparison.OrdinalIgnoreCase));
                        session.LoggedExercises.Add(log);
                        log.TrainingSession = session;
                        db.LoggedExercises.Add(log);
                        db.SaveChanges();
                    }
                }
            }
        }
        private void ParseValue()
        {
            baconTV.ItemsSource = new[]
            {
                // meget vigtigt detalje
                // at man smider roden i ienumerable
                PowerLogParser.Convert(lolobox.Text)
            };

            try
            {
                PowerLogParser.ParseInput(lolobox.Text).ToList().ForEach(x => syso.Text += x.ToString());
            }
            catch (Exception ex)
            {
                syso.Text = ex.Message;
            }
        }
 private static IEnumerable <Log> ParseInput(string input)
 {
     return(PowerLogParser.ParseInput(input).ToList());
 }
示例#4
0
        public static IEnumerable <LoggedExercise> ParseLog(UsersContext db, int userId, string comment, DateTime date, List <string> data, bool perssist = true, TrainingSession session = null)
        {
            int id   = userId;
            var user = db.UserProfiles.Find(id);

            if (session == null)
            {
                session = new TrainingSession {
                    Date = date, UserId = id, UserProfile = user, Comment = comment
                }
            }
            ;
            if (perssist)
            {
                db.TrainingSessions.Add(session);
                db.SaveChanges();
            }
            foreach (var expression in data)
            {
                var list = new List <LoggedExercise>();
                foreach (var log in PowerLogParser.ParseInput(expression).ToList())
                {
                    foreach (var set in log.Sets)
                    {
                        for (int i = 0; i < set.Sets; i++)
                        {
                            list.Add(new LoggedExercise
                            {
                                UserId       = id,
                                UserProfile  = user,
                                Reps         = set.Reps,
                                Weight       = set.Weight,
                                Date         = date,
                                FailedToLift = set.FailedToLift,
                                ForcedReps   = set.ForcedReps,
                                MaxEffort    = set.MaxEffort,
                                ToFailure    = set.ToFailure,
                                Comment      = set.Comment,
                                Exercise     = new Exercise {
                                    Name = log.Name
                                }
                            });
                        }
                    }
                }

                foreach (var log in list)
                {
                    log.Date = date;
                    var name = log.Exercise.Name;
                    log.Exercise =
                        db.Exercises.FirstOrDefault(
                            x => x.Name.Equals(log.Exercise.Name, StringComparison.OrdinalIgnoreCase));
                    if (null == log.Exercise)
                    {
                        var message = string.Format("Could not find exercise with name [<strong>{0}<strong>]",
                                                    HttpUtility.HtmlEncode(name));
                        throw new Exception(message);
                    }
                    if (perssist)
                    {
                        session.LoggedExercises.Add(log);
                        log.TrainingSession = session;
                        db.LoggedExercises.Add(log);
                        db.SaveChanges();
                    }
                    else
                    {
                        yield return(log);
                    }
                }
            }
        }
    }
示例#5
0
        static void Main(string[] args)
        {
            var x = @"
          __      _.._
       .-'__`-._.'.--.'.__.,
      /--'  '-._.'    '-._./
     /__.--._.--._.'``-.__/
     '._.-'-._.-._.-''-..'

              _,,,_
            .'     `'.
           /     ____ \
          |    .'_  _\/
          /    ) a  a|         .----.
         /    (    > |        /|     '--.
        (      ) ._  /        ||    ]|   `-.
        )    _/-.__.'`\       ||    ]|    ::|
       (  .-'`-.   \__ )      ||    ]|    ::|
        `/      `-./  `.      ||    ]|    ::|
       _ |    \      \  \     \|    ]|   .-'
      / \|     \   \  \  \     L.__  .--'(
     |   |\     `. /  /   \  ,---|_      \---------,
     |   `\'.     '. /`\   \/ .--._|=-    |_      /|
     |     \ '.     '._ './`\/ .-'          '.   / |
     |     |   `'.     `;-:-;`)|             |-./  |
     |    /_      `'--./_  ` )/'-------------')/)  |
     \   | `""""""""----""`\//`""""`/,===..'`````````/ (  |
      |  |            / `---` `==='          /   ) |
      /  \           /                      /   (  |
     |    '------.  |'--------------------'|     ) |
      \           `-|                      |    /  |
       `--...,______|                      |   (   |
              | |   |                      |    ) ,|
              | |   |                      |   ( /||
              | |   |                      |   )/ `""
             /   \  |                      |  (/
           .' /I\ '.|                      |  /)
        .-'_.'/ \'. |                      | /
        ```  `""""""` `| .-------------------.||
                    `""`                   `""`
 
 

";

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.OutputEncoding  = Encoding.UTF8;
            var line = string.Empty;

            while (line != "done")
            {
                try
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        foreach (var log in PowerLogParser.ParseInput(line))
                        {
                            Console.WriteLine(log);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write(x);
                    Console.Write("\n\nERROR:");
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write(@" LOLz haha! ");
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.HelpLink);
                    Console.WriteLine(e.StackTrace);
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                }
                line = Console.ReadLine();
            }
        }