public Task <List <IFile> > GetProjectNames() { if (mSmbFile == null) { return(Task.FromResult(new List <IFile>())); } return(Task.Factory.StartNew(() => { var result = new List <IFile>(); try { SmbOperations.WithRetries(() => { result.Clear(); #if DEBUG_SAMBA Android.Util.Log.Debug("SmbClient", "Getting projects"); #endif var subList = mSmbFile.ListFiles(); foreach (var element in subList) { try { if (element.IsFile && ( element.Name.EndsWith(".ares", StringComparison.InvariantCultureIgnoreCase) || element.Name.EndsWith(".apkg", StringComparison.InvariantCultureIgnoreCase))) { #if DEBUG_SAMBA Android.Util.Log.Debug("SmbClient", "Found project " + element.Name); #endif result.Add(new SambaFile(element)); } } catch (SmbException) { } catch (Java.IO.IOException) { } } return result; }, 3); } catch (SmbException ex) { LogException(ex); throw new System.IO.IOException(ex.Message, ex); } catch (Java.IO.IOException ex) { throw new System.IO.IOException(ex.Message, ex); } #if DEBUG_SAMBA Android.Util.Log.Debug("SmbClient", "Returning " + result.Count + " files."); #endif return result; })); }
public static bool FileExists(String smbUrl) { try { return(SmbOperations.WithRetries(() => { var smbFile = new SmbFile(smbUrl); return smbFile.Exists(); })); } catch (SmbException) { return(false); } catch (Java.IO.IOException) { return(false); } }
public override void Flush() { if (mStream == null) { throw new ObjectDisposedException("SambaInputStream"); } try { int dummy = SmbOperations.WithRetries(() => { mStream.Flush(); return(0); }); } catch (SmbException ex) { throw new System.IO.IOException(ex.Message, ex); } catch (Java.IO.IOException ex) { throw new System.IO.IOException(ex.Message, ex); } }
public override int Read(byte[] buffer, int offset, int count) { if (mStream == null) { throw new ObjectDisposedException("SambaInputStream"); } try { int res = SmbOperations.WithRetries(() => { return(mStream.Read(buffer, offset, count)); }); // note: java.io.Stream.Read returns -1 on end of input, but // System.IO.Stream must return 0 in that case if (res == -1) { #if DEBUG_SAMBA Android.Util.Log.Debug("SambaInputStream", "End of stream reached at " + mPos + "(length is " + mFile.Length() + ")"); #endif res = 0; } else { mPos += res; #if DEBUG_SAMBA Android.Util.Log.Debug("SambaInputStream", "Read " + res + " bytes from stream, new pos is " + mPos); #endif } return(res); } catch (SmbException ex) { throw new System.IO.IOException(ex.Message, ex); } catch (Java.IO.IOException ex) { throw new System.IO.IOException(ex.Message, ex); } }
public override void Write(byte[] buffer, int offset, int count) { if (mStream == null) { throw new ObjectDisposedException("SambaInputStream"); } try { int dummy = SmbOperations.WithRetries(() => { mStream.Write(buffer, offset, count); return(0); }); } catch (SmbException ex) { throw new System.IO.IOException(ex.Message, ex); } catch (Java.IO.IOException ex) { throw new System.IO.IOException(ex.Message, ex); } }
public Task <List <String> > GetSubFolderNames() { if (mSmbFile == null) { return(Task.FromResult(new List <String>())); } return(Task.Factory.StartNew(() => { var result = new List <String>(); try { bool hasTriedLastAuth = false; SmbOperations.WithRetries(() => { result.Clear(); try { #if DEBUG_SAMBA Android.Util.Log.Debug("SmbClient", "Getting sub folders"); #endif var subList = mSmbFile.ListFiles(); foreach (var element in subList) { try { if (!element.IsFile) { switch (element.Type) { case SmbFile.TypeFilesystem: case SmbFile.TypeWorkgroup: case SmbFile.TypeServer: case SmbFile.TypeShare: result.Add(element.Name); break; default: break; } } } catch (SmbException) { } catch (Java.IO.IOException) { } } return result; } catch (SmbAuthException ex) { NtlmPasswordAuthentication auth = null; if (!hasTriedLastAuth) { auth = NtlmAuthenticator.RequestNtlmPasswordAuthentication("LAST_USED_AUTH", ex); hasTriedLastAuth = true; } else { auth = NtlmAuthenticator.RequestNtlmPasswordAuthentication(mSmbFile.Path, ex); } if (auth != null) { mSmbFile = new SmbFile(mSmbFile.Path, auth); throw; } else { return result; } } }, 5); } catch (SmbException ex) { LogException(ex); throw new System.IO.IOException(ex.Message, ex); } catch (Java.IO.IOException ex) { throw new System.IO.IOException(ex.Message, ex); } return result; })); }