Exemple #1
0
        /// <summary>
        /// Executes tasks on the list according to given fileTargetListTask and fileTargetListSettings
        /// </summary>
        /// <param name="task"></param>
        /// <param name="settings"></param>
        /// <param name="jobName">Name of related Job - used for reporting/diagnostic purposes only</param>
        /// <returns></returns>
        public String runTask(fileTargetListTask task, fileTargetListSettings settings, String jobName = "unknown")
        {
            String output = "";

            switch (task)
            {
            case fileTargetListTask.scan:
                output = output.log(scanFiles(settings, true));
                break;

            case fileTargetListTask.saveList:
                String listFilename = jobName.getFilename(".txt");
                listFilename = filePathOperations.addUniqueSufix(listFilename);
                File.WriteAllLines(listFilename, targetList.ToArray());
                output = "List saved to: " + listFilename;
                break;

            case fileTargetListTask.showList:
                output = targetList.writeListOfCollection();
                break;

            case fileTargetListTask.backup:
                output = runBackup(settings.backup, true, jobName);
                break;

            case fileTargetListTask.done:
                break;
            }

            return(output);
        }
Exemple #2
0
        /// <summary>
        /// Skenira putanju - prema podesavanjima
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="doClearExistingInList">Da li prazni listu fajlova koju trenutno ima u memoriji</param>
        /// <returns></returns>
        public String scanFiles(fileTargetListSettings settings, Boolean doClearExistingInList = true)
        {
            String debug = "";
            String path  = settings.path;

            //if (Path.IsPathRooted(settings.path))
            //{
            //    path =
            //}
            if (!Directory.Exists(settings.path))
            {
                debug = debug.log("Current target path do not exists [" + settings.path + "] !");
                return(debug);
            }

            if (doClearExistingInList)
            {
                targetList = new List <string>();
            }

            String query = "*." + settings.fileExtension;

            query = query.Replace("..", ".");

            if (settings.doIncludeSubFolders)
            {
                targetList.AddRange(Directory.EnumerateFiles(settings.path, query, SearchOption.AllDirectories));
            }
            else
            {
                targetList.AddRange(Directory.EnumerateFiles(settings.path, query, SearchOption.TopDirectoryOnly));
            }

            // debug.log("Target files detected: " + targetList.Count() + " at path: " + settings.path);
            if (targetList.Count() == 0)
            {
                debug = debug.log("No files found on target path");
            }
            return(debug);
        }