Exemple #1
0
            public void Insert(IList <IDatum> items)
            {
                Assert(IsConnected);
                Assert(items.OfType <T>().Count() == items.Count);

                lock (m_table)
                {
                    IList <int> indices = m_table.Insert(items as IList <T>);

                    if (AutoFlush)
                    {
                        m_table.Flush();
                    }

                    DataInserted?.Invoke(indices, items);
                }
            }
Exemple #2
0
        private void DataProvider_DataInserted(IList <int> indices, IList <IDatum> data)
        {
            using (Lock())
            {
                Assert(indices.Count == data.Count);

                foreach (int ndx in indices)
                {
                    IDatum datum = data[ndx];
                    T      key   = m_selector(datum);

                    List <int> lst;

                    if (!m_dataIndices.TryGetValue(key, out lst))
                    {
                        lst = new List <int>();
                        m_dataIndices[key] = lst;
                    }

                    //datum inserted not at the end => adjust indicies
                    if (ndx < m_dataProvider.Count - 1)
                    {
                        foreach (List <int> l in m_dataIndices.Values)
                        {
                            for (int i = 0; i < lst.Count; ++i)
                            {
                                if (ndx <= l[i])
                                {
                                    ++l[i];
                                }
                            }
                        }
                    }
                    lst.Add(ndx);
                }

                DataInserted?.Invoke(data);
            }
        }
Exemple #3
0
        private void Source_DataInserted(IList <int> indices, IList <IDatum> data)
        {
            Monitor.Enter(m_lock);

            for (int i = 0; i < indices.Count; ++i) //le traitement en une seule passe est invalide.
            {
                IDatum datum = data[i];

                Assert(!m_ndxTable.ContainsKey(datum.ID));

                int ndx  = indices[i];
                var keys = from kv in m_ndxTable
                           where kv.Value >= ndx
                           select kv.Key;

                keys.ToList().ForEach(k => ++ m_ndxTable[k]);

                m_ndxTable.Add(datum.ID, ndx);
            }

            Monitor.Exit(m_lock);

            DataInserted?.Invoke(data);
        }
Exemple #4
0
        public void Insert(T[] data)
        {
            Assert(IsConnected);
            Assert(data != null);
            Assert(data.Count(d => d == null) == 0);


            var rowIndices = new int[data.Length];

            lock (m_rwLock)
            {
                for (int i = 0; i < data.Length; ++i)
                {
                    int ndxFrame = m_header.FirstDeletedFrameIndex == NULL_INDEX ?
                                   m_header.FrameCount : m_header.FirstDeletedFrameIndex;


                    if (m_header.FirstDeletedFrameIndex == NULL_INDEX)
                    {
                        m_writer.Position = 0;
                        data[i].Write(m_writer);

                        long framePos = GetFramePosition(ndxFrame);
                        WriteFrame(framePos);
                        ++m_header.FrameCount;
                    }
                    else
                    {
                        int pos = m_recycledData.BinarySearch(ndxFrame);
                        m_recycledData.RemoveAt(pos);

                        long framePos = GetFramePosition(ndxFrame);

                        if (m_recycledData.Count > 0)
                        {
                            ReadFrame(framePos);
                            m_reader.Position = 0;
                            m_header.FirstDeletedFrameIndex = m_reader.ReadInt();
                        }
                        else
                        {
                            m_header.FirstDeletedFrameIndex = NULL_INDEX;
                        }

                        m_writer.Position = 0;
                        data[i].Write(m_writer);
                        WriteFrame(framePos);
                    }

                    int ndxNew = FrameIndexToRowIndex(ndxFrame);

                    for (int j = 0; j < i; ++j)
                    {
                        if (ndxNew <= rowIndices[j])
                        {
                            ++rowIndices[j];
                        }
                    }

                    rowIndices[i] = ndxNew;
                }

                m_header.LastWriteTime = DateTime.Now;
                DataInserted?.Invoke(rowIndices, data);
            }
        }
Exemple #5
0
 private void OnDataInserted(DataType data)
 {
     DataInserted?.Invoke(data);
 }
Exemple #6
0
 void Table_DataInserted(int[] indices, T[] data) => DataInserted?.Invoke(indices,
                                                                          Array.ConvertAll(data, d => (IDataRow)d));