Exemplo n.º 1
0
        /// <summary>
        /// Given a template this creates a new session and assigns it.
        /// </summary>
        /// <param name="template">The template you want to load the session into.</param>
        protected void CreateSession(BaseTemplate template)
        {
            // Clear any old errors
            ClearError(ScriptForgeErrors.Codes.Missing_Session_Key);
            // Create the new session
            IDictionary <string, object> session = new TemplateSession();

            // Populate it
            PopulateSession(session);
            // Assign it
            template.Session = session;
            // Try to run it.
            try
            {
                // Initialize it
                template.Initialize();
            }
            catch (MissingSessionKeyException missingSessionKey)
            {
                DisplayError(ScriptForgeErrors.Codes.Missing_Session_Key, "The template is missing the session key '" + missingSessionKey.key + "' and can't be compiled.");
            }
            catch (System.Exception e)
            {
                DisplayError(ScriptForgeErrors.Codes.Other, "An exception was thrown when generating the code " + e.ToString());
            }
        }
Exemplo n.º 2
0
        public SessionTemplateViewModel(SessionTemplate model, IDataClient client, object parentVm, IDialogCoordinator dialogCoordinator)
            : base(model, new SessionTemplateValidator())
        {
            var canExecuteSave = this.WhenAnyValue(x => x.HasErrors, x => !x);

            Save = ReactiveCommand.CreateFromTask(async _ =>
            {
                var result = await client.UpdateSessionTemplate(this.Model).ConfigureAwait(true);
                await result.DisplayErrors(parentVm, dialogCoordinator).ConfigureAwait(true);
            },
                                                  canExecuteSave);

            var canRemove = this.WhenAnyValue(x => x.SelectedSession).Select(x => x != null);

            RemoveSession = ReactiveCommand.Create <SessionViewModel>(viewModel =>
            {
                Sessions.Remove(viewModel);
                Model.Sessions.Remove((TemplateSession)viewModel.Model);
            },
                                                                      canRemove);

            AddSession = ReactiveCommand.Create(() =>
            {
                var toAdd = new TemplateSession {
                    IsSessionEnd = true
                };

                if (Sessions.Count == 0)
                {
                    toAdd.OpeningDay = DayOfTheWeek.Monday;
                    toAdd.ClosingDay = DayOfTheWeek.Monday;
                }
                else
                {
                    DayOfTheWeek maxDay = (DayOfTheWeek)Math.Min(6, Sessions.Max(x => (int)x.OpeningDay) + 1);
                    toAdd.OpeningDay    = maxDay;
                    toAdd.ClosingDay    = maxDay;
                }
                Sessions.Add(new SessionViewModel(toAdd));
                Model.Sessions.Add(toAdd);
            });

            //populate session collection
            if (model.Sessions != null)
            {
                foreach (var session in model.Sessions)
                {
                    Sessions.Add(new SessionViewModel(session));
                }
            }
        }
Exemplo n.º 3
0
        private void AddSession()
        {
            var sessionToAdd = new TemplateSession {
                IsSessionEnd = true
            };

            if (TheSessionTemplate.Sessions?.Count == 0)
            {
                sessionToAdd.OpeningDay = DayOfTheWeek.Monday;
                sessionToAdd.ClosingDay = DayOfTheWeek.Monday;
            }
            else
            {
                var maxDay = (DayOfTheWeek)Math.Min(6, TheSessionTemplate.Sessions.Max(x => (int)x.OpeningDay) + 1);
                sessionToAdd.OpeningDay = maxDay;
                sessionToAdd.ClosingDay = maxDay;
            }

            TheSessionTemplate.Sessions.Add(sessionToAdd);
        }
        private void AddSessionBtn_Click(object sender, RoutedEventArgs e)
        {
            var toAdd = new TemplateSession();

            toAdd.IsSessionEnd = true;

            if (TheTemplate.Sessions.Count == 0)
            {
                toAdd.OpeningDay = DayOfTheWeek.Monday;
                toAdd.ClosingDay = DayOfTheWeek.Monday;
            }
            else
            {
                DayOfTheWeek maxDay = (DayOfTheWeek)Math.Min(6, TheTemplate.Sessions.Max(x => (int)x.OpeningDay) + 1);
                toAdd.OpeningDay = maxDay;
                toAdd.ClosingDay = maxDay;
            }
            TheTemplate.Sessions.Add(toAdd);
            SessionsGrid.ItemsSource = null;
            SessionsGrid.ItemsSource = TheTemplate.Sessions;
        }