static void ConfigurePlugin <TPlugin>()
            where TPlugin : GraffitiEvent, ISupportsMemento
        {
            TPlugin  plugin = PluginHelper.GetPluginWithCurrentSettings <TPlugin>();
            IMemento state  = plugin.CreateMemento();

            PluginMigrator.MigrateSettings(true, false, state, state);
        }
Beispiel #2
0
        public override StatusType SetValues(HttpContext context, NameValueCollection nvc)
        {
            IMemento oldState;
            IMemento newState;

            Settings settings = new Settings();

            _settingsMapper.Map(nvc, settings);

            try
            {
                var validation = _settingsValidator.Validate(settings).Interpret();
                if (validation.Failed)
                {
                    SetMessage(context, validation.Message);
                    return(validation.StatusType);
                }

                // Write back.
                oldState = CreateMemento();

                CategoryName    = settings.CategoryName;
                DateField       = settings.Date;
                SpeakerField    = settings.Speaker;
                YearQueryString = settings.YearQueryString;

                newState = CreateMemento();
            }
            catch (Exception ex)
            {
                SetMessage(context, String.Format("Error: {0}", ex.Message));
                return(StatusType.Error);
            }

            try
            {
                EnableEventHandlers = false;

                PluginMigrator.MigrateSettings(settings.CreateTargetCategoryAndFields,
                                               settings.MigrateFieldValues,
                                               newState,
                                               oldState);
                return(StatusType.Success);
            }
            catch (Exception ex)
            {
                SetMessage(context, String.Format("Error while migrating category and fields: {0}", ex.Message));
                return(StatusType.Error);
            }
            finally
            {
                EnableEventHandlers = true;
            }
        }
        public override StatusType SetValues(HttpContext context, NameValueCollection nvc)
        {
            IMemento oldState;
            IMemento newState;

            Settings settings = new Settings();

            _settingsMapper.Map(nvc, settings);

            try
            {
                var validation = _settingsValidator.Validate(settings).Interpret();
                if (validation.Failed)
                {
                    SetMessage(context, validation.Message);
                    return(validation.StatusType);
                }

                // Write back.
                oldState = CreateMemento();

                CategoryName                        = settings.CategoryName;
                StartDateField                      = settings.StartDate;
                EndDateField                        = settings.EndDate;
                SpeakerField                        = settings.Speaker;
                DateFormat                          = settings.DateFormat;
                ShortEndDateFormat                  = settings.ShortEndDateFormat;
                LocationField                       = settings.Location;
                UnknownText                         = settings.UnknownText;
                LocationUnknownField                = settings.LocationUnknown;
                YearQueryString                     = settings.YearQueryString;
                DefaultLocation                     = settings.DefaultLocation;
                RegistrationNeededField             = settings.RegistrationNeeded;
                RegistrationRecipientField          = settings.RegistrationRecipient;
                DefaultRegistrationRecipient        = settings.DefaultRegistrationRecipient;
                MaximumNumberOfRegistrationsField   = settings.MaximumNumberOfRegistrations;
                DefaultMaximumNumberOfRegistrations = settings.DefaultMaximumNumberOfRegistrations;
                RegistrationListField               = settings.RegistrationList;
                RegistrationMailSubject             = settings.RegistrationMailSubject;
                EarliestRegistrationField           = settings.EarliestRegistration;
                LatestRegistrationField             = settings.LatestRegistration;

                newState = CreateMemento();
            }
            catch (Exception ex)
            {
                SetMessage(context, String.Format("Error: {0}", ex.Message));
                return(StatusType.Error);
            }

            try
            {
                EnableEventHandlers = false;

                PluginMigrator.MigrateSettings(settings.CreateTargetCategoryAndFields,
                                               settings.MigrateFieldValues,
                                               newState,
                                               oldState);
                return(StatusType.Success);
            }
            catch (Exception ex)
            {
                SetMessage(context, String.Format("Error while migrating category and fields: {0}", ex.Message));
                return(StatusType.Error);
            }
            finally
            {
                EnableEventHandlers = true;
            }
        }