Example #1
0
        public static bool InteractiveValidationCallback(string message, ErrorSeverity severity, int code, StateHolder state)
        {
            Dictionary <int, bool> responses       = (Dictionary <int, bool>)state ["responses"];
            MessageProgress        messageProgress = null;

            if (state.ContainsKey("messageProgress"))
            {
                messageProgress = (MessageProgress)state ["messageProgress"];
            }

            if (responses.ContainsKey(code))
            {
                return(severity == ErrorSeverity.Warning && responses [code]);
            }

            try {
                if (messageProgress != null)
                {
                    messageProgress.Hide();
                }
                using (MessageError dlgError = new MessageError(message, severity)) {
                    if (severity == ErrorSeverity.Warning)
                    {
                        dlgError.Buttons = MessageButtons.YesNo | MessageButtons.Remember;
                        ResponseType resp = dlgError.Run();
                        if (dlgError.RememberChoice)
                        {
                            responses [code] = resp == ResponseType.Yes;
                        }

                        return(resp == ResponseType.Yes);
                    }
                    else
                    {
                        dlgError.Buttons = MessageButtons.OK | MessageButtons.Remember;
                        dlgError.Run();
                        if (dlgError.RememberChoice)
                        {
                            responses [code] = true;
                        }
                        return(false);
                    }
                }
            } finally {
                if (messageProgress != null)
                {
                    messageProgress.Show();
                }
            }
        }
Example #2
0
        public static void ImportData <T> (EventHandler <ValidateEventArgs> validateCallback = null, EventHandler <ImportEventArgs> commitCallback = null, bool usesLocation = false) where T : IStrongEntity, IPersistableEntity <T>
        {
            Dictionary <int, bool> responses = new Dictionary <int, bool> ();

            using (MessageProgress progress = new MessageProgress(Translator.GetString("Importing..."), "Icons.Import24.png", Translator.GetString("Importing in progress..."))) {
                bool cancelImport = false;
                progress.Response          += delegate { cancelImport = true; };
                progress.CustomProgressText = true;

                StateHolder state = new StateHolder();
                state ["responses"]       = responses;
                state ["messageProgress"] = progress;

                ImportData(delegate(T entity, long?locationId, int current, int total, out bool cancel)
                {
                    progress.Show();
                    progress.Progress     = ((double)current * 100) / (total - 1);
                    progress.ProgressText = string.Format(Translator.GetString("{0} of {1}"), current + 1, total);
                    PresentationDomain.ProcessUIEvents();
                    cancel = cancelImport;
                    if (validateCallback != null)
                    {
                        ValidateEventArgs args = new ValidateEventArgs(InteractiveValidationCallback, state);
                        validateCallback(entity, args);
                        if (!args.IsValid)
                        {
                            return;
                        }
                    }

                    if (!entity.Validate(InteractiveValidationCallback, state))
                    {
                        return;
                    }

                    entity.CommitChanges();

                    if (commitCallback != null)
                    {
                        commitCallback(entity, new ImportEventArgs(locationId));
                    }
                }, usesLocation);
            }
        }