示例#1
0
        public bool NotifySubmit(IStringLocalizer <MComponentsLocalization> pLocalizer)
        {
            bool submitSuccessful = true;

            lock (mLocker)
            {
                if (OnFormSubmit == null)
                {
                    return(submitSuccessful);
                }

                var args = new MFormContainerContextSubmitArgs()
                {
                    UserInterated = true
                };

                foreach (var handler in OnFormSubmit.GetInvocationList())
                {
                    try
                    {
                        handler.Method.Invoke(handler.Target, new object[] { this, args });
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error in the handler {0}: {1}", handler.Method.Name, e.Message);

                        string msg = e.ToString();

                        if (e is TargetInvocationException te)
                        {
                            msg = te.InnerException.ToString();

                            if (te.InnerException is UserMessageException ue)
                            {
                                msg = ue.Message;
                            }
                        }

                        Notificator.InvokeNotification(true, msg);
                        submitSuccessful = false;
                    }
                }

                Notificator.InvokeNotification(false, pLocalizer["Gespeichert!"]);
            }

            return(submitSuccessful);
        }
        public async Task <bool> NotifySubmit(IStringLocalizer <MComponentsLocalization> pLocalizer)
        {
            if (OnFormSubmit == null)
            {
                return(true);
            }

            bool submitSuccessful = true;

            try
            {
                await mLocker.WaitAsync();

                var args = new MFormContainerContextSubmitArgs()
                {
                    UserInterated = true
                };

                foreach (AsyncEventHandler <MFormContainerContextSubmitArgs> handler in OnFormSubmit.GetInvocationList())
                {
                    try
                    {
                        await handler(this, args);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error in the handler {0}: {1}", handler.Method.Name, e.Message);

                        string msg = e.ToString();

                        if (e is TargetInvocationException te)
                        {
                            msg = te.InnerException.ToString();

                            if (te.InnerException is UserMessageException ue)
                            {
                                msg = ue.Message;
                            }
                        }

                        Notificator.InvokeNotification(true, msg);
                        submitSuccessful = false;
                    }
                }

                if (FormContainer.OnAfterAllFormsSubmitted.HasDelegate)
                {
                    await FormContainer.OnAfterAllFormsSubmitted.InvokeAsync(new MFormContainerAfterAllFormsSubmittedArgs()
                    {
                        AllFormsSuccessful = submitSuccessful
                    });
                }

                Notificator.InvokeNotification(false, pLocalizer["Gespeichert!"]);
            }
            finally
            {
                mLocker.Release();
            }

            return(submitSuccessful);
        }