Exemplo n.º 1
0
 private void moveToPath(string destinationPath)
 {
     try
     {
         System.IO.File.Move(filePath, destinationPath);
     }
     catch (System.IO.IOException e)
     {
         // If the destination file already exists (0x800700B7 is "Cannot create a file when that file already
         // exists"), then delete it and retry the move.
         if (e.HResult == unchecked ((int)0x800700B7))
         {
             try
             {
                 System.IO.File.Delete(destinationPath);
                 System.IO.File.Move(filePath, destinationPath);
             }
             catch (System.IO.IOException e2)
             {
                 throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e2);
             }
         }
         else
         {
             throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
         }
     }
 }
Exemplo n.º 2
0
        public override void visitChildren(FileVisitor fileVisitor, DirectoryVisitor directoryVisitor, VisitFailed visitFailed)
        {
            try
            {
                IReadOnlyList <IStorageItem> storageItems = getStorageFolder().GetItemsAsync().DoSynchronously();

                foreach (IStorageItem storageItem in storageItems)
                {
                    StorageItemPathAttributes pathAttributes = new StorageItemPathAttributes(storageItem);

                    if (storageItem is IStorageFolder)
                    {
                        if (directoryVisitor != null)
                        {
                            directoryVisitor(new StorageFolderDirectory(this, (StorageFolder)storageItem));
                        }
                    }
                    else if (storageItem is IStorageFile)
                    {
                        if (fileVisitor != null)
                        {
                            fileVisitor(new StorageFileFile(this, (StorageFile)storageItem));
                        }
                    }
                    else
                    {
                        throw new Exception("Unknown type of StorageItem: " + storageItem);
                    }
                }
            }
            catch (System.IO.IOException e)
            {
                throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
            }
        }
Exemplo n.º 3
0
 public override long getLastModifiedTime()
 {
     try {
         return(SystemUtils.toMillisFromDateTime(System.IO.File.GetLastWriteTimeUtc(filePath)));
     }
     catch (System.IO.IOException e) {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 4
0
 public override long getSize()
 {
     try {
         return(new FileInfo(filePath).Length);
     }
     catch (System.IO.IOException e) {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 5
0
 public override void setLastModifiedTime(long value)
 {
     try {
         System.IO.File.SetLastWriteTimeUtc(filePath, SystemUtils.toDotNetDateTimeFromMillis(value));
     }
     catch (System.IO.IOException e) {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 6
0
 public override OutputStream openForCreate()
 {
     try {
         FileStream fileStream = System.IO.File.OpenWrite(filePath);
         return(new DotNetStreamOutputStream(fileStream));
     }
     catch (System.IO.IOException e) {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 7
0
 public override long getLastModifiedTime()
 {
     try
     {
         return(SystemUtils.toMillisFromDateTimeOffset(storageFolder.GetBasicPropertiesAsync().DoSynchronously().DateModified));
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 8
0
 public override void write(int oneByte)
 {
     try
     {
         dotNetStream.WriteByte((byte)oneByte);
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 9
0
 public override int read()
 {
     try
     {
         return(dotNetStream.ReadByte());
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 10
0
 public override void delete()
 {
     try
     {
         System.IO.Directory.Delete(directoryPath);
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 11
0
 protected internal override void doClose()
 {
     try
     {
         dotNetStream.Dispose();
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 12
0
 public override void flush()
 {
     try
     {
         dotNetStream.Flush();
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 13
0
 public override void write(sbyte[] buffer, int offset, int length)
 {
     try
     {
         dotNetStream.Write((byte[])(Array)buffer, offset, length);
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 14
0
 public override bool exists()
 {
     try
     {
         var directoryInfo = new DirectoryInfo(directoryPath);
         return(directoryInfo.Exists);
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 15
0
        public override void renameTo(string newName)
        {
            var destinationPath = getChildPath(newName);

            try
            {
                System.IO.Directory.Move(directoryPath, destinationPath);
            }
            catch (System.IO.IOException e)
            {
                throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
            }
        }
Exemplo n.º 16
0
 public override void delete()
 {
     try {
         // Delete the file; if it doesn't exist, nothing happens
         System.IO.File.Delete(filePath);
     }
     catch (System.IO.DirectoryNotFoundException e) {
         // If the directory doesn't exist, ignore the error
     }
     catch (System.IO.IOException e) {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 17
0
        public override long getSize()
        {
            ensureGotStorageFile();

            try
            {
                return((long)storageFile.GetBasicPropertiesAsync().DoSynchronously().Size);
            }
            catch (System.IO.IOException e)
            {
                throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
            }
        }
Exemplo n.º 18
0
        public override void moveTo(File destination)
        {
            ensureGotStorageFile();

            StorageFileFile destinationStorageFile = (StorageFileFile)destination;

            try {
                storageFile.MoveAsync(destinationStorageFile.ParentStorageFolderDirectory.getStorageFolder(), destinationStorageFile.getName(), NameCollisionOption.ReplaceExisting);
            }
            catch (System.IO.IOException e) {
                throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
            }
        }
Exemplo n.º 19
0
        public override void renameTo(string newName)
        {
            ensureGotStorageFile();

            try
            {
                storageFile.RenameAsync(newName, NameCollisionOption.ReplaceExisting).DoSynchronously();
            }
            catch (System.IO.IOException e)
            {
                throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
            }
        }
Exemplo n.º 20
0
 private void ensureGotStorageFile()
 {
     if (storageFile == null)
     {
         try
         {
             storageFile = parent.getStorageFolder().GetFileAsync(name).DoSynchronously();
         }
         catch (System.IO.IOException e)
         {
             throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
         }
     }
 }
Exemplo n.º 21
0
 public override void create()
 {
     try
     {
         var directoryInfo = new DirectoryInfo(directoryPath);
         if (!directoryInfo.Exists)
         {
             directoryInfo.Create();
         }
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 22
0
        public StorageFolder getStorageFolder()
        {
            if (storageFolder == null)
            {
                try
                {
                    storageFolder = parent.getStorageFolder().GetFolderAsync(name).DoSynchronously();
                }
                catch (System.IO.IOException e)
                {
                    throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
                }
            }

            return(storageFolder);
        }
Exemplo n.º 23
0
        public override InputStream openForRead()
        {
            ensureGotStorageFile();

            try
            {
                IInputStream inputStream = storageFile.OpenSequentialReadAsync().DoSynchronously();

                // TODO: Need to close the inputStream itself; add a closedListener to InputStream, i think
                // Use the default 16K buffer for AsStreamForRead()
                return(new DotNetStreamInputStream(inputStream.AsStreamForRead()));
            }
            catch (System.IO.IOException e)
            {
                throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
            }
        }
Exemplo n.º 24
0
 public override int read(sbyte[] buffer, int offset, int length)
 {
     try
     {
         int bytesRead = dotNetStream.Read((byte[])(Array)buffer, offset, length);
         if (bytesRead == 0)
         {
             return(-1); // JSimple input streams return -1 at end of stream, not 0
         }
         else
         {
             return(bytesRead);
         }
     }
     catch (System.IO.IOException e)
     {
         throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
     }
 }
Exemplo n.º 25
0
        public override OutputStream openForCreate()
        {
            try
            {
                storageFile =
                    parent.getStorageFolder().CreateFileAsync(name, CreationCollisionOption.ReplaceExisting)
                    .DoSynchronously();

                IRandomAccessStream randomAccessStream =
                    storageFile.OpenAsync(FileAccessMode.ReadWrite).DoSynchronously();
                IOutputStream outputStream = randomAccessStream.GetOutputStreamAt(0);

                // Use the default buffer for AsStreamForWrite()
                return(new DotNetStreamOutputStream(outputStream.AsStreamForWrite()));
            }
            catch (System.IO.IOException e)
            {
                throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
            }
        }
Exemplo n.º 26
0
        public override void visitChildren(FileVisitor fileVisitor, DirectoryVisitor directoryVisitor,
                                           VisitFailed visitFailed)
        {
            var directoryInfo = new DirectoryInfo(directoryPath);

            try
            {
                foreach (var fileSystemInfo in directoryInfo.EnumerateFileSystemInfos())
                {
                    if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        directoryVisitor(new FileSystemDirectory(fileSystemInfo.FullName));
                    }
                    else
                    {
                        fileVisitor(new FileSystemFile(this, fileSystemInfo.FullName));
                    }
                }
            }
            catch (System.IO.IOException e)
            {
                throw DotNetIOUtils.jSimpleExceptionFromDotNetIOException(e);
            }
        }