Exemple #1
0
 public SharePointSessionFactory(SharePointSessionInfo info, int initCount)
 {
     this.Generator  = new SharePointSessionGenerator(info);
     this.ObjectPool = new ObjectPool <SharePointSession>(this.Generator);
     if (initCount > 0)
     {
         List <ObjectPool <SharePointSession> .Ref> cache = new List <ObjectPool <SharePointSession> .Ref>();
         // Pre-cache the items...
         for (int i = 0; i < initCount; i++)
         {
             ObjectPool <SharePointSession> .Ref r = this.ObjectPool.GetObject();
             cache.Add(r);
         }
         // Now return them to the pool
         foreach (ObjectPool <SharePointSession> .Ref r in cache)
         {
             r.Dispose();
         }
     }
 }
Exemple #2
0
        public SharePointSession(SharePointSessionInfo info)
        {
            if (!string.IsNullOrWhiteSpace(info.ApplicationId))
            {
                this.ClientContext = new OfficeDevPnP.Core.AuthenticationManager().GetAzureADAppOnlyAuthenticatedContext(info.Url, info.ApplicationId, info.Domain, info.CertificateKey, info.CertificatePass);
                // this.ClientContext = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(info.Url, info.ApplicationId, info.CertificatePass);

                // this.ClientContext = new OfficeDevPnP.Core.AuthenticationManager().GetSharePointOnlineAuthenticatedContextTenant(info.Url, info.UserName + "@" + info.Domain, info.Password);

                // this.ClientContext.Credentials = new SharePointOnlineCredentials(info.UserName + "@" + info.Domain, info.Password);
            }
            else
            {
                // this.ClientContext = new ClientContext(info.Url);
                // this.ClientContext.Credentials = new NetworkCredential(info.UserName, info.Password, info.Domain);

                // This one pops up the authentication window where one can log in with MFA
                this.ClientContext = new OfficeDevPnP.Core.AuthenticationManager().GetWebLoginClientContext(info.Url);

                // Will this support app passwords?
                // this.ClientContext = new OfficeDevPnP.Core.AuthenticationManager().GetSharePointOnlineAuthenticatedContextTenant(info.Url, info.UserName, info.Password);
            }
            this.DocumentLibrary = this.ClientContext.Web.Lists.GetByTitle(info.Library);
            this.ClientContext.Load(this.DocumentLibrary, r => r.ForceCheckout, r => r.EnableVersioning, r => r.EnableMinorVersions, r => r.Title, r => r.ContentTypesEnabled, r => r.ContentTypes);
            this.ClientContext.Load(this.DocumentLibrary.RootFolder, f => f.ServerRelativeUrl, f => f.Name);
            this.ClientContext.Load(this.ClientContext.Web, w => w.Title, w => w.RoleDefinitions);
            ExecuteQuery();
            this.RootFolder = this.DocumentLibrary.RootFolder;
            this.BaseUrl    = this.RootFolder.ServerRelativeUrl;
            string user = info.UserName;

            if (user == null)
            {
                user = "******";
            }
            if (info.Domain != null)
            {
                user = string.Format("{0}\\{1}", info.Domain, user);
            }
            this.Id = string.Format("SHPT[{0}@{1}#{2}]", user, this.ClientContext.Url, Interlocked.Increment(ref counter));
        }
Exemple #3
0
 public SharePointSessionFactory(SharePointSessionInfo info) : this(info, 0)
 {
 }
Exemple #4
0
 public SharePointSessionGenerator(SharePointSessionInfo info)
 {
     this.Info = info;
 }