Пример #1
0
        /// <summary>
        /// Initializes the specified VFS drive.
        /// </summary>
        /// <param name="drive">The drive to initialize.</param>
        /// <returns>The <see cref="VfsDriveInfo"/> object which represents the initialized drive.</returns>
        protected override VfsDriveInfo InitializeNewDrive(PSDriveInfo drive)
        {
            if (drive is OrchardDriveInfo)
            {
                return((VfsDriveInfo)drive);
            }

            var driveParameters = (OrchardDriveParameters)DynamicParameters;

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

            if (!OrchardPsSnapIn.VerifyOrchardDirectory(driveParameters.OrchardRoot))
            {
                this.WriteError(
                    ThrowHelper.InvalidRootPathException(driveParameters.OrchardRoot),
                    ErrorIds.InvalidRootDirectory,
                    ErrorCategory.InvalidArgument,
                    drive);

                return(null);
            }

            VfsDriveInfo orchardDrive = null;

            this.TryCritical(
                () => orchardDrive = this.InitializeOrchardDrive(drive, driveParameters),
                ErrorIds.OrchardInitFailed,
                ErrorCategory.OpenError);

            return(orchardDrive);
        }
Пример #2
0
        /// <summary>
        /// Gives the provider the ability to map drives after initialization.
        /// </summary>
        /// <returns>
        /// A collection of <see cref="PSDriveInfo"/> objects for each drive the provider wants to mount. If no drives
        /// should be mounted, an empty collection should be returned.
        /// </returns>
        protected override Collection <PSDriveInfo> InitializeDefaultDrives()
        {
            var drives = new Collection <PSDriveInfo>();

            this.Try(
                () =>
            {
                Assembly entryAssembly = Assembly.GetEntryAssembly();
                string path            = entryAssembly != null ? entryAssembly.Location : Environment.CurrentDirectory;

                for (var di = new DirectoryInfo(path); di != null; di = di.Parent)
                {
                    if (OrchardPsSnapIn.VerifyOrchardDirectory(di.FullName))
                    {
                        var drive           = new PSDriveInfo("Orchard", ProviderInfo, "\\", "Orchard drive", Credential);
                        var driveParameters = new OrchardDriveParameters {
                            OrchardRoot = di.FullName
                        };
                        drives.Add(InitializeOrchardDrive(drive, driveParameters));
                        break;
                    }
                }
            },
                ErrorIds.DefaultDrivesInitFailed,
                ErrorCategory.OpenError);

            return(drives);
        }