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

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

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

            _net.HttpDownloadHelper(webOperation, "testpath", String.Empty, String.Empty);

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

            webOperation.VerifyAllExpectations();
        }
Пример #2
0
      private void RetrieveHttpInstance()
      {
         var net = new NetworkOps(_prefs);

         //DateTime start = Instrumentation.ExecStart;

         //try
         //{
            string httpPath = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Settings.Path, "/", Settings.FahLogFileName);
            string localFile = Path.Combine(_prefs.CacheDirectory, Settings.CachedFahLogFileName());
            net.HttpDownloadHelper(httpPath, localFile, Settings.Username, Settings.Password);

            try
            {
               httpPath = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Settings.Path, "/", Settings.UnitInfoFileName);
               localFile = Path.Combine(_prefs.CacheDirectory, Settings.CachedUnitInfoFileName());

               long length = net.GetHttpDownloadLength(httpPath, Settings.Username, Settings.Password);
               if (length < Constants.UnitInfoMax)
               {
                  net.HttpDownloadHelper(httpPath, localFile, Settings.Username, Settings.Password);
               }
               else
               {
                  if (File.Exists(localFile))
                  {
                     File.Delete(localFile);
                  }

                  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(localFile))
               {
                  File.Delete(localFile);
               }
               string message = String.Format(CultureInfo.CurrentCulture, "unitinfo download failed: {0}", ex.Message);
               _logger.WarnFormat(Constants.ClientNameFormat, Settings.Name, message);
            }

            try
            {
               httpPath = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Settings.Path, "/", Settings.QueueFileName);
               localFile = Path.Combine(_prefs.CacheDirectory, Settings.CachedQueueFileName());
               net.HttpDownloadHelper(httpPath, localFile, Settings.Username, Settings.Password);
            }
            /*** Remove Requirement for Queue to be Present ***/
            catch (WebException ex)
            {
               if (File.Exists(localFile))
               {
                  File.Delete(localFile);
               }
               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 PerformDownload(string downloadUrl)
        {
            Debug.Assert(Prefs != null);

             var net = new NetworkOps(Prefs);
             net.HttpWebOperationProgress += HttpWebOperationProgress;
             net.HttpDownloadHelper(downloadUrl, DownloadFilePath, String.Empty, String.Empty);
        }
Пример #4
0
        private void RetrieveHttpInstance()
        {
            var net = new NetworkOps(_prefs);

            //DateTime start = Instrumentation.ExecStart;

            //try
            //{
            string httpPath  = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Settings.Path, "/", Settings.FahLogFileName);
            string localFile = Path.Combine(_prefs.CacheDirectory, Settings.CachedFahLogFileName());

            net.HttpDownloadHelper(httpPath, localFile, Settings.Username, Settings.Password);

            try
            {
                httpPath  = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Settings.Path, "/", Settings.UnitInfoFileName);
                localFile = Path.Combine(_prefs.CacheDirectory, Settings.CachedUnitInfoFileName());

                long length = net.GetHttpDownloadLength(httpPath, Settings.Username, Settings.Password);
                if (length < Constants.UnitInfoMax)
                {
                    net.HttpDownloadHelper(httpPath, localFile, Settings.Username, Settings.Password);
                }
                else
                {
                    if (File.Exists(localFile))
                    {
                        File.Delete(localFile);
                    }

                    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(localFile))
                {
                    File.Delete(localFile);
                }
                string message = String.Format(CultureInfo.CurrentCulture, "unitinfo download failed: {0}", ex.Message);
                Logger.WarnFormat(Constants.ClientNameFormat, Settings.Name, message);
            }

            try
            {
                httpPath  = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Settings.Path, "/", Settings.QueueFileName);
                localFile = Path.Combine(_prefs.CacheDirectory, Settings.CachedQueueFileName());
                net.HttpDownloadHelper(httpPath, localFile, Settings.Username, Settings.Password);
            }
            /*** Remove Requirement for Queue to be Present ***/
            catch (WebException ex)
            {
                if (File.Exists(localFile))
                {
                    File.Delete(localFile);
                }
                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));
            //}
        }