Beispiel #1
0
 public static bool Test(ITable table, TableFlags tableFlags)
 {
     if (tableFlags.HasFlag(TableFlags.Private) == true && table.AccessInfo.IsPrivate == false)
     {
         return(false);
     }
     if (tableFlags.HasFlag(TableFlags.Public) == true && table.AccessInfo.IsPublic == false)
     {
         return(false);
     }
     if (tableFlags.HasFlag(TableFlags.Locked) == true && table.LockInfo.IsLocked == false)
     {
         return(false);
     }
     if (tableFlags.HasFlag(TableFlags.NotLocked) == true && table.LockInfo.IsLocked == true)
     {
         return(false);
     }
     if (tableFlags.HasFlag(TableFlags.IsBeingEdited) == true && table.TableState != TableState.IsBeingEdited)
     {
         return(false);
     }
     if (tableFlags.HasFlag(TableFlags.NotBeingEdited) == true && table.TableState == TableState.IsBeingEdited)
     {
         return(false);
     }
     return(true);
 }
        /// <summary>Opens or creates the table with the specified type.</summary>
        /// <typeparam name="TStruct">Row structure type.</typeparam>
        /// <param name="database">The database instance.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="flags">Flags for table loading.</param>
        /// <param name="excludedFields">Fields at <typeparamref name="TStruct" /> to be excluded.</param>
        /// <returns>Returns an <see cref="ITable{TValue}" /> instance for the specified table.</returns>
        public static ITable <TStruct> GetTable <TStruct>(this IDatabase database, string tableName = null, TableFlags flags = default,
                                                          params string[] excludedFields)
            where TStruct : struct
        {
            var layout = RowLayout.CreateTyped(typeof(TStruct), tableName, database.Storage, excludedFields);

            if (flags.HasFlag(TableFlags.IgnoreMissingFields))
            {
                return(new Table <TStruct>(database.GetTable(tableName ?? layout.Name)));
            }

            var table = database.GetTable(layout, flags);

            return(new Table <TStruct>(table));
        }
Beispiel #3
0
        /// <summary>Parse whole SM-Bios into SmBios.Data.BiosData structure</summary>
        /// <exception cref="T:System.IO.IOException">An I/O error occurred while opening the bios.</exception>
        public virtual BiosData ReadBios()
        {
            var result = new BiosData();

            while (BaseStream.Position < BaseStream.Length)
            {
                var header = ReadHeader();
                switch (header.Type)
                {
                case Const.DMI_TYPE_END:
                    return(result);

                case Const.DMI_TYPE_BIOS:
                    if (!Flags.HasFlag(TableFlags.Bios))
                    {
                        break;
                    }
                    var readerBios = new ReaderBios <TableBios>(this, header);
                    var tableBios  = readerBios.Result;
                    if (result.Bios == null)
                    {
                        result.Bios = new List <TableBios>();
                    }
                    result.Bios.Add(tableBios);
                    break;

                case Const.DMI_TYPE_BASEBOARD:
                    if (!Flags.HasFlag(TableFlags.BaseBoard))
                    {
                        break;
                    }
                    var readerBaseboard = new ReaderBaseboard <TableBaseboard>(this, header);
                    var tableBaseboard  = readerBaseboard.Result;
                    if (result.BaseBoard == null)
                    {
                        result.BaseBoard = new List <TableBaseboard>();
                    }
                    result.BaseBoard.Add(tableBaseboard);
                    break;

                case Const.DMI_TYPE_MEMORY:
                    if (!Flags.HasFlag(TableFlags.MemoryDevice))
                    {
                        break;
                    }
                    var readerMemory = new ReaderMemory <TableMemoryDevice>(this, header);
                    var tableMemory  = readerMemory.Result;
                    if (result.Memory == null)
                    {
                        result.Memory = new List <TableMemoryDevice>();
                    }
                    result.Memory.Add(tableMemory);
                    break;

                case Const.DMI_TYPE_PHYSMEM:
                    if (!Flags.HasFlag(TableFlags.PhysMemory))
                    {
                        break;
                    }
                    var readerPhysicalMemory = new ReaderPhysicalMemory <TablePhysicalMemory>(this, header);
                    var tablePhysicalMemory  = readerPhysicalMemory.Result;
                    if (result.PhyMemory == null)
                    {
                        result.PhyMemory = new List <TablePhysicalMemory>();
                    }
                    result.PhyMemory.Add(tablePhysicalMemory);
                    break;

                case Const.DMI_TYPE_PROCESSOR:
                    if (!Flags.HasFlag(TableFlags.Processor))
                    {
                        break;
                    }
                    var readerProcessor = new ReaderProcessor <TableProcessor>(this, header);
                    var tableProcessor  = readerProcessor.Result;
                    if (result.Processor == null)
                    {
                        result.Processor = new List <TableProcessor>();
                    }
                    result.Processor.Add(tableProcessor);
                    break;
                }
                BaseStream.Seek(Idx, SeekOrigin.Begin);
            }
            return(result);
        }
Beispiel #4
0
 /// <summary>Gets the string comparison to use for field name comparison.</summary>
 /// <param name="tableFlags">Flags to use for setting.</param>
 /// <returns>Returns a <see cref="StringComparison" /> value.</returns>
 public static StringComparison GetFieldNameComparison(this TableFlags tableFlags) => tableFlags.HasFlag(TableFlags.FieldNamesCaseInsensitive) ? StringComparison.InvariantCultureIgnoreCase : StringComparison.Ordinal;