/// <summary>
 /// Checks if the specified service info is valid.
 /// </summary>
 /// <param name="serviceInfo">The reference to the Discovery service info to
 /// be validated.</param>
 /// <exception cref="T:System.ApplicationException">
 /// <paramref name="serviceInfo"/> argument is null or does not contain
 /// valid service info.</exception>
 public void Validate(DiscoveryServiceInfo serviceInfo)
 {
     if (serviceInfo != null &&
         (string.IsNullOrEmpty(serviceInfo.RestUrl)))
     {
         throw new ApplicationException(Properties.Messages.Error_InvalidRoutingConfig);
     }
 }
Ejemplo n.º 2
0
            internal static async Task <DiscoveryServiceInfo> CreateAsync()
            {
                DiscoveryServiceInfo info = new DiscoveryServiceInfo()
                {
                    // In the initial Preview release of Service Discovery, you must use a temporary Resource ID
                    //     for Service Discovery ("Microsoft.SharePoint"), which will eventually be replaced with a different value.
                    // TODO: If this Resource ID ceases to work, check for an updated value at http://go.microsoft.com/fwlink/?LinkID=392944
                    ResourceId = "Microsoft.SharePoint",

                    ApiEndpoint = "https://api.office.com/discovery/me"
                };

                info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                return(info);
            }
Ejemplo n.º 3
0
            internal async static Task <Office365ServiceInfo> CreateAsync()
            {
                // Attempt to build an Office365ServiceInfo object based on cached API endpoint & resource ID information:
                Office365ServiceInfo info = new SharePointOneDriveServiceInfo()
                {
                    ResourceId  = (string)Office365Helper.GetFromCache("SharePointOneDriveResourceId"),
                    ApiEndpoint = (string)Office365Helper.GetFromCache("SharePointOneDriveApiEndpoint")
                };

                // If the cached Resource ID and API Endpoint are not empty, then use them:
                if ((info.ResourceId != null) && (info.ApiEndpoint != null))
                {
                    info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                    return(info);
                }

                // If did not return above, invoke the Discovery Service to obtain the resource ID and API endpoint:
                DiscoveryServiceInfo discoveryServiceInfo = await DiscoveryServiceInfo.CreateAsync();

                if (!discoveryServiceInfo.HasValidAccessToken)
                {
                    // Cannot communicated with Service Discovery, so return the empty SharePointOneDriveServiceInfo as is.
                    //     The missing access token will let the caller know that the service is not ready to be used.
                    return(info);
                }

                DiscoveryResult[] results = await discoveryServiceInfo.DiscoverServicesAsync();

                DiscoveryResult myFilesEndpoint = results.First(result => result.Capability == "MyFiles");

                // Update and cache the resource ID and API endpoint:
                info.ResourceId = myFilesEndpoint.ServiceResourceId;
                // NOTE: In the initial Preview release of Service Discovery, the "MyFiles" endpoint URL will always
                //     start with something like "https://contoso-my.sharepoint.com/personal/<username>_contoso_com/_api",
                //     but the path following "/_api" may change over time.  For consistency, it is safer to manually
                //     extract the root path, and then append a call for the location of the Documents folder:
                info.ApiEndpoint = myFilesEndpoint.ServiceEndpointUri.Substring(
                    0, myFilesEndpoint.ServiceEndpointUri.IndexOf("/_api", StringComparison.Ordinal)) +
                                   "/_api/web/getfolderbyserverrelativeurl('Documents')";
                Office365Helper.SaveInCache("SharePointOneDriveResourceId", info.ResourceId);
                Office365Helper.SaveInCache("SharePointOneDriveApiEndpoint", info.ApiEndpoint);
                info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                return(info);
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="serviceSettings">Discovery service settings.</param>
        /// <param name="servers">Available arcgis-servers.</param>
        /// <param name="solveServiceValidator">Services validator.</param>
        public DiscoveryService(DiscoveryServiceInfo serviceSettings,
                                ICollection <AgsServer> servers,
                                ISolveServiceValidator solveServiceValidator)
        {
            Debug.Assert(serviceSettings != null);
            Debug.Assert(servers != null);
            Debug.Assert(solveServiceValidator != null);

            // Validate services config.
            solveServiceValidator.Validate(serviceSettings);

            _discoveryServiceConfig = serviceSettings;

            _server = ServiceHelper.FindServerByName(serviceSettings.ServerName, servers);

            // Initialize service if server was found successfully.
            if (_server != null)
            {
                Initialize();
            }
        }
Ejemplo n.º 5
0
            internal async static Task <Office365ServiceInfo> CreateAsync()
            {
                // Attempt to build an Office365ServiceInfo object based on cached API endpoint & resource ID information:
                Office365ServiceInfo info = new OneDriveServiceInfo()
                {
                    ResourceId  = (string)Office365Helper.GetFromCache("OneDriveResourceId"),
                    ApiEndpoint = (string)Office365Helper.GetFromCache("OneDriveApiEndpoint")
                };

                // If the cached Resource ID and API Endpoint are not empty, then use them:
                if ((info.ResourceId != null) && (info.ApiEndpoint != null))
                {
                    info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                    return(info);
                }

                // If did not return above, invoke the Discovery Service to obtain the resource ID and API endpoint:
                DiscoveryServiceInfo discoveryServiceInfo = await DiscoveryServiceInfo.CreateAsync();

                if (!discoveryServiceInfo.HasValidAccessToken)
                {
                    // Cannot communicated with Service Discovery, so return the empty SharePointOneDriveServiceInfo as is.
                    //     The missing access token will let the caller know that the service is not ready to be used.
                    return(info);
                }

                DiscoveryResult[] results = await discoveryServiceInfo.DiscoverServicesAsync();

                DiscoveryResult myFilesEndpoint = results.First(result => result.Capability == "MyFiles");

                // Update and cache the resource ID and API endpoint:
                info.ResourceId  = myFilesEndpoint.ServiceResourceId;
                info.ApiEndpoint = myFilesEndpoint.ServiceEndpointUri;
                Office365Helper.SaveInCache("OneDriveResourceId", info.ResourceId);
                Office365Helper.SaveInCache("OneDriveApiEndpoint", info.ApiEndpoint);
                info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                return(info);
            }