Пример #1
0
        public int GetReorgCount(string fullNodeName)
        {
            int count = 0;

            try
            {
                using (var t = Engine.GetTransaction())
                {
                    foreach (byte[] doc in t.TextSearch("TS_Reorg").BlockAnd(fullNodeName).GetDocumentIDs())
                    {
                        DBreezeObject <BlockchainReorg> obj = t.Select <byte[], byte[]>("Reorg", 1.ToIndex(doc)).ObjectGet <BlockchainReorg>();
                        if (obj != null)
                        {
                            count++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(count);
        }
Пример #2
0
        public List <NodeLogMessage> GetLogMessages(string fullNodeName)
        {
            List <NodeLogMessage> logMessages = new List <NodeLogMessage>();

            try
            {
                using (var t = Engine.GetTransaction())
                {
                    foreach (byte[] doc in t.TextSearch("TS_LogMessage").BlockAnd(fullNodeName).GetDocumentIDs())
                    {
                        DBreezeObject <NodeLogMessage> obj = t.Select <byte[], byte[]>("LogMessage", 1.ToIndex(doc)).ObjectGet <NodeLogMessage>();
                        if (obj != null)
                        {
                            logMessages.Add(obj.Entity);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(logMessages);
        }
Пример #3
0
        public IEnumerable <SearchString> SelectAll()
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                // Documentation https://goo.gl/MbZAsB
                List <SearchString> entities             = new List <SearchString>();
                IEnumerable <Row <byte[], byte[]> > rows = transaction
                                                           .SelectForwardFromTo <byte[], byte[]>(_table,
                                                                                                 1.ToIndex(int.MinValue), true,
                                                                                                 1.ToIndex(int.MaxValue), true);

                foreach (Row <byte[], byte[]> row in rows)
                {
                    DBreezeObject <SearchString> obj = row.ObjectGet <SearchString>();

                    if (obj != null)
                    {
                        SearchString entity = obj.Entity;
                        entities.Add(entity);
                    }
                }

                return(entities);
            }
        }
Пример #4
0
        public static LocalItem GetOfflineItem(ServiceItem serviceitem)
        {
            using (var tr = db.GetTransaction())
            {
                IEnumerable <Row <byte[], byte[]> > result = null;
                if (serviceitem.MalID != default)
                {
                    result = tr.SelectForwardFromTo <byte[], byte[]>("library", 2.ToIndex(serviceitem.MalID, 0), true, 2.ToIndex(serviceitem.MalID, int.MaxValue), true);
                }
                else
                {
                    // Use with caution!
                    // collition with different service might happened in this case!
                    result = tr.SelectForwardFromTo <byte[], byte[]>("library", 4.ToIndex(serviceitem.Service, serviceitem.ServiceID, 0, 0), true, 2.ToIndex(serviceitem.Service, serviceitem.ServiceID, 0, int.MaxValue), true);
                }

                if (result?.Count() != 0)
                {
                    var firstresult = result.First();
                    DBreezeObject <LocalItem> localitem = firstresult.ObjectGet <LocalItem>();
                    return(localitem.Entity);
                }
                else
                {
                    return(null);
                }
            }
        }
        public Proxy Max()
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <Proxy> obj = transaction.Max <byte[], byte[]>(_table)
                                            .ObjectGet <Proxy>();

                if (obj != null)
                {
                    Proxy entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
Пример #6
0
        public SpecialKeyword Max()
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <SpecialKeyword> obj = transaction.Max <byte[], byte[]>(_table)
                                                     .ObjectGet <SpecialKeyword>();

                if (obj != null)
                {
                    SpecialKeyword entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
        public Proxy Select(int proxyId)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <Proxy> obj = transaction
                                            .Select <byte[], byte[]>(_table, 1.ToIndex(proxyId))
                                            .ObjectGet <Proxy>();

                if (obj != null)
                {
                    return(obj.Entity);
                }

                return(null);
            }
        }
        public SearchEngine Min()
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <SearchEngine> obj = transaction.Min <byte[], byte[]>(_table)
                                                   .ObjectGet <SearchEngine>();

                if (obj != null)
                {
                    SearchEngine entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
Пример #9
0
        public KeywordScrapeDetail Min()
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <KeywordScrapeDetail> obj = transaction.Min <byte[], byte[]>(_table)
                                                          .ObjectGet <KeywordScrapeDetail>();

                if (obj != null)
                {
                    KeywordScrapeDetail entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
Пример #10
0
        public Keyword Select(int keywordID)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <Keyword> obj = transaction
                                              .Select <byte[], byte[]>(_table, 1.ToIndex(keywordID))
                                              .ObjectGet <Keyword>();

                if (obj != null)
                {
                    return(obj.Entity);
                }

                return(null);
            }
        }
        public ProxyMultiplier Select(int searchEngineId, int regionId, int proxyId)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <ProxyMultiplier> obj = transaction
                                                      .Select <byte[], byte[]>(_table, 1.ToIndex(searchEngineId, regionId, proxyId))
                                                      .ObjectGet <ProxyMultiplier>();

                if (obj != null)
                {
                    ProxyMultiplier entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
Пример #12
0
        public SearchString Select(int searchEngineId, int regionId)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <SearchString> obj = transaction
                                                   .Select <byte[], byte[]>(_table, 2.ToIndex(searchEngineId, regionId))
                                                   .ObjectGet <SearchString>();

                if (obj != null)
                {
                    SearchString entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
Пример #13
0
        public InternationalUULE Select(int regionId)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <InternationalUULE> obj = transaction
                                                        .Select <byte[], byte[]>(_table, 2.ToIndex(regionId))
                                                        .ObjectGet <InternationalUULE>();

                if (obj != null)
                {
                    InternationalUULE entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
        public LocalUULE Select(int cityID)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <LocalUULE> obj = transaction
                                                .Select <byte[], byte[]>(_table, 2.ToIndex(cityID))
                                                .ObjectGet <LocalUULE>();

                if (obj != null)
                {
                    LocalUULE entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
        public SearchEngine Select(short searchEngineId)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <SearchEngine> obj = transaction
                                                   .Select <byte[], byte[]>(_table, 1.ToIndex(searchEngineId))
                                                   .ObjectGet <SearchEngine>();

                if (obj != null)
                {
                    SearchEngine entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
Пример #16
0
        public static async Task <string> GetCacheHttpResultAsync(string cachekey)
        {
            try
            {
                await Task.Yield();

                using (var tr = db.GetTransaction())
                {
                    DBreezeObject <string> localitem = tr.Select <byte[], byte[]>("cache", 1.ToIndex((string)cachekey)).ObjectGet <string>();
                    return(localitem?.Entity);
                }
            }
            catch
            {
                return(null);
            }
        }
Пример #17
0
        public KeywordScrapeDetail Select(short searchEngineId, short regionId, short cityId, int keywordId)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <KeywordScrapeDetail> obj = transaction
                                                          .Select <byte[], byte[]>(_table, 1.ToIndex(
                                                                                       searchEngineId, regionId, cityId, keywordId))
                                                          .ObjectGet <KeywordScrapeDetail>();

                if (obj != null)
                {
                    KeywordScrapeDetail entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
Пример #18
0
        public SpecialKeyword Select(int searchEngineId, int regionId, int keywordId)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <SpecialKeyword> obj = transaction
                                                     .Select <byte[], byte[]>(
                    _table, 1.ToIndex(searchEngineId, regionId, keywordId))
                                                     .ObjectGet <SpecialKeyword>();

                if (obj != null)
                {
                    SpecialKeyword entity = obj.Entity;
                    return(entity);
                }

                return(null);
            }
        }
Пример #19
0
        public IDictionary <int, Keyword> SelectMany(IEnumerable <int> keywordIds)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                Dictionary <int, Keyword> entities = new Dictionary <int, Keyword>();
                foreach (int keywordId in keywordIds)
                {
                    DBreezeObject <Keyword> obj = transaction
                                                  .Select <byte[], byte[]>(_table, 1.ToIndex(keywordId))
                                                  .ObjectGet <Keyword>();

                    if (obj != null)
                    {
                        entities[keywordId] = obj.Entity;
                    }
                }

                return(entities);
            }
        }
Пример #20
0
        public void UpdateLastCrawl(short searchEngineId, short regionId, short cityId, int keywordId, DateTime lastCrawl)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                DBreezeObject <KeywordScrapeDetail> obj = transaction
                                                          .Select <byte[], byte[]>(_table, 1.ToIndex(
                                                                                       searchEngineId, regionId, cityId, keywordId))
                                                          .ObjectGet <KeywordScrapeDetail>();

                if (obj == null)
                {
                    return;
                }

                obj.Entity.LastCrawl = lastCrawl;
                Insert(transaction, obj.Entity, false);

                transaction.Commit();
            }
        }
Пример #21
0
 public static Task UpdateOfflineItem(LocalItem item)
 {
     using (var tr = db.GetTransaction())
     {
         tr.SynchronizeTables("library");
         DBreezeObject <LocalItem> localitem = tr.Select <byte[], byte[]>("library", 1.ToIndex((int)item.Id)).ObjectGet <LocalItem>();
         localitem.Entity  = item;
         localitem.Indexes = new List <DBreezeIndex>()
         {
             new DBreezeIndex(1, item.Id)
             {
                 PrimaryIndex = true
             },
             new DBreezeIndex(2, item.MalID)
         };
         tr.ObjectInsert("library", localitem);
         tr.Commit();
     }
     return(Task.CompletedTask);
 }
Пример #22
0
        public IEnumerable <KeywordScrapeDetail> SelectToCrawl()
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                IEnumerable <Row <byte[], byte[]> > rows = transaction
                                                           .SelectForwardFromTo <byte[], byte[]>(
                    _table, 3.ToIndex(DateTime.Today.AddDays(-1), short.MinValue, short.MinValue, short.MinValue, short.MinValue, int.MinValue), true,
                    3.ToIndex(DateTime.Today, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, int.MaxValue), true);

                List <KeywordScrapeDetail> entities = new List <KeywordScrapeDetail>();
                foreach (Row <byte[], byte[]> row in rows)
                {
                    DBreezeObject <KeywordScrapeDetail> obj = row.ObjectGet <KeywordScrapeDetail>();
                    if (obj != null)
                    {
                        entities.Add(obj.Entity);
                    }
                }

                return(entities);
            }
        }
        public IEnumerable <Proxy> SelectAll()
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                var entities = new List <Proxy>();
                IEnumerable <Row <byte[], byte[]> > rows = transaction
                                                           .SelectForwardFromTo <byte[], byte[]>(
                    _table, 1.ToIndex(int.MinValue), true,
                    1.ToIndex(int.MaxValue), true);

                foreach (var row in rows)
                {
                    DBreezeObject <Proxy> obj = row.ObjectGet <Proxy>();
                    if (obj != null)
                    {
                        Proxy entity = obj.Entity;
                        entities.Add(entity);
                    }
                }

                return(entities);
            }
        }
Пример #24
0
        public static async Task CacheHttpResultAsync(string cachekey, string result)
        {
            await Task.Yield();

            using (var tr = db.GetTransaction())
            {
                DBreezeObject <string> localitem = tr.Select <byte[], byte[]>("cache", 1.ToIndex((string)cachekey)).ObjectGet <string>();
                tr.ObjectInsert("cache", new DBreezeObject <string>
                {
                    NewEntity = localitem == null,
                    Entity    = result,
                    Indexes   = new List <DBreezeIndex>()
                    {
                        new DBreezeIndex(1, cachekey)
                        {
                            PrimaryIndex = true
                        }
                    }
                });

                tr.Commit();
            }
        }
Пример #25
0
        public IEnumerable <KeywordScrapeDetail> SelectMany(short searchEngineId, short regionId, short cityId)
        {
            using (Transaction transaction = _engine.GetTransaction())
            {
                List <KeywordScrapeDetail>          entities = new List <KeywordScrapeDetail>();
                IEnumerable <Row <byte[], byte[]> > rows     = transaction
                                                               .SelectForwardFromTo <byte[], byte[]>(_table,
                                                                                                     1.ToIndex(searchEngineId, regionId, cityId, int.MinValue), true,
                                                                                                     1.ToIndex(searchEngineId, regionId, cityId, int.MaxValue), true);

                foreach (Row <byte[], byte[]> row in rows)
                {
                    DBreezeObject <KeywordScrapeDetail> obj = row.ObjectGet <KeywordScrapeDetail>();

                    if (obj != null)
                    {
                        KeywordScrapeDetail entity = obj.Entity;
                        entities.Add(entity);
                    }
                }

                return(entities);
            }
        }