Пример #1
0
        public SimplePackage(IPackageBuilder packageBuilder)
        {
            if (packageBuilder == null)
            {
                throw new ArgumentNullException("packageBuilder");
            }

            Id         = packageBuilder.Id;
            Version    = packageBuilder.Version;
            Title      = packageBuilder.Title;
            Authors    = new SafeEnumerable <string>(packageBuilder.Authors);
            Owners     = new SafeEnumerable <string>(packageBuilder.Owners);
            IconUrl    = packageBuilder.IconUrl;
            LicenseUrl = packageBuilder.LicenseUrl;
            ProjectUrl = packageBuilder.ProjectUrl;
            RequireLicenseAcceptance = packageBuilder.RequireLicenseAcceptance;
            DevelopmentDependency    = packageBuilder.DevelopmentDependency;
            Description               = packageBuilder.Description;
            Summary                   = packageBuilder.Summary;
            ReleaseNotes              = packageBuilder.ReleaseNotes;
            Language                  = packageBuilder.Language;
            Tags                      = packageBuilder.Tags;
            FrameworkAssemblies       = new SafeEnumerable <FrameworkAssemblyReference>(packageBuilder.FrameworkAssemblies);
            DependencySets            = new SafeEnumerable <PackageDependencySet>(packageBuilder.DependencySets);
            PackageAssemblyReferences = new SafeEnumerable <PackageReferenceSet>(packageBuilder.PackageAssemblyReferences);
            Copyright                 = packageBuilder.Copyright;
            _packageBuilder           = packageBuilder;
        }
        public IEnumerator <FileSyDirectoryInfo> GetEnumerator()
        {
            if (rootPath == null || !rootPath.Exists || rootDirectory.Value == null)
            {
                yield break;
            }

            IEnumerable <DirectoryInfo> matches = SafeEnumerable.Wrap(() =>
                                                                      enumerateOptions.Option == SearchOption.AllDirectories && pattern == "*"
                    ? rootPath.EnumerateDirectories(pattern, SearchOption.TopDirectoryOnly).ToArray()
                    : rootPath.EnumerateDirectories(pattern, SearchOption.TopDirectoryOnly));

            foreach (var directory in matches)
            {
                if (!parentDirectory.HasValue)
                {
                    parentDirectory = Optional.Wrap(Try.Execute(
                                                        () => rootPath.Parent == null ? null : new ManagedFileSyDirectoryInfo(rootPath.Parent), null));
                }

                yield return(new ManagedFileSyDirectoryInfo(directory, parentDirectory));
            }

            if (enumerateOptions.Option != SearchOption.AllDirectories)
            {
                yield break;
            }

            var subfolderMatches = pattern == "*"
                ? matches
                : SafeEnumerable.Wrap(() => rootPath.EnumerateDirectories("*", SearchOption.TopDirectoryOnly));

            foreach (var subfolder in subfolderMatches)
            {
                if (!enumerateOptions.EnumerateReparse && (subfolder.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
                {
                    continue;
                }

                var fileSystemInfos = new ManagedFileSyDirectoryEnumerable(subfolder, pattern, enumerateOptions, rootDirectory);

                foreach (var match in fileSystemInfos)
                {
                    yield return(match);
                }
            }
        }
        public IEnumerator <FileSyInfo> GetEnumerator()
        {
            if (rootPath == null || !rootPath.Exists || rootDirectory.Value == null)
            {
                yield break;
            }

            var fileMatches = SafeEnumerable.Wrap(() => rootPath.EnumerateFiles(pattern, SearchOption.TopDirectoryOnly));

            foreach (var file in fileMatches)
            {
                if (!parentDirectory.HasValue)
                {
                    parentDirectory = Optional.Wrap(Try.Execute(
                                                        () => rootPath.Parent == null ? null : new ManagedFileSyDirectoryInfo(rootPath.Parent), null));
                }

                yield return(new ManagedFileSyFileInfo(file, parentDirectory));
            }

            if (enumerateOptions.Option == SearchOption.TopDirectoryOnly)
            {
                yield break;
            }

            var subfolders = SafeEnumerable.Wrap(() => rootPath.EnumerateDirectories(pattern, SearchOption.TopDirectoryOnly));

            foreach (var subfolder in subfolders)
            {
                var subFolderInfo = new ManagedFileSyDirectoryInfo(subfolder, rootDirectory);

                yield return(subFolderInfo);

                if (!enumerateOptions.EnumerateReparse && (subfolder.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
                {
                    continue;
                }

                var fileSystemInfos = new ManagedFileSyFileSystemEnumerable(subfolder, pattern, enumerateOptions, rootDirectory);

                foreach (var entry in fileSystemInfos)
                {
                    yield return(entry);
                }
            }
        }