public void Init()
        {
            var prefs = MockRepository.GenerateStub <IPreferenceSet>();

            prefs.Stub(x => x.Get <bool>(Preference.UseProxy)).Return(false).Repeat.Any();
            _net = new NetworkOps(prefs);
        }
Example #2
0
        /// <summary>
        /// Send Hung Status Email
        /// </summary>
        private void SendHungEmail(string name)
        {
            string messageBody = String.Format("HFM.NET detected that Client '{0}' has entered a Hung state.", name);

            try
            {
                NetworkOps.SendEmail(Prefs.Get <bool>(Preference.EmailReportingServerSecure),
                                     Prefs.Get <string>(Preference.EmailReportingFromAddress),
                                     Prefs.Get <string>(Preference.EmailReportingToAddress),
                                     "HFM.NET - Client Hung Error", messageBody,
                                     Prefs.Get <string>(Preference.EmailReportingServerAddress),
                                     Prefs.Get <int>(Preference.EmailReportingServerPort),
                                     Prefs.Get <string>(Preference.EmailReportingServerUsername),
                                     Prefs.Get <string>(Preference.EmailReportingServerPassword));
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "{0}", ex.Message);
            }
        }
Example #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));
         //}
      }   
Example #4
0
      private void TestConnectionButtonClick(object sender, EventArgs e)
      {
         if (_net == null)
         {
            _net = new NetworkOps(_prefs);
         }

         try
         {
            SetWaitCursor();
            if (!_scheduledTasksModel.FtpModeEnabled)
            {
               Action<string> del = CheckFileConnection;
               del.BeginInvoke(WebSiteTargetPathTextBox.Text, CheckFileConnectionCallback, del);
            }
            else
            {
               string path = _scheduledTasksModel.WebRoot;
               string server = _scheduledTasksModel.WebGenServer;
               int port = _scheduledTasksModel.WebGenPort;
               string username = _scheduledTasksModel.WebGenUsername;
               string password = _scheduledTasksModel.WebGenPassword;

               FtpCheckConnectionDelegate del = _net.FtpCheckConnection;
               del.BeginInvoke(server, port, path, username, password, _scheduledTasksModel.FtpMode, FtpCheckConnectionCallback, del);
            }
         }
         catch (Exception ex)
         {
            _logger.ErrorFormat(ex, "{0}", ex.Message);
            ShowConnectionFailedMessage(ex.Message);
         }
      }
        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);
        }
Example #6
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));
            //}
        }