Beispiel #1
0
        public async Task Open()
        {
            TaskRunned = true;
            ResultData = await FileSystemInteraction.OpenFile();

            TaskRunned = false;
        }
Beispiel #2
0
        public async Task SaveAs()
        {
            TaskRunned = true;
            await FileSystemInteraction.SaveAsFile(ResultData);

            TaskRunned = false;
        }
Beispiel #3
0
            private void BlockedThreadRunner(object _args)
            {
                object[]              args       = (object[])_args;
                string                roothpath  = (string)args[0];
                FilenameFilter        filter     = (FilenameFilter)args[1];
                FileSystemInteraction folderList = (FileSystemInteraction)args[2];
                FileSystemInteraction fileList   = (FileSystemInteraction)args[3];

                EnumerateFileSystemEntries(roothpath, Callback, folderList, fileList);
                m_queue.SetCompleted();
            }
Beispiel #4
0
        /// <summary>
        /// Returns a list of all files found in the given folder.
        /// The search is recursive.
        /// </summary>
        /// <param name="rootpath">The folder to look in</param>
        /// <param name="callback">The function to call with the filenames</param>
        /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
        /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
        /// <param name="attributeReader">A function to call that obtains the attributes for an element, set to null to avoid reading attributes</param>
        /// <returns>A list of the full filenames</returns>
        public static IEnumerable<string> EnumerateFileSystemEntries(string rootpath, EnumerationFilterDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList, ExtractFileAttributes attributeReader)
        {
            Stack<string> lst = new Stack<string>();

            var isFolder = false;
            try
            {
                if (attributeReader == null)
                    isFolder = true;
                else
                    isFolder = (attributeReader(rootpath) & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory;
            }
            catch
            {
            }

            if (isFolder)
            {
                rootpath = AppendDirSeparator(rootpath);
                try
                {

                    System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Directory : attributeReader(rootpath);
                    if (callback(rootpath, rootpath, attr))
                        lst.Push(rootpath);
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, rootpath, ATTRIBUTE_ERROR | System.IO.FileAttributes.Directory);
                }

                while (lst.Count > 0)
                {
                    string f = AppendDirSeparator(lst.Pop());

                    yield return f;

                    try
                    {
                        foreach(string s in folderList(f))
                        {
                            var sf = AppendDirSeparator(s);
                            System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Directory : attributeReader(sf);
                            if (callback(rootpath, sf, attr))
                                lst.Push(sf);
                        }
                    }
                    catch (System.Threading.ThreadAbortException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        callback(rootpath, f, ATTRIBUTE_ERROR | System.IO.FileAttributes.Directory);
                    }

                    string[] files = null;
                    if (fileList != null)
                        try
                        {
                            files = fileList(f);
                        }
                        catch (System.Threading.ThreadAbortException)
                        {
                            throw;
                        }
                        catch (Exception)
                        {
                            callback(rootpath, f, ATTRIBUTE_ERROR);
                        }

                    if (files != null)
                        foreach(var s in files)
                        {
                            try
                            {
                                System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Normal : attributeReader(s);
                                if (!callback(rootpath, s, attr))
                                    continue;
                            }
                            catch (System.Threading.ThreadAbortException)
                            {
                                throw;
                            }
                            catch (Exception)
                            {
                                callback(rootpath, s, ATTRIBUTE_ERROR);
                                continue;
                            }
                            yield return s;
                        }
                }
            }
            else
            {
                try
                {
                    System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Normal : attributeReader(rootpath);
                    if (!callback(rootpath, rootpath, attr))
                        yield break;
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, rootpath, ATTRIBUTE_ERROR);
                    yield break;
                }

                yield return rootpath;
            }
        }
Beispiel #5
0
 /// <summary>
 /// Returns a list of all files found in the given folder.
 /// The search is recursive.
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
 /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
 /// <returns>A list of the full filenames</returns>
 public static IEnumerable<string> EnumerateFileSystemEntries(string rootpath, EnumerationFilterDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList)
 {
     return EnumerateFileSystemEntries(rootpath, callback, folderList, fileList, null);
 }
Beispiel #6
0
 /// <summary>
 /// Saves image
 /// Will OVERRIDE existing image if one has the same path
 /// </summary>
 /// <param name="filePath">Should include fileName and extension (extension should match file type)</param>
 public void saveImageToFile(String filePath)
 {
     FileSystemInteraction.deleteFile(filePath);
     image.Save(filePath);
 }
Beispiel #7
0
 public BlockedCollector(BlockingQueue<string> queue, string rootpath, FilenameFilter filter, FileSystemInteraction folderList, FileSystemInteraction fileList)
 {
     m_queue = queue;
     System.Threading.Thread t = new System.Threading.Thread(BlockedThreadRunner);
     t.Start(new object[] { rootpath, filter, folderList, fileList});
 }
Beispiel #8
0
 /// <summary>
 /// Returns an IEnumerable with all filesystem entries, recursive
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="filter">An optional filter to apply to the filenames</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
 /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
 /// <param name="attributeReader">A function to call that obtains the attributes for an element, set to null to skip symlink detection</param>
 /// <returns>The file system entries</returns>
 public static IEnumerable<string> EnumerateFileSystemEntriesBlocked(string rootpath, FilenameFilter filter, FileSystemInteraction folderList, FileSystemInteraction fileList, ExtractFileAttributes attributeReader)
 {
     BlockingQueue<string> queue = new BlockingQueue<string>();
     new BlockedCollector(queue, rootpath, filter, folderList, fileList);
     return new BlockingQueueAsEnumerable<string>(queue);
 }
Beispiel #9
0
        /// <summary>
        /// Returns a list of all files found in the given folder.
        /// The search is recursive.
        /// </summary>
        /// <param name="rootpath">The folder to look in</param>
        /// <param name="callback">The function to call with the filenames</param>
        /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
        /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
        /// <param name="attributeReader">A function to call that obtains the attributes for an element, set to null to avoid reading attributes</param>
        /// <returns>A list of the full filenames</returns>
        public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList, ExtractFileAttributes attributeReader)
        {
            if (!System.IO.Directory.Exists(rootpath))
                return;

            Queue<string> lst = new Queue<string>();
            lst.Enqueue(rootpath);

            while (lst.Count > 0)
            {
                string f = AppendDirSeparator(lst.Dequeue());
                try
                {
                    System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Directory : attributeReader(f);
                    if (!callback(rootpath, f, attr))
                        continue;

                    foreach (string s in folderList(f))
                        lst.Enqueue(s);
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, f, ATTRIBUTE_ERROR | System.IO.FileAttributes.Directory);
                }

                try
                {
                    if (fileList != null)
                        foreach (string s in fileList(f))
                        {
                            try
                            {
                                System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Normal : attributeReader(s);
                                callback(rootpath, s, attr);
                            }
                            catch (System.Threading.ThreadAbortException)
                            {
                                throw;
                            }
                            catch (Exception)
                            {
                                callback(rootpath, s, ATTRIBUTE_ERROR);
                            }
                        }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, f, ATTRIBUTE_ERROR);
                }
            }
        }
Beispiel #10
0
 public BlockedCollector(BlockingQueue <string> queue, string rootpath, FilenameFilter filter, FileSystemInteraction folderList, FileSystemInteraction fileList)
 {
     m_queue = queue;
     System.Threading.Thread t = new System.Threading.Thread(BlockedThreadRunner);
     t.Start(new object[] { rootpath, filter, folderList, fileList });
 }
Beispiel #11
0
        // END OF DATA MANIPULATION METHODS

        // MISC METHODS
        public void saveToFile(String filePath)
        {
            String[] lines = { message };
            FileSystemInteraction.writeToTextFile(filePath, lines);
        }
Beispiel #12
0
        /// <summary>
        /// Returns a list of all files found in the given folder.
        /// The search is recursive.
        /// </summary>
        /// <param name="rootpath">The folder to look in</param>
        /// <param name="callback">The function to call with the filenames</param>
        /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
        /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
        /// <param name="attributeReader">A function to call that obtains the attributes for an element, set to null to avoid reading attributes</param>
        /// <returns>A list of the full filenames</returns>
        public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList, ExtractFileAttributes attributeReader)
        {
            if (!System.IO.Directory.Exists(rootpath))
            {
                return;
            }

            Queue <string> lst = new Queue <string>();

            lst.Enqueue(rootpath);

            while (lst.Count > 0)
            {
                string f = AppendDirSeparator(lst.Dequeue());
                try
                {
                    System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Directory : attributeReader(f);
                    if (!callback(rootpath, f, attr))
                    {
                        continue;
                    }

                    foreach (string s in folderList(f))
                    {
                        lst.Enqueue(s);
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, f, ATTRIBUTE_ERROR | System.IO.FileAttributes.Directory);
                }

                try
                {
                    if (fileList != null)
                    {
                        foreach (string s in fileList(f))
                        {
                            try
                            {
                                System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Normal : attributeReader(s);
                                callback(rootpath, s, attr);
                            }
                            catch (System.Threading.ThreadAbortException)
                            {
                                throw;
                            }
                            catch (Exception)
                            {
                                callback(rootpath, s, ATTRIBUTE_ERROR);
                            }
                        }
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, f, ATTRIBUTE_ERROR);
                }
            }
        }
Beispiel #13
0
 /// <summary>
 /// Returns a list of all files found in the given folder.
 /// The search is recursive.
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
 /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
 /// <returns>A list of the full filenames</returns>
 public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList)
 {
     EnumerateFileSystemEntries(rootpath, callback, folderList, fileList, null);
 }
Beispiel #14
0
 /// <summary>
 /// Returns a list of all files found in the given folder.
 /// The search is recursive.
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
 /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
 /// <returns>A list of the full filenames</returns>
 public static IEnumerable <string> EnumerateFileSystemEntries(string rootpath, EnumerationFilterDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList)
 {
     return(EnumerateFileSystemEntries(rootpath, callback, folderList, fileList, null));
 }
Beispiel #15
0
 /// <summary>
 /// Returns a list of all files found in the given folder.
 /// The search is recursive.
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
 /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
 /// <returns>A list of the full filenames</returns>
 public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList)
 {
     EnumerateFileSystemEntries(rootpath, callback, folderList, fileList, null);
 }
Beispiel #16
0
        /// <summary>
        /// Returns a list of all files found in the given folder.
        /// The search is recursive.
        /// </summary>
        /// <param name="rootpath">The folder to look in</param>
        /// <param name="callback">The function to call with the filenames</param>
        /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
        /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
        /// <param name="attributeReader">A function to call that obtains the attributes for an element, set to null to avoid reading attributes</param>
        /// <returns>A list of the full filenames</returns>
        public static IEnumerable <string> EnumerateFileSystemEntries(string rootpath, EnumerationFilterDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList, ExtractFileAttributes attributeReader)
        {
            Stack <string> lst = new Stack <string>();

            var isFolder = false;

            try
            {
                if (attributeReader == null)
                {
                    isFolder = true;
                }
                else
                {
                    isFolder = (attributeReader(rootpath) & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory;
                }
            }
            catch
            {
            }

            if (isFolder)
            {
                rootpath = AppendDirSeparator(rootpath);
                try
                {
                    System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Directory : attributeReader(rootpath);
                    if (callback(rootpath, rootpath, attr))
                    {
                        lst.Push(rootpath);
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, rootpath, ATTRIBUTE_ERROR | System.IO.FileAttributes.Directory);
                }

                while (lst.Count > 0)
                {
                    string f = AppendDirSeparator(lst.Pop());

                    yield return(f);

                    try
                    {
                        foreach (string s in folderList(f))
                        {
                            var sf = AppendDirSeparator(s);
                            System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Directory : attributeReader(sf);
                            if (callback(rootpath, sf, attr))
                            {
                                lst.Push(sf);
                            }
                        }
                    }
                    catch (System.Threading.ThreadAbortException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        callback(rootpath, f, ATTRIBUTE_ERROR | System.IO.FileAttributes.Directory);
                    }

                    string[] files = null;
                    if (fileList != null)
                    {
                        try
                        {
                            files = fileList(f);
                        }
                        catch (System.Threading.ThreadAbortException)
                        {
                            throw;
                        }
                    }
Beispiel #17
0
        /// <summary>
        /// Returns an IEnumerable with all filesystem entries, recursive
        /// </summary>
        /// <param name="rootpath">The folder to look in</param>
        /// <param name="filter">An optional filter to apply to the filenames</param>
        /// <param name="callback">The function to call with the filenames</param>
        /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
        /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
        /// <param name="attributeReader">A function to call that obtains the attributes for an element, set to null to skip symlink detection</param>
        /// <returns>The file system entries</returns>
        public static IEnumerable <string> EnumerateFileSystemEntriesBlocked(string rootpath, FilenameFilter filter, FileSystemInteraction folderList, FileSystemInteraction fileList, ExtractFileAttributes attributeReader)
        {
            BlockingQueue <string> queue = new BlockingQueue <string>();

            new BlockedCollector(queue, rootpath, filter, folderList, fileList);
            return(new BlockingQueueAsEnumerable <string>(queue));
        }