/// <summary> /// Остановить процедуру сохранения /// </summary> public void Stop() { bool blocked = false; try { if (mutex.WaitOne(1000)) { blocked = true; state = SaverState.Stopped; timer.Change(Timeout.Infinite, timeToBuffer); if (callBackMutex.WaitOne(3000)) { measuring = null; callBackMutex.ReleaseMutex(); } state = SaverState.Stopped; } } finally { if (blocked) { mutex.ReleaseMutex(); } } }
/// <summary> /// Запустить процедуру сохранения /// </summary> public void Start() { bool blocked = false; try { if (mutex.WaitOne(1000)) { blocked = true; state = SaverState.Started; measuring = t_measuring.Virtualize(adapter); timer.Change(0, timeToBuffer); state = SaverState.Started; } } finally { if (blocked) { mutex.ReleaseMutex(); } } }
/// <summary> /// Загрузить базу данных /// </summary> /// <param name="provider">Класс реализующий сервисные функции работы с базой данных</param> /// <returns>Состояние базы данных после выполнение операции загрузки БД</returns> public static DataBaseState LoadDB(DataBaseProvider provider) { if (provider != null) { switch (State) { case DataBaseState.Loaded: throw new InvalidOperationException("Не допустимая операция. Перез загрузкой БД, необходимо завершить работу с текущей."); case DataBaseState.Unloaded: case DataBaseState.Default: parameters.Clear(); try { DataBaseParameter[] parames = provider.Parameters; if (parames != null) { foreach (DataBaseParameter parameter in parames) { if (parameter != null) { parameters.Insert(parameter); } } _provider = provider; measuring = t_measuring.Virtualize(provider.Adapter); } State = DataBaseState.Loaded; return(State); } catch (Exception ex) { throw new Exception(ex.Message, ex); } default: break; } } return(DataBaseState.Default); }
/// <summary> /// Виртуализируем таблицу времени /// </summary> /// <param name="Adapter">Объет определяющий подключение к БД</param> /// <returns>В случае успеха виртуализировнная таблица времени, в противном случае null</returns> public static t_measuring Virtualize(DataBaseAdapter Adapter) { SqlConnection connection = null; try { connection = new SqlConnection(Adapter.ConnectionString); connection.Open(); if (connection.State == ConnectionState.Open) { using (SqlCommand command = connection.CreateCommand()) { command.CommandText = string.Format("Select * From {0} Order By id Desc", "dbo.t_measuring"); using (SqlDataReader reader = command.ExecuteReader()) { t_measuring measuring = new t_measuring(Adapter); measuring.LastId = 0; measuring.LastTime = DateTime.Now.Ticks; measuring.LastDept = 0.0f; if (reader != null) { if (reader.IsClosed == false) { while (reader.Read()) { measuring.LastId = reader.GetInt32(0); DateTime t = DateTime.FromOADate(reader.GetDouble(1)); measuring.LastTime = t.Ticks; measuring.LastDept = 0.0f; break; } } return(measuring); } 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(); } } }
/// <summary> /// Виртуализируем таблицу времени /// </summary> /// <param name="Adapter">Объет определяющий подключение к БД</param> /// <returns>В случае успеха виртуализировнная таблица времени, в противном случае null</returns> public static t_measuring Virtualize(DataBaseAdapter Adapter) { SqlConnection connection = null; try { connection = new SqlConnection(Adapter.ConnectionString); connection.Open(); if (connection.State == ConnectionState.Open) { SqlCommand command = connection.CreateCommand(); command.CommandText = string.Format("Select * From {0} Order By id Desc", "dbo.t_measuring"); SqlDataReader reader = command.ExecuteReader(); t_measuring measuring = new t_measuring(Adapter); measuring.LastId = 0; measuring.LastTime = DateTime.Now.Ticks; measuring.LastDept = 0.0f; if (reader != null) { if (reader.IsClosed == false) { while (reader.Read()) { measuring.LastId = reader.GetInt32(0); DateTime t = DateTime.FromOADate(reader.GetDouble(1)); measuring.LastTime = t.Ticks; measuring.LastDept = 0.0f; break; } } return measuring; } 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(); } } }
/// <summary> /// Остановить процедуру сохранения /// </summary> public void Stop() { bool blocked = false; try { if (mutex.WaitOne(1000)) { blocked = true; state = SaverState.Stopped; timer.Change(Timeout.Infinite, timeToBuffer); if (callBackMutex.WaitOne(3000)) { measuring = null; callBackMutex.ReleaseMutex(); } state = SaverState.Stopped; } } finally { if (blocked) mutex.ReleaseMutex(); } }
/// <summary> /// Запустить процедуру сохранения /// </summary> public void Start() { bool blocked = false; try { if (mutex.WaitOne(1000)) { blocked = true; state = SaverState.Started; measuring = t_measuring.Virtualize(adapter); timer.Change(0, timeToBuffer); state = SaverState.Started; } } finally { if (blocked) mutex.ReleaseMutex(); } }
/// <summary> /// Загрузить базу данных /// </summary> /// <param name="provider">Класс реализующий сервисные функции работы с базой данных</param> /// <returns>Состояние базы данных после выполнение операции загрузки БД</returns> public static DataBaseState LoadDB(DataBaseProvider provider) { if (provider != null) { switch (State) { case DataBaseState.Loaded: throw new InvalidOperationException("Не допустимая операция. Перез загрузкой БД, необходимо завершить работу с текущей."); case DataBaseState.Unloaded: case DataBaseState.Default: parameters.Clear(); try { DataBaseParameter[] parames = provider.Parameters; if (parames != null) { foreach (DataBaseParameter parameter in parames) { if (parameter != null) { parameters.Insert(parameter); } } _provider = provider; measuring = t_measuring.Virtualize(provider.Adapter); } State = DataBaseState.Loaded; return State; } catch (Exception ex) { throw new Exception(ex.Message, ex); } default: break; } } return DataBaseState.Default; }