public override void Init(int flowCount, long flowRecordCount)
        {
            engine = StorageEngine.FromFile(Path.Combine(DataDirectory, "test.stsdb"));
            table  = engine.Scheme.CreateOrOpenXTable <long, Tick>(new Locator(CollectionName));

            engine.Scheme.Commit();
        }
Beispiel #2
0
        public List <OCMessage> GetOCMessage(Contact contract, DateTime dtStart, DateTime dtEnd)
        {
            List <OCMessage> list = new List <OCMessage>();

            lock (locker)
            {
                using (var repository = StorageEngine.FromFile(DATABASE_NAME))
                {
                    var table = repository.Scheme.CreateOrOpenXTable <long, OCMessage>(
                        new Locator(contract.ContactName));
                    repository.Scheme.Commit();

                    var ocMessages = table.Where(w => w.Record.MessageTime >= dtStart &&
                                                 w.Record.MessageTime < dtEnd)
                                     .Select(s => s.Record);

                    if (ocMessages != null)
                    {
                        foreach (var v in ocMessages)
                        {
                            var msg = new OCMessage()
                            {
                                ContactId   = v.ContactId,
                                MessageText = v.IsCompressed ? SevenZip.Decompress(v.MessageText) : v.MessageText,
                                MessageTime = v.MessageTime
                            };
                            list.Add(msg);
                        }
                    }
                }
            }

            return(list);
        }
Beispiel #3
0
        public List <Contact> GetContractList()
        {
            List <Contact> list = null;

            lock (locker)
            {
                using (var repository = StorageEngine.FromFile(DATABASE_NAME))
                {
                    var table = repository.Scheme.CreateOrOpenXTable <long, Contact>(
                        new Locator(TABLENAME_CONTRACT));
                    repository.Scheme.Commit();

                    var v = table.OrderBy(f => f.Record.ContactName).Select(s => s.Record);

                    if (v != null)
                    {
                        list = v.ToList();
                    }

                    table.Close();
                }
            }

            return(list);
        }
Beispiel #4
0
        private void SaveContractCoversationDailyDate(Contact contract, DateTime date)
        {
            if (contract != null)
            {
                DateTime convDay = new DateTime(date.Year, date.Month, date.Day);

                lock (locker)
                {
                    using (var repository = StorageEngine.FromFile(DATABASE_NAME))
                    {
                        var table = repository.Scheme.CreateOrOpenXTable <long, DateTime>(
                            new Locator(string.Format("{0}_MsgDate", contract.Id)));
                        repository.Scheme.Commit();

                        var d = table.FirstOrDefault(f => f.Record.Year == date.Year &&
                                                     f.Record.Month == date.Month &&
                                                     f.Record.Day == date.Day);

                        if (d == null)
                        {
                            long id = table.Count == 0 ? 0 : table.LastRow.Key + 1;
                            table[id] = date.Date;
                        }

                        table.Commit();
                        table.Close();
                    }
                }
            }
        }
Beispiel #5
0
        public int GetTotalDailyMessageCount(Contact contract)
        {
            lock (locker)
            {
                using (var repository = StorageEngine.FromFile(DATABASE_NAME))
                {
                    var table = repository.Scheme.CreateOrOpenXTable <long, DateTime>(
                        new Locator(string.Format("{0}_MsgDate", contract.Id)));
                    repository.Scheme.Commit();

                    int total = table.Count();

                    return(total);
                }
            }
        }
Beispiel #6
0
        private void SaveMessage(
            Contact contract,
            string messageBody,
            DateTime dtBeginTime,
            bool isCompressed)
        {
            var message = new OCMessage
            {
                ContactId    = contract.Id,
                MessageText  = messageBody,
                MessageTime  = dtBeginTime,
                IsCompressed = isCompressed
            };

            lock (locker)
            {
                using (var repository = StorageEngine.FromFile(DATABASE_NAME))
                {
                    var table = repository.Scheme.CreateOrOpenXTable <long, OCMessage>(
                        new Locator(contract.ContactName));
                    repository.Scheme.Commit();

                    var msg = table.FirstOrDefault(f => f.Record.MessageTime == dtBeginTime);

                    if (msg == null)
                    {
                        long id = table.Count == 0 ? 0 : table.LastRow.Key + 1;
                        table[id] = message;
                    }
                    else
                    {
                        table[msg.Key] = message;
                    }

                    table.Commit();
                    table.Close();
                }
            }
        }
Beispiel #7
0
        private Contact SaveContract(string ContactName, DateTime date)
        {
            Contact contract = new Contact()
            {
                ContactName = ContactName, LastConversationTime = date
            };

            lock (locker)
            {
                using (var repository = StorageEngine.FromFile(DATABASE_NAME))
                {
                    var table = repository.Scheme.CreateOrOpenXTable <long, Contact>(
                        new Locator(TABLENAME_CONTRACT));
                    repository.Scheme.Commit();

                    var c = table.FirstOrDefault(f => f.Record.ContactName == ContactName);

                    if (c == null)
                    {
                        long id = table.Count == 0 ? 0 : table.LastRow.Key + 1;
                        contract.Id = id;
                        table[id]   = contract;
                    }
                    else
                    {
                        contract.Id = c.Key;
                        table[c.Key].LastConversationTime = date;
                    }

                    table.Commit();
                    table.Close();
                }
            }

            return(contract);
        }
Beispiel #8
0
        public List <DateTime> GetCoversationDateList(
            Contact contract,
            DateTime searchDate,
            SearchDirection direction = SearchDirection.None)
        {
            List <DateTime> list = new List <DateTime>();

            bool insertAt0 = true;

            lock (locker)
            {
                using (var repository = StorageEngine.FromFile(DATABASE_NAME))
                {
                    var table = repository.Scheme.CreateOrOpenXTable <long, DateTime>(
                        new Locator(string.Format("{0}_MsgDate", contract.Id)));
                    repository.Scheme.Commit();

                    var v = table.Where(w => w.Record == searchDate).FirstOrDefault();

                    var first = table.FirstOrDefault();
                    var last  = table.LastOrDefault();

                    //avoid the first/last' forward/backward
                    if (v == null &&
                        (direction == SearchDirection.Forward ||
                         direction == SearchDirection.Backward))
                    {
                        logger.Warn(string.Format("Cannot found record of {0}", searchDate));

                        return(list);
                    }

                    IEnumerable <Row <long, DateTime> > enumerator = null;

                    if (direction == SearchDirection.None ||
                        direction == SearchDirection.Last)
                    {
                        enumerator = table.Backward();
                        insertAt0  = true;
                    }
                    else if (direction == SearchDirection.First)
                    {
                        enumerator = table.Forward();
                        insertAt0  = false;
                    }
                    else if (direction == SearchDirection.Forward)
                    {
                        if (v.Key != last.Key)
                        {
                            enumerator = table.Forward(v.Key);
                            insertAt0  = false;
                        }
                    }
                    else if (direction == SearchDirection.Backward)
                    {
                        if (v.Key != first.Key)
                        {
                            enumerator = table.Backward(v.Key);
                            insertAt0  = true;
                        }
                    }

                    if (enumerator != null)
                    {
                        foreach (var row in enumerator.Take(PageSize))
                        {
                            if (insertAt0)
                            {
                                list.Insert(0, row.Record);
                            }
                            else
                            {
                                list.Add(row.Record);
                            }
                        }
                    }
                }
            }

            return(list);
        }