Exemplo n.º 1
0
        async public override Task <bool> Refresh()
        {
            await base.Refresh();

            try
            {
                string server = ConfigTextStream.ExtractValue(_connectionString, "server");
                string user   = ConfigTextStream.ExtractValue(_connectionString, "user");
                string pwd    = ConfigTextStream.ExtractValue(_connectionString, "pwd");

                var url = server
                          .UrlAppendPath(this._name)
                          .UrlAppendParameters("f=json");

                if (!String.IsNullOrEmpty(user) && !String.IsNullOrEmpty(pwd))
                {
                    string token = await RequestTokenCache.RefreshTokenAsync(server, user, pwd);

                    url = url.UrlAppendParameters($"token={token}");
                }

                var jsonServices = await WebFunctions.DownloadObjectAsync <JsonServices>(url);

                if (jsonServices != null)
                {
                    if (jsonServices.Folders != null)
                    {
                        foreach (var folder in jsonServices.Folders)
                        {
                            base.AddChildObject(
                                new GeoServicesFolderExplorerObject(
                                    this._parent,
                                    this._name.UrlAppendPath(folder),
                                    _connectionString)
                                );
                        }
                    }
                    if (jsonServices.Services != null)
                    {
                        foreach (var service in jsonServices.Services.Where(s => s.Type.ToLower() == "mapserver"))
                        {
                            base.AddChildObject(
                                new GeoServicesServiceExplorerObject(
                                    this,
                                    service.ServiceName,
                                    this._name,
                                    _connectionString));
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

                return(false);
            }
        }
Exemplo n.º 2
0
        async private Task HandleTokenExceptionAsync(int i, TokenRequiredException ex)
        {
            if (i < 3)  // drei mal probieren lassen
            {
                string serviceUrl = ServiceUrl();
                string user       = ConfigTextStream.ExtractValue(ConnectionString, "user");
                string pwd        = ConfigTextStream.ExtractValue(ConnectionString, "pwd");

                _token = await RequestTokenCache.RefreshTokenAsync(serviceUrl, user, pwd, _token);
            }
            else
            {
                throw ex;
            }
        }