private void okButton1_Click(object sender, CancellationSourceEventArgs e)
        {
            try
            {
                UserContext.Logout(LoginStatus.InProgress);
                ProfileDTO newProfile = new ProfileDTO();
                bool       res        = false;
                this.SynchronizationContext.Send(delegate
                {
                    res = usrCreateProfile1.SaveProfile(newProfile);
                }, null);
                if (!res)
                {
                    return;
                }

                newProfile.Privacy.CalendarView = Privacy.Public;
                newProfile.Privacy.Sizes        = Privacy.Public;
                var sessionData = ServiceManager.CreateProfile(newProfile);
                if (sessionData != null)
                {
                    UserContext.CreateUserContext(sessionData);
                    CreatedSessionData = sessionData;
                }
                ThreadSafeClose();
            }
            catch (EMailSendException ex)
            {
                TasksManager.SetException(ex);
                this.SynchronizationContext.Send(delegate
                {
                    ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrProblemWithSendingEmail, ErrorWindow.MessageBox);
                }, null);
            }
            catch (ValidationException validException)
            {
                TasksManager.SetException(validException);
                this.SynchronizationContext.Send(delegate
                {
                    FMMessageBox.ShowValidationError(validException.Results);
                }, null);
            }
            catch (UniqueException uniqueEx)
            {
                TasksManager.SetException(uniqueEx);
                this.SynchronizationContext.Send(delegate
                {
                    ExceptionHandler.Default.Process(uniqueEx, ApplicationStrings.ErrorCreateProfileUnique, ErrorWindow.MessageBox);
                }, null);
            }
        }
 private void usrProgressIndicatorButtons1_OkClick(object sender, CancellationSourceEventArgs e)
 {
     try
     {
         var msg = usrMessageView1.SaveChanges();
         ServiceManager.SendMessage(msg);
         ThreadSafeClose();
     }
     catch (ValidationException validException)
     {
         TasksManager.SetException(validException);
         this.SynchronizationContext.Send(delegate
         {
             FMMessageBox.ShowValidationError(validException.Results);
         }, null);
     }
 }
 private void okButton1_Click(object sender, CancellationSourceEventArgs e)
 {
     if (!ValidateChildren())
     {
         return;
     }
     try
     {
         var savedProfile = usrProfileEdit1.SaveProfile();
         if (savedProfile != null)
         {
             UserContext.SessionData.FillProfileData(savedProfile);
             UserContext.RefreshUserData();
             ThreadSafeClose(System.Windows.Forms.DialogResult.OK);
         }
     }
     catch (ValidationException validException)
     {
         this.SynchronizationContext.Send(delegate
         {
             FMMessageBox.ShowValidationError(validException.Results);
         }, null);
     }
     catch (OldDataException validException)
     {
         this.SynchronizationContext.Send(delegate
         {
             ExceptionHandler.Default.Process(validException, ApplicationStrings.ErrorOldDataModification, ErrorWindow.MessageBox);
         }, null);
     }
     catch (UniqueException uniqueEx)
     {
         this.SynchronizationContext.Send(delegate
         {
             ExceptionHandler.Default.Process(uniqueEx, ApplicationStrings.ErrorCreateProfileUnique, ErrorWindow.MessageBox);
         }, null);
     }
     catch (Exception ex)
     {
         this.SynchronizationContext.Send(delegate
         {
             ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorCreateProfile, ErrorWindow.EMailReport);
         }, null);
     }
 }
        private void okButton1_Click(object sender, EventArgs e)
        {
            updateTrainingPlan();
            if (!validationProvider1.DoValidate(this))
            {
                DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }

            //ValidatorFactory valFactory= EnterpriseLibraryContainer.Current.GetInstance<ValidatorFactory>();
            var validator = new ObjectValidator(typeof(TrainingPlan));
            var result    = validator.Validate(plan);

            if (!result.IsValid)
            {
                DialogResult = System.Windows.Forms.DialogResult.None;
                FMMessageBox.ShowValidationError(result);
            }
        }
Example #5
0
        public CancellationTokenSource RunAsynchronousOperation(Action <OperationContext> method, Action <OperationContext> operationStateCallback = null, Action <OperationContext> exceptionCallback = null, bool addToList = true)
        {
            OperationContext context = new OperationContext(this);
            var tokenSource          = new CancellationTokenSource();

            context.CancellatioToken = tokenSource.Token;

            var task = context.CurrentTask = Task.Factory.StartNew(delegate(object cancellationToken)
            {
                ControlHelper.EnsureThreadLocalized();
                var arg   = (OperationContext)cancellationToken;
                arg.State = OperationState.Started;
                onTaskStateChanged(arg);
                if (operationStateCallback != null)
                {
                    // SynchronizationContext.Send(state => operationStateCallback(arg), arg);
                    sendThreadSafe(operationStateCallback, arg);
                }
                try
                {
                    method((OperationContext)cancellationToken);
                    if (addToList && !ContainsTask(context.CurrentTask))
                    {
                        return;
                    }
                    arg.State = OperationState.Ended;
                    onTaskStateChanged(arg);

                    if (operationStateCallback != null)
                    {
                        //SynchronizationContext.Send(state => operationStateCallback(arg), arg);
                        sendThreadSafe(operationStateCallback, arg);
                    }
                }
                catch (OperationCanceledException)
                {
                    arg.State = OperationState.Cancelled;
                    onTaskStateChanged(arg);
                    if (operationStateCallback != null)
                    {
                        sendThreadSafe(operationStateCallback, arg);
                    }
                }
                catch (ProfileDeletedException ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    UserContext.Logout(resetAutologon: false, skipLogoutOnServer: true);
                    SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorCurrentProfileDeleted, ErrorWindow.MessageBox), arg);
                }
                catch (UserDeletedException ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorProfileDeleted, ErrorWindow.MessageBox), arg);
                }
                catch (OldDataException ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorOldDataModification, ErrorWindow.MessageBox), arg);
                }
                catch (ValidationException ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    SynchronizationContext.Send(state => FMMessageBox.ShowValidationError(ex.Results), arg);
                }
                catch (EndpointNotFoundException ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    UserContext.Logout(resetAutologon: false, skipLogoutOnServer: true);
                    SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorConnectionProblem, ErrorWindow.MessageBox), arg);
                }
                catch (TimeoutException ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    UserContext.Logout(resetAutologon: false, skipLogoutOnServer: true);
                    SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorConnectionProblem, ErrorWindow.MessageBox), arg);
                }
                catch (DatabaseVersionException ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    UserContext.Logout(resetAutologon: false, skipLogoutOnServer: true);
                    SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorOldVersionOfBodyArchitect, ErrorWindow.MessageBox), arg);
                }
                catch (MaintenanceException ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    UserContext.Logout(resetAutologon: false, skipLogoutOnServer: true);
                    SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorMaintenanceMode, ErrorWindow.MessageBox), arg);
                }
                catch (Exception ex)
                {
                    setExceptionState(arg, operationStateCallback, ex);
                    SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, ex.Message, ErrorWindow.EMailReport), arg);
                    //Application.Exit();
                }
                finally
                {
                    RemoveTask(arg.CurrentTask);
                }
            }, context, tokenSource.Token);

            if (addToList)
            {
                AddTask(context.CurrentTask, context, operationStateCallback);
            }
            if (exceptionCallback != null)
            {
                LogUnhandledExceptions(task, exceptionCallback, context);
            }
            return(tokenSource);
        }