Example #1
0
        public void UpdateSitClientPingPending(SitClient clientToUpdate)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            DateTime      timestamp     = DateTime.Now;

            SqlCommand cmd = new SqlCommand();
            string     sql = "";

            cmd.CommandType = System.Data.CommandType.Text;
            try
            {
                int IsPingPending = clientToUpdate.PingPending ? 1 : 0;
                sql             = "Update SitClients set PingPending = " + IsPingPending + ", LastUpdate = '" + timestamp.ToString() + "' where Ip = '" + clientToUpdate.Ip + "'";
                cmd.CommandText = sql;

                cmd.Connection = sqlConnection;

                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                logger.Trace("Exception in database call: " + ex.ToString());
            }
        }
Example #2
0
        public void DeleteSitClient(SitClient clientToDelete)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);

            SqlCommand cmd = new SqlCommand();
            string     sql = "";

            cmd.CommandType = System.Data.CommandType.Text;
            try
            {
                sql = "DELETE FROM SitClients WHERE Id = " + clientToDelete.Id;

                cmd.CommandText = sql;

                cmd.Connection = sqlConnection;

                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                logger.Trace("Exception in database call: " + ex.ToString());
            }
        }
Example #3
0
        public void EditOrInsertSitClient(SitClient clientToUpdate)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            DateTime      timestamp     = DateTime.Now;

            SqlCommand cmd = new SqlCommand();
            string     sql = "";

            cmd.CommandType = System.Data.CommandType.Text;
            try
            {
                if (clientToUpdate.Id >= 0)
                {
                    sql = "Update SitClients set Ip = '" + clientToUpdate.Ip + "', Name = '" + clientToUpdate.Name + "', LastUpdate = '" + timestamp.ToString() + "', PingPending = 0 where Id = '" + clientToUpdate.Id + "'";
                }
                else
                {
                    sql = "insert into SitClients (Name, Ip, IsCLientUp, PingRoundTripTime, LastUpdate, PingPending, CreationDate) values ('" + clientToUpdate.Name + "', '" + clientToUpdate.Ip + "', 0, 0, '" + timestamp.ToString() + "', 0, '" + timestamp.ToString() + "')";
                }
                cmd.CommandText = sql;

                cmd.Connection = sqlConnection;

                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                logger.Trace("Exception in database call: " + ex.ToString());
            }
        }
Example #4
0
        public void UpdateSitClientHeartBeat(SitClient clientToUpdate)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            DateTime      timestamp     = DateTime.Now;

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.Text;
            try
            {
                if (RetrieveSitClient(clientToUpdate.Name) != null)
                {
                    logger.Trace("Updating HeartBeat for client name: " + clientToUpdate.Name + ", HeartBeat: " + timestamp.ToString());
                    cmd.CommandText = "Update SitClients set LastHeartBeat = '" + timestamp.ToString() + "' , LastUpdate = '" + timestamp.ToString() + "' where Name = '" + clientToUpdate.Name + "'";
                }
                else
                {
                    logger.Trace("Inserting client name: " + clientToUpdate.Name + ", HeartBeat: " + timestamp.ToString());
                    cmd.CommandText = "INSERT SitClients (Name, LastHeartBeat) VALUES ('" + clientToUpdate.Name + "', '" + timestamp.ToString() + "')";
                }

                cmd.Connection = sqlConnection;

                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                logger.Trace("Exception in database call: " + ex.ToString());
            }
        }
Example #5
0
        public List <SitClient> RetrieveSitClientsHistory()
        {
            List <SitClient> sitClients = new List <SitClient>();

            SqlCommand    command;
            string        sql = null;
            SqlDataReader dataReader;

            sql = @"select * from SitClientsHistory";

            SqlConnection cnn;

            cnn = new SqlConnection(connectionString);
            try
            {
                cnn.Open();
                command    = new SqlCommand(sql, cnn);
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    SitClient sitClientToAdd = new SitClient();
                    if (!dataReader.IsDBNull(0))
                    {
                        sitClientToAdd.Id = Convert.ToInt32(dataReader.GetValue(0));
                    }
                    if (!dataReader.IsDBNull(1))
                    {
                        sitClientToAdd.Name = Convert.ToString(dataReader.GetValue(1));
                    }
                    if (!dataReader.IsDBNull(2))
                    {
                        sitClientToAdd.Ip = Convert.ToString(dataReader.GetValue(2));
                    }
                    if (!dataReader.IsDBNull(3))
                    {
                        sitClientToAdd.IsClientUp = Convert.ToBoolean(dataReader.GetValue(3));
                    }
                    if (!dataReader.IsDBNull(4))
                    {
                        sitClientToAdd.PingRoundTripTime = Convert.ToInt32(dataReader.GetValue(4));
                    }
                    if (!dataReader.IsDBNull(5))
                    {
                        sitClientToAdd.LastUpdate = Convert.ToDateTime(dataReader.GetValue(5));
                    }

                    sitClients.Add(sitClientToAdd);
                }
                dataReader.Close();
                command.Dispose();
                cnn.Close();
            }
            catch (Exception ex)
            {
                logger.Trace("Exception in database call: " + ex.ToString());
            }

            return(sitClients);
        }
        public HttpResponseMessage DeleteSitClient(HttpRequestMessage argument)
        {
            string data = argument.Content.ReadAsStringAsync().Result;

            SitClient jsonArgument = JsonConvert.DeserializeObject <SitClient>(data);

            sitClientsRepository.DeleteSitClient(jsonArgument);
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        public IHttpActionResult UpdateSitClientHeartBeat(string argument)
        {
            SitClient clientToUpdate = new SitClient();

            clientToUpdate.Name = argument;

            sitClientsRepository.UpdateSitClientHeartBeat(clientToUpdate);

            return(Ok());
        }
        public void PingSitClient(SitClient c)
        {
            //c.PingPending = true;
            //UpdateSitClientPingPending(c);

            try
            {
                Ping pingSender = new Ping();

                // The class Client has a property tcpClient of type TcpClient
                IPAddress address = IPAddress.Parse(c.Ip);
                PingReply reply   = pingSender.Send(address);

                if (reply.Status == IPStatus.Success)
                {
                    if (debugMode)
                    {
                        logger.Trace("Success  " + c.Name + " ip: " + c.Ip + " RoundtripTime: " + reply.RoundtripTime);
                    }
                    c.IsClientUp        = true;
                    c.PingRoundTripTime = Convert.ToInt32(reply.RoundtripTime);
                    rtdsManager.updateRtdsTag(c.Name, true);
                }
                else
                {
                    if (debugMode)
                    {
                        logger.Trace("Failed   " + c.Name + " ip: " + c.Ip);
                    }
                    c.IsClientUp        = false;
                    c.PingRoundTripTime = 0;
                    rtdsManager.updateRtdsTag(c.Name, false);
                }

                clientsToUpdate.Add(c);
                //UpdateSitClientIsUpFlag(c);
                //InsertSitClientHistory(c);
            }
            catch (Exception ex)
            {
                logger.Trace("Error in testing " + c.Name + " ip: " + c.Ip + " probably ip was null or invalid");
                //c.PingPending = false;
                c.IsClientUp = false;
                rtdsManager.updateRtdsTag(c.Name, false);
                //UpdateSitClientPingPending(c);
                //UpdateSitClientIsUpFlag(c);
                //InsertSitClientHistory(c);
                clientsToUpdate.Add(c);
            }
        }