Exemple #1
0
        public void ConfigNode(object commondata)
        {
            common_data = commondata;
            object conf = ((object[])common_data)[0];

            foreach (object[] tab in (object[])conf)
            {
                PType    tp_tab_element = PType.FromPObject(tab[2]);
                object[] key_grades     = (object[])tab[3];
                for (int i = 0; i < key_grades.Length; i++)
                {
                    var sportion = KVSequencePortion.Create(this, tp_tab_element);
                    cell_list.Root.AppendElement(sportion.pobj);
                    int iportion = sportion_list.Count;
                    sportion_list.Add(sportion);

                    key_grades[i] = new object[] { iportion };
                }
            }
            cell_list.Flush(); // Этот Flush нужен
            fob.Flush();
            object v = cell_list.Root.Get();

            cell_common.Clear();
            cell_common.Fill(common_data);
        }
Exemple #2
0
        public DataNode(string path)
        {
            this.path = path;
            //this.tp_element = tp_element;
            string     dbpath     = path + "DataNodeStorage.bin";
            bool       fob_exists = File.Exists(dbpath);
            FileStream fs         = new FileStream(dbpath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            fob = new FileOfBlocks(fs);
            Stream first_stream = fob.GetFirstAsStream();

            if (!fob_exists)
            {
                PagedStream.InitPagedStreamHead(first_stream, 8L, 0, PagedStream.HEAD_SIZE);
                fob.Flush();
            }
            main_stream = new PagedStream(fob, fob.GetFirstAsStream(), 8L);

            //long sz = PagedStream.HEAD_SIZE;

            // Если main_stream нулевой длины, надо инициировать конфигурацию стримов
            bool toinit = main_stream.Length == 0;

            if (toinit)
            {
                // инициируем 2 головы для потоков
                PagedStream.InitPagedStreamHead(main_stream, 0L, 0L, -1L);
                PagedStream.InitPagedStreamHead(main_stream, PagedStream.HEAD_SIZE, 0L, -1L);
                //PagedStream.InitPagedStreamHead(main_stream, 2 * sz, 0L, -1L);

                main_stream.Flush(); fob.Flush();
            }
            // создадим 2 потока
            Stream stream_common_params = new FileStream(path + "common.pac", FileMode.OpenOrCreate, FileAccess.ReadWrite); //new PagedStream(fob, main_stream, 0L);
            Stream stream_SP_list       = new FileStream(path + "splist.pac", FileMode.OpenOrCreate, FileAccess.ReadWrite); //new PagedStream(fob, main_stream, 1 * PagedStream.HEAD_SIZE);

            //PagedStream stream_offsets = new PagedStream(fob, main_stream, 2 * sz); // пока не знаю для чего...

            // Создадим ячейки
            tp_common = new PTypeRecord(
                new NamedType("configuration", tp_configuration));
            cell_common = new PaCell(tp_common, stream_common_params, false);
            tp_list     = new PTypeSequence(KVSequencePortion.tp_pobj);
            cell_list   = new PaCell(tp_list, stream_SP_list, false);

            // Инициализируем
            if (toinit)
            {
                cell_common.Fill(new object[] { new object[0] });
                cell_list.Fill(new object[0]);
            }
            common_data = cell_common.Root.Get();
            foreach (object[] p in cell_list.Root.ElementValues())
            {
                KVSequencePortion kvsp = new KVSequencePortion(this, p);
                sportion_list.Add(kvsp);
            }
        }