2015-02-10 39 views
0

我正在嘗試對OneDrive Windows客戶端執行非常基本的連接檢查。使用C檢查OneDrive連接性

我一直在用Live SDK玩轉,但這通常會導致我失去授權用戶和建立會話的路徑。我對任何上傳/下載功能不感興趣,也不需要將OneDrive集成到我的應用程序中。這導致我認爲SDK不是正確的路線。

有什麼想法?

回答

0

如果你只是尋找一個連接性檢查,你可能希望在網絡連接配置文件調用,在.net中是可用的,例如:

  ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); 
      if (internetConnectionProfile == null) 
      { 
       Debug.WriteLine("CanPerformODOperations: not connected to Internet"); 
       return OneDriveStatus.noInternetConnection; 
      } 

      if (App.Settings.UnrestrictedDownloads) 
      { 
       Debug.WriteLine("CanPerformODOperations: app settings set to unrestricted downloads"); 
       return OneDriveStatus.OK; 
      } 

      if (internetConnectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess) 
      { 
       Debug.WriteLine("CanPerformODOperations: not got Internet access"); 
       return OneDriveStatus.noUnrestrictedNetwork; 
      } 

      ConnectionCost cost = internetConnectionProfile.GetConnectionCost(); 
      if (cost == null || cost.NetworkCostType == NetworkCostType.Unrestricted) 
      { 
       Debug.WriteLine("CanPerformODOperations: cost is null or unrestricted"); 
       return OneDriveStatus.OK; 
      } 

      Debug.WriteLine("CanPerformODOperations: not got an unrestricted network"); 
      return OneDriveStatus.noUnrestrictedNetwork; 

,我定義爲OneDriveStatus:

public enum OneDriveStatus { unknownProblem, noInternetConnection, noUnrestrictedNetwork, OK }; 

我只嘗試登錄,如果我從這些調用中獲得OneDriveStatus.OK。