public void GetFtpDownloadLength_Test()
        {
            var webOperation = MockRepository.GenerateMock <IWebOperation>();

            webOperation.Expect(x => x.GetDownloadLength()).Return(100);
            var webRequest = MockRepository.GenerateStub <IFtpWebRequest>();

            webOperation.Stub(x => x.WebRequest).Return(webRequest);

            long length = _net.GetFtpDownloadLength(webOperation, String.Empty, String.Empty, FtpMode.Active);

            Assert.AreEqual(100, length);

            Assert.AreEqual(RequestCacheLevel.NoCacheNoStore, webRequest.CachePolicy.Level);
            Assert.AreEqual(false, webRequest.UsePassive);

            webOperation.VerifyAllExpectations();
        }
      private void RetrieveFtpInstance()
      {
         var net = new NetworkOps(_prefs);

         //DateTime start = Instrumentation.ExecStart;

         //try
         //{
            string localFilePath = Path.Combine(_prefs.CacheDirectory, Settings.CachedFahLogFileName());
            net.FtpDownloadHelper(Settings.Server, Settings.Port, Settings.Path, Settings.FahLogFileName, localFilePath,
                                  Settings.Username, Settings.Password, Settings.FtpMode);

            try
            {
               localFilePath = Path.Combine(_prefs.CacheDirectory, Settings.CachedUnitInfoFileName());

               long length = net.GetFtpDownloadLength(Settings.Server, Settings.Path, Settings.UnitInfoFileName,
                                                      Settings.Username, Settings.Password, Settings.FtpMode);
               if (length < Constants.UnitInfoMax)
               {
                  net.FtpDownloadHelper(Settings.Server, Settings.Port, Settings.Path, Settings.UnitInfoFileName, localFilePath,
                                        Settings.Username, Settings.Password, Settings.FtpMode);
               }
               else
               {
                  if (File.Exists(localFilePath))
                  {
                     File.Delete(localFilePath);
                  }

                  string message = String.Format(CultureInfo.CurrentCulture, "unitinfo download (file is too big: {0} bytes).", length);
                  _logger.WarnFormat(Constants.ClientNameFormat, Settings.Name, message);
               }
            }
            /*** Remove Requirement for UnitInfo to be Present ***/
            catch (WebException ex)
            {
               if (File.Exists(localFilePath))
               {
                  File.Delete(localFilePath);
               }
               string message = String.Format(CultureInfo.CurrentCulture, "unitinfo download failed: {0}.", ex.Message);
               _logger.WarnFormat(Constants.ClientNameFormat, Settings.Name, message);
            }

            try
            {
               localFilePath = Path.Combine(_prefs.CacheDirectory, Settings.CachedQueueFileName());
               net.FtpDownloadHelper(Settings.Server, Settings.Port, Settings.Path, Settings.QueueFileName, localFilePath,
                                     Settings.Username, Settings.Password, Settings.FtpMode);
            }
            /*** Remove Requirement for Queue to be Present ***/
            catch (WebException ex)
            {
               if (File.Exists(localFilePath))
               {
                  File.Delete(localFilePath);
               }
               string message = String.Format(CultureInfo.CurrentCulture, "queue download failed: {0}", ex.Message);
               _logger.WarnFormat(Constants.ClientNameFormat, Settings.Name, message);
            }
         //}
         //finally
         //{
         //   _logger.Info(Constants.ClientNameFormat, Settings.Name, Instrumentation.GetExecTime(start));
         //}
      }   
Exemple #3
0
        private void RetrieveFtpInstance()
        {
            var net = new NetworkOps(_prefs);

            //DateTime start = Instrumentation.ExecStart;

            //try
            //{
            string localFilePath = Path.Combine(_prefs.CacheDirectory, Settings.CachedFahLogFileName());

            net.FtpDownloadHelper(Settings.Server, Settings.Port, Settings.Path, Settings.FahLogFileName, localFilePath,
                                  Settings.Username, Settings.Password, Settings.FtpMode);

            try
            {
                localFilePath = Path.Combine(_prefs.CacheDirectory, Settings.CachedUnitInfoFileName());

                long length = net.GetFtpDownloadLength(Settings.Server, Settings.Path, Settings.UnitInfoFileName,
                                                       Settings.Username, Settings.Password, Settings.FtpMode);
                if (length < Constants.UnitInfoMax)
                {
                    net.FtpDownloadHelper(Settings.Server, Settings.Port, Settings.Path, Settings.UnitInfoFileName, localFilePath,
                                          Settings.Username, Settings.Password, Settings.FtpMode);
                }
                else
                {
                    if (File.Exists(localFilePath))
                    {
                        File.Delete(localFilePath);
                    }

                    string message = String.Format(CultureInfo.CurrentCulture, "unitinfo download (file is too big: {0} bytes).", length);
                    Logger.WarnFormat(Constants.ClientNameFormat, Settings.Name, message);
                }
            }
            /*** Remove Requirement for UnitInfo to be Present ***/
            catch (WebException ex)
            {
                if (File.Exists(localFilePath))
                {
                    File.Delete(localFilePath);
                }
                string message = String.Format(CultureInfo.CurrentCulture, "unitinfo download failed: {0}.", ex.Message);
                Logger.WarnFormat(Constants.ClientNameFormat, Settings.Name, message);
            }

            try
            {
                localFilePath = Path.Combine(_prefs.CacheDirectory, Settings.CachedQueueFileName());
                net.FtpDownloadHelper(Settings.Server, Settings.Port, Settings.Path, Settings.QueueFileName, localFilePath,
                                      Settings.Username, Settings.Password, Settings.FtpMode);
            }
            /*** Remove Requirement for Queue to be Present ***/
            catch (WebException ex)
            {
                if (File.Exists(localFilePath))
                {
                    File.Delete(localFilePath);
                }
                string message = String.Format(CultureInfo.CurrentCulture, "queue download failed: {0}", ex.Message);
                Logger.WarnFormat(Constants.ClientNameFormat, Settings.Name, message);
            }
            //}
            //finally
            //{
            //   Logger.Info(Constants.ClientNameFormat, Settings.Name, Instrumentation.GetExecTime(start));
            //}
        }