Пример #1
0
        private DbItemsCollection getRelevantBlocks(bool NonRetain)
        {
            DbfFile dbf = new DbfFile(encoding);

            dbf.Open(blocksPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            DbfRecord record = new DbfRecord(dbf.Header);

            DbItemsCollection dbItemsCollection = new DbItemsCollection();

            while (dbf.ReadNext(record))
            {
                if (record.IsDeleted)
                {
                    continue;
                }
                try
                {
                    DbItem dbItem = new DbItem(record, DatabaseType.NormalBlocks);

                    if (dbItem.bBlockType == DbType10 ||
                        dbItem.bBlockType == DbType20) //DB
                    {
                        dbItemsCollection.Add(dbItem.DatabaseId, dbItem);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            dbf.Close();

            // Remove entries that only contain DbType10 or 20, or where
            // the attribute is identical.
            List <int> removeIndexes = new List <int>();

            foreach (var blockItem in dbItemsCollection.getDbItems())
            {
                if (!blockItem.Value.ContainsKey(DbType10) ||
                    !blockItem.Value.ContainsKey(DbType20) ||
                    blockItem.Value[DbType10].currentNonRetain == NonRetain)
                {
                    removeIndexes.Add(blockItem.Key);
                }
            }
            foreach (var key in removeIndexes)
            {
                dbItemsCollection.Remove(key);
            }
            return(dbItemsCollection);
        }
Пример #2
0
        /// <summary>
        /// Update BAUSTEIN.DBF (only timestamp, attribs buildup not known)
        /// This is needed for the compare function to detect the difference.
        /// </summary>
        /// <param name="NonRetain"></param>
        /// <param name="newTime"></param>
        private void updateBlocksListItemsAttr(
            DbItemsCollection dbItemsCollection,
            bool NonRetain,
            string newTime = null)
        {
            DbfFile dbf = new DbfFile(encoding);

            dbf.Open(blocksListPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            DbfRecord record = new DbfRecord(dbf.Header);

            while (dbf.ReadNext(record))
            {
                if (record.IsDeleted)
                {
                    continue;
                }
                try
                {
                    DbItem dbItem = new DbItem(record, DatabaseType.NormalBlocksList);

                    //Only one record with each ID
                    if (dbItemsCollection.getDbItems().ContainsKey(dbItem.DatabaseId) &&
                        dbItemsCollection.getDbItems()
                        [dbItem.DatabaseId][DbType10].currentNonRetain != NonRetain)
                    {
                        //Update attribute with new timestamp1
                        dbItem.updateDbItemAttribs(record, newTime);
                        dbf.Update(record);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            dbf.Close();
        }
Пример #3
0
        /// <summary>
        /// Update SUBBLK.DBF
        /// This file contains the all blocks, which contains
        /// the actual NonRetain attribute and timestamp
        /// that will be shown in the block online.
        /// </summary>
        /// <param name="dbItemsCollection"></param>
        /// <param name="NonRetain"></param>
        /// <param name="newTime"></param>
        private void updateBlockItemsAttr(
            DbItemsCollection dbItemsCollection,
            bool NonRetain,
            string newTime = null)
        {
            DbfFile dbf = new DbfFile(encoding);

            dbf.Open(blocksPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

            foreach (var blockItems in dbItemsCollection.getDbItems().Values)
            {
                if (!blockItems.ContainsKey(DbType10))
                {
                    continue;
                }

                // Update only if the current attribute state is different from the given one.
                if (!blockItems[DbType10].currentNonRetain == NonRetain)
                {
                    // update reader with the saved record
                    DbfRecord rec = dbf.Read(blockItems[DbType10].recIndex);
                    // Modify the record stored in memory
                    blockItems[DbType10].updateDbItemAttribute(
                        rec, NonRetain, newTime);
                    // Write the modified record to the database
                    dbf.Update(rec);

                    if (blockItems.ContainsKey(DbType20))
                    {
                        // update reader with the saved record
                        rec = dbf.Read(blockItems[DbType20].recIndex);
                        // Modify the record stored in memory
                        blockItems[DbType20].updateDbItemAttribute(
                            rec, NonRetain, newTime);
                        // Write the modified record to the database
                        dbf.Update(rec);
                    }
                }
                else
                {
                }
            }
            dbf.Close();
        }