コード例 #1
0
        public async void licence()
        {
            // Challenge the user for portal credentials (OAuth credential request for arcgis.com)
            CredentialRequestInfo loginInfo = new CredentialRequestInfo();

            // Use the OAuth implicit grant flow
            loginInfo.GenerateTokenOptions = new GenerateTokenOptions
            {
                TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit,
            };

            // Indicate the url (portal) to authenticate with (ArcGIS Online)
            loginInfo.ServiceUri = new Uri("http://www.arcgis.com/sharing/rest");

            try
            {
                // Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler
                Credential cred = await AuthenticationManager.Current.GetCredentialAsync(loginInfo, false);

                // Connect to the portal (ArcGIS Online) using the credential
                ArcGISPortal arcgisPortal = await ArcGISPortal.CreateAsync(loginInfo.ServiceUri, cred);

                // Get LicenseInfo from the portal
                LicenseInfo licenseInfo = await arcgisPortal.GetLicenseInfoAsync();

                // ... code here to license the app immediately and/or save the license (JSON string) to take the app offline ...
                // License the app using the license info
                ArcGISRuntimeEnvironment.SetLicense(licenseInfo);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to initialize the ArcGIS Runtime with the client ID provided: " + ex.Message);

                // TODO: handle exceptions
            }
        }