Exemple #1
0
        public bool Compare(NanoDBLayout otherLayout)
        {
            if (this.Elements.Length == otherLayout.Elements.Length)
            {
                return(!this.Elements.Where((t, i) => t != otherLayout.Elements[i]).Any());
            }

            return(false);
        }
Exemple #2
0
        public bool CreateNew(NanoDBLayout layout, int indexBy, int sortBy = -1)
        {
            int layoutSize = layout.Elements.Length;

            if (layoutSize <= 0 || layoutSize > 255 || indexBy >= layout.Elements.Length)
            {
                return(false);
            }

            using (FileStream stream = new FileStream(this.Path, FileMode.Create, FileAccess.Write))
            {
                stream.Write(NanoDBConstants.MagicBytes.GetArray(), 0, NanoDBConstants.MagicBytes.Length);

                stream.WriteByte((byte)NanoDBConstants.DatabaseStructureVersion);
                stream.WriteByte((byte)layoutSize);
                stream.WriteByte((byte)indexBy);

                byte[] layoutIds = new byte[layoutSize];

                for (int i = 0; i < layoutSize; i++)
                {
                    layoutIds[i] = layout.Elements[i].Id;
                }

                stream.Write(layoutIds, 0, layoutSize);

                stream.WriteByte(0x00);
                stream.WriteByte(NanoDBConstants.LineFlagBackup);

                for (int i = 0; i < layout.RowSize - 1; i++)
                {
                    stream.WriteByte(0x00);
                }

                this.Layout       = layout;
                this.contentIndex = new Dictionary <string, NanoDBLine>();
                this.indexedBy    = indexBy;
                this.initialized  = true;

                if (sortBy >= 0 && sortBy < layoutSize && sortBy != indexBy)
                {
                    this.sortIndex = new Dictionary <string, List <NanoDBLine> >();

                    this.sortedBy = sortBy;
                    this.Sorted   = true;
                }
            }

            return(true);
        }