예제 #1
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            Loaded -= OnLoaded;
            var env = WMSEnvironment.Instance.DbSystemInfo.Environment;

            if (!string.IsNullOrEmpty(env))
            {
                ErrorBox.AddAdditionalParam(BugReportResources.Environment, env);
            }

            var ver = WMSEnvironment.Instance.DbSystemInfo.Version;

            if (!string.IsNullOrEmpty(ver))
            {
                ErrorBox.AddAdditionalParam(BugReportResources.VersionDB, ver);
            }

            var sdcl = WMSEnvironment.Instance.SdclCode;

            if (!string.IsNullOrEmpty(sdcl))
            {
                ErrorBox.AddAdditionalParam(BugReportResources.SdclCode, sdcl);
            }

            var endpoint = WMSEnvironment.Instance.EndPoint;

            if (!string.IsNullOrEmpty(endpoint))
            {
                ErrorBox.AddAdditionalParam(BugReportResources.SDCL_Endpoint, endpoint);
            }

            // регистрируем сервис отображения вкладок
            IoC.Instance.RegisterInstance(typeof(IDocumentManagerService), DocServiceHost, LifeTime.Singleton);

            // регистрируем сервис отображения диалогов
            IoC.Instance.RegisterInstance(typeof(IDocumentManagerService), DocServiceFloat, LifeTime.Singleton, "Float");
        }
예제 #2
0
        internal static void ShowError(string message, Exception ex, string[] attachments, Dictionary <string, string> additionalParams, bool isBtnSandMailEnable = true, string mandantCode = null, bool isMandantListVisible = true)
        {
            // первая ошибка содержит описание
            var trueEx    = ExceptionHelper.GetFirstMeaningException(ex);
            var exMessage = ExceptionHelper.GetErrorMessage(trueEx);

            if (!string.IsNullOrEmpty(exMessage))
            {
                Log.Debug(exMessage);
            }

            // пробуем вытащить пояснение пользователю: оно может быть во вложенной ошибке
            var exReason = trueEx.InnerException is ICustomException
            ? string.Format(GeneralResources.ExceptionResources.ErrorReason, ExceptionHelper.GetErrorMessage(trueEx.InnerException))
            : string.Empty;

            // собираем подробную информацию
            var exDetails = ExceptionHelper.ExceptionToString(ex);

            if (exDetails == exMessage)
            {
                exDetails = null;
            }

            //var totalDescription = string.Format("{0}{1}{2}",
            //    string.IsNullOrEmpty(message) ? string.Empty : string.Format("{0}{1}", message, Environment.NewLine),
            //    string.IsNullOrEmpty(exReason) ? string.Empty : string.Format("{0}{1}", exReason, Environment.NewLine),
            //    exDetails);

            var totalDescription = string.Format("{0}{1}{2}",
                                                 string.IsNullOrEmpty(message) ? string.Empty : string.Format("{0} ", message),
                                                 string.IsNullOrEmpty(exReason) ? string.Empty : string.Format("{0}{1}{0} ", Environment.NewLine, exReason),
                                                 exDetails);

            // Проверка, что нет открытого окна с такой же ошибкой. Сообщение добавлем в уже открытое
            if (!string.IsNullOrEmpty(exMessage))
            {
                var collection = Application.Current.MainWindow.OwnedWindows;
                var res        = collection
                                 .OfType <ErrorBox>()
                                 .FirstOrDefault(w => exMessage.Equals(w.LabelErrorCaption.Text) && w.MemoEditMainTxt.Text != null && !w.MemoEditMainTxt.Text.Contains(exReason));

                if (res != null)
                {
                    if (!string.IsNullOrEmpty(exReason))
                    {
                        res.MemoEditMainTxt.Text += totalDescription;
                    }
                    return;
                }
            }

            var wind = new ErrorBox
            {
                Message                 = message,
                Exception               = ex,
                Attachments             = attachments,
                CurrentAdditionalParams = additionalParams,
                Owner                 = Application.Current.MainWindow.IsLoaded ? Application.Current.MainWindow : null,
                CanSendMail           = isBtnSandMailEnable,
                LabelErrorCaption     = { Text = exMessage },
                MemoEditMainTxt       = { Text = totalDescription },
                MandantListVisibility = isMandantListVisible ? Visibility.Visible : Visibility.Collapsed,
            };

            if (wind.Owner == null)
            {
                var viewService = IoC.Instance.Resolve <IViewService>();
                try
                {
                    var owner = viewService.GetActiveWindow();
                    if (owner != null)
                    {
                        wind.Owner = owner;
                    }
                }
                finally
                {
                    if (wind.Owner == null)
                    {
                        wind.Topmost = true;  //крайний случай
                    }
                }
            }

            wind.RefreshMandants();
            if (!string.IsNullOrEmpty(mandantCode) && wind.Mandants != null)
            {
                wind.SelectedItem = wind.Mandants.FirstOrDefault(p => mandantCode.EqIgnoreCase(p.MandantCode));
            }

            wind.ShowDialog();
        }