Rock.Apps.CheckScannerUtility.App.LogException C# (CSharp) Méthode

LogException() public static méthode

Silently tries to log the exception to the server's exception log service
public static LogException ( Exception ex ) : void
ex System.Exception The ex.
Résultat void
        public static void LogException( Exception ex)
        {
            try
            {
                RockConfig config = RockConfig.Load();
                RockRestClient client = new RockRestClient( config.RockBaseUrl );
                client.Login( config.Username, config.Password );
                client.PostData<Exception>( "api/ExceptionLogs/LogException", ex );
            }
            catch
            {
                // intentionally ignore if we can't log the exception to the server
            }
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            _rockConfig.CaptureAmountOnScan = chkCaptureAmountOnScan.IsChecked == true;

            _rockConfig.RequireControlAmount    = chkRequireControlAmount.IsChecked == true;
            _rockConfig.RequireControlItemCount = chkRequireControlItemCount.IsChecked == true;
            AddAccountsForAmountsToSave();
            if (_rockConfig.CaptureAmountOnScan && _rockConfig.SelectedAccountForAmountsIds.Count() == 0)
            {
                MessageBox.Show("Please select at least one account", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            try
            {
                txtRockUrl.Text = txtRockUrl.Text.Trim();
                Uri rockUrl      = new Uri(txtRockUrl.Text);
                var validSchemes = new string[] { Uri.UriSchemeHttp, Uri.UriSchemeHttps };
                if (!validSchemes.Contains(rockUrl.Scheme))
                {
                    txtRockUrl.Text = "http://" + rockUrl.AbsoluteUri;
                }

                RockRestClient client = new RockRestClient(txtRockUrl.Text);
                client.Login(_rockConfig.Username, _rockConfig.Password);
                BatchPage.LoggedInPerson = client.GetData <Person>(string.Format("api/People/GetByUserName/{0}", _rockConfig.Username));
            }
            catch (WebException wex)
            {
                HttpWebResponse response = wex.Response as HttpWebResponse;
                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        // valid URL but invalid login, so navigate back to the LoginPage
                        _rockConfig.RockBaseUrl = txtRockUrl.Text;
                        _rockConfig.Save();
                        LoginPage loginPage = new LoginPage(true);
                        this.NavigationService.Navigate(loginPage);
                        return;
                    }
                }

                lblAlert.Content    = wex.Message;
                lblAlert.Visibility = Visibility.Visible;
                return;
            }
            catch (Exception ex)
            {
                App.LogException(ex);
                lblAlert.Content    = ex.Message;
                lblAlert.Visibility = Visibility.Visible;
                return;
            }

            _rockConfig.RockBaseUrl = txtRockUrl.Text;

            switch (cboScannerInterfaceType.SelectedItem as string)
            {
            case "MagTek COM":
                _rockConfig.ScannerInterfaceType = RockConfig.InterfaceType.MICRImageRS232;
                break;

            case "MagTek Image Safe":
                _rockConfig.ScannerInterfaceType = RockConfig.InterfaceType.MagTekImageSafe;
                break;

            default:
                _rockConfig.ScannerInterfaceType = RockConfig.InterfaceType.RangerApi;
                break;
            }

            string imageOption = cboImageOption.SelectedValue as string;

            _rockConfig.Sensitivity = txtSensitivity.Text.Trim().AsInteger().ToString();
            _rockConfig.Plurality   = txtPlurality.Text.Trim().AsInteger().ToString();

            switch (imageOption)
            {
            case "Grayscale":
                _rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeGrayscale;
                break;

            case "Color":
                _rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeColor;
                break;

            default:
                _rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeBitonal;
                break;
            }

            string comPortName = cboMagTekCommPort.SelectedItem as string;

            if (!string.IsNullOrWhiteSpace(comPortName))
            {
                _rockConfig.MICRImageComPort = short.Parse(comPortName.Replace("COM", string.Empty));
            }

            var campusFilter = cboCampusFilter.SelectedItem as Campus;

            _rockConfig.CampusIdFilter = campusFilter?.Id;

            _rockConfig.Save();
            BatchPage.LoadLookups();

            // shutdown the scanner so that options will be reloaded when the batch page loads
            if (BatchPage.rangerScanner != null)
            {
                BatchPage.rangerScanner.ShutDown();
            }

            BatchPage.UnbindAllEvents();
            BatchPage.BindDeviceToPage();
            BatchPage.ConnectToScanner();
            BatchPage.LoadFinancialBatchesGrid();
            BatchPage.UpdateBatchUI(BatchPage.SelectedFinancialBatch);

            this.NavigationService.Navigate(BatchPage);
        }
All Usage Examples Of Rock.Apps.CheckScannerUtility.App::LogException