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

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

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

            long length = _net.GetHttpDownloadLength(webOperation, String.Empty, String.Empty);

            Assert.AreEqual(100, length);

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

            webOperation.VerifyAllExpectations();
        }
      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));
         //}
      }
Exemple #3
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));
            //}
        }