public override bool IsUserInRole(string username, string roleName)
 {
     if (string.IsNullOrEmpty(username))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(roleName))
     {
         return(false);
     }
     using (TazehaContext Context = new TazehaContext())
     {
         User User = null;
         User = Context.Users.FirstOrDefault(Usr => Usr.UserName == username);
         if (User == null)
         {
             return(false);
         }
         Role Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
         if (Role == null)
         {
             return(false);
         }
         return(Context.Roles.Contains(Role));
     }
 }
 public override string[] GetAllRoles()
 {
     using (TazehaContext Context = new TazehaContext())
     {
         return(Context.Roles.Select(Rl => Rl.RoleName).ToArray());
     }
 }
 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
 {
     if (string.IsNullOrEmpty(roleName))
     {
         return(false);
     }
     using (TazehaContext Context = new TazehaContext())
     {
         Role Role = null;
         Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
         if (Role == null)
         {
             return(false);
         }
         if (throwOnPopulatedRole)
         {
             if (Role.Users.Any())
             {
                 return(false);
             }
         }
         else
         {
             Role.Users.Clear();
         }
         Context.Roles.Remove(Role);
         Context.SaveChanges();
         return(true);
     }
 }
Beispiel #4
0
        public static void SetSitePageRank(int StartIndex = 0)
        {
            var context  = new TazehaContext();
            int TopCount = 100;
            var sites    = context.Sites.Where(x => !x.PageRank.HasValue && !x.IsBlog).OrderBy(x => x.Id).Skip(StartIndex).Take(TopCount).Select(x => new { x.Id, x.SiteUrl }).ToDictionary(x => x.Id, x => x.SiteUrl);

            foreach (var site in sites)
            {
                try
                {
                    string siteUrl = site.Value;
                    siteUrl = siteUrl.IndexOfX("www.") > -1 || siteUrl.IndexOfX("http://") > -1 ? siteUrl : "www." + siteUrl;
                    siteUrl = siteUrl.IndexOfX("http://") > -1 ? siteUrl : "http://" + siteUrl;
                    byte PageRank = GooglePageRank.GetPageRank(siteUrl);
                    setPageRank(site.Key, PageRank);
                    GeneralLogs.WriteLog("OK @SetSitePageRank " + siteUrl + " " + PageRank);
                }
                catch (Exception ex)
                {
                    setPageRank(site.Key, 0);
                    GeneralLogs.WriteLog("Error @setPageRank SiteId:" + site.Key + " " + ex.Message);
                }
            }
            if (context.Sites.Where(x => x.PageRank == null && !x.IsBlog).OrderBy(x => x.Id).Skip(StartIndex).Count() > 0)
            {
                SetSitePageRank(StartIndex + TopCount);
            }
        }
 public override bool ValidateUser(string username, string password)
 {
     if (string.IsNullOrEmpty(username))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(password))
     {
         return(false);
     }
     using (TazehaContext Context = new TazehaContext())
     {
         User User = null;
         User = Context.Users.FirstOrDefault(Usr => Usr.UserName == username);
         if (User == null)
         {
             return(false);
         }
         if (!User.IsApproved)
         {
             return(false);
         }
         if (User.IsLockedOut)
         {
             return(false);
         }
         String  HashedPassword        = User.Password;
         Boolean VerificationSucceeded = (HashedPassword != null && Crypto.VerifyHashedPassword(HashedPassword, password));
         if (VerificationSucceeded)
         {
             User.PasswordFailuresSinceLastSuccess = 0;
             User.LastLoginDate    = DateTime.UtcNow;
             User.LastActivityDate = DateTime.UtcNow;
         }
         else
         {
             int?Failures = User.PasswordFailuresSinceLastSuccess;
             if (Failures < MaxInvalidPasswordAttempts)
             {
                 User.PasswordFailuresSinceLastSuccess += 1;
                 User.LastPasswordFailureDate           = DateTime.UtcNow;
             }
             else if (Failures >= MaxInvalidPasswordAttempts)
             {
                 User.LastPasswordFailureDate = DateTime.UtcNow;
                 User.LastLockoutDate         = DateTime.UtcNow;
                 User.IsLockedOut             = true;
             }
         }
         Context.SaveChanges();
         if (VerificationSucceeded)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #6
0
        public static string GetConfig(string Name)
        {
            if (ConfigDic.ContainsKey(Name))
            {
                return(ConfigDic.SingleOrDefault(x => x.Key == Name).Value);
            }
            else
            {
                string Value;
                using (var entiti = new TazehaContext())
                {
                    if (entiti.ProjectSetups.Any(x => x.Title == Name))
                    {
                        Value = entiti.ProjectSetups.First(x => x.Title == Name).Value;
                    }
                    else
                    {
                        Value = appSettings.Get(Name);
                    }

                    lock (ConfigDic)
                        ConfigDic.Add(Name, Value);
                }
                return(Value);
            }
        }
Beispiel #7
0
        private static void SpeedUP(Feed feed)
        {
            TazehaContext Context = new TazehaContext();

            feed.LastUpdateDateTime = DateTime.Now;
            if (feed.UpdateSpeed > 5)
            {
                //------feed ro saritar pooyesh kon(TAghire level)----
                var newdurations = Context.UpdateDurations.FromHttpCache <UpdateDuration>().Where <UpdateDuration>(x => x.PriorityLevel < feed.UpdateDuration.PriorityLevel);
                if (newdurations.Count() == 0)
                {
                    //-------agar be kamtarin baze updater resid---1Hour-----
                    feed.UpdateSpeed = 0;
                }
                else
                {
                    UpdateDuration newduration = newdurations.OrderByDescending(x => x.PriorityLevel).First();
                    feed.Id          = newduration.Id;
                    feed.UpdateSpeed = 0;
                }
            }
            else
            {
                feed.UpdateSpeed = feed.UpdateSpeed.HasValue ? feed.UpdateSpeed + 1 : 1;
            }
        }
Beispiel #8
0
        public static void TagsTableSaveChanges()
        {
            try
            {
                var entiti        = new TazehaContext();
                var TagsTableMain = entiti.Tags.ToList <Tag>();
                TagsTable.ForEach(x => x.RepeatCount     = x.RepeatCount == null ? 0 : x.RepeatCount);
                TagsTableMain.ForEach(x => x.RepeatCount = x.RepeatCount == null ? 0 : x.RepeatCount);

                int NumberOfChanges = 0;
                for (int i = 0; i < TagsTableMain.Count; i++)
                {
                    if (TagsTableMain[i].RepeatCount < TagsTable[i].RepeatCount)
                    {
                        TagsTableMain[i].RepeatCount = TagsTable[i].RepeatCount;
                        NumberOfChanges++;
                    }
                }
                entiti.SaveChanges();
                GeneralLogs.WriteLogInDB(">OK TagsTableSaveChanges NumberOfChanges:" + NumberOfChanges);
            }
            catch
            {
                GeneralLogs.WriteLogInDB(">Error TagsTableSaveChanges ");
            }
        }
Beispiel #9
0
        public static void FirstIndexing(FeedItem feedItem)
        {
            //--------condition for alternate items------
            if (feedItem.ItemId == 0)
            {
                return;
            }
            var entiti = new TazehaContext();

            if (TagsTable.Count == 0)
            {
                TagsTable = entiti.Tags.ToList <Tag>();
            }
            int InsertCount = 0;

            foreach (var tag in TagsTable)
            {
                if (feedItem.Title.ContainsX(tag.Value) || feedItem.Description.ContainsX(tag.Value))
                {
                    tag.RepeatCount = tag.RepeatCount == null ? 1 : tag.RepeatCount + 1;
                    InsertCount++;
                }
            }
            if (InsertCount > 0)
            {
                try
                {
                    entiti.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }
        }
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     if (string.IsNullOrEmpty(username))
     {
         return(null);
     }
     using (TazehaContext Context = new TazehaContext())
     {
         User User = null;
         User = Context.Users.FirstOrDefault(Usr => Usr.UserName == username);
         if (User != null)
         {
             if (userIsOnline)
             {
                 User.LastActivityDate = DateTime.UtcNow;
                 Context.SaveChanges();
             }
             return(new MembershipUser(System.Web.Security.Membership.Provider.Name, User.UserName, User.Id, User.Email, null, null, User.IsApproved, User.IsLockedOut, User.CreateDate, User.LastLoginDate, User.LastActivityDate, User.LastPasswordChangedDate, User.LastLockoutDate));
         }
         else
         {
             return(null);
         }
     }
 }
        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            if (providerUserKey is Guid)
            {
            }
            else
            {
                return(null);
            }

            using (TazehaContext Context = new TazehaContext())
            {
                User User = null;
                User = Context.Users.Find(providerUserKey);
                if (User != null)
                {
                    if (userIsOnline)
                    {
                        User.LastActivityDate = DateTime.UtcNow;
                        Context.SaveChanges();
                    }
                    return(new MembershipUser(System.Web.Security.Membership.Provider.Name, User.UserName, User.Id, User.Email, null, null, User.IsApproved, User.IsLockedOut, User.CreateDate, User.LastLoginDate, User.LastActivityDate, User.LastPasswordChangedDate, User.LastLockoutDate));
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #12
0
        public string getThumbnailRandomInToday(string CatCode)
        {
            try
            {
                TazehaContext context = new TazehaContext();
                var           cat     = context.Categories.SingleOrDefault(x => x.Code == CatCode);
                var           items   = context.PhotoItems.Where(x => x.Id == cat.Id && x.CreationDate.Value.Day == DateTime.Now.Day && x.CreationDate.Value.Month == DateTime.Now.Month && x.CreationDate.Value.Year == DateTime.Now.Year);
                if (items.Count() == 0)
                {
                    for (int i = 1; i < 15; i++)
                    {
                        DateTime Yeasertday = DateTime.Now.AddDays(-i);
                        items = context.PhotoItems.Where(x => x.Id == cat.Id && x.CreationDate.Value.Day == Yeasertday.Day && x.CreationDate.Value.Month == Yeasertday.Month && x.CreationDate.Value.Year == Yeasertday.Year);
                        if (items.Count() > 0)
                        {
                            break;
                        }
                    }
                }

                var item = items.Shuffle().First();
                return(item.PhotoThumbnail);
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
Beispiel #13
0
        //public static void InsertRSSFeed(RssFeed feed, Site Site)
        //{
        //    RssChannel channel = (RssChannel)feed.Channels[0];
        //    var entiti = new TazehaContext();
        //    Feed dbfeed = new Feed();
        //    dbfeed.CopyRight = feed.Channels[0].Copyright;
        //    dbfeed.Description = feed.Channels[0].Description.SubstringX(0, 100);
        //    dbfeed.Link = feed.Url.SubstringX(0, 400);// feed.Channels[0].Link.AbsolutePath;
        //    dbfeed.Title = feed.Channels[0].Title.SubstringX(0, 148);
        //    dbfeed.Id = ServiceFactory.Get<IAppConfigBiz>().DefaultSearchDuration();
        //    dbfeed.Id = Site.Id;
        //    dbfeed.FeedType = 0;
        //    dbfeed.CreationDate = DateTime.Now;
        //    entiti.Feeds.Add(dbfeed);
        //    entiti.SaveChanges();
        //    GeneralLogs.WriteLog("OK  HasRSS " + Site.SiteUrl);
        //    try
        //    {
        //        ThreadPool.QueueUserWorkItem(FeedItemsOperation.InsertFeedItemsRss, new object[] { channel.Items, dbfeed.Id });
        //    }
        //    catch
        //    { }
        //}
        public void InsertAtomFeed(SyndicationFeed atomfeed, Site Site)
        {
            var entiti = new TazehaContext();
            var dbfeed = new Feed();

            if (atomfeed.Copyright != null)
            {
                dbfeed.CopyRight = atomfeed.Copyright.Text;
            }
            if (atomfeed.Description != null)
            {
                dbfeed.Description = atomfeed.Description.Text.SubstringX(0, 999);
            }
            dbfeed.Link             = atomfeed.BaseUri.ToString();// feed.Channels[0].Link.AbsolutePath;
            dbfeed.Title            = atomfeed.Title.Text.SubstringX(0, 148);
            dbfeed.UpdateDurationId = _appConfigBiz.DefaultSearchDuration();
            dbfeed.SiteId           = Site.Id;
            dbfeed.FeedType         = FeedType.Atom;//-----for Atom----------
            dbfeed.CreationDate     = DateTime.Now;
            entiti.Feeds.Add(dbfeed);
            entiti.SaveChanges();
            GeneralLogs.WriteLog("OK HasAtom " + Site.SiteUrl);
            try
            {
                new FeedItemsOperation(_appConfigBiz).InsertFeedItemsAtom(new object[] { atomfeed.Items, dbfeed.Id });
            }
            catch { }
        }
Beispiel #14
0
        public string getWebParts(string Content, int Width)
        {
            TazehaContext context = new TazehaContext();
            string        AllStr  = string.Empty;
            //var continers = context.WebPartsContainers.Where(x => x.ContainerCode == Content).Select(x => x.WebPartId);
            //var webparts = new List<WebPart>();
            //if (continers != null)
            //    webparts = context.WebParts.Where(x => continers.Concat(x.WebPartId)).ToList();
            var webparts = from x in context.WebParts
                           join y in context.WebPartsContainers on x.WebPartId equals y.WebPartId
                           where y.ContainerCode == Content
                           select x;
            int adscount = webparts.Count();

            if (adscount < 10)
            {
                var webparts2 = context.WebParts.Where(x => x.Global == true).Take(10 - adscount);
                webparts = webparts.Union(webparts2);
            }
            //ads = ads.OrderBy(x => x.AdsType).ToList();
            foreach (var item in webparts)
            {
                string res = "<div class='DWebPartItem'>";
                res    += item.HtmlContent;
                res    += "</div><br />";
                AllStr += res;
            }
            return(AllStr);
        }
Beispiel #15
0
        //public static List<FeedItem> InsertFeedItems(RssItemCollection items, decimal feedId)
        //{
        //    var entiti = new TazehaContext();
        //    var feed = entiti.Feeds.SingleOrDefault(x => x.Id == feedId);
        //    return InsertFeedItems(items, feed);
        //}
        public List <FeedItem> InsertFeedItems(IEnumerable <SyndicationItem> items, decimal feedId)
        {
            var entiti = new TazehaContext();
            var feed   = entiti.Feeds.SingleOrDefault(x => x.Id == feedId);

            return(InsertFeedItems(items, feed));
        }
Beispiel #16
0
        static void setPageRank(decimal SiteID, byte PageRank)
        {
            var context = new TazehaContext();
            var site    = context.Sites.SingleOrDefault(x => x.Id == SiteID);

            site.PageRank = PageRank;
            context.SaveChanges();
        }
Beispiel #17
0
 public ClientUpdater(IBaseServer baseservice, IFeedBusiness feedBusiness, IAppConfigBiz appConfigBiz, bool?IsLocaly)
     : base(baseservice, IsLocaly)
 {
     context       = new TazehaContext();
     server        = baseservice;
     feedBiz       = feedBusiness;
     _appConfigBiz = appConfigBiz;
 }
        public override int GetNumberOfUsersOnline()
        {
            DateTime DateActive = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(Convert.ToDouble(System.Web.Security.Membership.UserIsOnlineTimeWindow)));

            using (TazehaContext Context = new TazehaContext())
            {
                return(Context.Users.Where(Usr => Usr.LastActivityDate > DateActive).Count());
            }
        }
 public override bool ChangePassword(string username, string oldPassword, string newPassword)
 {
     if (string.IsNullOrEmpty(username))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(oldPassword))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(newPassword))
     {
         return(false);
     }
     using (TazehaContext Context = new TazehaContext())
     {
         User User = null;
         User = Context.Users.FirstOrDefault(Usr => Usr.UserName == username);
         if (User == null)
         {
             return(false);
         }
         String  HashedPassword        = User.Password;
         Boolean VerificationSucceeded = (HashedPassword != null && Crypto.VerifyHashedPassword(HashedPassword, oldPassword));
         if (VerificationSucceeded)
         {
             User.PasswordFailuresSinceLastSuccess = 0;
         }
         else
         {
             int?Failures = User.PasswordFailuresSinceLastSuccess;
             if (Failures < MaxInvalidPasswordAttempts)
             {
                 User.PasswordFailuresSinceLastSuccess += 1;
                 User.LastPasswordFailureDate           = DateTime.UtcNow;
             }
             else if (Failures >= MaxInvalidPasswordAttempts)
             {
                 User.LastPasswordFailureDate = DateTime.UtcNow;
                 User.LastLockoutDate         = DateTime.UtcNow;
                 User.IsLockedOut             = true;
             }
             Context.SaveChanges();
             return(false);
         }
         String NewHashedPassword = Crypto.HashPassword(newPassword);
         if (NewHashedPassword.Length > 128)
         {
             return(false);
         }
         User.Password = NewHashedPassword;
         User.LastPasswordChangedDate = DateTime.UtcNow;
         Context.SaveChanges();
         return(true);
     }
 }
Beispiel #20
0
        public string TopAnalyseReport()
        {
            TazehaContext context    = new TazehaContext();
            string        str        = "";
            var           itemscount = context.FeedItems.Count();
            var           sitecount  = context.Sites.Count();

            str = string.Format("تعداد سایت های یافته شده {0} {1} مجموع مطالب موجود {2}  ", sitecount, " و ", itemscount);
            return(str);
        }
Beispiel #21
0
        public virtual ActionResult Share(string item, SocialNetwork.SocialNetworkItems sn)
        {
            TazehaContext context = new TazehaContext();

            //context.FeedItems.FirstOrDefault(x => x.FeedItemId == Item).Vote++;
            if (item.Length > 10)
            {
                var id = Guid.Parse(item);
                context.SocialTrackers.Add(new SocialTracker()
                {
                    FeedItemRef = id, CreationDate = DateTime.Now, SocialNetworkRef = (int)sn
                });
                context.SaveChanges();
            }
            else if (item.Length > 3)
            {
                var id = long.Parse(item);
                context.SocialTrackers.Add(new SocialTracker()
                {
                    ItemRef = id, CreationDate = DateTime.Now, SocialNetworkRef = (int)sn
                });
                context.SaveChanges();
            }

            var url = "http://www.facebook.com/share.php?v=4&src=bm&u=";

            switch (sn)
            {
            case SocialNetwork.SocialNetworkItems.FaceBook:
                url = "http://www.facebook.com/share.php?v=4&src=bm&u=";
                break;

            case SocialNetwork.SocialNetworkItems.GooglePlus:
                url = "https://plus.google.com/share?url=";
                break;

            case SocialNetwork.SocialNetworkItems.Twitter:
                url = "http://twitter.com/home?status";
                break;

            case SocialNetwork.SocialNetworkItems.LinkedIn:
                url = "http://www.linkedin.com/shareArticle?mini=true&url=";
                break;

            case SocialNetwork.SocialNetworkItems.Balatarin:
                url = "http://www.balatarin.com/links/submit?phase=2&url=";
                break;

            case SocialNetwork.SocialNetworkItems.Cloob:
                url = "http://www.cloob.com/share/link/add?url=";
                break;
            }
            //add entity to social tracker
            return(Redirect(url + Request.UrlReferrer.ToString()));
        }
Beispiel #22
0
        public virtual JsonResult GetCats(ViewMode viewMode)
        {
            var context = new TazehaContext();
            var cats    =
                context.Categories.Where(c => viewMode.ToString().Contains(c.ViewMode.ToString()))
                .Select(c => new { title = c.Title, code = c.Code });

            return(Json(cats.ToList(), JsonRequestBehavior.AllowGet));

            return(null);
        }
Beispiel #23
0
        public List <FeedItem> InsertItemsSqlLucene(RssItemCollection items, Feed feed)
        {
            var              entiti           = new TazehaContext();
            List <FeedItem>  listReturnBack   = new List <FeedItem>();
            IRepositorySaver RepositorySql    = new SqlRepository();
            IRepositorySaver RepositoryLucene = new LuceneRepositoryAsService();
            int              erroroccur       = 0;

            foreach (RssItem item in items)
            {
                if (erroroccur > 2)
                {
                    return(listReturnBack);
                }
                if (!Utility.HasFaWord(item.Title))
                {
                    continue;
                }

                FeedItem dbitem = new FeedItem();
                dbitem.Title       = HtmlRemoval.StripTagsRegex(item.Title).Replace("\t", "").Replace("\n", "").Replace("\r", "");
                dbitem.Link        = item.Link.ToString();
                dbitem.Description = HtmlRemoval.StripTagsRegex(item.Description).Replace("\t", "").Replace("\n", "").Replace("\r", "");
                //-------------------------Baray DB koochiK!!-----------------
                dbitem.Description = dbitem.Description.SubstringX(0, _appConfigBiz.MaxDescriptionLength());
                dbitem.SiteId      = feed.SiteId;
                dbitem.FeedId      = feed.Id;
                if (item.PubDate.Year > 1350 && item.PubDate < DateTime.Now.AddDays(2))
                {
                    dbitem.PubDate = item.PubDate;
                }
                else
                {
                    break;
                }
                dbitem.CreateDate = DateTime.Now;
                //dbitem.Cats = feed.Categories.Select(x => x.Id).ToList();
                dbitem.SiteTitle   = feed.Site.SiteTitle;
                dbitem.SiteUrl     = feed.Site.SiteUrl;
                dbitem.SiteId      = feed.SiteId;
                dbitem.IndexedType = dbitem.IndexedType.HasValue ? dbitem.IndexedType + 1 : 1;
                var feedItem = new FeedItem {
                    Link = dbitem.Link, Title = dbitem.Title, PubDate = dbitem.PubDate, CreateDate = DateTime.Now, FeedId = feed.Id
                };

                if (RepositorySql.AddItem(feedItem))
                {
                    RepositoryLucene.AddItem(dbitem);
                    listReturnBack.Add(dbitem);
                    Indexer.Indexer.FirstIndexing(dbitem);
                }
            }
            return(listReturnBack);
        }
Beispiel #24
0
 private void AfterOneCall(StartUp inputParams, UpdateDuration duration)
 {
     #region NoIsParting
     TazehaContext context = new TazehaContext();
     int           ItemCountPriorityCode = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id && x.Site.IsBlog == inputParams.IsBlog && (x.Deleted == 0 || (int)x.Deleted > 10)).Count();
     int           LastCount             = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id && x.Site.IsBlog == inputParams.IsBlog && (x.Deleted == 0 || (int)x.Deleted > 10)).OrderBy(x => x.Id).Skip(inputParams.StartIndex).Take <Feed>(inputParams.TopCount).Count();
     int           NextCount             = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id && x.Site.IsBlog == inputParams.IsBlog && (x.Deleted == 0 || (int)x.Deleted > 10)).OrderBy(x => x.Id).Skip(inputParams.StartIndex + inputParams.TopCount).Take <Feed>(inputParams.TopCount).Count();
     if (NextCount > 0)
     {
         var LastUpdateIndex = context.ProjectSetups.SingleOrDefault(x => x.Title == "LastUpdat:" + inputParams.StartUpConfig);
         if (LastUpdateIndex != null)
         {
             //LastUpdateIndex.Value = (InputParams.StartIndex + InputParams.TopCount + InputParams.TopCount).ToString();
             LastUpdateIndex.Value = (inputParams.StartIndex + inputParams.TopCount).ToString();
             context.SaveChanges();
         }
         else
         {
             //entiti.ProjectSetup.AddObject(new ProjectSetup { Title = "LastUpdat:" + InputParams.StartUpConfig, Value = (InputParams.StartIndex + InputParams.TopCount + InputParams.TopCount).ToString(), Meaning = "last index updater of feed of priority" });
             context.ProjectSetups.Add(new ProjectSetup {
                 Title = "LastUpdat:" + inputParams.StartUpConfig, Value = (inputParams.StartIndex + inputParams.TopCount).ToString(), Meaning = "last index updater of feed of priority"
             });
             context.SaveChanges();
         }
         inputParams.StartIndex += inputParams.TopCount;
         if (!duration.IsParting.HasValue || !duration.IsParting.Value)
         {
             StartByDuration(inputParams, null, 0);
         }
     }
     else
     {
         //-----------------------When all items updated------------------
         if (duration != null)
         {
             var LastUpdateIndex = context.ProjectSetups.SingleOrDefault(x => x.Title == "LastUpdat:" + inputParams.StartUpConfig);
             if (LastUpdateIndex != null)
             {
                 LastUpdateIndex.Value = "0";
                 context.SaveChanges();
             }
             else
             {
                 context.ProjectSetups.Add(new ProjectSetup {
                     Title = "LastUpdat:" + inputParams.StartUpConfig, Value = "0", Meaning = "last index updater of feed of priority"
                 });
                 context.SaveChanges();
             }
             GeneralLogs.WriteLogInDB(">OK UpdaterSleeping... duration:" + duration.Code);
             ///for test task with windows----
         }
     }
     #endregion
 }
Beispiel #25
0
        public virtual JsonResult GetFeeds(int siteId)
        {
            var context = new TazehaContext();
            var feeds   = context.Sites.SingleOrDefault(s => s.Id == siteId).Feeds;

            if (feeds != null)
            {
                return(Json(feeds.Select(f => new { title = f.Title, link = f.Link }).ToList(), JsonRequestBehavior.AllowGet));
            }
            return(null);
        }
Beispiel #26
0
        public string getAds(string Content, int Width)
        {
            TazehaContext context = new TazehaContext();
            string        allAds  = string.Empty;
            //var continer = context.AdsContainers.SingleOrDefault(x => x.ContainerCode == Content);
            //var ads = new List<Ad>();
            //if (continer != null)
            //    ads = context.Ads.Where(x => x.AdsId == continer.AdsId).ToList();
            var ads = (from x in context.Ads
                       join y in context.AdsContainers on x.AdsId equals y.AdsId
                       where y.ContainerCode == Content && x.Disable != true
                       select x).ToList();
            int adscount = ads.Count();

            if (adscount < 10)
            {
                var ads2 = context.Ads.Where(x => x.Global == true && (!x.Disable.HasValue || x.Disable.Value != true)).Take(10 - adscount).ToList();
                ads.AddRange(ads2);
            }
            ads = ads.OrderBy(x => x.AdsType).ToList();
            foreach (var item in ads)
            {
                string res = "<div class='DAdsItem'>";
                if (item.AdsType == 1)
                {
                    //---------Image--------
                    res += string.Format("<a href='{2}'><img src='/AdsFiles/Gif/{0}.gif' alt='{1}' title='{1}' style='margin:5px' width='{3}' /></a>", item.AdsId, item.Title, item.Link, Width);
                }
                else if (item.AdsType == 2)
                {
                    //------------Flash------
                    res += string.Format(@"<object width='{1}'  style='display: block' type='application/x-shockwave-flash'
                    data='/AdsFiles/Flash/{0}.swf'>
                    <param value='/AdsFiles/Flash/{0}.swf' name='movie'>
                    <param value='false' name='menu'>
                    </object>'", item.AdsId, Width);
                }
                else if (item.AdsType == 3)
                {
                    res += string.Format(item.Content);
                }
                else
                {
                    //------------Text------
                    res += string.Format("<a href='{0}' class='AdsTextTitle' >{1}</a><div class='AdsTextDesc'>{2}</div><br />", item.Link, item.Title, item.Content);
                }
                res    += "</div>";
                allAds += res;
            }
            return(allAds);
        }
Beispiel #27
0
        public List <FeedItem> FeedItems(int TopCount)
        {
            if (HttpContext.Current.Cache["Recommendation_FeedItems"] != null)
            {
                var items = HttpContext.Current.Cache["Recommendation_FeedItems"] as List <FeedItem>;
                return(items.Shuffle().Take(TopCount).ToList());
            }
            var context   = new TazehaContext();
            var date      = DateTime.Now.AddDays(-3);
            var feeditems = context.FeedItems.Where(x => x.CreateDate >= date && x.VisitsCount > atLeastVisitCount).OrderByDescending(x => x.VisitsCount).Take(TopCount).ToList();

            HttpContext.Current.Cache.AddToChache_Hours("Recommendation_FeedItems", feeditems, DefaultHourTime);
            return(feeditems.Take(TopCount).ToList());
        }
Beispiel #28
0
 public virtual ActionResult TagsUsersAdding(string TagContent)
 {
     try
     {
         var context = new TazehaContext();
         var user    = context.Users.SingleOrDefault(x => x.UserName == User.Identity.Name);
         context.Tags.SingleOrDefault(x => x.EnValue == TagContent || x.Value == TagContent).Users.Add(user);
         context.SaveChanges();
         return(Json(true, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(false, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #29
0
 public virtual ActionResult SitesUsersDeleting(string SiteURL)
 {
     try
     {
         var context = new TazehaContext();
         var user    = context.Users.SingleOrDefault(x => x.UserName == User.Identity.Name);
         context.Sites.SingleOrDefault(x => x.SiteUrl == SiteURL).Users.Remove(user);
         context.SaveChanges();
         return(Json(true, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(false, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #30
0
 public virtual ActionResult CatsUsersAdding(string CatCode)
 {
     try
     {
         var context = new TazehaContext();
         var user    = context.Users.SingleOrDefault(x => x.UserName == User.Identity.Name);
         context.Categories.SingleOrDefault(x => x.Code == CatCode).Users.Add(user);
         context.SaveChanges();
         return(Json(true, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(false, JsonRequestBehavior.AllowGet));
     }
 }