static void Main() { var db = new DataBase.DataBase(); var service = new Service(db); using (ServiceHost host = new ServiceHost(service, new Uri("localhost:8080"))) { try { host.Open(); Console.WriteLine("host started!"); Console.ReadLine(); host.Close(); } catch (TimeoutException timeProblem) { Console.WriteLine(timeProblem.Message); Console.ReadLine(); } catch (CommunicationException commProblem) { Console.WriteLine(commProblem.Message); Console.ReadLine(); } } }
static void Main(string[] args) { DataBase test = new DataBase("test.txt"); Record rec = test.ReadRecord(6); test.indexes.Add(new Index("test.txt")); test.indexes[0].CreateIndex(0, test.file_keys); Console.ReadKey(); }
private DataBaseState state; // текущее состояние БД #endregion Fields #region Constructors /// <summary> /// Инициализирует новый экземпляр класса /// </summary> public DataBaseManager() { mutex = new Mutex(); state = DataBaseState.Default; adapter = new DataBaseAdapter(); server = new DataBaseServer(adapter); dataBase = new DataBase(adapter); server = new DataBaseServer(adapter); }
public void TestAddMethod() { DataBase.DataBase db = new DataBase.DataBase(); FieldInfo currentIndexInfo = typeof(DataBase.DataBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); currentIndexInfo.SetValue(db, 16); Assert.That(() => db.Add(1), Throws.InvalidOperationException); }
public void TestValidConstructor(int[] values) { DataBase.DataBase db = new DataBase.DataBase(values); FieldInfo fieldValue = typeof(DataBase.DataBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(p => p.FieldType == typeof(int[])); int[] valueInClass = (int[])(fieldValue.GetValue(db)); Assert.That(valueInClass, Is.EquivalentTo(values.Concat(new int[valueInClass.Length - values.Length]))); }
//отображение элементов выбранной бд private void DataBaseCollectionListBox_SelectedIndexChanged(object sender, EventArgs e) { if (DataBaseCollectionListBox.SelectedIndex != -1) { DataBase.DataBase db = (DataBase.DataBase)DataBaseCollectionListBox.SelectedItem; DataBasItemCollectionListBox.Items.Clear(); foreach (DataBaseItem dbi in db.DataBaseItems) { DataBasItemCollectionListBox.Items.Add(dbi); } } }
public void TestAddMethod(int value) { DataBase.DataBase db = new DataBase.DataBase(); db.Add(value); FieldInfo fieldInfo = typeof(DataBase.DataBase).GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == typeof(int[])); FieldInfo currentIndexInfo = typeof(DataBase.DataBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); int firstValue = ((int[])fieldInfo.GetValue(db)).First(); int currentIndex = (int)currentIndexInfo.GetValue(db); Assert.That(firstValue, Is.EqualTo(value)); Assert.That(currentIndex, Is.EqualTo(1)); }
public void FetchMethod(int[] values) { DataBase.DataBase db = new DataBase.DataBase(); FieldInfo fieldValue = typeof(DataBase.DataBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(p => p.FieldType == typeof(int[])); fieldValue.SetValue(db, values); FieldInfo currentIndexInfo = typeof(DataBase.DataBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); currentIndexInfo.SetValue(db, values.Length); Assert.That(db.Fetch(), Is.EquivalentTo(values)); }
public void Remove(int[] values) { DataBase.DataBase db = new DataBase.DataBase(); FieldInfo currentIndexInfo = typeof(DataBase.DataBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); FieldInfo fieldValue = typeof(DataBase.DataBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(p => p.FieldType == typeof(int[])); fieldValue.SetValue(db, values); currentIndexInfo.SetValue(db, values.Length); db.Remove(); int currentIndex = (int)currentIndexInfo.GetValue(db); Assert.That(currentIndex, Is.EqualTo(values.Length - 1)); }
protected void PagerNavication_PagerIndexChanged(object sender, DataBase.UserControls.PagerIndexChagedEventArgs e) { BindData(); }
private static void _tcpMod_Receive(object sender, DataBase.ReceiveEventArgs e) { TcpModule tcp = (TcpModule)sender; if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.CheckConnection) { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.CheckConnectionOK); } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AskDictionary) { Dictionary di = new Dictionary(); di.ReadFromIni(); NetworkTransferObjects obj = new NetworkTransferObjects(); obj.Dictionary = di; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AskDictionaryOk); } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AskDbCollection) { NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AskDbCollectionOk); } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AddBase) { NetworkTransferObjects obj = new NetworkTransferObjects(); DataBase.DataBase addDb = (DataBase.DataBase)e.NetDataObj.DataBase; if (addDb != null) { if (m_DbCollection.AddDataBase(addDb)) { Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AddBaseOk); } else { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.AddBaseFail); } } } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.DelBase) { DataBase.DataBase addDb = (DataBase.DataBase)e.NetDataObj.DataBase; if (addDb != null) { if (m_DbCollection.DeleteDataBase(addDb)) { NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.DelBaseOk); } } } //ADDQRITEMINBASE if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AddQrItemInBase) { QrCodeData qrcode = (QrCodeData)e.NetDataObj.QrCodeData; if (qrcode != null) { if (m_DbCollection.AddQrCodeToDataBases(qrcode)) { Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AddQrItemInBaseOk); } else { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.AddQrItemInBaseFail); } } } //ADDQRITEMSINBASE if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AddQrItemSInBase) { QrCodeData[] qrcode = (QrCodeData[])e.NetDataObj.QrCodeDataArray; if (qrcode != null) { if (m_DbCollection.AddQrCodeSerialToDataBases(qrcode)) { Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AddQrItemSInBaseOk); } else { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.AddQrItemSInBaseFail); } } } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.DelDbItems) { int db_index = e.NetDataObj.DbIndex; if (db_index != -1) { if (m_DbCollection.DeleteItemsFromDb((List <DataBaseItem>)e.NetDataObj.DataBaseItemsList, db_index)) { Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.DelDbItemsOK); } else { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.DelDbItemsFail); } } } }
public void TestInvalidRemove() { DataBase.DataBase db = new DataBase.DataBase(); Assert.That(() => db.Remove(), Throws.InvalidOperationException); }
public void InvalidFetchMethod() { DataBase.DataBase db = new DataBase.DataBase(); Assert.That(db.Fetch, Throws.InvalidOperationException); }
public Service() { _dataBase = new DataBase.DataBase(); GetUsersList(); }
/// <summary> /// Инициализирует новый экземпляр класса /// </summary> /// <param name="info">Объект System.Runtime.Serialization.SerializationInfo для извлечения данных.</param> /// <param name="context">Целевое местоположение сериализации.</param> protected DataBaseManager(SerializationInfo info, StreamingContext context) { mutex = new Mutex(); state = DataBaseState.Default; adapter = new DataBaseAdapter(); adapter.UserID = info.GetString("UserID"); adapter.Password = info.GetString("Password"); server = new DataBaseServer(adapter); dataBase = new DataBase(adapter); server = new DataBaseServer(adapter); }