private void ExecuteWildCardFileOperation(ClientDatabaseBase <HistorianKey, HistorianValue> database, string fileName, Action <List <Guid> > fileOperation)
        {
            HashSet <string> sourceFiles = new HashSet <string>(FilePath.GetFileList(fileName).Select(Path.GetFullPath), StringComparer.OrdinalIgnoreCase);
            List <Guid>      files       = database.GetAllAttachedFiles().Where(file => sourceFiles.Contains(Path.GetFullPath(file.FileName))).Select(file => file.Id).ToList();

            fileOperation(files);
        }
        private void m_dailyTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                ClientDatabaseBase <HistorianKey, HistorianValue> database = GetClientDatabase();

                // Get list of files that have both a start time and an end time that are greater than the maximum archive days. We check both start and end times
                // since PMUs can provide bad time (not currently being filtered) and you don't want to accidentally delete a file with otherwise in-range data.
                ArchiveDetails[] filesToDelete = database.GetAllAttachedFiles().Where(file => (DateTime.UtcNow - file.StartTime).TotalDays > MaximumArchiveDays && (DateTime.UtcNow - file.EndTime).TotalDays > MaximumArchiveDays).ToArray();
                database.DeleteFiles(filesToDelete.Select(file => file.Id).ToList());
                OnStatusMessage("Deleted the following old archive files:\r\n    {0}", filesToDelete.Select(file => FilePath.TrimFileName(file.FileName, 75)).ToDelimitedString(Environment.NewLine + "    "));
            }
            catch (Exception ex)
            {
                OnProcessException(new InvalidOperationException($"Failed to limit maximum archive size: {ex.Message}", ex));
            }
        }
        public void GetAllFiles()
        {
            Logger.Console.Verbose = VerboseLevel.All;

            using (SnapServer server = CreateServer())
            {
                using (SnapClient client = SnapClient.Connect(server))
                    using (ClientDatabaseBase db = client.GetDatabase("PPA"))
                    {
                        foreach (ArchiveDetails f in db.GetAllAttachedFiles())
                        {
                            Console.WriteLine("{0}MB {1} TO {2}; ID:{3} Name: {4}",
                                              (f.FileSize / 1024d / 1024d).ToString("0.0"),
                                              f.FirstKey, f.LastKey, f.Id, f.FileName);
                        }
                    }
            }
        }
        public void DetatchFiles()
        {
            Logger.Console.Verbose = VerboseLevel.All;

            using (SnapServer server = CreateServer())
            {
                using (SnapClient client = SnapClient.Connect(server))
                    using (ClientDatabaseBase <HistorianKey, HistorianValue> db = client.GetDatabase <HistorianKey, HistorianValue>("PPA"))
                    {
                        using (TreeStream <HistorianKey, HistorianValue> stream = db.Read(null, null, null))
                        {
                            Console.WriteLine(stream.Count());
                        }
                        db.DetatchFiles(db.GetAllAttachedFiles().Select(x => x.Id).ToList());
                        using (TreeStream <HistorianKey, HistorianValue> stream = db.Read(null, null, null))
                        {
                            Console.WriteLine(stream.Count());
                        }
                    }
            }
        }
        private void ExecuteFolderOperation(ClientDatabaseBase <HistorianKey, HistorianValue> database, string folderName, Action <List <Guid> > folderOperation)
        {
            List <Guid> files = database.GetAllAttachedFiles().Where(file => Path.GetFullPath(file.FileName).StartsWith(folderName, StringComparison.OrdinalIgnoreCase)).Select(file => file.Id).ToList();

            folderOperation(files);
        }