/// <summary> /// Send out daily ship fit availability summaries for all accounts. /// <param name="twitterContext">A twitter context for the sending of messages.</param> /// </summary> internal async Task SendDailySummary(LinqToTwitter::TwitterContext twitterContext) { // Fetch all enabled accounts and their notification recipients. IEnumerable<Account> accounts = this.doctrineShipsRepository.GetAccountsForNotifications(); // Are there any enabled accounts? if (accounts != null && accounts.Any() == true) { foreach (var account in accounts) { // Are there any recipients for this account? if (account.NotificationRecipients != null && account.NotificationRecipients.Any() == true) { // Get the summary message for the current account. string summaryMessage = GetDailySummaryMessage(account); // As long as the summary message is not empty, continue. if (summaryMessage != string.Empty) { foreach (var recipient in account.NotificationRecipients) { // If the current recipient is set to receive daily summaries, send a message. if (recipient.ReceivesDailySummary == true) { await this.SendDirectMessage(twitterContext, recipient.TwitterHandle, summaryMessage); } } } } } } }
static void Main(string[] args) { //CrossJoin(); LinqToTwitter.QueryExpression(); //Functions.CreateTask(@"d:\temp\infile.txt", @"d:\temp\outfile.txt"); //Tuple<string, decimal> tuple1 = new Tuple<string, decimal>("Surface Pro 4", 899M); //var generic = Generic.Create(new //{ // Name = "Surface Book", // Price = 1349.00M //}); //var generic2 = new //{ // Name = "Surface Book", // Price = 1349.00M //}; //var immutableDevice = new { Name = "Surface Book", Price = 1349.00M }; ////var mapped1 = from zero in new[] { 0 } select zero; // 0 //var mapped1 = from zero in 0 select zero; // 0 //var mapped2 = from three in 1 + 2 select Math.Sqrt(three + 1); //var mapped3 = new[] { 0 }.Select(zero => zero); // 0 //string mapped = from newGuid in Guid.NewGuid() select newGuid.ToString(); //FluentListHandler(); //ComposeLinq(); //QueryMethods(); //open a 4GB file for asynchronous reading in blocks of 64K //var inFile = new FileStream(@"d:\temp\4GBfile.txt", // FileMode.Open, FileAccess.Read, FileShare.Read, 2 << 15, true); //open a file for asynchronous writing in blocks of 64K //var outFile = new FileStream(@"d:\temp\Encrypted.txt", // FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 2 << 15, true); //inFile.AsyncRead(2 << 15).Select(Encrypt).WriteToStream(outFile).Subscribe( // _ => Console.WriteLine("Successfully encrypted the file."), // error => Console.WriteLine("An error occurred while encrypting the file: {0}", error.Message)); //Func<double, double> sqrt = Math.Sqrt; //Func<double, double> abs = Math.Abs; //Func<double, double> log = Math.Log; //CallAnd(); //var absSqrt = sqrt.Compose(abs); //Console.WriteLine("absSqrt = " + absSqrt(-2)); //var absSqrtLog1 = log.Compose(sqrt).Compose(abs); //var absSqrtLog2 = log.Compose(sqrt.Compose(abs)); //Console.WriteLine("absSqrtLog1 = " + absSqrtLog1(-2)); //Console.WriteLine("absSqrtLog2 = " + absSqrtLog2(-2)); Console.ReadKey(); }
/// <summary> /// Creates instance from class /// </summary> /// <param name="tweet">handled tweet</param> public TweetPane(Twitter.Status tweet) { InitializeComponent(); Tweet = tweet; richTextBoxMessage.Text = tweet.Text; labelCreated.Text = tweet.CreatedAt.ToString(); labelUserName.Text = tweet.User.Name; pictureBoxImage.Image = WebImages[tweet.User.ProfileImageUrlHttps]; linklabelFavorite.Enabled = !tweet.Favorited; linkLabelRetweet.Enabled = !tweet.Retweeted; }
public Status(LinqToTwitter.Status status) { StatusID = status.StatusID; Text = status.Text; RetweetCount = status.RetweetCount; Retweeted = status.Retweeted; if (Retweeted) RetweetedStatus = new Status(status.RetweetedStatus); CreatedAt = status.CreatedAt; User = new User(status.User); Entities = new EntityCollection(); if (status.Entities != null) { if (status.Entities.UrlEntities != null) { foreach (var ent in status.Entities.UrlEntities) { Entities.UrlEntities.Add(new MediaEntity() { ExpandedUrl = ent.ExpandedUrl, Url = ent.Url }); } } if (status.Entities.MediaEntities != null) { foreach (var ent in status.Entities.MediaEntities) { Entities.MediaEntities.Add(new MediaEntity() { ExpandedUrl = ent.ExpandedUrl, Url = ent.Url }); } } if (status.Entities.UserMentionEntities != null) { foreach (var ent in status.Entities.UserMentionEntities) { Entities.UserMentionEntities.Add(new UserEntity() { Id = ent.Id, ScreenName = ent.ScreenName, Name = ent.Name }); } } } }
public User(LinqToTwitter.User user) { UserID = ulong.Parse(user.UserIDResponse); ScreenName = user.ScreenNameResponse; Name = user.Name; Following = user.Following; FollowersCount = user.FollowersCount; Url = user.Url; Description = user.Description; LangResponse = user.LangResponse; FriendsCount = user.FriendsCount; ProfileImageUrl = user.ProfileImageUrl; }
public void setTweet(LinqToTwitter.Status status) { imageAuthor.Load(status.User.ProfileImageUrl); name.Text = status.User.Name; tweet.Text = status.Text; }
public TwitterMeSource(LinqToTwitter.Status[] feedList) { this.mFeedList = feedList; }
/// <summary> /// Perform hourly maintenance tasks. /// </summary> /// <param name="corpApiId">A valid eve api id (keyID) for the Doctrine Ships in-game corporation.</param> /// <param name="corpApiKey">A valid eve api key (vCode) for the Doctrine Ships in-game corporation.</param> /// <param name="twitterContext">A twitter context for the sending of messages.</param> public async Task HourlyMaintenance(int corpApiId, string corpApiKey, LinqToTwitter::TwitterContext twitterContext) { // Credit any accounts where payments have been made to the corporate wallet. AccountManager.CreditAccountPayments(corpApiId, corpApiKey); // Send out any ship fit availability alerts for all accounts. await TaskManager.SendAvailabilityAlert(twitterContext); }
/// <summary> /// Perform daily maintenance tasks. /// </summary> /// <param name="twitterContext">A twitter context for the sending of messages.</param> public async Task DailyMaintenance(LinqToTwitter::TwitterContext twitterContext) { // Delete any contracts where the expired date has passed. ContractManager.DeleteExpiredContracts(); // Deletes log entries older than 7 days. TaskManager.DeleteOldLogs(); // Deletes short urls older than 30 days. TaskManager.DeleteOldShortUrls(); // Debit any accounts with subscription payments that are due. AccountManager.DebitDueAccounts(); // Send out daily ship fit availability summaries for all accounts. await TaskManager.SendDailySummary(twitterContext); }
/// <summary> /// Send a twitter direct message. /// <param name="twitterContext">A twitter context for the sending of messages.</param> /// </summary> internal async Task<bool> SendDirectMessage(LinqToTwitter::TwitterContext twitterContext, string screenName, string message) { try { var result = await twitterContext.NewDirectMessageAsync(screenName, message); if (result != null) { this.logger.LogMessage("Sent A Direct Message To '" + result.RecipientScreenName + "' With Message '" + result.Text + "'.", 2, "Message", MethodBase.GetCurrentMethod().Name); return true; } else { return false; } } catch (Exception e) { logger.LogMessage("An error occured while sending a twitter message. Are the twitter api credentials correct?", 0, "Message", MethodBase.GetCurrentMethod().Name); logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name); return false; } }
/// <summary> /// Send out any ship fit availability alerts for all accounts. /// <param name="twitterContext">A twitter context for the sending of messages.</param> /// </summary> internal async Task SendAvailabilityAlert(LinqToTwitter::TwitterContext twitterContext) { // Fetch all enabled accounts and their notification recipients. IEnumerable<Account> accounts = this.doctrineShipsRepository.GetAccountsForNotifications(); // Are there any enabled accounts? if (accounts != null && accounts.Any() == true) { foreach (var account in accounts) { // Are there any recipients for this account? if (account.NotificationRecipients != null && account.NotificationRecipients.Any() == true) { // Get the alert message for the current account. string alertMessage = GetAvailabilityAlertMessage(account); // As long as the alert message is not empty, continue. if (alertMessage != string.Empty) { foreach (var recipient in account.NotificationRecipients) { // If the current recipient is set to receive alerts and has not received one too recently, send a message. if (recipient.ReceivesAlerts == true && Time.HasElapsed(recipient.LastAlert, TimeSpan.FromHours(recipient.AlertIntervalHours))) { await this.SendDirectMessage(twitterContext, recipient.TwitterHandle, alertMessage); // Update the LastAlert timestamp for the current recipient. recipient.LastAlert = DateTime.UtcNow; this.doctrineShipsRepository.UpdateNotificationRecipient(recipient); this.doctrineShipsRepository.Save(); } } } } } } }
public static async Task<bool> CreateBatch(int wallId) { bool result = false; //IList<Task> taskList = new List<Task>(); Wall wall = null; using (var db = new MySelfieEntities()) { var query = db.Photos .Where(x => x.WallId == wallId) .Where(x => x.Status == "approved") .OrderBy(x => x.ApprovedAt) .Take(9); var results = query.Select(x => x.Filename).ToList(); if (results.Count == 9) { wall = db.Walls.Single(x => x.WallId == wallId); var existingPacketCount = db.Packets .Where(x => x.WallId == wallId) .Where(x => x.Status == "new") .Count(); var wallTotalSeconds = (wall.PhotoShownLengthSecond.Value * 9) + wall.AdShownLengthSecond; var secondsUntilStart = wallTotalSeconds * existingPacketCount; var packet = new[] { new { slides = results, sponsor = "Wall/Image/" + wall.WallId } }; try { var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); var json = jss.Serialize(packet); var entity = new Packet { WallId = wallId, JSONBody = json, StartTime = DateTime.UtcNow.AddSeconds(secondsUntilStart.IfNotNull(x => x.Value)), EndTime = DateTime.UtcNow.AddSeconds(secondsUntilStart.IfNotNull(x => x.Value) + wallTotalSeconds.IfNotNull(x => x.Value)), DurationMillisecond = wallTotalSeconds.IfNotNull(x => x.Value) * 1000, Status = "new", CreatedAt = DateTime.UtcNow }; db.Packets.Add(entity); string message = "Created new packet: " + Environment.NewLine + "WallId: " + entity.WallId + Environment.NewLine + "JSONBody: " + entity.JSONBody + Environment.NewLine + "StartTime: " + entity.StartTime + Environment.NewLine + "EndTime: " + entity.EndTime + Environment.NewLine + "DurationMillisecond: " + entity.DurationMillisecond + Environment.NewLine + "CreatedAt: " + entity.CreatedAt + Environment.NewLine; Logger.Log(message, "info", "system", "creating a packet", "Packet Created", db, false); var context = GetTwitterContext(new WallModel(wall)); foreach (var photo in query) { photo.Status = "packed"; photo.Packet = entity; if (photo.Source == "Twitter") { await PhotoStatusChangeModel.PublishTweet(photo.Username, entity.StartTime, wall.RetweetMessage, context); } if (photo.Source == "Instagram") { PhotoStatusChangeModel.PublishInstagramComment(photo.Username, entity.StartTime, wall.RetweetMessage, wall.PostingAccount_InstagramToken, photo.SocialIDstring); } } db.SaveChanges(); //foreach(var task in taskList) //{ // await task; //} } catch (Exception ex) { Logger.Log(ex.ToString(), "error", "system", "creating a packet", "Error creating packet", db, true); result = false; } result = true; } else { result = false; } } // end using db //if (result) // result is true when a packet was created //{ // var context = GetTwitterContext(new WallModel(wall)); // foreach (var photo in packetPhotos) // { // if (photo.Source == "Twitter") // { // var t = new Thread(() => PhotoStatusChangeModel.PublishTweet(photo.Username, newPacket.StartTime, wall.RetweetMessage, context)); // t.Start(); // } // if (photo.Source == "Instagram") // { // var t = new Thread(() => PhotoStatusChangeModel.PublishInstagramComment(photo.Username, newPacket.StartTime, wall.RetweetMessage, wall.PostingAccount_InstagramToken, photo.SocialIDstring)); // t.Start(); // } // } //} return result; }
public Tweet(LinqToTwitter.Status tweet) { // TODO: Complete member initialization this.tweet = tweet; }
/// <summary> /// Create record to represent a twitter status. /// The result is returned as a normalized "StatusUpdateRecord" (the same record type is used for the different social network providers, to /// make the mashups easier to write and consume) /// </summary> /// <param name="search"></param> /// <returns></returns> private static IRecord CreateStatusRecord(LinqToTwitter.Status status) { if(String.IsNullOrEmpty(status.User.ScreenName)) status.User.ScreenName = status.User.Identifier.ScreenName; if(String.IsNullOrEmpty(status.User.UserID)) status.User.UserID = status.User.Identifier.UserID; return RecordBase.CreateRecord(new StatusUpdateRecord { User = new SocialProfileRecord { UserID = status.User.UserID, Description = status.User.Description, LastName = status.User.Name, FirstName = "", ScreenName = "@" + status.User.ScreenName, PictureUrl = String.IsNullOrEmpty(status.User.ProfileImageUrlHttps) ? status.User.ProfileImageUrl : status.User.ProfileImageUrlHttps, //ProfileUrl = status.User.Url ?? ("https://twitter.com/" + status.User.ScreenName) // per Twitter guidelines we actually need this one to go to the Twitter profile, not their specified URL ProfileUrl = "https://twitter.com/" + status.User.ScreenName }, Favorited = status.Favorited, Retweeted = status.Retweeted, StatusID = status.StatusID, Text = Twitterize(status.Text), CreatedAt = status.CreatedAt, Icon = "tweet.ico", StatusUrl = String.Format(TWITTER_STATUS_URL, status.User.ScreenName, status.StatusID), SocialNetwork = "Twitter" }); }
void TweetPane_Reply(Twitter.Status tweet) { textBoxTweetContent.Text = "@" + tweet.User.Identifier.ScreenName; textBoxTweetContent.Focus(); }