コード例 #1
0
 public SPOSiteContext(CmdletContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     this.Context = context;
 }
コード例 #2
0
        internal static SPOSiteContext InstantiateSPOSiteContext(Uri url, PSCredential credentials, PSHost host, bool isNetworkCredentials)
        {
            if (!IsValidServerVersion(url))
            {
                throw new InvalidOperationException("Could not connect to SharePoint Online: unsupported version of service.");
            }
            CmdletContext context = new CmdletContext(url.AbsoluteUri, host);
            if (isNetworkCredentials)
            {
                context.AuthenticationMode = ClientAuthenticationMode.Default;
                context.Credentials = credentials.GetNetworkCredential();
            }
            else
            {
                context.Credentials = new SharePointOnlineCredentials(credentials.UserName, credentials.Password);
            }

            if (context.HasPendingRequest)
                context.ExecuteQuery();
            return new SPOSiteContext(context);
        }