Assembly tryResolveAssembly(DirectoryInfoBase directory, ResolveEventArgs args)
        {
            try {
                if (directory.Exists)
                {
                    var files = directory.GetFiles("*.dll")
                                .Concat(directory.GetFiles("*.exe"));

                    foreach (var f in files)
                    {
                        var assemblyName = AssemblyName.GetAssemblyName(f.FullName);

                        if (assemblyName.FullName == args.Name)
                        {
                            return(Assembly.Load(assemblyName));
                        }
                    }
                }
            }
            catch (Exception ex) {
                log.WarnException("Could not resolve assembly: " + args.Name, ex);
            }

            return(null);
        }
Exemple #2
0
            public void SetsTemporaryFileAsSongPath()
            {
                var fileSystem = new MockFileSystem();
                var metadata   = new NetworkSong();

                var song = MobileSong.Create(metadata, Observable.Never <byte[]>(), fileSystem);

                DirectoryInfoBase tempDir = fileSystem.DirectoryInfo.FromDirectoryName(fileSystem.Path.GetTempPath());

                Assert.Equal(song.OriginalPath, tempDir.GetFiles().First().FullName);
                Assert.Equal(song.PlaybackPath, tempDir.GetFiles().First().FullName);
            }
Exemple #3
0
 internal static FileInfoBase[] GetFilesWithRetry(this DirectoryInfoBase info)
 {
     return(OperationManager.Attempt(() =>
     {
         return info.GetFiles();
     }));
 }
Exemple #4
0
        public FileInfoBase FromFileName(string fileName)
        {
            FileInfo fileInfo = new FileInfo(fileName);

            lock (_files)
            {
                VfsFileInfo file;
                if (!_files.TryGetValue(fileInfo.FullName, out file))
                {
                    DirectoryInfoBase info = _fileSystem.DirectoryInfo.FromDirectoryName(fileInfo.Directory.FullName);
                    if (info.Exists)
                    {
                        file = (VfsFileInfo)info.GetFiles().Where(f => f.Name == fileInfo.Name).FirstOrDefault();
                        if (file == null)
                        {
                            file = new VfsFileInfo(_fileSystem, fileInfo);
                        }
                    }
                    else
                    {
                        file = new VfsFileInfo(_fileSystem, fileInfo);
                    }

                    _files[fileInfo.FullName] = file;
                }
                return(file);
            }
        }
        private bool CollectFiles(DirectoryInfoBase directory, INode rootNode, GeneralTree <INode> tree)
        {
            List <INode> collectedNodes = new List <INode>();

            foreach (FileInfoBase file in directory.GetFiles().Where(file => this.relevantFileDetector.IsRelevant(file)))
            {
                INode node = null;
                try
                {
                    node = this.featureNodeFactory.Create(rootNode.OriginalLocation, file);
                }
                catch (Exception)
                {
                    if (log.IsWarnEnabled)
                    {
                        log.Warn("The file, {0}, will be ignored because it could not be read in properly", file.FullName);
                    }
                }

                if (node != null)
                {
                    collectedNodes.Add(node);
                }
            }

            foreach (var node in OrderFileNodes(collectedNodes))
            {
                tree.Add(node);
            }

            return(collectedNodes.Count > 0);
        }
Exemple #6
0
        internal static Dictionary <string, FileInfoBase> GetJobDirectoryFileMap(string sourceDirectory)
        {
            DirectoryInfoBase jobBinariesDirectory = FileSystemHelpers.DirectoryInfoFromDirectoryName(sourceDirectory);

            FileInfoBase[] files = jobBinariesDirectory.GetFiles("*.*", SearchOption.AllDirectories);

            int sourceDirectoryPathLength = sourceDirectory.Length + 1;

            return(files.ToDictionary(p => p.FullName.Substring(sourceDirectoryPathLength), q => q, StringComparer.OrdinalIgnoreCase));
        }
        private static FileInfoBase[] FindAllCsprojFiles(DirectoryInfoBase directory)
        {
            FileInfoBase[] fileInfos = directory.GetFiles("*.csproj", SearchOption.TopDirectoryOnly);
            if (fileInfos.Length == 0)
            {
                SystemContext.ConsoleErrorWriteLine("No csproj file found for default namespace. Please specify a namespace as a command argument.");
                throw new FileNotFoundException();
            }

            return(fileInfos);
        }
Exemple #8
0
    public void DoSomething()
    {
        // The directory can be determined at runtime.
        // It could, for example, be provided by another service.
        string directory = @"C:\SomeWhere\";

        // Create an instance of the DirectoryInfoWrapper concrete type.
        DirectoryInfoBase directoryInfo = this.fileSystem.DirectoryInfo.FromDirectoryName(directory);
        // Do something with the directory (it has the exact same interface as
        // System.IO.DirectoryInfo).
        var files = directoryInfo.GetFiles();
    }
 private IEnumerable <KeyValuePair <string, string> > ExpandDirectory(
     DirectoryInfoBase directoryInfo,
     string phonePath)
 {
     foreach (var item in directoryInfo.GetFiles("*", SearchOption.AllDirectories))
     {
         var relativePath = MakeRelative(item, directoryInfo);
         yield return
             (new KeyValuePair <string, string>(
                  item.FullName,
                  this.fileSystem.Path.Combine(phonePath, relativePath)));
     }
 }
Exemple #10
0
        private static string TryReadNpmVersion(DirectoryInfoBase nodeDir)
        {
            var npmRedirectionFile = nodeDir.GetFiles("npm.txt").FirstOrDefault();

            if (npmRedirectionFile == null)
            {
                return(null);
            }
            using (StreamReader reader = new StreamReader(npmRedirectionFile.OpenRead()))
            {
                return(reader.ReadLine());
            }
        }
Exemple #11
0
        private static int CalculateHashForJob(string jobBinariesPath)
        {
            var updateDatesString = new StringBuilder();
            DirectoryInfoBase jobBinariesDirectory = FileSystemHelpers.DirectoryInfoFromDirectoryName(jobBinariesPath);

            FileInfoBase[] files = jobBinariesDirectory.GetFiles("*.*", SearchOption.AllDirectories);
            foreach (FileInfoBase file in files)
            {
                updateDatesString.Append(file.LastWriteTimeUtc.Ticks);
            }

            return(updateDatesString.ToString().GetHashCode());
        }
Exemple #12
0
        public void DeleteContents(string path)
        {
            DirectoryInfoBase directory = fileSystem.DirectoryInfo.FromDirectoryName(path);

            foreach (FileInfoBase file in directory.GetFiles().Where(file => !UndeletableRootNames.Contains(file.Name)))
            {
                file.Delete();
            }

            foreach (DirectoryInfoBase childDirectory in directory.GetDirectories().Where(childDirectory => !UndeletableRootNames.Contains(childDirectory.Name)))
            {
                childDirectory.Delete(true);
            }
        }
        private bool CollectFiles(DirectoryInfoBase directory, INode rootNode, Tree tree)
        {
            List <INode> collectedNodes = new List <INode>();

            foreach (FileInfoBase file in directory.GetFiles().Where(file => this.relevantFileDetector.IsRelevant(file)))
            {
                INode node = this.featureNodeFactory.Create(rootNode.OriginalLocation, file);
                collectedNodes.Add(node);
            }

            foreach (var node in OrderFileNodes(collectedNodes))
            {
                tree.Add(node);
            }

            return(collectedNodes.Count > 0);
        }
Exemple #14
0
        protected void CopyDirectory(DirectoryInfoBase source, DirectoryInfoBase target)
        {
            var fs = this.FileSystem;

            fs.Directory.CreateDirectory(target.FullName);

            foreach (var file in source.GetFiles())
            {
                fs.File.Copy(file.FullName, fs.Path.Combine(target.FullName, file.Name), true);
            }

            foreach (var directory in source.GetDirectories())
            {
                var nextTargetSubDir = target.CreateSubdirectory(directory.Name);
                CopyDirectory(directory, nextTargetSubDir);
            }
        }
            public IEnumerable <FileInfoBase> FindLogFiles()
            {
                if (!_directory.Exists)
                {
                    return(new List <FileInfoBase>());
                }

                var files = _directory.GetFiles(LogFilenamePattern, SearchOption.TopDirectoryOnly)
                            .Where(f => !f.FullName.EndsWith(LogErrorsSuffix, StringComparison.OrdinalIgnoreCase))
                            .OrderByDescending(f => f.LastWriteTimeUtc)
                            .Take(FileOpenLimit)
                            .ToList();

                var fileNames = files.Select(f => f.FullName);

                // Remove any deleted files
                var newIncludedFiles = new HashSet <string>(IncludedFiles.Intersect(fileNames));
                var newExcludedFiles = new HashSet <string>(ExcludedFiles.Intersect(fileNames));

                foreach (var file in files)
                {
                    if (newIncludedFiles.Contains(file.FullName) || newExcludedFiles.Contains(file.FullName))
                    {
                        continue;
                    }

                    var line = ReadFirstLine(file);
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        if (IsLineInExpectedFormat(line))
                        {
                            newIncludedFiles.Add(file.FullName);
                        }
                        else
                        {
                            newExcludedFiles.Add(file.FullName);
                        }
                    }
                }

                var results = files.Where(f => newIncludedFiles.Contains(f.FullName));

                IncludedFiles = newIncludedFiles;
                ExcludedFiles = newExcludedFiles;
                return(results);
            }
Exemple #16
0
        private bool CollectFiles(DirectoryInfoBase directory, INode rootNode, GeneralTree <INode> tree)
        {
            List <INode> collectedNodes = new List <INode>();

            foreach (FileInfoBase file in directory.GetFiles().Where(file => this.relevantFileDetector.IsRelevant(file)))
            {
                INode node = null;
                try
                {
                    node = this.featureNodeFactory.Create(rootNode.OriginalLocation, file);
                }
                catch (Exception ex)
                {
                    if (Log.IsWarnEnabled)
                    {
                        // retrieving the name as file.FullName may trigger an exception if the FullName is too long
                        // so we retreive Name and DirectoryName separately
                        // https://github.com/picklesdoc/pickles/issues/199
                        var fullName = file.Name + " in directory " + file.DirectoryName;
                        Log.Warn("The file {0} will be ignored because it could not be read in properly", fullName);
                    }

                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug(ex, "Exception received");
                    }
                }

                if (node != null)
                {
                    collectedNodes.Add(node);
                }
            }

            foreach (var node in OrderFileNodes(collectedNodes))
            {
                tree.Add(node);
            }

            return(collectedNodes.Count > 0);
        }
Exemple #17
0
        internal static void Copy(string sourcePath,
                                  string destinationPath,
                                  DirectoryInfoBase sourceDirectory,
                                  DirectoryInfoBase destinationDirectory,
                                  Func <string, DirectoryInfoBase> createDirectoryInfo,
                                  bool skipScmFolder)
        {
            // Skip hidden directories and directories that begin with .
            if (skipScmFolder && IsSourceControlFolder(sourceDirectory))
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
            }

            foreach (var sourceFile in sourceDirectory.GetFiles())
            {
                string path = GetDestinationPath(sourcePath, destinationPath, sourceFile);

                sourceFile.CopyTo(path, overwrite: true);
            }


            var destDirectoryLookup = GetDirectories(destinationDirectory);

            foreach (var sourceSubDirectory in sourceDirectory.GetDirectories())
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = createDirectoryInfo(path);
                }

                Copy(sourcePath, destinationPath, sourceSubDirectory, targetSubDirectory, createDirectoryInfo, skipScmFolder);
            }
        }
Exemple #18
0
        private void RebuildFromFolder(SubscriptionInfo subscriptionInfo, string folderPath, bool restricted, int startPercent = 0, int endPercent = 100)
        {
            if (folderPath == null)
            {
                throw new ArgumentNullException(nameof(folderPath));
            }

            using (IDbConnection db = _dbConnectionFactory.Open())
            {
                DirectoryInfoBase directoryInfo = _fileSystem.DirectoryInfo.FromDirectoryName(folderPath);
                FileInfoBase[]    files         = directoryInfo.GetFiles("*.mp3", SearchOption.AllDirectories);

                int index = 0;
                foreach (IGrouping <string, FileInfoBase> albumFiles in files.GroupBy(f => f.DirectoryName))
                {
                    using (IDbTransaction transaction = db.OpenTransaction())
                    {
                        _logger.Debug("Fetching album");
                        DbAlbum album = db.Single <DbAlbum>(a => a.Path == albumFiles.Key);

                        foreach (FileInfoBase file in albumFiles)
                        {
                            int progress =
                                (int)Math.Round((index + 1) / (double)files.Length * (endPercent - startPercent)) +
                                startPercent;
                            PublishProgress(subscriptionInfo, progress);
                            _logger.DebugFormat("Processing file {0}", file.FullName);
                            DbRecording recording;

                            bool saveTagFile = false;

                            _logger.Debug("Reading tag file");
                            using (File tagFile = File.Create(_fileAbstractionFactory(file.FullName, true)))
                            {
                                string recordingId = tagFile.GetCustomField(SoundWordsRecordingIdField);
                                if (recordingId != null)
                                {
                                    _logger.Debug("Fetching recording");
                                    recording = db.Single <DbRecording>(r => r.Uid == recordingId) ?? new DbRecording {
                                        Uid = recordingId
                                    };
                                }
                                else
                                {
                                    recording = new DbRecording {
                                        Uid = Guid.NewGuid().ToString("N")
                                    };
                                    saveTagFile = true;
                                    tagFile.SetCustomField(SoundWordsRecordingIdField, recording.Uid);
                                }

                                if (album == null)
                                {
                                    string uid = tagFile.GetCustomField(SoundWordsAlbumIdField) ?? Guid.NewGuid().ToString("N");

                                    album = new DbAlbum
                                    {
                                        Uid        = uid,
                                        Name       = (tagFile.Tag.Album ?? "Ukjent").Trim(),
                                        Path       = albumFiles.Key,
                                        Restricted = restricted
                                    };
                                }

                                UpdateAttachments(albumFiles.Key, album);

                                if (album.Id != 0)
                                {
                                    _logger.Debug("Saving album");
                                    db.Update(album);
                                }
                                else
                                {
                                    _logger.Debug("Creating album");
                                    album.Id = db.Insert(album, true);
                                }

                                if (tagFile.GetCustomField(SoundWordsAlbumIdField) != album.Uid)
                                {
                                    tagFile.SetCustomField(SoundWordsAlbumIdField, album.Uid);
                                    saveTagFile = true;
                                }

                                recording.AlbumId    = album.Id;
                                recording.Title      = (tagFile.Tag.Title ?? "Ukjent").Trim();
                                recording.Track      = (ushort)tagFile.Tag.Track;
                                recording.Comment    = tagFile.Tag.Comment;
                                recording.Year       = tagFile.Tag.Year != 0 ? (ushort?)tagFile.Tag.Year : null;
                                recording.Path       = file.FullName;
                                recording.Restricted = restricted;

                                if (recording.Id == 0)
                                {
                                    _logger.DebugFormat("Creating recording: {0}", recording.Dump());
                                    recording.Id = db.Insert(recording, true);
                                }
                                else
                                {
                                    _logger.DebugFormat("Saving recording: {0}", recording.Dump());
                                    db.Update(recording);
                                }

                                db.Delete <DbRecordingSpeaker>(rs => rs.RecordingId == recording.Id);

                                foreach (string performer in tagFile.Tag.Performers)
                                {
                                    _logger.DebugFormat($"Creating speaker {performer}");
                                    NameInfo  nameInfo = performer.ToNameInfo();
                                    DbSpeaker speaker  = db.Single <DbSpeaker>(s =>
                                                                               s.FirstName == nameInfo.FirstName && s.LastName == nameInfo.LastName);

                                    if (speaker == null)
                                    {
                                        speaker = new DbSpeaker
                                        {
                                            Uid       = Guid.NewGuid().ToString("N"),
                                            FirstName = nameInfo.FirstName,
                                            LastName  = nameInfo.LastName
                                        };

                                        speaker.Id = db.Insert(speaker, true);
                                    }

                                    if (!db.Exists <DbRecordingSpeaker>(rs =>
                                                                        rs.RecordingId == recording.Id && rs.SpeakerId == speaker.Id))
                                    {
                                        db.Insert(new DbRecordingSpeaker
                                        {
                                            RecordingId = recording.Id,
                                            SpeakerId   = speaker.Id
                                        });
                                    }
                                }

                                if (saveTagFile)
                                {
                                    _logger.Debug("Writing ID tag data");
                                    tagFile.Save();
                                }
                            }

                            index++;
                        }

                        _logger.Info("Committing transaction");
                        transaction.Commit();
                    }
                }
            }
        }
Exemple #19
0
 static IEnumerable <FileInfoBase> GetDeletableFiles(DirectoryInfoBase parentDirectory)
 {
     return(parentDirectory.GetFiles().Where(IsDeletable));
 }