コード例 #1
0
ファイル: WebApi.cs プロジェクト: sebastiandymel/NoahMobile
        public static DiscoveryResponse Discovery(Uri resourceServerBaseAddress, string friendlyName,
                                                  ref ConnectionPreferenceType connectionpreference, string ipAddress, TimeSpan timeout)
        {
            try
            {
                Log.DebugFormat("Himsa.Noah.MobileAccessLayer.WebApi::Discovery called.");
                string path             = String.Format("api/discovery/{0}/preference/{1}", friendlyName, connectionpreference);
                var    discoveryReponse = new DiscoveryResponse {
                    RemoteHostId = Guid.Empty
                };
                if (connectionpreference == ConnectionPreferenceType.CloudOnly)
                {
                    discoveryReponse = Helpers.Get <DiscoveryResponse>(resourceServerBaseAddress, path, null, null,
                                                                       null,
                                                                       null, null, timeout);
                }
                else
                {
                    ServerList data = NoahServerUdpBrowser.BrowseForNoahServers(friendlyName, ipAddress).Result;
                    foreach (var server in data.Servers)
                    {
                        discoveryReponse = new DiscoveryResponse
                        {
                            LocalHostIpAddress = server.ServerIp,
                            RemoteHostId       = server.RemoteHostId
                        };
                    }

                    if ((connectionpreference == ConnectionPreferenceType.LocalPrefered) && (discoveryReponse.RemoteHostId == Guid.Empty))
                    {
                        discoveryReponse = Helpers.Get <DiscoveryResponse>(resourceServerBaseAddress, path, null, null,
                                                                           null,
                                                                           null, null, timeout);
                        connectionpreference = ConnectionPreferenceType.CloudOnly;
                    }
                }
                Log.DebugFormat("Himsa.Noah.MobileAccessLayer.WebApi::Discovery: {0} found.", discoveryReponse == null ? 0 : 1);
                return(discoveryReponse);
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Himsa.Noah.MobileAccessLayer.WebApi::Discovery: {0}", e);
                throw;
            }
        }
コード例 #2
0
 /// <summary>
 /// This method is used to aquire the Noah servers Remote Host Id and/or Local Host Ip Address.
 /// </summary>
 /// <param name="resourceServerBaseAddress">The base url for the OAuth authentication site in the cloud.</param>
 /// <param name="friendlyName">Friendly name. This is the Noah Mobile Alias, found in the Noah Setup.</param>
 /// <param name="connectionpreference">Preferred connection (remote, local or both).</param>
 /// <param name="timeout">Timeout. Optional. If left out, systems deafult timeout is used.</param>
 /// <returns>Returns a <see cref="DiscoveryResponse"/>.</returns>
 /// <remarks>
 ///     <list type="bullet">
 ///         <item>
 ///             <description>TThrows exception in case of error.</description>
 ///         </item>
 ///     </list>
 /// </remarks>
 public static DiscoveryResponse Discovery(Uri resourceServerBaseAddress, string friendlyName, ref ConnectionPreferenceType connectionpreference, string ipAddress, TimeSpan?timeout = null)
 {
     try
     {
         return(WebApi.Discovery(resourceServerBaseAddress, friendlyName, ref connectionpreference, ipAddress, timeout ?? WebApi.DefaultTimeout));
     }
     catch (Exception e)
     {
         Log.ErrorFormat("Himsa.Noah.MobileAccessLayer.AccessLayer::Discovery: {0}", e);
         throw;
     }
 }