简体   繁体   English

使用C#检查OneDrive连接

[英]Checking OneDrive connectivity with C#

I am trying to perform a very basic connectivity check against the OneDrive windows client. 我正在尝试对OneDrive Windows客户端执行非常基本的连接检查。

I've been toying around with the Live SDK but that generally leads me down the path of authorizing the user and establishing a session. 我一直在玩Live SDK,但这通常会使我走上授权用户和建立会话的道路。 I am not interested in any upload/download functionality and do not need to integrate OneDrive within my app. 我对任何上传/下载功能都不感兴趣,不需要在我的应用程序中集成OneDrive。 This leads me to think that the SDK is not the proper route to go down. 这使我认为SDK不是正确的选择。

Any thoughts? 有什么想法吗?

If you are just looking for a connectivity check, you probably want to the network connection profile calls that are available in .Net, eg: 如果您只是在寻找连通性检查,则可能希望调用.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;

where I define OneDriveStatus as: 我将OneDriveStatus定义为:

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

I only attempt a login if I get OneDriveStatus.OK back from those calls. 如果从这些调用中返回OneDriveStatus.OK,则仅尝试登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM