Example #1
0
        protected override PSDriveInfo RemoveDrive(PSDriveInfo drive)
        {
            WriteVerbose($"SPOProvider::RemoveDrive (Drive.Name = ’{drive.Name}’)");

            var spoDrive = drive as SPODriveInfo;

            if (spoDrive == null)
            {
                return(null);
            }

            //Remove proxy aliases
            if (spoDrive.Provider.Drives.Count < 2)
            {
                SPOProxyImplementation.RemoveAlias(SessionState);
            }

            spoDrive.ClearState();
            return(spoDrive);
        }
Example #2
0
        protected override PSDriveInfo NewDrive(PSDriveInfo drive)
        {
            WriteVerbose($"SPOProvider::NewDrive (Drive.Name = ’{drive.Name}’, Drive.Root = ’{drive.Root}’)");

            var spoParametes = DynamicParameters as SPODriveParameters;
            Web web          = null;

            if (spoParametes?.Context != null)
            {
                var webUrl = spoParametes.Url ?? spoParametes.Context.Url;
                web = spoParametes.Context.Clone(webUrl).Web;
            }
            else if (spoParametes?.Web != null)
            {
                var webUrl = spoParametes.Url ?? spoParametes.Web.EnsureProperty(w => w.Url);
                web = spoParametes.Web.Context.Clone(webUrl).Web;
            }
            else if (PnPConnection.Current != null)
            {
                var webUrl = spoParametes?.Url ?? PnPConnection.Current.Context.Web.EnsureProperty(w => w.Url);
                web = PnPConnection.Current.Context.Clone(webUrl).Web;
            }
            else
            {
                WriteErrorInternal(PnPResources.NoSharePointConnection, drive.Root, ErrorCategory.ConnectionError);
            }

            if (web != null)
            {
#if DEBUG
                SetCounter(web.Context);
#endif
                var itemTimeout   = (spoParametes != null && spoParametes.ItemCacheTimeout != default(int)) ? spoParametes.ItemCacheTimeout : DefaultItemCacheTimeout;
                var webTimeout    = (spoParametes != null && spoParametes.WebCacheTimeout != default(int)) ? spoParametes.WebCacheTimeout : DefaultWebCacheTimeout;
                var normalizePath = NormalizePath(IsPropertyAvailable(web, "ServerRelativeUrl") ? web.ServerRelativeUrl : web.EnsureProperty(w => w.ServerRelativeUrl));

                //Set root to host root and current location to normalized path
                var normalizedDrive = new SPODriveInfo(new PSDriveInfo(drive.Name, drive.Provider, "/", drive.Description, drive.Credential, drive.DisplayRoot))
                {
                    Web             = web,
                    ItemTimeout     = itemTimeout,
                    WebTimeout      = webTimeout,
                    CurrentLocation = normalizePath
                };

                //Add web to cache
                normalizedDrive.CachedWebs.Add(new SPODriveCacheWeb
                {
                    Web         = normalizedDrive.Web,
                    LastRefresh = DateTime.Now,
                    Path        = normalizePath
                });

                //Add proxy aliases
                if (spoParametes == null || !spoParametes.NoProxyCmdLets)
                {
                    SPOProxyImplementation.AddAlias(SessionState);
                }
                return(normalizedDrive);
            }
            return(null);
        }