public void CreateContinuousData(ContinuousBufferDto continuousData)
        {
            ContinuousBufferDto cd  = new ContinuousBufferDto();
            String connectionString = ConfigurationManager.ConnectionStrings["SQLServer"].ToString();

            if (connectionString != string.Empty)
            {
                var ValueExist = false;
                try
                {
                    SqlConnection checkConnection = new SqlConnection(connectionString);
                    checkConnection.Open();
                    SqlCommand cmdCheck = new SqlCommand("Select * From [Abbon.UDP.Database].dbo.ContinuousData Where WellId = " + continuousData.WellId
                                                         + " and Time = " + continuousData.Time
                                                         + " and DiffPressure = " + continuousData.DiffPressure
                                                         + " and Pressure = " + continuousData.Pressure
                                                         + " and Temperature = " + continuousData.Temperature);
                    var valueFound = cmdCheck.ExecuteScalar();
                    checkConnection.Close();

                    if (valueFound == null)
                    {
                        ValueExist = true;
                    }
                }
                catch (Exception ex)
                {
                    Log.Verbose("Exception raised in SQL Command", ex.Message);
                }

                if (ValueExist)
                {
                    try
                    {
                        SqlConnection sc  = new SqlConnection();
                        SqlCommand    cmd = new SqlCommand();
                        cmd.CommandType = System.Data.CommandType.Text;
                        cmd.CommandText = "INSERT [Abbon.UDP.Database].dbo.ContinuousData(WellId, Time,DiffPressure,Pressure,Temperature)" +
                                          "VALUES(@WellId, @Time,@DiffPressure,@Pressure,@Temperature)";
                        cmd.Parameters.AddWithValue("(@WellId", continuousData.WellId);
                        cmd.Parameters.AddWithValue("(@Time", continuousData.Time);
                        cmd.Parameters.AddWithValue("(@DiffPressure", continuousData.DiffPressure);
                        cmd.Parameters.AddWithValue("(@Pressure", continuousData.Pressure);
                        cmd.Parameters.AddWithValue("(@Temperature", continuousData.Temperature);
                        cmd.Connection = sc;
                        sc.Open();
                        cmd.ExecuteNonQuery();
                        sc.Close();
                    }
                    catch (Exception ex)
                    {
                        Log.Verbose("Exception raised in SQL Command", ex.Message);
                    }
                }
            }
            else
            {
                Log.Fatal("Could not connect to SQL Server.  Connection String with name SQLServer Missing!");
            }
        }
        public ObservableCollection <ContinuousBufferDto> GetContinuousData()
        {
            using (Entities entity = new Entities())
            {
                ObservableCollection <ContinuousBufferDto> retval = new ObservableCollection <ContinuousBufferDto>();
                foreach (ContinuousData cd in entity.ContinuousDatas.OrderBy(x => x.Id))
                {
                    ContinuousBufferDto cbd = new ContinuousBufferDto();
                    cbd.WellId       = cd.WellId;
                    cbd.Time         = cd.Time;
                    cbd.DiffPressure = cd.DiffPressure;
                    cbd.Pressure     = cd.Pressure;
                    cbd.Temperature  = cd.Temperature;

                    retval.Add(cbd);
                }
                return(retval);
            }
        }
예제 #3
0
        //static DeviceClient deviceClient;


        static void Main(string[] args)
        {
            //Creates a UdpClient for reading incoming data.
            UdpClient receivingUdpClient = new UdpClient(50002);

            //Creates an IPEndPoint to record the IP Address and port number of the sender.
            //The IPendPoint will allow you to read datagrams send from any source.
            //IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse("10.0.10.136"), 50002);
            IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

            #region test
            //try
            //{
            //    //Blocks until a message returns on this socket from a remote host.
            //    Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);

            //    string returnData = Encoding.ASCII.GetString(receiveBytes);

            //    Console.WriteLine("This is the message you received " +
            //                                 returnData.ToString());
            //    Console.WriteLine("This message was sent from " +
            //                                RemoteIpEndPoint.Address.ToString() +
            //                                " on their port number " +
            //                                RemoteIpEndPoint.Port.ToString());
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.ToString());
            //    Console.ReadKey();
            //}
            #endregion

            while (true)
            {
                try
                {
                    //Creates an IPEndPoint to record the IP Address and port number of the sender.
                    //The IPEndPoint will allow you to read datagrams sent from any source.
                    Byte[] packet = receivingUdpClient.Receive(ref RemoteIpEndPoint);

                    string returnData = Encoding.ASCII.GetString(packet);

                    int        packetSize = BitConverter.ToUInt16(new byte[] { packet[4], packet[5] }, 0);
                    FlagIdEnum flag       = (FlagIdEnum)packet[8];
                    TypeIdEnum type       = (TypeIdEnum)packet[6];
                    var        command    = (Enums.AcquisitionCommandIdEnum)packet[7];

                    var x = new Program();
                    x.init(packet);
                    x.HeaderData(packet);

                    AcquisitionDataBlock adb = x.ProcessData(packet);

                    ContinuousBufferDto cb = new ContinuousBufferDto();
                    cb.WellId       = adb.WellId;
                    cb.Time         = adb.TimeStamp;
                    cb.DiffPressure = adb.Process2DP;
                    cb.Pressure     = adb.Process4P;
                    cb.Temperature  = adb.Process1Temp;

                    //Store ContinuousBufferDto to database.

                    Console.WriteLine("This is the message you received "); //+ returnData.ToString());
                    Console.WriteLine("Size : " + packetSize);
                    Console.WriteLine("Flag : " + flag);
                    Console.WriteLine("Type : " + type);

                    Console.WriteLine("Process1Temp : " + adb.Process1Temp);
                    Console.WriteLine("Process4P : " + adb.Process4P);



                    Console.WriteLine("This message was sent from " +
                                      RemoteIpEndPoint.Address.ToString() +
                                      " on their port number " +

                                      RemoteIpEndPoint.Port.ToString());
                    Console.WriteLine("------------------------------------");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.ReadKey();
                }
            }
        }
예제 #4
0
 public void DeleteContinuousData(ContinuousBufferDto cd)
 {
     this.ContinuousDataRepository.DeleteContinuousData(cd);
 }
예제 #5
0
 public void CreateContinuousData(ContinuousBufferDto cd)
 {
     this.ContinuousDataRepository.CreateContinuousData(cd);
 }
 public void DeleteContinuousData(ContinuousBufferDto continuousData)
 {
     throw new NotImplementedException();
 }