Example #1
0
        static public AttemptResult OpenStreamForWriting(string path, out Stream stream, long milliseconds = DEFAULT_WAIT)
        {
            return(Attempter.AttemptFailOnException(delegate(out Stream inner_stream) {
                inner_stream = null;

                try
                {
                    inner_stream = new FileStream(path, FileMode.Create, FileAccess.Write);
                }
                catch (IOException) { return AttemptResult.Tried; }

                return AttemptResult.Succeeded;
            }, out stream, milliseconds));
        }
Example #2
0
        static public AttemptResult MoveDirectory(string path, string new_path, bool overwrite, long milliseconds = DEFAULT_WAIT)
        {
            if (DoesDirectoryExist(path))
            {
                if (overwrite || DoesDirectoryExist(new_path) == false)
                {
                    return(Attempter.AttemptFailOnException(delegate() {
                        Directory.Move(path, new_path);

                        return AttemptResult.Succeeded;
                    }, milliseconds));
                }
            }

            return(AttemptResult.Failed);
        }
Example #3
0
        static public AttemptResult CreateDirectory(string directory, long milliseconds = DEFAULT_WAIT)
        {
            if (DoesDirectoryExist(directory) == false)
            {
                return(Attempter.AttemptFailOnException(delegate() {
                    DirectoryInfo info = Directory.CreateDirectory(directory);
                    if (info != null)
                    {
                        return AttemptResult.Succeeded;
                    }

                    return AttemptResult.Failed;
                }, milliseconds));
            }

            return(AttemptResult.Unneeded);
        }
Example #4
0
        static public AttemptResult DeleteFile(string filename, long milliseconds = DEFAULT_WAIT)
        {
            if (DoesFileExist(filename))
            {
                return(Attempter.AttemptFailOnException(delegate() {
                    try
                    {
                        File.Delete(filename);
                    }
                    catch (IOException) { return AttemptResult.Tried; }

                    return AttemptResult.Succeeded;
                }, milliseconds));
            }

            return(AttemptResult.Unneeded);
        }
Example #5
0
        static public AttemptResult MoveFile(string src_filename, string dst_filename, bool overwrite, long milliseconds = DEFAULT_WAIT)
        {
            if (DoesFileExist(src_filename))
            {
                if (overwrite || DoesFileExist(dst_filename) == false)
                {
                    DeleteFile(dst_filename);

                    return(Attempter.AttemptFailOnException(delegate() {
                        File.Move(src_filename, dst_filename);

                        return AttemptResult.Succeeded;
                    }, milliseconds));
                }
            }

            return(AttemptResult.Failed);
        }
Example #6
0
        static public AttemptResult OpenStreamForReading(string path, out Stream stream, long milliseconds = DEFAULT_WAIT)
        {
            return(Attempter.AttemptFailOnException(delegate(out Stream inner_stream) {
                inner_stream = null;

                if (DoesFileExist(path))
                {
                    try
                    {
                        inner_stream = new FileStream(path, FileMode.Open, FileAccess.Read);
                    }
                    catch (FileNotFoundException) { return AttemptResult.Failed; }
                    catch (IOException) { return AttemptResult.Tried; }

                    return AttemptResult.Succeeded;
                }

                return AttemptResult.Failed;
            }, out stream, milliseconds));
        }
Example #7
0
        static public AttemptResult CopyFile(string src_filename, string dst_filename, bool overwrite, long milliseconds = DEFAULT_WAIT)
        {
            if (DoesFileExist(src_filename))
            {
                if (overwrite || DoesFileExist(dst_filename) == false)
                {
                    return(Attempter.AttemptFailOnException(delegate() {
                        try
                        {
                            File.Copy(src_filename, dst_filename, overwrite);
                        }
                        catch (FileNotFoundException) { return AttemptResult.Failed; }
                        catch (IOException) { return AttemptResult.Tried; }

                        return AttemptResult.Succeeded;
                    }, milliseconds));
                }

                return(AttemptResult.Unneeded);
            }

            return(AttemptResult.Failed);
        }