Beispiel #1
0
        public static bool AddEntry(Entry entry)
        {
            bool result;

            if (string.IsNullOrEmpty(entry.Content))
            {
                return(false);
            }

            SqlServerIo sql = SqlServerIo.Create();

            if (!sql.Ready)
            {
                return(false);
            }

            //naa
            entry.FixForMultipleLineFeeds();

            result = sql.Execute(false, NEW_ENTRY_SQL, entry.Baslik, entry.Suser, entry.Date.ToString(), entry.Content);

            if (result)
            {
                if (!sql.Read())
                {
                    result = false;
                }
                else
                {
                    entry.SetId(sql.GetValueOfColumn <int>("BaslikId"));


                    CacheManager.InvalidateCacheSet(KeysetId.Baslik(entry.BaslikID));

                    var indexKeyid = KeysetId.Index(entry.Baslik[0]);
                    CacheManager.InvalidateCacheSet(indexKeyid);

                    if (sql.GetValueOfColumn <int>("IsNewBaslikInsert") == 1)
                    {
                        //invalidate also todays section keyset a.k.a Taze
                        CacheManager.InvalidateCacheSet(KeysetId.Todays());
                    }
                }
            }


            SqlServerIo.Release(sql);

            return(result);
        }
Beispiel #2
0
        public static SearchAndIndexQueryResult FetchBasliksUsingSearch(bool fresh, string content, string suser, DateTime begin, DateTime end, int pageNumber, string pagerHash, bool leaveDatesAsIs)
        {
            SearchAndIndexQueryResult resultSet;
            SqlServerIo sql;
            TimeSpan    invTimeout;
            int         rowBegin, rowEnd;
            string      query;
            KeysetId    keysetId;
            string      baslik, descr, deceptedDate;
            int         entryCount;
            bool        resultCached;

            rowBegin = (pageNumber * BasliksPerPage) + 1;
            rowEnd   = rowBegin + BasliksPerPage - 1;

            //Workarounds, workarounds, workarounds !
            if (begin != DateTime.MinValue && end != DateTime.MinValue)
            {
                if (leaveDatesAsIs)
                {
                    deceptedDate = begin.AddTicks((end - begin).Ticks / 2).ToString();
                }
                else
                {
                    //push it out of from the search date range to reverse daterange check logic
                    deceptedDate = end.AddDays(2).ToString();
                }
            }
            else
            {
                deceptedDate = string.Empty;
            }

            query = BuildFetchSQLQuery(ref pagerHash, content, suser, begin, end, rowBegin, rowEnd);


            if (fresh)
            {
                keysetId   = KeysetId.Todays(true);
                invTimeout = TodaysTimeout;
            }
            else
            {
                keysetId   = KeysetId.Search(pagerHash, true);
                invTimeout = SearchResultTimeout;
            }

            resultCached = CacheManager.TryGetCachedQueryResult <SearchAndIndexQueryResult>(query, out resultSet);

            if (!resultCached)
            {
                sql = SqlServerIo.Create();

                if (!sql.Execute(false, query))
                {
                    SqlServerIo.Release(sql);
                    return(new SearchAndIndexQueryResult());
                }

                resultSet = new SearchAndIndexQueryResult
                {
                    PagerHash = pagerHash
                };

                while (sql.Read())
                {
                    baslik     = sql.GetValueOfColumn <string>("Baslik");
                    entryCount = sql.GetValueOfColumn <int>("EntryCount");

                    if (resultSet.TotalRecordCount == 0)
                    {
                        resultSet.TotalRecordCount = sql.GetValueOfColumn <int>("TotalRecordCount");
                    }

                    if (entryCount > 0)
                    {
                        descr = content;
                    }
                    else
                    {
                        descr = Strev(content);
                    }

                    if (string.IsNullOrEmpty(suser))
                    {
                        suser = string.Empty;
                    }

                    resultSet.Entries.Add(
                        new Entry(
                            baslik,
                            suser,
                            deceptedDate,
                            descr, entryCount)
                        );

                    resultSet.PhysicalRecordCount++;
                }

                resultSet.LogicalRecordCount = resultSet.Entries.Count;

                SqlServerIo.Release(sql);

                CacheManager.CacheObject(keysetId, true, query, resultSet, invTimeout);
            }

            return(resultSet);
        }