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

            webOperation.Expect(x => x.Download("testpath"));
            var webRequest = MockRepository.GenerateStub <IFtpWebRequest>();

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

            _net.FtpDownloadHelper(webOperation, "testpath", String.Empty, String.Empty, FtpMode.Active);

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

            webOperation.VerifyAllExpectations();
        }
示例#2
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));
         //}
      }   
示例#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));
            //}
        }