/// <summary>
        /// Finds the files to cache for the specified cache task
        /// </summary>
        /// <param name="taskID"></param>
        private List <udtFileInfo> GetFilesToCache(int taskID = 0)
        {
            var filesToCache = new List <udtFileInfo>();

            var sql = " SELECT Entry_ID, Dataset_ID, Job, Client_Path, Server_Path," +
                      " Parent_Path, Dataset_Folder, Results_Folder_Name, Filename, Queued, Optional" +
                      " FROM V_MyEMSL_FileCache";

            if (taskID > 0)
            {
                sql += " WHERE Task_ID = " + taskID;
            }
            else
            {
                sql += " WHERE State = 1 AND " +
                       " Dataset_ID IN (SELECT TOP 1 Dataset_ID FROM V_MyEMSL_FileCache WHERE State = 1)";
            }

            var success = mDbTools.GetQueryResultsDataTable(sql, out var dataTable);

            if (success)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    var fileInfo = new udtFileInfo
                    {
                        EntryID           = row["Entry_ID"].CastDBVal(0),
                        DatasetID         = row["Dataset_ID"].CastDBVal(0),
                        Job               = row["Job"].CastDBVal(0),
                        ClientPath        = row["Client_Path"].CastDBVal(""),
                        ServerPath        = row["Server_Path"].CastDBVal(""),
                        ParentPath        = row["Parent_Path"].CastDBVal("").TrimStart('\\'),
                        DatasetFolder     = row["Dataset_Folder"].CastDBVal(""),
                        ResultsFolderName = row["Results_Folder_Name"].CastDBVal(""),
                        Filename          = row["Filename"].CastDBVal(""),
                        Queued            = row["Queued"].CastDBVal(DateTime.Now),
                        Optional          = IntToBool(row["Optional"].CastDBVal(0))
                    };

                    filesToCache.Add(fileInfo);
                }
            }

            return(filesToCache);
        }
        private List <udtFileInfo> GetOldestCachedFiles(int maxFileCount)
        {
            var oldestCachedFiles = new List <udtFileInfo>();

            if (maxFileCount < 50)
            {
                maxFileCount = 50;
            }

            var sql = "SELECT TOP " + maxFileCount +
                      " Entry_ID, Client_Path, Server_Path, Parent_Path, Dataset_Folder, Results_Folder_Name, Filename" +
                      " FROM V_MyEMSL_FileCache " +
                      " WHERE State = 3 " +
                      " ORDER BY Queued";

            var success = mDbTools.GetQueryResultsDataTable(sql, out var dataTable);

            if (success)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    var fileInfo = new udtFileInfo
                    {
                        EntryID           = row["Entry_ID"].CastDBVal(0),
                        ClientPath        = row["Client_Path"].CastDBVal(""),
                        ServerPath        = row["Server_Path"].CastDBVal(""),
                        ParentPath        = row["Parent_Path"].CastDBVal("").TrimStart('\\'),
                        DatasetFolder     = row["Dataset_Folder"].CastDBVal(""),
                        ResultsFolderName = row["Results_Folder_Name"].CastDBVal(""),
                        Filename          = row["Filename"].CastDBVal("")
                    };

                    oldestCachedFiles.Add(fileInfo);
                }
            }

            return(oldestCachedFiles);
        }
        private List<udtFileInfo> GetOldestCachedFiles(int maxFileCount)
        {
            var lstFiles = new List<udtFileInfo>();

            if (maxFileCount < 50)
                maxFileCount = 50;

            var sql = "SELECT TOP " + maxFileCount +
                      " Entry_ID, Client_Path, Server_Path, Parent_Path, Dataset_Folder, Results_Folder_Name, Filename" +
                      " FROM V_MyEMSL_FileCache " +
                      " WHERE State = 3 " +
                      " ORDER BY Queued";

            using (var cnDB = new SqlConnection(this.MTSConnectionString))
            {
                cnDB.Open();

                var cmd = new SqlCommand(sql, cnDB);
                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    var fileInfo = new udtFileInfo
                    {
                        EntryID = GetDBInt(reader, "Entry_ID"),
                        ClientPath = GetDBString(reader, "Client_Path"),
                        ServerPath = GetDBString(reader, "Server_Path"),
                        ParentPath = GetDBString(reader, "Parent_Path").TrimStart('\\'),
                        DatasetFolder = GetDBString(reader, "Dataset_Folder"),
                        ResultsFolderName = GetDBString(reader, "Results_Folder_Name"),
                        Filename = GetDBString(reader, "Filename")
                    };

                    lstFiles.Add(fileInfo);
                }
            }

            return lstFiles;
        }
        /// <summary>
        /// Finds the files to cache for the specified cache task
        /// </summary>
        /// <param name="taskID"></param>
        /// <returns></returns>
        private List<udtFileInfo> GetFilesToCache(int taskID)
        {
            var lstFiles = new List<udtFileInfo>();

            var sql = " SELECT Entry_ID, Dataset_ID, Job, Client_Path, Server_Path," +
                      " Parent_Path, Dataset_Folder, Results_Folder_Name, Filename, Queued, Optional" +
                      " FROM V_MyEMSL_FileCache";

            if (taskID > 0)
            {
                sql += " WHERE Task_ID = " + taskID;
            }
            else
            {
                sql += " WHERE State = 1 AND " +
                             " Dataset_ID IN (SELECT TOP 1 Dataset_ID FROM V_MyEMSL_FileCache WHERE State = 1)";
            }

            using (var cnDB = new SqlConnection(this.MTSConnectionString))
            {
                cnDB.Open();

                var cmd = new SqlCommand(sql, cnDB);
                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    var fileInfo = new udtFileInfo
                    {
                        EntryID = GetDBInt(reader, "Entry_ID"),
                        DatasetID = GetDBInt(reader, "Dataset_ID"),
                        Job = GetDBInt(reader, "Job"),
                        ClientPath = GetDBString(reader, "Client_Path"),
                        ServerPath = GetDBString(reader, "Server_Path"),
                        ParentPath = GetDBString(reader, "Parent_Path").TrimStart('\\'),
                        DatasetFolder = GetDBString(reader, "Dataset_Folder"),
                        ResultsFolderName = GetDBString(reader, "Results_Folder_Name"),
                        Filename = GetDBString(reader, "Filename"),
                        Queued = GetDBDate(reader, "Queued"),
                        Optional = TinyIntToBool(GetDBInt(reader, "Optional"))
                    };

                    lstFiles.Add(fileInfo);
                }
            }

            return lstFiles;
        }