Exemplo n.º 1
0
        private void HandleIndexing()
        {
            int    pageNum;
            string pagerHash;
            string indexVal;

            SearchAndIndexQueryResult result;

            pageNum   = GetValue <int>("pagenum");
            pagerHash = GetValue <string>("ph");
            indexVal  = GetValue <string> ("index");

            if (!string.IsNullOrEmpty(pagerHash) && IsValidPagerHash(pagerHash))
            {
                PushResponseItem("LogicalEntryCount", 0);
                return;
            }

            if (pageNum > 0)
            {
                pageNum--;
            }
            else
            {
                pageNum = 0;
            }

            result = SozlukDataStore.FetchBasliks(indexVal, pageNum, pagerHash);

            if (result.HasEntry)
            {
                PushResponseItem("TotalRecordCount", result.TotalRecordCount);
                PushResponseItem("LogicalEntryCount", result.LogicalRecordCount);
                PushResponseItem("PhysicalEntryCount", result.PhysicalRecordCount);
                PushResponseItem("TotalPageCount", SozlukDataStore.CalcPageCount(result.TotalRecordCount, RecordPerPageType.Basliks));
                PushResponseItem("CurrentPageNum", pageNum + 1);

                if (!string.IsNullOrEmpty(result.PagerHash))
                {
                    PushResponseItem("PagerHash", result.PagerHash);
                }

                foreach (var entry in result.Entries)
                {
                    PushResponseContent(entry.GetTransportString());
                }


                result.Entries.Clear();
                result.Entries = null;
            }
            else
            {
                PushResponseItem("LogicalEntryCount", 0);
            }
        }
Exemplo n.º 2
0
        private void HandleSearch()
        {
            bool     noDate;
            int      pageNum   = GetValue <int>("pagenum");
            string   pagerHash = GetValue <string>("ph");
            string   term      = GetValue <string>("term");
            string   suser     = GetValue <string>("suser");
            DateTime beginDate = GetValue <DateTime>("date");
            DateTime endDate   = GetValue <DateTime>("todate");

            noDate = beginDate == DateTime.MinValue;

            if (noDate)
            {
                endDate = DateTime.MinValue; //no date
            }
            else if (endDate == DateTime.MinValue)
            {
                //begin set but end not. so assume the end to the today like sozluk-cgi does
                endDate = DateTime.Now;

                if (beginDate > endDate)
                {
                    //We are damn sure that there will be no record :P
                    PushResponseItem("LogicalEntryCount", 0);
                    return;
                }
            }

            if (!string.IsNullOrEmpty(suser) && !Suser.IsSuserNameAllowed(suser))
            {
                PushResponseItem("LogicalEntryCount", 0);
                return;
            }

            if (!string.IsNullOrEmpty(pagerHash) && IsValidPagerHash(pagerHash))
            {
                PushResponseItem("LogicalEntryCount", 0);
                return;
            }

            if (!string.IsNullOrEmpty(term))
            {
                term = NormalizeTerm(term);
            }

            if (pageNum > 0)
            {
                pageNum--;
            }

            SearchAndIndexQueryResult result;

            result = SozlukDataStore.FetchBasliksUsingSearch(
                false, term, suser, beginDate, endDate,
                pageNum, pagerHash, noDate);

            if (result.HasEntry)
            {
                PushResponseItem("TotalRecordCount", result.TotalRecordCount);
                PushResponseItem("LogicalEntryCount", result.LogicalRecordCount);
                PushResponseItem("PhysicalEntryCount", result.PhysicalRecordCount);
                PushResponseItem("TotalPageCount", SozlukDataStore.CalcPageCount(result.TotalRecordCount, RecordPerPageType.Basliks));
                PushResponseItem("CurrentPageNum", pageNum + 1);


                if (!string.IsNullOrEmpty(result.PagerHash))
                {
                    PushResponseItem("PagerHash", result.PagerHash);
                }


                foreach (var entry in result.Entries)
                {
                    PushResponseContent(entry.GetTransportString());
                }

                result.Entries.Clear();
                result.Entries = null;
            }
            else
            {
                PushResponseItem("LogicalEntryCount", 0);
            }
        }
Exemplo n.º 3
0
        public override bool Process()
        {
            ViewQueryResult queryResult;
            int             pageNumber, baslikId;
            bool            latest = false;

            pageNumber = GetValue <int>("pagenum");
            baslikId   = GetValue <int>("bid");

            if (HasKey("latest"))
            {
                latest = true;
            }

            if (baslikId < 0)
            {
                baslikId = 0;
            }

            if (pageNumber > 0)
            {
                pageNumber--;
            }
            else
            {
                pageNumber = 0;
            }

            if (latest && baslikId > 0)
            {
                BaslikBasicInfo bbi;

                if (CacheManager.TryGetCachedResult <BaslikBasicInfo>("BBI_" + baslikId.ToString(), out bbi))
                {
                    pageNumber = SozlukDataStore.CalcPageCount(bbi.TotalEntries, RecordPerPageType.Entries) - 1;
                }
            }

            queryResult = SozlukDataStore.FetchEntriesOfBaslik(
                GetValue <string>("baslik"),
                baslikId,
                pageNumber);

            if (queryResult.HasEntry)
            {
                PushResponseItem("RecordCount", queryResult.PhysicalRecordCount);
                PushResponseItem("TotalPageCount", SozlukDataStore.CalcPageCount(queryResult.TotalRecordCount, RecordPerPageType.Entries));
                PushResponseItem("RecordsPerPage", SozlukDataStore.RecordsPerPage);
                PushResponseItem("CurrentPageNum", pageNumber + 1);
                PushResponseItem("BaslikId", queryResult.BaslikId);
                PushResponseItem("Baslik", queryResult.Entries[0].Baslik);


                foreach (var entry in queryResult.Entries)
                {
                    PushResponseContent(entry.GetTransportString());
                }
            }
            else
            {
                PushResponseItem("RecordCount", 0);
            }

            return(true);
        }