Beispiel #1
0
        private void AddDefaultDrives(CmdletProvider providerInstance, ProviderRuntime runtime)
        {
            DriveCmdletProvider driveProvider = providerInstance as DriveCmdletProvider;

            if (driveProvider == null)
            {
                return;
            }

            var drives = driveProvider.InitializeDefaultDrives(runtime);

            if (drives == null)
            {
                throw new PSInvalidOperationException("The default drive collection for this null!");
            }

            if (drives.Count == 0)
            {
                drives = providerInstance.GetDriveFromProviderInfo();
            }

            foreach (PSDriveInfo driveInfo in drives)
            {
                if (driveInfo == null)
                {
                    continue;
                }
                try
                {
                    // always to global scope
                    // use NewSkipInit because the dafault drives are inited
                    _sessionState.RootSessionState.Drive.NewSkipInit(driveInfo,
                                                                     SessionStateScope <PSDriveInfo> .ScopeSpecifiers.Global.ToString());
                }
                catch
                {
                    // TODO: What should we do if the drive name is not unique?
                    // => I guess overwrite the old one and write a warning (however this works from here)
                }
            }
        }
Beispiel #2
0
        private void InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider)
        {
            List <PSDriveInfo>  drives        = new List <PSDriveInfo>();
            DriveCmdletProvider driveProvider = providerInstance as DriveCmdletProvider;

            if (driveProvider != null)
            {
                Collection <PSDriveInfo> collection = driveProvider.DoInitializeDefaultDrives();
                if ((collection != null) && (collection.Count > 0))
                {
                    drives.AddRange(collection);
                    _providersCurrentDrive[provider] = collection[0];
                }
            }

            if (drives.Count > 0)
            {
                foreach (PSDriveInfo driveInfo in drives)
                {
                    if (driveInfo != null)
                    {
                        // TODO: need to set driveInfo.Root
                        // TODO:this should be automatically called when using DriveIntrinsics.New! #providerSupport
                        driveProvider.DoNewDrive(driveInfo);

                        try
                        {
                            //always to global scope
                            _executionContext.SessionState.Drive.New(driveInfo,
                                                                     SessionStateScope <PSDriveInfo> .ScopeSpecifiers.Global.ToString());
                        }
                        catch
                        {
                            // TODO: What should we do if the drive name is not unique?
                            // => I guess overwrite the old one and write a warning (however this works from here)
                        }
                    }
                }
            }
        }
        private void InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider)
        {
            List <PSDriveInfo>  drives        = new List <PSDriveInfo>();
            DriveCmdletProvider driveProvider = providerInstance as DriveCmdletProvider;

            if (driveProvider != null)
            {
                Collection <PSDriveInfo> collection = driveProvider.DoInitializeDefaultDrives();
                if ((collection != null) && (collection.Count > 0))
                {
                    drives.AddRange(collection);
                    _providersCurrentDrive[provider] = collection[0];
                }
            }

            if (drives.Count > 0)
            {
                foreach (PSDriveInfo driveInfo in drives)
                {
                    if (driveInfo != null)
                    {
                        // TODO: need to set driveInfo.Root

                        driveProvider.DoNewDrive(driveInfo);

                        try
                        {
                            _drives.Add(driveInfo.Name, driveInfo);
                        }
                        catch
                        {
                            // TODO: What should we do if the drive name is not unique?
                        }
                    }
                }
            }
        }