public bool IsNew(long id) { using (var db = new MySelfieEntities()) { var result = db.Photos.Any(x => x.SocialID == id); return !result; } }
private void SavePic(MySelfie.Scraper.InstagramObject.Datum data, string originalURL, string fileName) { var azureURL = this.StorePicture(originalURL, fileName); var urls = data.images.standard_resolution.url; var hashTags = ""; try { hashTags = String.Join("|", data.tags.Select(x => x.To<string>())); } catch { } using (var db = new MySelfieEntities()) { var entity = new Photo(); entity.Username = data.user.username; entity.Text = data.caption.text; //entity.SocialCreatedAt = new DateTime(long.Parse(data.created_time)); entity.SocialCreatedAt = DateTime.UtcNow; entity.SocialID = long.Parse(data.caption.id); entity.SocialIDstring = data.id; entity.HashTags = hashTags; entity.Urls = urls; entity.Filename = azureURL; entity.OriginalURL = originalURL; entity.Source = "Instagram"; entity.HasPhoto = true; entity.CreatedAt = DateTime.UtcNow; entity.Approved = false; entity.Status = "new"; entity.WallId = this._wallId; db.Photos.Add(entity); try { db.SaveChanges(); } catch (Exception ex) { Logger.Log("SaveTweetPic error: " + ex.ToString()); } } }
public TweetPicTask(int wallId) { using (var db = new MySelfieEntities()) { var entity = db.Walls.Single(x => x.WallId == wallId); this._model = new WallModel(entity); this._pullLastID = db.Photos .Where(x => x.WallId == wallId) .OrderByDescending(x => x.SocialID) .Select(x => x.SocialID) .FirstOrDefault() .IfNotNull(x => x, 0); } this.LastCommandTime = DateTime.Now; this.setTwitterCredentials(this._model); this._startTime = DateTime.Now; this._pullDelayMilliseconds = 10000; this._pullMaxAmount = 100; this._isStreaming = false; this._keepPulling = true; if (this._isStreaming) { this.configureStream(); } this._processingThreadList = new List<Thread>(); this._currentProcesses = 0; this._finishedProcesses = 0; this._processNotificationFrequency = 500; // how often system will log activity this._errorCount = 0; this._totalSkippedPull = 0; this._totalNewPulled = 0; this._totalPulls = 0; this._totalRecievedPull = 0; this._pullNotificationFrequency = 10; // how often system will log activity this._tweetRepo = new TweetPicRepository(this._model.WallId); }
public static void Log(string message, string type, string username, string context, string header) { using (var db = new MySelfieEntities()) { var entity = new WorkerStatus(); entity.Message = message; entity.TimeStamp = DateTime.UtcNow; entity.Type = type; entity.UserName = username; entity.Context = context; entity.Status = "new"; entity.Header = header; db.WorkerStatus.Add(entity); db.SaveChanges(); } }
public InstagramPicTask(int wallId) { using (var db = new MySelfieEntities()) { var entity = db.Walls.Single(x => x.WallId == wallId); this._model = new WallModel(entity); this._pullLastID = db.Photos .Where(x => x.WallId == wallId) .OrderByDescending(x => x.SocialID) .Select(x => x.SocialID) .FirstOrDefault() .IfNotNull(x => x, 0); } if (this._model.Instagram_AccessToken.IsEmptyOrNull()) { this._model.Instagram_AccessToken = "1545103628.1fb234f.e6f242fd81fe48c1a156444871e803b3"; // TESTING } this.LastCommandTime = DateTime.Now; this._startTime = DateTime.Now; this._pullDelayMilliseconds = 10000; this._pullMaxAmount = 100; this._keepPulling = true; this._processingThreadList = new List<Thread>(); this._currentProcesses = 0; this._finishedProcesses = 0; this._processNotificationFrequency = 100; // how often system will log activity this._errorCount = 0; this._totalSkippedPull = 0; this._totalNewPulled = 0; this._totalPulls = 0; this._totalRecievedPull = 0; this._pullNotificationFrequency = 10; // how often system will log activity this._repo = new InstagramPicRepository(this.WallId); }
private void SaveTweetPic(ITweet tweet, string originalURL, string fileName) { var azureURL = this.StorePicture(originalURL, fileName); var urls = String.Join("|", tweet.Urls.Select(x => x.ExpandedURL)); var hashTags = String.Join("|", tweet.Hashtags.Select(x => x.Text)); using (var db = new MySelfieEntities()) { var entity = new Photo(); entity.Username = tweet.Creator.ScreenName; entity.Text = tweet.Text; entity.SocialCreatedAt = tweet.CreatedAt; entity.SocialID = tweet.Id; entity.SocialIDstring = tweet.IdStr; entity.HashTags = hashTags; entity.Urls = urls; entity.Filename = azureURL; entity.OriginalURL = originalURL; entity.Source = "Twitter"; entity.HasPhoto = true; entity.CreatedAt = DateTime.UtcNow; entity.Approved = false; entity.Status = "new"; entity.WallId = this._wallId; db.Photos.Add(entity); try { db.SaveChanges(); } catch (Exception ex) { Logger.Log("SaveTweetPic error: " + ex.ToString()); } } }
public static void Main(string[] foo) { var exitEvent = new ManualResetEvent(false); Console.CancelKeyPress += (sender, args) => { args.Cancel = true; exitEvent.Set(); }; Logger.Log("Starting up main process"); List<Wall> wallList; using (var db = new MySelfieEntities()) { wallList = db.Walls.Where(x => x.IsActive).ToList(); } var taskList = new List<IPicTask>(); var threadList = new List<Thread>(); try { foreach(var wall in wallList) { var thread = new Thread(() => { IPicTask task = new TweetPicTask(wall.WallId); taskList.Add(task); Logger.Log("Twitter Task starting to watch " + wall.Hashtag); task.Start(); }); threadList.Add(thread); thread.Start(); var instagram = new Thread(() => { IPicTask task = new InstagramPicTask(wall.WallId); taskList.Add(task); Logger.Log("Instagram Task starting to watch " + wall.Hashtag); task.Start(); }); threadList.Add(instagram); instagram.Start(); } //foreach(var task in taskList) //{ // var thread = new Thread(() => // { // using (var db = new MySelfieEntities()) // { // var commands = db.WorkerCommands // .Where(x => x.WallId == task.WallId) // .Where(x => x.TimeStamp > task.LastCommandTime) // .OrderBy(x => x.TimeStamp) // .ToList(); // } // }); //} } catch (Exception ex) { Logger.Log("Top Level Error: " + ex.ToString()); } exitEvent.WaitOne(); Logger.Log("Ending main process"); }