Back to Devexpress

RequestResultBase.ResultCode Property

windowsforms-devexpress-dot-xtramap-dot-requestresultbase.md

latest11.5 KB
Original Source

RequestResultBase.ResultCode Property

Returns the code that contains information on whether or not the last request was successful.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public RequestResultCode ResultCode { get; }
vb
Public ReadOnly Property ResultCode As RequestResultCode

Property Value

TypeDescription
RequestResultCode

A RequestResultCode enumeration value.

|

Available values:

NameDescription
Success

The request was successful.

| | BadRequest |

The request was incorrect.

| | ServerError |

The request was unsuccessful because of a server error.

| | Timeout |

The request was terminated because the time was out.

|

Example

To manually generate map items for received GIS data, do the following.

csharp
using DevExpress.XtraEditors;
using DevExpress.XtraMap;
using System;
using System.Text;

namespace MapControl_SearchProcessing {
    public partial class Form1 : XtraForm {

        string BingKey { get { return "YourBingKey"; } }

        public Form1() {
            InitializeComponent();
            SearchProvider.SearchCompleted += OnSearchCompleted;
            SearchLayer.DataRequestCompleted += OnDataRequestCompleted;
            BingMapDataProvider.BingKey = BingKey;
            SearchProvider.BingKey = BingKey;
        }

        private void btnSearch_Click(object sender, EventArgs e) {
            SearchProvider.Search(teKeyword.Text);
        }

        #region #SearchResultProcessing
        void OnSearchCompleted(object sender, BingSearchCompletedEventArgs e) {
            if(e.Cancelled) return;
            if(e.RequestResult.ResultCode != RequestResultCode.Success) {
                meResult.Text = "The Bing Search service does not work for this location.";
                return;
            }

            StringBuilder resultList = new StringBuilder("");
            int resCounter = 1;
            foreach(BingLocationInformation resultInfo in e.RequestResult.SearchResults) {
                resultList.Append(String.Format("Result {0}: \r\n", resCounter));
                resultList.Append(String.Format("Name: {0}\r\n", resultInfo.DisplayName));              
                resultList.Append(String.Format("Address: {0}\r\n", resultInfo.Address.FormattedAddress));
                resultList.Append(String.Format("Confidence level: {0}\r\n", resultInfo.Confidence));
                resultList.Append(String.Format("Geographic coordinates: {0}\r\n", resultInfo.Location));
                resultList.Append(String.Format("Match code: {0}\r\n", resultInfo.MatchCode));
                resultList.Append(String.Format(" ______________________________ \r\n"));
                resCounter++;
            }
            meResult.Text = resultList.ToString();
        }
        #endregion #SearchResultProcessing

        void OnDataRequestCompleted(object sender, RequestCompletedEventArgs e) {
            mapControl.ZoomToFitLayerItems(0.4);
        }
    }
}
csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MapControl_SearchProcessing {
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraMap
Imports System
Imports System.Text

Namespace MapControl_SearchProcessing
    Partial Public Class Form1
        Inherits XtraForm

        Private ReadOnly Property BingKey() As String
            Get
                Return "YourBingKey"
            End Get
        End Property

        Public Sub New()
            InitializeComponent()
            AddHandler SearchProvider.SearchCompleted, AddressOf OnSearchCompleted
            AddHandler SearchLayer.DataRequestCompleted, AddressOf OnDataRequestCompleted
            BingMapDataProvider.BingKey = BingKey
            SearchProvider.BingKey = BingKey
        End Sub

        Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
            SearchProvider.Search(teKeyword.Text)
        End Sub

        #Region "#SearchResultProcessing"
        Private Sub OnSearchCompleted(ByVal sender As Object, ByVal e As BingSearchCompletedEventArgs)
            If e.Cancelled Then
                Return
            End If
            If e.RequestResult.ResultCode <> RequestResultCode.Success Then
                meResult.Text = "The Bing Search service does not work for this location."
                Return
            End If

            Dim resultList As New StringBuilder("")
            Dim resCounter As Integer = 1
            For Each resultInfo As BingLocationInformation In e.RequestResult.SearchResults
                resultList.Append(String.Format("Result {0}: " & ControlChars.CrLf, resCounter))
                resultList.Append(String.Format("Name: {0}" & ControlChars.CrLf, resultInfo.DisplayName))
                resultList.Append(String.Format("Address: {0}" & ControlChars.CrLf, resultInfo.Address.FormattedAddress))
                resultList.Append(String.Format("Confidence level: {0}" & ControlChars.CrLf, resultInfo.Confidence))
                resultList.Append(String.Format("Geographic coordinates: {0}" & ControlChars.CrLf, resultInfo.Location))
                resultList.Append(String.Format("Match code: {0}" & ControlChars.CrLf, resultInfo.MatchCode))
                resultList.Append(String.Format(" ______________________________" & ControlChars.CrLf))
                resCounter += 1
            Next resultInfo
            meResult.Text = resultList.ToString()
        End Sub
        #End Region ' #SearchResultProcessing

        Private Sub OnDataRequestCompleted(ByVal sender As Object, ByVal e As RequestCompletedEventArgs)
            mapControl.ZoomToFitLayerItems(0.4)
        End Sub
    End Class
End Namespace
vb
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Threading.Tasks
Imports System.Windows.Forms

Namespace MapControl_SearchProcessing
    Friend NotInheritable Class Program

        Private Sub New()
        End Sub

        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        <STAThread> _
        Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Application.Run(New Form1())
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the ResultCode property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-map-execute-the-search-operation-for-multiple-locations/CS/GetSearchLocationAdditionalInfo/Form1.cs#L47

csharp
SearchRequestResult result = e.RequestResult;
if (result.ResultCode == RequestResultCode.Success) {
    List<LocationInformation> regions = result.SearchResults;

winforms-map-get-geo-point-info-from-bing-geocode-service/CS/RequestLocationInformation/Form1.cs#L76

csharp
if(e.Cancelled == true) return;
if(e.Result.ResultCode != RequestResultCode.Success) {
    meResult.Text = "The Bing Geocode service does not work for this location.";

map-for-winforms-azure-geocoding/CS/AzureGeocoding/Form1.cs#L73

csharp
if (e.Cancelled == true) return;
if (e.Result.ResultCode != RequestResultCode.Success) {
    memoEdit1.Text = "The Azure Geocode service does not work for this location.";

winforms-map-execute-the-search-operation-for-multiple-locations/VB/GetSearchLocationAdditionalInfo/Form1.vb#L47

vb
Dim result As SearchRequestResult = e.RequestResult
If result.ResultCode = RequestResultCode.Success Then
    Dim regions As List(Of LocationInformation) = result.SearchResults

winforms-map-get-geo-point-info-from-bing-geocode-service/VB/RequestLocationInformation/Form1.vb#L81

vb
If e.Cancelled = True Then Return
If e.Result.ResultCode <> RequestResultCode.Success Then
    meResult.Text = "The Bing Geocode service does not work for this location."

map-for-winforms-azure-geocoding/VB/AzureGeocoding/Form1.vb#L79

vb
If (e.Cancelled) Then Return
If (e.Result.ResultCode <> RequestResultCode.Success) Then
    memoEdit1.Text = "The Azure Geocode service does not work for this location."

See Also

RequestResultBase Class

RequestResultBase Members

DevExpress.XtraMap Namespace