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); } }
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())); }
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 }
//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 { } }
public bool UpdateFeeds(List <FeedContract> feeds) { var ids = feeds.Select(x => x.FeedId).ToList(); var dbFeeds = context.Feeds.Where(x => ids.Any(f => f == x.FeedId)); foreach (var dbfeed in dbFeeds) { dbfeed.LastUpdatedItemUrl = feeds.FirstOrDefault(x => x.FeedId == dbfeed.FeedId).LastFeedItemUrl; if (!string.IsNullOrEmpty(dbfeed.LastUpdatedItemUrl) && feeds.SingleOrDefault(f => f.FeedId == dbfeed.FeedId).FeedItems.Count > 0) { dbfeed.UpdatingCount = dbfeed.UpdatingCount == null ? 1 : dbfeed.UpdatingCount + 1; dbfeed.LastUpdateDateTime = DateTime.Now; BaseUpdater.CheckForChangeDuration(dbfeed, true); } else { BaseUpdater.CheckForChangeDuration(dbfeed, false); } dbfeed.LastUpdaterVisit = DateTime.Now; } context.SaveChanges(); GeneralLogs.WriteLog("UpdateFeeds[AsService] : " + string.Join("[br /]", dbFeeds.Select(x => x.Link)), TypeOfLog.OK); return(true); }
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); } } }
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); } } }
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); } }
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 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 "); } }
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(); }
public bool AddItem(FeedItem item) { var context = new TazehaContext(); var itemdb = context.FeedItems.FirstOrDefault(x => x.Link == item.Link); if (itemdb == null) { context.FeedItems.Add(item); context.SaveChanges(); } else if (itemdb.FeedId != item.FeedId) { itemdb.AlternativeFeedId = item.FeedId; context.SaveChanges(); } else { return(false); } return(true); }
private bool UpdateItemFeeds(IEnumerable <FeedContract> feeds) { #region send items List <FeedItemSP> items = feeds.SelectMany(feed => feed.FeedItems.Select(item => new FeedItemSP { Cats = !string.IsNullOrEmpty(feed.Cats) ? feed.Cats.Split(' ').Select(x => int.Parse(x)) : null, CreateDate = DateTime.Now, Description = item.Description, Link = item.Link, PubDate = item.PubDate, FeedId = feed.Id, SiteId = feed.SiteId, SiteTitle = feed.SiteTitle, SiteUrl = feed.SiteUrl, Title = item.Title })).ToList(); IRepositorySaver saver = new LuceneSaverRepository(); saver.AddItems(items); NumberOfNewItemsToday += items.Count; if (NumberOfNewItemsToday > 100) { Optimize(); } #endregion #region UpdateFeed var ids = feeds.Select(x => x.Id).ToList(); var dbFeeds = Context.Feeds.Where(x => ids.Any(f => f == x.Id)); foreach (var dbfeed in dbFeeds) { dbfeed.LastUpdatedItemUrl = feeds.FirstOrDefault(x => x.Id == dbfeed.Id).LastFeedItemUrl; if (!string.IsNullOrEmpty(dbfeed.LastUpdatedItemUrl)) { dbfeed.UpdatingCount = dbfeed.UpdatingCount == null ? 1 : dbfeed.UpdatingCount + 1; dbfeed.LastUpdaterVisit = DateTime.Now; CheckForChangeDuration(dbfeed, true); } else { CheckForChangeDuration(dbfeed, false); } dbfeed.LastUpdaterVisit = DateTime.Now; } Context.SaveChanges(); GeneralLogs.WriteLog("UpdateFeeds[" + UpdaterName + "] : " + string.Join("[br /]", dbFeeds.Select(x => x.Link)), TypeOfLog.OK); #endregion return(true); }
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)); } }
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)); } }
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)); } }
public UpdateDuration GetLast(string Code, int CountOfFeed) { TazehaContext context = new TazehaContext(); var duration = context.UpdateDurations.SingleOrDefault(x => x.Code.StartsWith(Code)); if (duration.StartIndex > duration.FeedsCount) { duration.StartIndex = 0; } else { duration.StartIndex = duration.StartIndex + CountOfFeed; } context.SaveChanges(); return(duration); }
public static void SetConfig(string Name, string Value) { TazehaContext entiti = new TazehaContext(); var config = entiti.ProjectSetups.SingleOrDefault(x => x.Title == Name); if (config != null) { config.Value = Value; } else { entiti.ProjectSetups.Add(new ProjectSetup { Title = Name, Value = Value }); } entiti.SaveChanges(); //ConfigurationManager.AppSettings[Name.Trim()] = Value; }
public override bool UnlockUser(string userName) { using (TazehaContext Context = new TazehaContext()) { User User = null; User = Context.Users.FirstOrDefault(Usr => Usr.UserName == userName); if (User != null) { User.IsLockedOut = false; User.PasswordFailuresSinceLastSuccess = 0; Context.SaveChanges(); return(true); } else { return(false); } } }
public override void AddUsersToRoles(string[] usernames, string[] roleNames) { using (TazehaContext Context = new TazehaContext()) { var Users = Context.Users.Where(Usr => usernames.Contains(Usr.UserName)); var Roles = Context.Roles.Where(Rl => roleNames.Contains(Rl.RoleName)); foreach (User user in Users) { foreach (Role role in Roles) { if (!user.Roles.Contains(role)) { user.Roles.Add(role); } } } Context.SaveChanges(); } }
public override void CreateRole(string roleName) { if (!string.IsNullOrEmpty(roleName)) { using (TazehaContext Context = new TazehaContext()) { Role Role = null; Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName); if (Role == null) { Role NewRole = new Role { RoleId = Guid.NewGuid(), RoleName = roleName }; Context.Roles.Add(NewRole); Context.SaveChanges(); } } } }
public override bool DeleteUser(string username, bool deleteAllRelatedData) { if (string.IsNullOrEmpty(username)) { return(false); } using (TazehaContext Context = new TazehaContext()) { User User = null; User = Context.Users.FirstOrDefault(Usr => Usr.UserName == username); if (User != null) { Context.Users.Remove(User); Context.SaveChanges(); return(true); } else { return(false); } } }
private static void CheckForChangeDuration(Feed feed, bool hasNewFeedItem) { TazehaContext Context = new TazehaContext(); if (!feed.LastUpdateDateTime.HasValue) { feed.LastUpdateDateTime = DateTime.Now; Context.SaveChanges(); return; } TimeSpan lastupdatetime = DateTime.Now.Subtract(feed.LastUpdateDateTime.Value); TimeSpan delaytime = TimeSpan.Parse(feed.UpdateDuration.DelayTime); //---agar dar baze zamani kamtar az delay tarif shode feed update shode bood if (lastupdatetime < delaytime && hasNewFeedItem) { SpeedUP(feed); } else if (lastupdatetime > delaytime && !hasNewFeedItem) { SpeedDOWN(feed); } else { //---------dar baze zamani kamtar az delay update nashode bashe //------agar fasle akharin update kamtar az 2barabare delay bood bazham speed afzayesh yabad delaytime += delaytime; if (lastupdatetime < delaytime && feed.UpdateSpeed > 2) { SpeedUP(feed); } // else //EventLog.GeneralLogs.WriteLog("Info ElseFeedUpdating..." + feed.Id + "|" + feed.Link); } }
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { using (TazehaContext Context = new TazehaContext()) { foreach (String username in usernames) { String us = username; User user = Context.Users.FirstOrDefault(U => U.UserName == us); if (user != null) { foreach (String roleName in roleNames) { String rl = roleName; Role role = Context.Roles.FirstOrDefault(R => R.RoleName == rl); if (role != null) { Context.Roles.Remove(role); } } } } Context.SaveChanges(); } }
public override void UpdateIsParting() { //TazehaContext Context = new TazehaContext(); StartUp inputparams = new StartUp(); EventsLog.GeneralLogs.WriteLogInDB("Start Updater is parting localy", TypeOfLog.Start); #region ForFirst List <UpdateDuration> periods = new List <UpdateDuration>(); if (DurationDic.Count == 0) { periods = Context.UpdateDurations.FromHttpCache <UpdateDuration>().Where(x => x.IsParting.HasValue && x.IsParting.Value == true && x.IsLocalyUpdate.HasValue && x.IsLocalyUpdate == true).ToList(); foreach (var period in periods) { //period.FeedsCount = entiti.Feeds.Where(x => x.Id.Value == period.Id).Count(); DurationDic.Add(period, 0); } } else { periods = DurationDic.Select(x => x.Key).ToList(); } #endregion int durationCounter = 0; foreach (var duration in periods) { if (StopUpdater) { return; } inputparams.StartUpConfig = duration.Code; var FeedsCount = Context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id && ((int)x.Deleted < 1 || (int)x.Deleted > 10)).Count(); //&& (x.Site.IsBlog == inputparams.IsBlog || inputparams.IsBlog == 2) && TimeSpan delaytime = TimeSpan.Parse(duration.DelayTime); var Partnumber = delaytime.Hours * 60 / Config.GetTimeInterval(); //20 min intervall var TopCount = FeedsCount / Partnumber != 0 ? FeedsCount / Partnumber : FeedsCount % Partnumber; if (TopCount == 0) { continue; } inputparams.TopCount = TopCount; #region get Last Index if (DurationDic[duration] == 0) { int LastUpdateIndex = 0; var lastupdateindex = Context.ProjectSetups.SingleOrDefault(x => x.Title == "LastUpdat:" + inputparams.StartUpConfig.Trim()); if (lastupdateindex != null) { LastUpdateIndex = int.Parse(lastupdateindex.Value); } DurationDic[duration] = LastUpdateIndex; } #endregion inputparams.StartIndex = DurationDic[duration]; StartByDuration(inputparams, duration, durationCounter); #region save last state Context = new TazehaContext(); var projStup = Context.ProjectSetups.SingleOrDefault(x => x.Title == "LastUpdat:" + inputparams.StartUpConfig); if (DurationDic[duration] + 1 >= FeedsCount) { projStup.Value = "0"; Context.SaveChanges(); DurationDic[duration] = 0; } else { DurationDic[duration] = DurationDic[duration] + TopCount; projStup = Context.ProjectSetups.SingleOrDefault(x => x.Title == "LastUpdat:" + inputparams.StartUpConfig); projStup.Value = (DurationDic[duration]).ToString(); Context.SaveChanges(); } #endregion } EventsLog.GeneralLogs.WriteLogInDB("End UpdateIsParting", TypeOfLog.End, typeof(UpdaterClassic)); }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { if (string.IsNullOrEmpty(username)) { status = MembershipCreateStatus.InvalidUserName; return(null); } if (string.IsNullOrEmpty(password)) { status = MembershipCreateStatus.InvalidPassword; return(null); } if (string.IsNullOrEmpty(email)) { status = MembershipCreateStatus.InvalidEmail; return(null); } string HashedPassword = Crypto.HashPassword(password); if (HashedPassword.Length > 128) { status = MembershipCreateStatus.InvalidPassword; return(null); } using (TazehaContext Context = new TazehaContext()) { if (Context.Users.Where(Usr => Usr.UserName == username).Any()) { status = MembershipCreateStatus.DuplicateUserName; return(null); } if (Context.Users.Where(Usr => Usr.Email == email).Any()) { status = MembershipCreateStatus.DuplicateEmail; return(null); } User NewUser = new User { Id = Guid.NewGuid(), UserName = username, Password = HashedPassword, IsApproved = isApproved, Email = email, CreateDate = DateTime.UtcNow, LastPasswordChangedDate = DateTime.UtcNow, PasswordFailuresSinceLastSuccess = 0, LastLoginDate = DateTime.UtcNow, LastActivityDate = DateTime.UtcNow, LastLockoutDate = DateTime.UtcNow, IsLockedOut = false, LastPasswordFailureDate = DateTime.UtcNow }; Context.Users.Add(NewUser); Context.SaveChanges(); status = MembershipCreateStatus.Success; return(new MembershipUser(System.Web.Security.Membership.Provider.Name, NewUser.UserName, NewUser.Id, NewUser.Email, null, null, NewUser.IsApproved, NewUser.IsLockedOut, NewUser.CreateDate, NewUser.LastLoginDate, NewUser.LastActivityDate, NewUser.LastPasswordChangedDate, NewUser.LastLockoutDate)); } }
//one call is fuctionality for update duration that has many feeds private Feed UpdatingFeed(long feedId) { int NumberOfNewItem = 0; var entiti = new TazehaContext(); Feed dbfeed = entiti.Feeds.Single <Feed>(x => x.Id == feedId); dbfeed.UpdatingCount = dbfeed.UpdatingCount == null ? 1 : dbfeed.UpdatingCount + 1; dbfeed.LastUpdaterVisit = DateTime.Now; try { if (dbfeed.FeedType == 0 || !dbfeed.FeedType.HasValue) { #region Feed RssFeed feed = RssFeed.Read(dbfeed.Link); //-----------shart check kardane inke feed aslan update shode dar site marja ya kheir------------ if (feed == null) { dbfeed.Deleted = Common.Share.DeleteStatus.NotWork; } else if (feed.Channels.Count > 0) { bool Exist = false; if (Exist) { GeneralLogs.WriteLog("NoUpdated(last item exist) feed: " + feedId, TypeOfLog.Info); } else { //--------Feed has new items----------- if (feed.Channels.Count > 0) { RssChannel channel = (RssChannel)feed.Channels[0]; List <FeedItemSP> listReturnBack; if (channel.Items.LatestPubDate() != channel.Items[0].PubDate) { listReturnBack = FeedItemsOperation.InsertFeedItems(channel.ItemsSorted, dbfeed); } else { listReturnBack = FeedItemsOperation.InsertFeedItems(channel.Items, dbfeed); } GeneralLogs.WriteLog("Updating feed " + dbfeed.Id + " Num:" + listReturnBack.Count + " " + dbfeed.Link, TypeOfLog.OK); } } } #endregion } else if (dbfeed.FeedType.HasValue && dbfeed.FeedType.Value == Common.Share.FeedType.Atom) { #region Atom //-----------------atom feed-------------- XmlReader reader = XmlReader.Create(dbfeed.Link); SyndicationFeed atomfeed = SyndicationFeed.Load(reader); int i = 0; if (atomfeed == null) { dbfeed.Deleted = Common.Share.DeleteStatus.NotWork; } else if (atomfeed.Items.Any()) { foreach (SyndicationItem item in atomfeed.Items) { i++; break; } if (i > 0) { List <FeedItem> listReturnBack = FeedItemsOperation.InsertFeedItems(atomfeed.Items, dbfeed); GeneralLogs.WriteLog("OK updating atom " + dbfeed.Id + " Num:" + listReturnBack.Count + " " + dbfeed.Link); } } #endregion } } catch (Exception ex) { #region Exception if (ex.Message.IndexOf("404") > 0) { dbfeed.Deleted = Common.Share.DeleteStatus.NotFound; } else if (ex.Message.IndexOf("403") > 0) { dbfeed.Deleted = Common.Share.DeleteStatus.Forbidden; } else if (ex.Message.IndexOfX("timed out") > 0) { //------request time out dbfeed.Deleted = Common.Share.DeleteStatus.RequestTimeOut; } //-----------log error----- if (ex.Message.IndexOfX("Inner Exception") > 0) { CrawlerLog.FailLog(dbfeed, ex.InnerException.Message.SubstringX(0, 1020)); } else { GeneralLogs.WriteLog("Info " + ex.Message); } #endregion } #region LASTFLOW try { CheckForChangeDuration(dbfeed, NumberOfNewItem > 0 ? true : false); CrawlerLog.SuccessLog(dbfeed, NumberOfNewItem); entiti.SaveChanges(); } catch (Exception ex) { GeneralLogs.WriteLog(ex.Message); } #endregion return(dbfeed); }
public List <FeedItem> InsertFeedItems(IEnumerable <SyndicationItem> Items, Feed feed) { var listReturnBack = new List <FeedItem>(); var entiti = new TazehaContext(); var erroroccur = 0; foreach (SyndicationItem item in Items) { if (erroroccur > 2) { return(listReturnBack); } try { if (!Utility.HasFaWord(item.Title.Text)) { continue; } FeedItem dbitem = new FeedItem(); dbitem.Title = HtmlRemoval.StripTagsRegex(item.Title.Text).Replace("\t", "").Replace("\n", "").Replace("\r", ""); dbitem.Link = item.Links[0].Uri.AbsoluteUri; dbitem.Description = item.Summary == null ? string.Empty : HtmlRemoval.StripTagsRegex(item.Summary.Text).Replace("\t", "").Replace("\n", "").Replace("\r", ""); //-------------------------Baray DB koochi!!----------------- dbitem.Description = dbitem.Description.SubstringX(0, 1000); dbitem.CreateDate = DateTime.Now; dbitem.SiteId = feed.SiteId; dbitem.FeedId = feed.Id; if (item.PublishDate != null) { dbitem.PubDate = item.PublishDate.DateTime; } dbitem.IndexedType = dbitem.IndexedType.HasValue ? dbitem.IndexedType + 1 : 1; //dbitem.Cats = feed.Categories.Select(x => x.Id); dbitem.SiteTitle = feed.Site.SiteTitle; dbitem.SiteUrl = feed.Site.SiteUrl; dbitem.SiteId = feed.SiteId; var feedItem = new FeedItem { Link = dbitem.Link, Title = dbitem.Title, PubDate = dbitem.PubDate, CreateDate = DateTime.Now, FeedId = feed.Id }; entiti.FeedItems.Add(feedItem); entiti.SaveChanges(); dbitem.Id = Guid.Parse(feedItem.Id.ToString()); LuceneRepositoryAsService lucene = new LuceneRepositoryAsService(); lucene.AddItem(dbitem); //Helper.Utility.InsertItemToCloudant(dbitem); listReturnBack.Add(dbitem); Indexer.Indexer.FirstIndexing(dbitem); } catch (Exception ex) { if (ex.Message.IndexOfX("Inner Exception") > 0) { if (ex.InnerException.Message.IndexOfX("Cannot insert duplicate key") > -1) { //if (item.Links[0].Uri.AbsoluteUri.ContainsX(Crawler.BaseSite.SiteUrl)) break; } else { GeneralLogs.WriteLog("Errror @InsertFeedItems" + ex.InnerException.Message); } } else { GeneralLogs.WriteLog("Errror @InsertFeedItems" + ex.Message); } erroroccur++; } } //baraye in biroon forech gharar dadam ke har seri baraye set shodane IndexType save anjam nashe //try //{ // entiti.SaveChanges(); //} //catch (Exception ex) //{ // if (ex.Message.IndexOfX("Inner Exception") > 0) // EventLog.LogsBuffer.WriteLog(">Errror @InsertFeedItems2" + ex.InnerException.Message); // else // EventLog.LogsBuffer.WriteLog(">Errror @InsertFeedItems2" + ex.Message); //} return(listReturnBack); }