Пример #1
0
        /// <summary>
        /// Constructor of FormOptions class
        /// </summary>
        /// <param name="ConfigXML">Represents the parsed config XML file</param>
        public FormOptions(Xmlconfig configXML, User AdminUser)
        {
            InitializeComponent();

              this.AdminUser = AdminUser;

              ConfigInitialized = false;
              RainfallLogDirPath = string.Empty;
              AppLogDirPath = string.Empty;
              WinrarDirPath = string.Empty;
              GSMCOMPort = string.Empty;
              GSMBaudRate = 0;
              GSMStopBits = StopBits.One;
              GSMParity = Parity.None;
              ArduinoCOMPort = string.Empty;
              ArduinoBaudRate = 0;
              ArduinoStopBits = StopBits.One;
              ArduinoParity = Parity.None;
              NumFailedReads = 0;
              NumInactiveMins = 0;
              this.configXML = configXML;

              #region Initializing the Option parameters

              LoadGUIFromConfig();
              SaveAllTabs(true);

              ConfigInitialized = configXML.Settings[Conf.CONFIG_INITIALIZED_TAG].boolValue;

              if (ConfigInitialized == false)
              {
            MessageBox.Show("It seems like the application has not been configured yet. Please configure it first" + "\n" + Util.GetMethodNameAndLineNum(),
                        "SENSIT Server",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Asterisk);
            this.ShowDialog();

            if (ConfigInitialized)
            {
              configXML.Settings[Conf.CONFIG_INITIALIZED_TAG].boolValue = true;
              configXML.Save(Conf.CONFIG_FILE_PATH);
            }
            else
            {
              this.Close();
              this.Dispose();
            }
              }

              #endregion
        }
Пример #2
0
        private void HandleLogin()
        {
            User user = new User(this.txtPassword.Text, false);

              if ((LoginSuccessful = user.Equals(adminUser)) == false)
              {
            MessageBox.Show("Password mismatch.\n\n" + "Please send an e-mail to [email protected] requesting for the login Text in case you do not have it.\n" + Util.GetMethodNameAndLineNum(),
                        "Login Failed",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
            this.txtPassword.Focus();
            this.txtPassword.SelectAll();
              }
              else
              {
            this.Close();
              }
        }
Пример #3
0
 /// <summary>
 /// Compares the login credentials of the object user with anotherUser
 /// </summary>
 /// <param name="anotherUser">User object to compare with</param>
 /// <returns>true if both the login credentials match, false otherwise</returns>
 public bool Equals(User anotherUser)
 {
     return (this.PasswordHash.Equals(anotherUser.PasswordHash));
 }
Пример #4
0
        /// <summary>
        /// Constructor for FormLogin
        /// </summary>
        /// <param name="AdminUser">Has AdminUser username and pasword hash</param>
        public FormLogin(User adminUser)
        {
            InitializeComponent();

              this.adminUser = adminUser;
        }
Пример #5
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            #region Loading the configuration XML file

              try
              {
            ConfigXML = new Xmlconfig(Conf.CONFIG_FILE_PATH, false);
              }
              catch (Exception exc)
              {
            LoggerError("The " + Conf.CONFIG_FILE_PATH + " file is either corrupted or does not exist. It will be reset to original form.\n\n" + exc.Message);
            #if DEBUG
            MessageBox.Show("The " + Conf.CONFIG_FILE_PATH + " file is either corrupted or does not exist. It will be reset to original form.\n\n" + exc.Message + "\n" + Util.GetMethodNameAndLineNum(),
                        "SENSIT Server",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
            #endif

            /* Copy contents from config.template.xml file.
             * This will be the case when the application is
             * started for the very first time after installation.
             */
            try
            {
              File.Copy(Conf.CONFIG_TEMPLATE_FILE_PATH, Conf.CONFIG_FILE_PATH, true);
            }
            catch (Exception exc1)
            {
              LoggerError("Could not open " + Conf.CONFIG_TEMPLATE_FILE_PATH + "\n" + exc1.Message);
            #if DEBUG
              MessageBox.Show("Could not open " + Conf.CONFIG_TEMPLATE_FILE_PATH + "\n" + exc1.Message + "\n" + Util.GetMethodNameAndLineNum(),
                          "SENSIT Server",
                          MessageBoxButtons.OK,
                          MessageBoxIcon.Error);
            #endif
              this.Close();
            }
              }

              ConfigXML = new Xmlconfig(Conf.CONFIG_FILE_PATH, false);

              #region Loading the information about the known sensors
              {
            KnownSensors = new Dictionary<string, Sensor>();
            IList<ConfigSetting> sensorList = ConfigXML.Settings[Conf.SENSOR_LIST_NODE].Children();

            foreach (ConfigSetting sensorNode in sensorList)
            {
              string Id = sensorNode[Conf.SENSOR_ID_TAG].Value;
              string description = sensorNode[Conf.SENSOR_DESC_TAG].Value;
              string state = sensorNode[Conf.SENSOR_STATE_TAG].Value;
              float pingInterval = sensorNode[Conf.SENSOR_PING_INTERVAL_TAG].floatValue;

              KnownSensors.Add(Id, new Sensor(Id, state, description, pingInterval));
              // Updating the sensor info in the checked list box
              AddToListKnownSensors(Id);
            }
              }
              #endregion

              ConfigXML.Save(Conf.CONFIG_FILE_PATH);
              #endregion

              #region Ask user to login. Only when correctly logged in, do proceed to other tasks
              string passwordHash = ConfigXML.Settings[Conf.ADMIN_NODE][Conf.PASSWORD_HASH_TAG].Value;
              bool rememberPassword = ConfigXML.Settings[Conf.ADMIN_NODE][Conf.REMEMBER_PASSWORD_TAG].boolValue;

              if (passwordHash.Length == 0)
              {
            /* Case when the server is started for the 1st time after fresh installation
             * hence give default password
             */
            AdminUser = new User("sensit123", false);
              }
              else
              {
            // Server has already been started so load the saved password's hash
            AdminUser = new User(passwordHash, true);
              }

              ConfigXML.Settings[Conf.ADMIN_NODE][Conf.PASSWORD_HASH_TAG].Value = AdminUser.PasswordHash;
              ConfigXML.Settings[Conf.ADMIN_NODE][Conf.REMEMBER_PASSWORD_TAG].boolValue = rememberPassword;

              if (rememberPassword == false || passwordHash.Length == 0)
              {
            FormLogin frmLogin = new FormLogin(AdminUser);
            frmLogin.ShowDialog();
            if (frmLogin.LoginSuccessful == false)
            {
              this.Close();
              return;
            }
              }
              #endregion
        }