Esempio n. 1
0
        public TaskListItemViewModel Create(TaskEditModel editModel)
        {
            TaskDefinition definition = _taskDefinitionDAO.Get(editModel.DefinitionId);

            TimeSpan allowedExposureTime = new TimeSpanFactory().CreateFromStrings(editModel.Hours, editModel.Minutes);

            Task task = new Task()
            {
                Title                  = editModel.Title,
                Role                   = _roleDAO.Get(editModel.RoleId),
                NoiseProtection        = _noiseProtectionDAO.Get(editModel.NoiseProtectionId),
                NoiseLevelGuideline    = Convert.ToDecimal(editModel.NoiseLevelGuideline.Trim(), new CultureInfo("en-US")),
                Frequency              = editModel.Frequency,
                AllowedExposureMinutes = Convert.ToInt32(allowedExposureTime.TotalMinutes),
                TaskDefinition         = definition,
                ButtonPressed          = editModel.ButtonPressed,
                CultureName            = editModel.SelectedCultureName,
            };

            definition.Tasks.Add(task);

            _taskDefinitionDAO.Store(definition);

            TaskListItemViewModel viewModel = CreateTaskListItemViewModel(task);

            return(viewModel);
        }
        protected override IDisposable Subscribe()
        {
            _exceptionStream = new Subject <NumberedException>();

            return(_exceptionStream
                   .Do(OnRawMessage)
                   .Sample(TimeSpanFactory.FromSeconds(2))
                   .ObserveOn(this)
                   .Subscribe(OnNotificationMessage));
        }
Esempio n. 3
0
        protected override IDisposable Subscribe()
        {
            _exceptionStream = new Subject <BadOrderException>();

            return(_exceptionStream
                   .Do(OnRawMessage)
                   .Buffer(TimeSpanFactory.FromSeconds(2))
                   .Where(g => g.Any())
                   .ObserveOn(this)
                   .Subscribe(g => OnNotificationMessage(BadOrderMessage(g))));
        }
        protected override IDisposable Subscribe()
        {
            _exceptionStream = new Subject <Exception>();

            return(_exceptionStream
                   .Do(OnRawMessage)
                   .Do(ex => IsConnected = false)
                   .Delay(TimeSpanFactory.FromSeconds(3))
                   .SampleResponsive(TimeSpanFactory.FromSeconds(2))
                   .Where(ex => !IsConnected)
                   .ObserveOn(this)
                   .Subscribe(OnNotificationMessage));
        }
Esempio n. 5
0
        public TaskViewModel EditGenericTaskForm(int id)
        {
            Task task = _taskDAO.Get(id);

            IList <SelectOptionViewModel> roles            = new List <SelectOptionViewModel>();
            IList <SelectOptionViewModel> noiseProtections = new List <SelectOptionViewModel>();

            roles.Add(new SelectOptionViewModel(TaskResources.SelectOne, "0"));
            foreach (Role role in _roleDAO.GetAllFilteredByCurrentCulture())
            {
                // We want separate handling for rotation tasks, as the view should be quite different
                if (role.RoleType != RoleTypeEnum.Rotation)
                {
                    roles.Add(new SelectOptionViewModel(role.Title, role.Id.ToString(CultureInfo.InvariantCulture))
                    {
                        IsSelected = (role.RoleDefinition.Id == task.Role.RoleDefinition.Id)
                    });
                }
            }

            noiseProtections.Add(new SelectOptionViewModel(TaskResources.SelectOne, "0"));
            foreach (NoiseProtection noiseProtection in _noiseProtectionDAO.GetAllFilteredByCurrentCulture())
            {
                var selectOption = new SelectOptionViewModel(noiseProtection.Title, noiseProtection.Id.ToString(CultureInfo.InvariantCulture))
                {
                    IsSelected = (noiseProtection.NoiseProtectionDefinition.Id == task.NoiseProtection.NoiseProtectionDefinition.Id)
                };
                noiseProtections.Add(selectOption);
            }

            TimeSpan allowedExposureTime = new TimeSpanFactory().CreateFromMinutes(task.AllowedExposureMinutes);

            IList <SelectOptionViewModel> languages = new LanguageListBuilder().CreateSelectedLanguageList(task.CultureName);
            TaskViewModel viewModel = new TaskViewModel(languages)
            {
                Id    = task.Id,
                Title = task.Title,
                NoiseLevelGuideline = task.NoiseLevelGuideline.ToString(CultureInfo.InvariantCulture),
                Frequency           = task.Frequency,
                Hours            = allowedExposureTime.Hours.ToString(CultureInfo.InvariantCulture),
                Minutes          = allowedExposureTime.Minutes.ToString(CultureInfo.InvariantCulture),
                DefinitionId     = task.TaskDefinition.Id,
                Roles            = roles,
                NoiseProtections = noiseProtections,
                ButtonPressed    = task.ButtonPressed
            };

            return(viewModel);
        }
Esempio n. 6
0
        protected override IDisposable Subscribe()
        {
            _exceptionStream = new Subject <Exception>();

            var comparer = new ExceptionEqualityComparer();

            return(_exceptionStream
                   .Do(OnRawMessage)
                   .GroupBy(ex => ex, comparer)
                   .Subscribe(
                       streamOfGivenType =>
                       streamOfGivenType
                       .SampleResponsive(TimeSpanFactory.FromSeconds(2))
                       .ObserveOn(this)
                       .Subscribe(OnNotificationMessage)));
        }
Esempio n. 7
0
        public TaskListItemViewModel Edit(TaskEditModel editModel)
        {
            Task task = _taskDAO.Get(editModel.Id);

            TimeSpan allowedExposureTime = new TimeSpanFactory().CreateFromStrings(editModel.Hours, editModel.Minutes);

            task.Title = editModel.Title;
            task.NoiseLevelGuideline    = Convert.ToDecimal(editModel.NoiseLevelGuideline.Trim(), new CultureInfo("en-US"));
            task.AllowedExposureMinutes = Convert.ToInt32(allowedExposureTime.TotalMinutes);
            task.Role            = _roleDAO.Get(editModel.RoleId);
            task.NoiseProtection = _noiseProtectionDAO.Get(editModel.NoiseProtectionId);
            task.ButtonPressed   = editModel.ButtonPressed;
            task.Frequency       = editModel.Frequency;


            _taskDAO.Store(task);

            TaskListItemViewModel viewModel = CreateTaskListItemViewModel(task);

            return(viewModel);
        }
        private SelectedTask CreateSelectedTaskRegular(RegularViewModel viewModel, Task task)
        {
            var selectedTask = new SelectedTask
            {
                Title             = task.Title,
                Role              = task.Role.Title,
                NoiseProtection   = task.NoiseProtection.Title,
                NoiseProtectionId = task.NoiseProtection.Id,
                ButtonPressed     = task.ButtonPressed,
                Task              = task,
                CreatedBy         = string.IsNullOrEmpty(User.Identity.Name) ? Session.SessionID : User.Identity.Name,
                CreatedDate       = DateTime.Now.Date
            };

            var noiseProtection = _noiseProtectionDAO.Get(viewModel.NoiseProtectionId);

            selectedTask.NoiseProtection   = noiseProtection.Title;
            selectedTask.NoiseProtectionId = noiseProtection.Id;

            selectedTask.ButtonPressed = viewModel.ButtonPressed;

            if (viewModel.BackgroundNoise != "<80")
            {
                int bNoise;
                int.TryParse(viewModel.BackgroundNoise, out bNoise);
                if (bNoise != 0)
                {
                    selectedTask.BackgroundNoise = bNoise;
                }
            }

            if (viewModel.NoiseLevelMeassured != task.NoiseLevelGuideline && viewModel.NoiseLevelMeassured != 0)
            {
                selectedTask.NoiseLevel       = viewModel.NoiseLevelMeassured;
                selectedTask.IsNoiseMeassured = true;
            }
            else
            {
                selectedTask.NoiseLevel       = task.NoiseLevelGuideline;
                selectedTask.IsNoiseMeassured = false;
            }

            if (string.IsNullOrEmpty(viewModel.Percentage))
            {
                var timeSpan = new TimeSpanFactory().CreateFromStrings(viewModel.Hours, viewModel.Minutes);

                selectedTask.Hours         = timeSpan.Hours;
                selectedTask.Minutes       = timeSpan.Minutes;
                selectedTask.Percentage    = (int)Math.Round(task.CalculatePercentage(task.TaskDefinition.RoleType.ToString(), selectedTask.NoiseLevel, selectedTask.ButtonPressed, selectedTask.BackgroundNoise, selectedTask.Task.Frequency, noiseProtection, timeSpan));
                selectedTask.UsePercentage = false;
            }
            else
            {
                selectedTask.Percentage = string.IsNullOrEmpty(viewModel.Percentage) ? 0 : int.Parse(viewModel.Percentage);
                var timeSpan = task.CalculateTimeSpan(task.TaskDefinition.RoleType.ToString(), selectedTask.NoiseLevel, selectedTask.ButtonPressed, selectedTask.BackgroundNoise, selectedTask.Task.Frequency, noiseProtection, selectedTask.Percentage);
                selectedTask.Hours         = timeSpan.Hours;
                selectedTask.Minutes       = timeSpan.Minutes;
                selectedTask.UsePercentage = true;
            }

            return(selectedTask);
        }
        public PartialViewResult EditTaskRegular(int id, RegularViewModel viewModel)
        {
            var selectedTask = _selectedTaskDAO.Get(id);

            var validationViewModel = ValidateInput(viewModel, selectedTask.Task);

            if (validationViewModel.ValidationErrors.Count > 0)
            {
                Response.StatusCode = 500;
                return(PartialView("_ValidationErrorSummary", validationViewModel));
            }

            selectedTask.ButtonPressed = viewModel.ButtonPressed;

            if (viewModel.BackgroundNoise != "<80")
            {
                int bNoise;
                if (int.TryParse(viewModel.BackgroundNoise, out bNoise))
                {
                    selectedTask.BackgroundNoise = bNoise;
                }
                else if (string.IsNullOrEmpty(viewModel.BackgroundNoise))
                {
                    selectedTask.BackgroundNoise = 0;
                }
            }

            if (viewModel.NoiseLevelMeassured == 0)
            {
                selectedTask.NoiseLevel       = selectedTask.Task.NoiseLevelGuideline;
                selectedTask.IsNoiseMeassured = false;
            }
            else if (viewModel.NoiseLevelMeassured != selectedTask.Task.NoiseLevelGuideline && viewModel.NoiseLevelMeassured != 0)
            {
                selectedTask.NoiseLevel       = viewModel.NoiseLevelMeassured;
                selectedTask.IsNoiseMeassured = true;
            }

            var noiseProtection = _noiseProtectionDAO.Get(viewModel.NoiseProtectionId);

            if (noiseProtection != null)
            {
                selectedTask.NoiseProtection   = noiseProtection.Title;
                selectedTask.NoiseProtectionId = noiseProtection.Id;
            }

            if (string.IsNullOrEmpty(viewModel.Hours) && string.IsNullOrEmpty(viewModel.Minutes))
            {
                selectedTask.Percentage = string.IsNullOrEmpty(viewModel.Percentage) ? 0 : int.Parse(viewModel.Percentage);
                var timeSpan = selectedTask.Task.CalculateTimeSpan(selectedTask.Task.TaskDefinition.RoleType.ToString(), selectedTask.NoiseLevel, selectedTask.ButtonPressed, selectedTask.BackgroundNoise, selectedTask.Task.Frequency, noiseProtection, selectedTask.Percentage);
                selectedTask.Hours         = timeSpan.Hours;
                selectedTask.Minutes       = timeSpan.Minutes;
                selectedTask.UsePercentage = true;
            }
            else
            {
                var timeSpan = new TimeSpanFactory().CreateFromStrings(viewModel.Hours, viewModel.Minutes);

                selectedTask.Hours         = timeSpan.Hours;
                selectedTask.Minutes       = timeSpan.Minutes;
                selectedTask.Percentage    = (int)Math.Round(selectedTask.Task.CalculatePercentage(selectedTask.Task.TaskDefinition.RoleType.ToString(), selectedTask.NoiseLevel, selectedTask.ButtonPressed, selectedTask.BackgroundNoise, selectedTask.Task.Frequency, noiseProtection, new TimeSpan(0, selectedTask.Hours, selectedTask.Minutes, 0)));
                selectedTask.UsePercentage = false;
            }

            _selectedTaskDAO.Store(selectedTask);

            return(PartialView("_SelectedTask", new SelectedTaskViewModel(selectedTask)));
        }