public void ExerciseRepository_UnitOfWork_AddAndModify_Operates_As_Expected()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);

            IExercise modifiedExercise;
            var       currentTime = Funcs.RemoveMilliSeconds(DateTime.Now);

            using (var uow = Funcs.GetUnitOfWork())
            {
                Exercise newExercise = CreateMetronomeExercise();
                uow.Exercises.Add(newExercise);
                // --- do not commit !!!

                IExercise existingExercise = uow.Exercises.Get(newExercise.Id);

                existingExercise.Title = "Modified Exercise Title";
                existingExercise.TargetMetronomeSpeed = 200;

                uow.Exercises.Update(existingExercise);
                // --- do not commit !!!
                modifiedExercise = uow.Exercises.Get(existingExercise.Id);

                uow.Rollback();

                IExercise testDelegate() => uow.Exercises.Get(modifiedExercise.Id);

                Assert.That(testDelegate, Throws.TypeOf <DatabaseEntityNotFoundException>());
            }
        }
        public static IExercise <T> GetExercise <T>(int option)
        {
            IExercise <T> exercise = null;

            switch (option)
            {
            case 5:
                exercise = new BubbleSortAlgorithm <T>();
                break;

            case 6:
                exercise = new MergeSortRecursive <T>();
                break;

            case 7:
                exercise = new MergeSortIterative <T>();
                break;

            case 8:
                exercise = new LinkedListStructure <T>();
                break;

            default:
                break;
            }

            return(exercise);
        }
示例#3
0
 public SuperSet(string name, int iterations, IExercise first, IExercise second)
 {
     Name   = name ?? "Nameless Super Set";
     Cycles = iterations > -1 ? iterations : 0;
     First  = first;
     Second = second;
 }
示例#4
0
        static IExercise ShowMenu(IList <IExercise> exercises)
        {
            int menu;

            do
            {
                Console.Clear();
                Console.WriteLine("Test your match skills :)\r\n");
                for (int i = 0; i < exercises.Count; i++)
                {
                    Console.WriteLine("\t{0}\t{1}", i, exercises[i].GetType().Name);
                }
                Console.WriteLine("\r\n\t99\tExit\r\n");
                Console.Write("Please enter your choice: ");
                if (!int.TryParse(Console.ReadLine(), out menu))
                {
                    // wrong input
                    menu = -1;
                }
                if (menu != 99)
                {
                    if (menu >= exercises.Count)
                    {
                        menu = -1;
                    }
                }
            }  while (menu < 0);
            IExercise result = null;

            if (menu != 99)
            {
                result = exercises[menu];
            }
            return(result);
        }
示例#5
0
        public void CloudService_GetFullExercise(object sender, Domain.CloudService.GetFullExerciseCompletedEventArgs e)
        {
            // Convert
            IExercise exercise = _factory.CreateDomainExercise(e.Result);

            // Call
            _callBackGetFullExercise(exercise);
        }
 public void finishExercise(IExercise exercise)
 {
     if (_currentExercise.Equals(exercise))
     {
         _exercisesUserData[exercise.getName()] = exercise.save();
         _currentExercise = null;
         MainActivity.getInstance().showTasksWindow();
     }
 }
        private IEnumerable <ExerciseActivity> GetExerciseActivities(IExercise entity)
        {
            var results = Connection.Query <ExerciseActivity>("sp_GetExerciseActivitiesByExercise",
                                                              param: new
            {
                _exerciseId = entity.Id
            }, commandType: CommandType.StoredProcedure);

            return(results);
        }
示例#8
0
        private static void FindSolution <T>() where T : IExercise
        {
            Type targetType = typeof(T);

            IExercise exercise = Activator.CreateInstance(targetType) as IExercise;

            exercise.ReadInput();
            exercise.Solve();
            exercise.PrintResult();
        }
示例#9
0
        public void Update(IExercise exercise)
        {
            if (exercise.Id <= 0)
            {
                throw new ArgumentException("An existing exercise must have an id");
            }

            unitOfWork.Exercises.Update(exercise);
            unitOfWork.Commit();
        }
示例#10
0
 public AddEditExerciseVM(long workoutId, IExercise exercise)
     : base(false)
 {
     _item = new Exercise(exercise)
     {
         IdWorkout = workoutId
     };
     PageName = AppResources.AddEdit_Exercise;
     Rollback();
 }
示例#11
0
        // :ISyncService
        public void SaveExercise(Users user, IExercise exercise, SyncCallbackSaveExercise callback)
        {
            // Setup
            Exercises dbExercise = _factory.CreateDBExercise(exercise);

            _callBackSaveExercise = callback;

            // Call
            _client.SaveExerciseAsync(user, dbExercise);
        }
示例#12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IExercise excercise, IExerciseService exerciseService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors("Origin");
            app.UseMvc();
        }
示例#13
0
        // :Helper functions
        private void _FullExerciseRetrieved(IExercise exercise)
        {
            // Setup
            App.SelectedExercise = exercise;

            // Navigate
            if (!App.RunningInBackground)
            {
                (_application.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Views/ExerciseDetailedView.xaml", UriKind.Relative));
            }
        }
示例#14
0
 private QuestionModel Map(IExercise exercise)
 {
     return(new QuestionModel
     {
         QuestionCode = exercise.QuestionCode,
         QuestionCategory = exercise.QuestionCategory,
         QuestionTitle = exercise.QuestionTitle,
         QuestionCreatedBy = exercise.QuestionCreatedBy,
         QuestionCreatedOn = exercise.QuestionCreatedOn,
         QuestionComments = exercise.QuestionComments
     });
 }
 public static void ExecuteExercise(IExercise exercise)
 {
     try {
         exercise.Start();
         exercise.Execute();
     }
     catch {
         exercise.MarkNegativePoints();
         exercise.End();
     }
     exercise.End();
 }
示例#16
0
        void Start()
        {
            _rigidbody2D = GetComponent <Rigidbody2D>();
            _animator    = GetComponent <Animator>();

            GameManager.Instance.OnGamePause += OnGamePause;
            BehaviourManager.Instance.Add(this);

            _exercises       = MathTrialManager.Instance.GetExercisesByName("SpikeBall");
            _currentExercise = ArrayUtils.GetRandomItem(_exercises);

            Debug.Log($"{gameObject.name}: setting exercise to {_currentExercise.Name}");
        }
示例#17
0
        // --- Methoden ---

        private async Task DeleteExercise(IExercise exercise)
        {
            var response = await DisplayAlert("Warnung", $"Datensatz löschen?", "Löschen", "Abbrechen");

            if (!response)
            {
                return;
            }

            await connection.DeleteAsync(exercise);

            this.exercise.Remove(exercise);
        }
示例#18
0
 public TimedExercise(IExercise exercise, TimeSpan time, string name = null)
 {
     if (name != null)
     {
         Name = name;
     }
     else
     {
         Name = exercise != null ? $"Timed {exercise.Name}" : "Timed Exercise";
     }
     Time     = time;
     Exercise = exercise;
 }
示例#19
0
        public void Add(IExercise exercise)
        {
            if (exercise.Id > 0)
            {
                throw new ArgumentException("A new exercise cannot have an id");
            }

            exercise.DateCreated  = DateTime.Now;
            exercise.DateModified = exercise.DateCreated;

            unitOfWork.Exercises.Add(exercise);
            unitOfWork.Commit();
        }
示例#20
0
        // :Commands
        /// <summary>
        /// Show exercise in detailed vied.
        /// </summary>
        private void _ShowNonSyncedExercise(DateTime startTime)
        {
            // Setup
            IExercise exercise = App.NewExercisesStack.Where(x => x.ExerciseStart == startTime).FirstOrDefault();

            App.SelectedExercise = exercise;

            // Navigate
            if (!App.RunningInBackground)
            {
                (_application.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Views/ExerciseDetailedView.xaml", UriKind.Relative));
            }
        }
        private void DeleteMissingExerciseActivities(IExercise entity)
        {
            var results = GetExerciseActivities(entity);

            var missingIds = results
                             .Select(a => a.Id)
                             .Except(entity.ExerciseActivity.Select(a => a.Id));

            foreach (var id in missingIds)
            {
                Connection.Execute("sp_DeleteExerciseActivity",
                                   param: new { _id = id }, commandType: CommandType.StoredProcedure);
            }
        }
示例#22
0
 private static void ProcessTextAsset(TextAsset textAsset, UnityEngine.Object[] resources,
                                      List <IExercise> exercises)
 {
     try
     {
         string        xmlText       = textAsset.text;
         XmlParsedData xmlParsedData = ParseXml(xmlText);
         IExercise     exercise      = CreateExercise(xmlParsedData, textAsset.name, resources);
         exercises.Add(exercise);
     }
     catch (XmlParserException ex)
     {
         Debug.LogError($"Error with processing text asset \"{textAsset.name}\": {ex.Message}");
     }
 }
示例#23
0
        /// <summary>
        /// Request staring trial for the player
        /// </summary>
        /// <param name="sourceMob">Requesting mob</param>
        public void RequestMathTrial(Mob sourceMob)
        {
            Debug.Log("MathTrial requested");
            if (_temporaryInvulnerable)
            {
                return;
            }
            SetInvulnerable(true);

            IExercise exercise = sourceMob.Exercise;

            _pendingMob = sourceMob;
            GameManager.Instance.RequestGamePause(true);
            ShowExercise(exercise);
        }
示例#24
0
 public static void ExecuteExercise(IExercise exercise)
 {
     try
     {
         exercise.Start();
         exercise.Execute();
     }
     catch (Exception ex)
     {
         exercise.MarkNegativePoints();
     }
     finally {
         exercise.End();
     }
 }
 protected virtual void EndEditingExercise(IExercise exercise, EditorCloseOperation operation,
                                           EntityLifeCycleState entityLifeCycleState)
 {
     if (operation == EditorCloseOperation.Saved)
     {
         if (entityLifeCycleState == EntityLifeCycleState.AsExistingEntity)
         {
             exerciseService.Update(exercise);
         }
         else
         {
             exerciseService.Add(exercise);
         }
     }
     CurrentViewModel = exerciseSearchViewModel;
 }
        public void StartEdit(IExercise exercise)
        {
            LifeCycleState = exercise.Id > 0 ? EntityLifeCycleState.AsExistingEntity : EntityLifeCycleState.AsNewEntity;
            Exercise       = exercise;

            if (Exercise != null)
            {
                this.ErrorsChanged -= Exercise_ErrorsChanged;
            }

            this.Revert();

            TrackChanges = true;

            this.ErrorsChanged += Exercise_ErrorsChanged;
        }
示例#27
0
        void Start()
        {
            BehaviourManager.Instance.Add(this);
            _rigidbody2d = GetComponent <Rigidbody2D>();

            Transform body = transform.Find("Body");

            _spriteRenderer = body.gameObject.GetComponent <SpriteRenderer>();
            _animator       = GetComponent <Animator>();

            GameManager.Instance.OnGamePause += OnGamePause;

            _exercises       = MathTrialManager.Instance.GetExercisesByName("Blob");
            _currentExercise = ArrayUtils.GetRandomItem(_exercises);

            Debug.Log($"{gameObject.name}: setting exercise to {_currentExercise.Name}");
        }
        public ExerciseResult <T> ExecuteExercise <T>(string parameterValue, IExercise exercise)
        {
            // 1 - Instantiate the Exercise
            var execution = ExerciseFactory.Create(exercise.AssemblyName, exercise.ParameterTypeEnum);

            // 2 - Convert the provided parameter values to the respective parameter of the exercise
            var parameterValueConverted = ParamFactory.CreateParameter(parameterValue, exercise.ParameterTypeEnum);

            // 3 - Execute the exercise based on the parameter values
            var result = execution.Execute(parameterValueConverted);

            return(new ExerciseResult <T>()
            {
                Success = true,
                ResultValue = (T)result
            });
        }
示例#29
0
        /// <summary>
        /// Displays exercise to the player
        /// </summary>
        /// <param name="exercise">Exercise to show</param>
        public void ShowExercise(IExercise exercise)
        {
            if (!_initialized)
            {
                DoInitialization();
                _initialized = true;
            }

            if (exercise != null)
            {
                _exercise        = exercise;
                _textDrawer.text = exercise.Text;
                SetImageSprite(exercise.Sprite);
            }

            gameObject.SetActive(true);
        }
        public bool FillFromTaggedTask(String id, IExercise task) {
            var typeMap = getTypeMap();

            Type taskType;
            if (typeMap.TryGetValue(id, out taskType)) {
                var attribute = (TaskAttribute)Attribute.GetCustomAttribute(taskType, typeof(TaskAttribute));

                IEvaluator evaluator = (IEvaluator)kernel.Get(taskType);
                task.Evaluator = evaluator;
                if (!String.IsNullOrEmpty(attribute.Text)) {
                    task.Description = attribute.Text;
                }
                return true;
            }
            //we could not find the type
            return false;
        }
 private void InsertNewExerciseActivities(IExercise exercise)
 {
     foreach (ExerciseActivity activity in exercise.ExerciseActivity)
     {
         if (activity.Id <= 0)
         {
             Connection.ExecuteScalar <int>(sql: "sp_InsertExerciseActivity",
                                            param: new
             {
                 _exerciseId     = exercise.Id,
                 _seconds        = activity.Seconds,
                 _metronomeSpeed = activity.MetronomeSpeed,
                 _manualProgress = activity.ManualProgress
             },
                                            commandType: CommandType.StoredProcedure
                                            );
         }
     }
 }
示例#32
0
        // Functions
        // :IExerciseFactory
        public Exercises CreateDBExercise(IExercise exercise)
        {
            // Setup
            Exercises createdExercise = new Exercises();

            // Convert
            // :Exercise
            createdExercise.RoutePoints = new ObservableCollection<RoutePoints>();
            createdExercise.ExerciseStart = exercise.ExerciseStart;
            createdExercise.ExerciseEnd = exercise.ExerciseEnd;

            // :Points
            foreach (var point in exercise.Points)
            {
                var createdPoint = new RoutePoints();
                createdPoint.Latitude = point.Latitude;
                createdPoint.Longitude = point.Longitude;
                createdPoint.Time = point.Time;

                createdExercise.RoutePoints.Add(createdPoint);
            }

            return (createdExercise);
        }
示例#33
0
 // Functions
 // :Constructors
 /// <summary>
 /// Created new viewmodel.
 /// </summary>
 /// <param name="exercise">Exercise to create the viewmodel around.</param>
 public ExerciseDetailedViewModel(IExercise exercise)
 {
     // Setup
     _exercise = exercise;
 }
示例#34
0
        // :Helper functions
        private void _FullExerciseRetrieved(IExercise exercise)
        {
            // Setup
            App.SelectedExercise = exercise;

            // Navigate
            if(!App.RunningInBackground)
                (_application.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Views/ExerciseDetailedView.xaml", UriKind.Relative));
        }
示例#35
0
 // Functions
 // :Constructors and deconstructors
 public RunningExerciseViewModel(TaskFactory taskFactory)
 {
     // Setup
     _exercise = new Exercise();
     _taskFactory = taskFactory;
 }
示例#36
0
        // :ISyncService
        public void SaveExercise(Users user, IExercise exercise, SyncCallbackSaveExercise callback)
        {
            // Setup
            Exercises dbExercise = _factory.CreateDBExercise(exercise);
            _callBackSaveExercise = callback;

            // Call
            _client.SaveExerciseAsync(user, dbExercise);
        }
示例#37
0
 public void AddExercise(IMovable unit, IExercise exercise)
 {
     Debug.Assert(mCurrentIdleUnits.Contains(unit));
     Debug.Assert(mUnitToServant.ContainsKey(unit));
     Debug.Assert(mUnitToServant[unit] == null);
     Servant servant = new Servant(unit, exercise);
     servant.RegisterAtExercise();
     mAiServants.Add(servant);
     mUnitToServant[unit] = servant;
     mCurrentIdleUnits.Remove(unit);
 }
示例#38
0
 public Servant(IMovable unit, IExercise exercise)
 {
     //Debug.Assert(unit.Allegiance == Allegiance.Computer);
     mUnit = unit;
     mExercise = exercise;
 }