Beispiel #1
0
        protected override void MapUriRequested(HttpMapTileDataSource sender, MapTileUriRequestedEventArgs args)
        {
            var deferral = args.Request.GetDeferral();

            if (!(args.ZoomLevel < 4 && Epsg == 4326))
            {
                var extent      = GetTileExtent(args.X, args.Y, args.ZoomLevel);
                var urlTemplate = string.Concat(ServiceUrl,
                                                ServiceUrl.EndsWith("?")
            ? string.Empty
            : ServiceUrl.EndsWith("&") ? string.Empty : (ServiceUrl.Contains("?") ? "&" : "?"), WmsPostFix);
                var url = string.Format(CultureInfo.InvariantCulture,
                                        urlTemplate, extent.XLow, extent.YLow, extent.XHigh, extent.YHigh, TileSize, Epsg,
                                        string.Join(",", Layers),
                                        Version, ReferenceSystemName, ImageType);

#if DEBUG
                Debug.WriteLine("Tile x={0}, y={1}, zoom={2}", args.X, args.Y, args.ZoomLevel);
                Debug.WriteLine("adding uri {0}", url);
#endif
                args.Request.Uri = new Uri(url);
            }
            deferral.Complete();
        }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        if (StopProcessing || String.IsNullOrEmpty(ServiceUrl))
        {
            // Do nothing
            StopProcessing = true;
        }
        else if (!RequestHelper.IsPostBack())
        {
            // This message is hidden by javascript as soon as possible
            ShowWarning(ResHelper.GetString("webservices.checker.initialmessage"), null, null);

            // Request javascript proxy directly to avoid logon screen redirection
            string url = URLHelper.GetAbsoluteUrl(ServiceUrl.EndsWith("/js") ? ServiceUrl : ServiceUrl.TrimEnd('/') + "/js");

            // Prepare the script
            StringBuilder actionScript = new StringBuilder();
            actionScript.Append(@"
function CheckService(){
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open('GET', ", ScriptHelper.GetString(url), @", false);
    xmlHttp.send();
    return xmlHttp.status;
}

function CheckFailed(label, message, status){
    if (", (OnCheckFailed != null).ToString().ToLowerCSafe(), @") {
        ", ControlsHelper.GetPostBackEventReference(this, "##PARAM##").Replace("'##PARAM##'", "status"), @";
    } else if ((label != null) && (label.length > 0)) {
        label.empty();
        label.append(message);
        label.show();
    }
}

function PerformServiceCheck(){
    var label = $j('#", MessagesPlaceHolder.ClientID, ClientIDSeparator, MessagesPlaceHolder.WarningLabel.ID, @"');
    label.hide();    

    var status = CheckService();
    switch (status) {
        case 404:
            CheckFailed(label, ", ScriptHelper.GetString(NotFoundText), @", status);           
            break;

        case 401:
            CheckFailed(label, ", ScriptHelper.GetString(NotAuthorizedText), @", status); 
            break;

        case 403:
            CheckFailed(label, ", ScriptHelper.GetString(DisabledText), @", status);
            break;

        case 500:
            CheckFailed(label, ", ScriptHelper.GetString(ServerErrorText), @", status);
            break;

        default:
            if (", MessagesPlaceHolder.UseRelativePlaceHolder.ToString().ToLowerCSafe(), @") {
                label.parent().hide();
            }
    }
}");
            ScriptHelper.RegisterJQuery(Page);
            ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "WebServiceChecker_" + ClientID, ScriptHelper.GetScript(actionScript.ToString()));

            ScriptHelper.RegisterStartupScript(Page, typeof(string), "PerformServiceCheck_" + ClientID, "PerformServiceCheck();", true);
        }
    }