Example #1
0
        /// For SUBBLK.dbf// alle blokker
        ///     For blocknumber X:
        ///       if subbloktype = 10
        ///           Timestamp1 er nytt
        ///           Attribute : set bit number 5av7
        ///       if subbloktype = 20
        ///           Timestamp1 og 2  er nytt
        /// For Baustein.dbf //liste over alle blokker
        ///     For blocknumber X:
        ///       if typ = 10        ///
        ///           Attribs: ? Timestamp1 er nytt // Unknown how this is built up, so skipping this step.
        /// For BSTCNTOF.dbf // Block folder list // modifiser timestamp.

        /// <summary>
        /// Clear the NonRetain attribute of all DataBlocks.
        /// </summary>
        /// <returns>A collection of the modified DataBlocks</returns>
        public DbItemsCollection clearNonRetainAttr()
        {
            DateTime now     = DateTime.Now;
            string   newTime = encoding.GetString(s7timeFromDateTime(now));

            DbItemsCollection dbItemsCollection = getRelevantBlocks(NonRetain: false);

            updateBlockItemsAttr(dbItemsCollection, NonRetain: false, newTime: newTime);
            updateBlocksListItemsAttr(dbItemsCollection, NonRetain: false, newTime: newTime);

            return(dbItemsCollection);
        }
Example #2
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);
        }
Example #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();
        }
Example #4
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();
        }
Example #5
0
 /// <summary>
 /// Undo clearing the NonRetain attribute.
 /// Must be called after clearNonRetainAttr(), with
 /// its result as an input.
 /// </summary>
 /// <param name="dbItemsCollection"></param>
 public void undoClearingNonRetainAttr(DbItemsCollection dbItemsCollection)
 {
     updateBlockItemsAttr(dbItemsCollection, NonRetain: true);
     updateBlocksListItemsAttr(dbItemsCollection, NonRetain: true);
 }