/// <summary> /// Copies files to a local destination /// </summary> /// <param name="fromPath">The path from which to copy files (relative to basePath)</param> /// <param name="toPath">The path to which to copy files (relative to basePath)</param> /// <param name="overwrite">Whether or not to overwrite existing files</param> /// <returns>True indicates success, False indicates non fatal error</returns> public override bool CopyFile(string fromPath, string toPath, bool overwrite) { fromPath = Path.Combine(m_path, fromPath); toPath = Path.Combine(m_path, toPath); try { // Delete existing file if we're supposed to overwrite if (overwrite && File.Exists(toPath)) { File.Delete(toPath); } // Move the file File.Copy(fromPath, toPath); return(true); } catch (Exception e) { if (RetryOnException(e)) { return(false); } else { SiteDestinationException ex = new SiteDestinationException(e, SiteDestinationException.TransferException, GetType().Name, 0); ex.DestinationExtendedMessage = e.Message; throw ex; } } }
/// <summary> /// Copies files to a local destination /// </summary> /// <param name="fromPath">The path from which to copy files (relative to basePath)</param> /// <param name="toPath">The path to which to copy files (relative to basePath)</param> /// <param name="overwrite">Whether or not to overwrite existing files</param> /// <returns>True indicates success, False indicates non fatal error</returns> public override bool CopyFile(string fromPath, string toPath, bool overwrite) { fromPath = Path.Combine(m_path, fromPath); toPath = Path.Combine(m_path, toPath); try { // Delete existing file if we're supposed to overwrite if (overwrite && File.Exists(toPath)) File.Delete(toPath); // Move the file File.Copy(fromPath, toPath); return true; } catch (Exception e) { if (RetryOnException(e)) return false; else { SiteDestinationException ex = new SiteDestinationException(e, SiteDestinationException.TransferException, GetType().Name, 0); ex.DestinationExtendedMessage = e.Message; throw ex; } } }
/// <summary> /// Retrieves a file from the destination and copies it to the specified path. /// </summary> /// <param name="fromPath">the file to retrieve from the destination (relative to basePath)</param> /// <param name="toPath">the local location to save the contents of the file (fully-qualified path)</param> /// <param name="isBinary">true if the file is binary</param> override public bool GetFile(String fromPath, string toPath, bool isBinary) { fromPath = Path.Combine(m_path, fromPath); FileInfo fromFile = new FileInfo(fromPath); FileInfo toFile = new FileInfo(fromPath); if (fromFile.Equals(toFile)) { //then the source is the same as the destination, so ignore return(true); } try { // Delete existing file if (File.Exists(toPath)) { File.Delete(toPath); } // Copy the file File.Copy(fromPath, toPath); return(true); } catch (Exception e) { if (RetryOnException(e)) { return(false); } else { SiteDestinationException ex = new SiteDestinationException(e, SiteDestinationException.TransferException, GetType().Name, 0); ex.DestinationExtendedMessage = e.Message; throw ex; } } }
public DestinationServerFailedException(SiteDestinationException siteException) : base() { _siteException = siteException; }
public DestinationServerFailedException(SiteDestinationException siteException) : base() { _siteException = siteException; }
/// <summary> /// Throws the correct Site Destination exception for a given WinInet Error Code. /// This attempts to map common WinInet errors to corresponding Destination errors. /// </summary> /// <param name="error">The WinInet error code</param> private void ThrowDestinationException(int error) { // Exception detail data string exceptionType = null; string extendedMessage = WinInet.GetExtendedInfo(); if (extendedMessage == null || extendedMessage == String.Empty) extendedMessage = "The source of the error is unknown."; SiteDestinationException exception = null; // This wraps the lower level WinInet errors into higher level // Site destination exceptions. It also gathers extened info from // the connection to assist with troubleshooting. switch (error) { case ERROR_INTERNET.CANNOT_CONNECT: exceptionType = SiteDestinationException.ConnectionException; break; case ERROR_INTERNET.NAME_NOT_RESOLVED: exceptionType = SiteDestinationException.ConnectionException; break; case ERROR_INTERNET.ITEM_NOT_FOUND: exceptionType = SiteDestinationException.TransferException; break; case ERROR_INTERNET.TIMEOUT: exceptionType = SiteDestinationException.TransferException; break; case ERROR_INTERNET.LOGIN_FAILURE: exception = new LoginException(null, error); break; case ERROR_INTERNET.INCORRECT_PASSWORD: exception = new LoginException(null, error); break; case ERROR_INTERNET.INCORRECT_USER_NAME: exception = new LoginException(null, error); break; case ERROR_INTERNET.EXTENDED_ERROR: exceptionType = SiteDestinationException.UnexpectedException; break; default: exceptionType = SiteDestinationException.UnexpectedException; break; } // Set up a sitedestination exception with the correct information if (exception == null) { exception = new SiteDestinationException( null, exceptionType, GetType().Name, error); } exception.DestinationErrorCode = error; exception.DestinationType = GetType().Name; exception.DestinationExtendedMessage = extendedMessage; // throw it throw exception; }
/// <summary> /// Throws the correct Site Destination exception for a given WinInet Error Code. /// This attempts to map common WinInet errors to corresponding Destination errors. /// </summary> /// <param name="error">The WinInet error code</param> private void ThrowDestinationException(int error) { // Exception detail data string exceptionType = null; string extendedMessage = WinInet.GetExtendedInfo(); if (extendedMessage == null || extendedMessage == String.Empty) { extendedMessage = "The source of the error is unknown."; } SiteDestinationException exception = null; // This wraps the lower level WinInet errors into higher level // Site destination exceptions. It also gathers extended info from // the connection to assist with troubleshooting. switch (error) { case ERROR_INTERNET.CANNOT_CONNECT: exceptionType = SiteDestinationException.ConnectionException; break; case ERROR_INTERNET.NAME_NOT_RESOLVED: exceptionType = SiteDestinationException.ConnectionException; break; case ERROR_INTERNET.ITEM_NOT_FOUND: exceptionType = SiteDestinationException.TransferException; break; case ERROR_INTERNET.TIMEOUT: exceptionType = SiteDestinationException.TransferException; break; case ERROR_INTERNET.LOGIN_FAILURE: exception = new LoginException(null, error); break; case ERROR_INTERNET.INCORRECT_PASSWORD: exception = new LoginException(null, error); break; case ERROR_INTERNET.INCORRECT_USER_NAME: exception = new LoginException(null, error); break; case ERROR_INTERNET.EXTENDED_ERROR: exceptionType = SiteDestinationException.UnexpectedException; break; default: exceptionType = SiteDestinationException.UnexpectedException; break; } // Set up a sitedestination exception with the correct information if (exception == null) { exception = new SiteDestinationException( null, exceptionType, GetType().Name, error); } exception.DestinationErrorCode = error; exception.DestinationType = GetType().Name; exception.DestinationExtendedMessage = extendedMessage; // throw it throw exception; }
/// <summary> /// Retrieves a file from the destination and copies it to the specified path. /// </summary> /// <param name="fromPath">the file to retrieve from the destination (relative to basePath)</param> /// <param name="toPath">the local location to save the contents of the file (fully-qualifed path)</param> /// <param name="isBinary">true if the file is binary</param> override public bool GetFile(String fromPath, string toPath, bool isBinary) { fromPath = Path.Combine(m_path, fromPath); FileInfo fromFile = new FileInfo(fromPath); FileInfo toFile = new FileInfo(fromPath); if (fromFile.Equals(toFile)) { //then the source is the same as the destination, so ignore return true; } try { // Delete existing file if (File.Exists(toPath)) File.Delete(toPath); // Copy the file File.Copy(fromPath, toPath); return true; } catch (Exception e) { if (RetryOnException(e)) return false; else { SiteDestinationException ex = new SiteDestinationException(e, SiteDestinationException.TransferException, GetType().Name, 0); ex.DestinationExtendedMessage = e.Message; throw ex; } } }