Пример #1
0
        public Address Add(ObjectDB obj)
        {
            Position pos = null;

            for (int offsetX = 0; offsetX < Size; offsetX++)
            {
                for (int offsetY = 0; offsetY < Size; offsetY++)
                {
                    if (Content[offsetX, offsetY] == null)
                    {
                        pos = new Position(offsetX, offsetY);
                        goto enf;
                    }
                }
            }

enf:

            if (pos == null)
            {
                throw new Exception("Секция переполнена!");
            }

            return(Set(obj, pos));
        }
Пример #2
0
        public static Section ReadSection(string sourceFile, DataBuilder builder = null, string DefaultBuilderPassword = "******")
        {
            if (builder == null)
            {
                builder = new XorBuilder();
                ((XorBuilder)builder).Key = Database.CurrentDatabase.TextEncoding.GetBytes(DefaultBuilderPassword);
            }

            Section section;
            int     size;

            using (BinaryReader reader = new BinaryReader(File.Open(sourceFile, FileMode.Open)))
            {
                //READING METAINFO
                byte section_version = reader.ReadByte();

                if (section_version != DB_SECTION_VERSION)
                {
                    throw new Exception("Секция повреждена или недоступна!");
                }

                size = reader.ReadInt32();
                byte[]   metadata = reader.ReadBytes(size);
                MetaInfo info     = MetaInfo.ReadFrom(builder.Decode(metadata));

                section = new Section(info.Address, info.Label, builder);

                int    sz;
                byte[] data;

                while (reader.PeekChar() > -1)
                {
                    byte     objectId = reader.ReadByte();
                    ObjectDB obj      = (ObjectDB)Activator.CreateInstance(ObjectDB.RestoreObject(objectId));

                    int ox = reader.ReadInt32();
                    int oy = reader.ReadInt32();

                    sz   = reader.ReadInt32();
                    data = builder.Decode(reader.ReadBytes(sz));

                    obj.Label = Database.CurrentDatabase.TextEncoding.GetString(data);

                    sz   = reader.ReadInt32();
                    data = builder.Decode(reader.ReadBytes(sz));

                    obj.Content = data;

                    section.Set(obj, new Position(ox, oy));
                }
            }

            section.Builder = builder;

            return(section);
        }
Пример #3
0
        public Address Set(ObjectDB obj, Position pos)
        {
            if (Content[pos.X, pos.Y] != null)
            {
                Remove(pos);
            }

            Content[pos.X, pos.Y] = obj;

            if (Logger != null)
            {
                Logger.Push(ContentLogger.EVENT_SETUP, pos.AsAddress(Address).ToString());
            }

            return(new Address(Info.Address, pos.X, pos.Y));
        }
Пример #4
0
 public static void UnregisterObject(ObjectDB obj)
 {
     Objects.Remove(obj);
 }
Пример #5
0
 public static void RegisterObject(ObjectDB obj)
 {
     Objects.Add(obj);
 }
Пример #6
0
 public Address Set(ObjectDB obj, int x, int y)
 {
     return(Set(obj, new Position(x, y)));
 }