Exemplo n.º 1
0
        public void ResizeTable(uint tableID, int szDatum)
        {
            Assert(Tables[tableID] != null);
            Assert(szDatum >= Tables[tableID].DatumSize);

            lock (m_lock)
            {
                IDBTable tbl = GetTable(tableID, true);

                if (tbl.DatumSize < szDatum)
                {
                    string tmpFile = Path.GetTempFileName();
                    using (new AutoReleaser(() => File.Delete(tmpFile)))
                        using (FileStream fs = File.Create(tmpFile))
                        {
                            var tmpWriter       = new RawDataWriter(fs, Encoding.UTF8);
                            IDBTableProvider dp = m_accessPath.GetDataProvider(tableID);

                            using (dp.Lock())
                            {
                                foreach (IDataRow row in dp.Enumerate())
                                {
                                    row.Write(tmpWriter);
                                }


                                var tmpReader = new RawDataReader(fs, Encoding.UTF8);
                                int count     = dp.Count;

                                BeginTableProcessing?.Invoke(tableID);

                                using (new AutoReleaser(() => EndTableProcessing?.Invoke(tableID)))
                                {
                                    uint ver = tbl.Version;
                                    uint tag = tbl.Tag;

                                    dp.Disconnect();
                                    tbl.Disconnect();
                                    File.Delete(tbl.FilePath);
                                    tbl.Create(szDatum, tag);
                                    dp.Connect();

                                    fs.Position = 0;

                                    for (int i = 0; i < count; ++i)
                                    {
                                        IDataRow datum = m_dataFactory.CreateDatum(tableID);
                                        datum.Read(tmpReader);
                                        dp.Insert(datum);
                                    }

                                    tbl.Version = ver;
                                    tbl.Flush();
                                }
                            }
                        }
                }
            }
        }
Exemplo n.º 2
0
            public IDBTableProvider GetDataProvider(uint idTable)
            {
                Assert(m_tblManager.Tables[idTable] != null);

                IDBTableProvider dp = m_providers.Find(item => item.DataSource.ID == idTable);

                if (dp == null)
                {
                    dp = m_tblManager.Tables[idTable].DataProvider;
                    m_providers.Add(dp);
                }

                if (!dp.IsConnected)
                {
                    dp.Connect();
                }

                return(dp);
            }