SalesForceBackup/SalesForceWebDownloader.cs
/// <summary>
/// Downloads the backups from the SalesForce.com website.
/// </summary>
/// <returns>An array of the paths to the files that were downloaded.</returns>
Downloads the backups from the SalesForce.com website.
Downloads the backups from the SalesForce . com website .
public string[] Download()
        {
            var files = new List<string>();
            var sfClient = new SforceService();
            try
            {
                Console.WriteLine("Connecting to SalesForce.com...");
                var currentLoginResult = sfClient.login(_appSettings.Get(AppSettingKeys.Username),
                    _appSettings.Get(AppSettingKeys.Password));
                sfClient.Url = currentLoginResult.serverUrl;
                var sessionId = currentLoginResult.sessionId;
                sfClient.SessionHeaderValue = new SessionHeader {sessionId = sessionId};
                Console.WriteLine("Getting files for download...");
                var page = GetSalesForcePage(_appSettings.Get(AppSettingKeys.DataExportPage), sessionId);
                var regex = new Regex(_appSettings.Get(AppSettingKeys.FilenamePattern), RegexOptions.IgnoreCase);
                var matches = regex.Match(page.Content.ReadAsStringAsync().Result);
                foreach (var match in matches.Groups.Cast<object>()
                    .Where(file => !file.ToString().StartsWith("<a href") && !string.IsNullOrEmpty(file.ToString())))
                {
                    var fileName = match.ToString().Split(new[] {'&'})[0];
                    var url = String.Format("{0}{1}", _appSettings.Get(AppSettingKeys.DownloadPage),
                        match.ToString().Replace("&amp;", "&"));
                    Console.WriteLine("Downloading {0} from SalesForce.com...", fileName);
                    var download = GetSalesForcePage(url, sessionId);
                    var array = download.Content.ReadAsByteArrayAsync().Result;
                    using (var fileStream = File.Create(fileName))
                    {
                        fileStream.Write(array, 0, array.Length);
                    }
                    var filePath = String.Join(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture),
                        new [] { Environment.CurrentDirectory, fileName });
                    files.Add(filePath);
                }
            }
            catch (Exception e)
            {
                _errorHandler.HandleError(e);
            }
            return files.ToArray();
        }
public string [ ] Download ( ) { var files = new List < string > ( ) ; var sfClient = new SforceService ( ) ; try { Console . WriteLine ( " " ) ; var currentLoginResult = sfClient . login ( _appSettings . Get ( AppSettingKeys . Username ) , _appSettings . Get ( AppSettingKeys . Password ) ) ; sfClient . Url = currentLoginResult . serverUrl ; var sessionId = currentLoginResult . sessionId ; sfClient . SessionHeaderValue = new SessionHeader { sessionId = sessionId } ; Console . WriteLine ( " " ) ; var page = GetSalesForcePage ( _appSettings . Get ( AppSettingKeys . DataExportPage ) , sessionId ) ; var regex = new Regex ( _appSettings . Get ( AppSettingKeys . FilenamePattern ) , RegexOptions . IgnoreCase ) ; var matches = regex . Match ( page . Content . ReadAsStringAsync ( ) . Result ) ; foreach ( var match in matches . Groups . Cast < object > ( ) . Where ( file => ! file . ToString ( ) . StartsWith ( " " ) && ! string . IsNullOrEmpty ( file . ToString ( ) ) ) ) { var fileName = match . ToString ( ) . Split ( new [ ] { ' ' } ) [ 0 ] ; var url = String . Format ( " " , _appSettings . Get ( AppSettingKeys . DownloadPage ) , match . ToString ( ) . Replace ( " " , " " ) ) ; Console . WriteLine ( " " , fileName ) ; var download = GetSalesForcePage ( url , sessionId ) ; var array = download . Content . ReadAsByteArrayAsync ( ) . Result ; using ( var fileStream = File . Create ( fileName ) ) { fileStream . Write ( array , 0 , array . Length ) ; } var filePath = String . Join ( Path . DirectorySeparatorChar . ToString ( CultureInfo . InvariantCulture ) , new [ ] { Environment . CurrentDirectory , fileName } ) ; files . Add ( filePath ) ; } } catch ( Exception e ) { _errorHandler . HandleError ( e ) ; } return files . ToArray ( ) ; }
Downloads the backups from the SalesForce.com website.
Downloads the backups from the SalesForce . com website .
//Login to SalesForce //Change the binding to the new endpoint //Create a new session header object and set the session id to that returned by the login //Retrieve the page containing the list of SalesForce exports. //Find any available downloads on the page //Get the correctly formatted download file //Retrieve the file
An array of the paths to the files that were downloaded.
An array of the paths to the files that were downloaded .