Esempio n. 1
0
        /// <summary>
        /// Добавить параметр на запись в БД
        /// </summary>
        /// <param name="value">Параметр для записи</param>
        public void ToWrite(DataBaseParameterValue value)
        {
            bool blocked = false;

            try
            {
                if (mutex.WaitOne(1000))
                {
                    if (state == SaverState.Started)
                    {
                        if (in_out_mutex.WaitOne(1000))
                        {
                            blocked = true;
                            input.Add(value);
                        }
                    }

                    mutex.ReleaseMutex();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (blocked)
                {
                    in_out_mutex.ReleaseMutex();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Добавить параметр на запись в БД
        /// </summary>
        /// <param name="value">Параметр для записи</param>
        public void ToWrite(DataBaseParameterValue value)
        {
            bool blocked = false;
            try
            {
                if (mutex.WaitOne(1000))
                {
                    if (state == SaverState.Started)
                    {
                        if (in_out_mutex.WaitOne(1000))
                        {
                            blocked = true;
                            input.Add(value);
                        }
                    }

                    mutex.ReleaseMutex();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (blocked) in_out_mutex.ReleaseMutex();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Получить все значения параметра из БД
        /// </summary>
        /// <param name="Identifier">Идентификатор параметра</param>
        /// <returns>В случае успеха массив значений параметра, в противном случае null</returns>
        public DataBaseParameterValue[] GetParameterValues(Guid Identifier)
        {
            SqlConnection connection = null;
            try
            {
                connection = new SqlConnection(adapter.ConnectionString);
                connection.Open();

                if (connection.State == ConnectionState.Open)
                {
                    if (Peek(Identifier))
                    {
                        SqlCommand command = connection.CreateCommand();

                        command.Parameters.Add(structure.MainTable["guid"].Parameter);
                        command.Parameters[0].Value = Identifier.ToString();

                        command.CommandText = string.Format("Select tab_val From {0} Where guid = @guid", structure.MainTable.Name);

                        object result = command.ExecuteScalar();
                        if (result != null)
                        {
                            string tbl = string.Format("dbo.{0}", (string)result);

                            SqlCommand cmd = connection.CreateCommand();

                            cmd.CommandText = string.Format("Select dbo.t_measuring.val_Time, {0}.val_prm From dbo.t_measuring, {0} Where " +
                                "dbo.t_measuring.id = {0}.id", tbl);

                            SqlDataReader reader = cmd.ExecuteReader();
                            if (reader != null)
                            {
                                if (reader.IsClosed == false)
                                {
                                    List<DataBaseParameterValue> values = new List<DataBaseParameterValue>();
                                    while (reader.Read())
                                    {
                                        DateTime time = DateTime.FromOADate(reader.GetDouble(0));
                                        Single value = reader.GetFloat(1);

                                        DataBaseParameterValue val = new DataBaseParameterValue(Identifier, time.Ticks, value);
                                        values.Add(val);
                                    }

                                    return values.ToArray();
                                }
                                else
                                    return null;
                            }
                            else
                                throw new Exception("Не удалось считать данные параметра");
                        }
                        else
                            throw new Exception("Не удалось считать данные параметра");
                    }
                    else
                        throw new Exception("Указанного параметр отсутствует в БД");
                }
                else
                    throw new Exception("Не удалось подключиться к БД");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (connection != null)
                {
                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }

                    connection.Dispose();
                }
            }
        }