Beispiel #1
0
        public AttemptResult Rename(string new_name, bool overwrite, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            new_name = Filename.CleanFilename(new_name);

            AttemptResult result = GetStreamSystem().Rename(
                GetPath(),
                new_name,
                overwrite,
                milliseconds
                );

            if (result.IsDesired())
            {
                if (RenameInternal(new_name))
                {
                    name = new_name;
                }
                else
                {
                    this.OrphanHoldable();
                }
            }

            return(result);
        }
Beispiel #2
0
        static public bool IsUndesired(this AttemptResult item)
        {
            if (item.IsDesired() == false)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public virtual AttemptResult MoveDirectoryForeign(string src_path, StreamSystem dst, string dst_path, bool overwrite, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            AttemptResult result = CopyDirectoryForeign(src_path, dst, dst_path, overwrite, milliseconds);

            if (result.IsDesired())
            {
                DeleteDirectory(src_path);
            }

            return(result);
        }
Beispiel #4
0
        public AttemptResult Delete(long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            AttemptResult result = GetStreamSystem().Delete(
                GetPath(),
                milliseconds
                );

            if (result.IsDesired())
            {
                this.OrphanHoldable();
            }

            return(result);
        }
Beispiel #5
0
        static public AttemptResult Write(this StreamSystem item, string path, AttemptProcess <Stream> process, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            Stream        stream;
            AttemptResult result = item.OpenStreamForWriting(path, out stream, milliseconds);

            using (stream)
            {
                if (result.IsDesired())
                {
                    return(process(stream));
                }
            }

            return(result);
        }
Beispiel #6
0
        public AttemptResult Rename(string new_name, bool overwrite, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            AttemptResult result = GetStreamSystem().Rename(
                GetPath(),
                new_name,
                overwrite,
                milliseconds
                );

            if (result.IsDesired())
            {
                SetName(new_name);
            }

            return(result);
        }
Beispiel #7
0
        static public AttemptResult AttemptReadBytes <T>(this StreamSystem item, string path, Operation <T, byte[]> operation, out T output, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            byte[]        bytes;
            AttemptResult result = item.AttemptReadBytes(path, out bytes, milliseconds);

            if (result.IsDesired())
            {
                output = operation(bytes);
            }
            else
            {
                output = default(T);
            }

            return(result);
        }
Beispiel #8
0
        public AttemptResult MoveTo(StreamDirectory destination, bool overwrite, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            AttemptResult result = GetStreamSystem().Move(
                GetPath(),
                destination.GetStreamSystem(),
                destination.GetChildPath(GetName()),
                overwrite,
                milliseconds
                );

            if (result.IsDesired())
            {
                SetParentDirectory(destination);
            }

            return(result);
        }
Beispiel #9
0
        static public AttemptResult AttemptReadText <T>(this StreamSystem item, string path, Operation <T, string> operation, out T output, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            T             temp   = default(T);
            AttemptResult result = item.AttemptReadText(path, delegate(string text) {
                temp = operation(text);
            }, milliseconds);

            if (result.IsDesired())
            {
                output = temp;
            }
            else
            {
                output = default(T);
            }

            return(result);
        }
Beispiel #10
0
        static public AttemptResult AttemptRead(this StreamSystem item, string path, TryProcess <Stream> process, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            Stream        stream;
            AttemptResult result = item.OpenStreamForReading(path, out stream, milliseconds);

            using (stream)
            {
                if (result.IsDesired())
                {
                    if (process(stream) == false)
                    {
                        result = AttemptResult.Failed;
                    }
                }
            }

            return(result);
        }
Beispiel #11
0
        static public AttemptResult AttemptReadLines <T>(this StreamSystem item, string path, Operation <T, IEnumerable <string> > operation, out T output, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            T             temp   = default(T);
            AttemptResult result = item.AttemptReadLines(path, delegate(IEnumerable <string> lines) {
                temp = operation(lines);
            }, milliseconds);

            if (result.IsDesired())
            {
                output = temp;
            }
            else
            {
                output = default(T);
            }

            return(result);
        }
Beispiel #12
0
        static public AttemptResult AttemptReadRandomLine <T>(this StreamSystem item, string path, Operation <T, string> operation, out T output, RandIntSource source, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            T             temp   = default(T);
            AttemptResult result = item.AttemptReadRandomLine(path, delegate(string line) {
                temp = operation(line);
            }, source, milliseconds);

            if (result.IsDesired())
            {
                output = temp;
            }
            else
            {
                output = default(T);
            }

            return(result);
        }