示例#1
0
        public static bool PublishPost(Core core, Job job)
        {
            core.LoadUserProfile(job.UserId);
            User owner = core.PrimitiveCache[job.UserId];
            ItemKey sharedItemKey = new ItemKey(job.ItemId, job.ItemTypeId);
            IActionableItem sharedItem = null;

            core.ItemCache.RequestItem(sharedItemKey);
            try
            {
                sharedItem = (IActionableItem)core.ItemCache[sharedItemKey];
            }
            catch
            {
                try
                {
                    sharedItem = (IActionableItem)NumberedItem.Reflect(core, sharedItemKey);
                    HttpContext.Current.Response.Write("<br />Fallback, had to reflect: " + sharedItemKey.ToString());
                }
                catch
                {
                    job.Cancel = true;
                    return true; // Item is probably deleted, report success to delete from queue
                }
            }

            UpdateQuery uQuery = new UpdateQuery(typeof(ItemInfo));
            uQuery.AddCondition("info_item_id", sharedItemKey.Id);
            uQuery.AddCondition("info_item_type_id", sharedItemKey.TypeId);

            try
            {
                if (owner.UserInfo.TumblrAuthenticated) // are we still authenticated
                {
                    string postDescription = job.Body;

                    Tumblr t = new Tumblr(core.Settings.TumblrApiKey, core.Settings.TumblrApiSecret);
                    TumblrPost post = t.StatusesUpdate(new TumblrAccessToken(owner.UserInfo.TumblrToken, owner.UserInfo.TumblrTokenSecret), owner.UserInfo.TumblrHostname, sharedItem.PostType, string.Empty, postDescription, sharedItem.Info.ShareUri, sharedItem.Data, sharedItem.DataContentType);

                    if (post != null)
                    {
                        uQuery.AddField("info_tumblr_post_id", post.Id);
                    }

                    core.Db.Query(uQuery);
                }
            }
            catch (System.Net.WebException ex)
            {
                HttpWebResponse response = (HttpWebResponse)ex.Response;
                if (response.StatusCode == HttpStatusCode.Forbidden)
                {
                    return true; // This request cannot succeed, so remove it from the queue
                }
                job.Error = ex.ToString();
                return false; // Failed for other reasons, retry
            }

            return true; // success
        }
示例#2
0
        public static bool PublishPost(Core core, Job job)
        {
            core.LoadUserProfile(job.UserId);
            User owner = core.PrimitiveCache[job.UserId];
            ItemKey sharedItemKey = new ItemKey(job.ItemId, job.ItemTypeId);
            IActionableItem sharedItem = null;

            core.ItemCache.RequestItem(sharedItemKey);
            try
            {
                sharedItem = (IActionableItem)core.ItemCache[sharedItemKey];
            }
            catch
            {
                try
                {
                    sharedItem = (IActionableItem)NumberedItem.Reflect(core, sharedItemKey);
                    HttpContext.Current.Response.Write("<br />Fallback, had to reflect: " + sharedItemKey.ToString());
                }
                catch
                {
                    return true; // Item is probably deleted, report success to delete from queue
                }
            }

            UpdateQuery uQuery = new UpdateQuery(typeof(ItemInfo));
            uQuery.AddCondition("info_item_id", sharedItemKey.Id);
            uQuery.AddCondition("info_item_type_id", sharedItemKey.TypeId);

            try
            {
                if (owner.UserInfo.FacebookAuthenticated) // are we still authenticated
                {
                    string postDescription = job.Body;

                    Facebook fb = new Facebook(core.Settings.FacebookApiAppid, core.Settings.FacebookApiSecret);

                    FacebookAccessToken token = fb.OAuthAppAccessToken(core, owner.UserInfo.FacebookUserId);
                    FacebookPost post = fb.StatusesUpdate(token, postDescription, sharedItem.Info.ShareUri, owner.UserInfo.FacebookSharePermissions);

                    if (post != null)
                    {
                        uQuery.AddField("info_facebook_post_id", post.PostId);
                    }

                    core.Db.Query(uQuery);
                }
            }
            catch (System.Net.WebException ex)
            {
                HttpWebResponse response = (HttpWebResponse)ex.Response;
                if (response.StatusCode == HttpStatusCode.Forbidden)
                {
                    return true; // This request cannot succeed, so remove it from the queue
                }
                return false; // Failed for other reasons, retry
            }

            return true; // success
        }
        internal static void NotifyFriendRequest(Core core, Job job)
        {
            core.LoadUserProfile(job.ItemId);
            User friendProfile = core.PrimitiveCache[job.ItemId];

            ApplicationEntry ae = core.GetApplication("Profile");
            ae.SendNotification(core, core.Session.LoggedInMember, friendProfile, core.LoggedInMemberItemKey, core.LoggedInMemberItemKey, "_WANTS_FRIENDSHIP", core.Session.LoggedInMember.Uri, "friend");
        }
 public override void PushJob(Job jobMessage)
 {
     PushJob(TimeSpan.FromDays(7), jobMessage);
 }
 public override void DeleteJob(Job job)
 {
     Task deleteResult = null;
     try
     {
         deleteResult = provider.DeleteMessageAsync(new QueueName(SanitiseQueueName(job.QueueName)), new MessageId(job.JobId), null, CancellationToken.None);
         deleteResult.Wait();
     }
     catch (System.AggregateException)
     {
     }
     catch (System.Net.WebException)
     {
         // some jobs won't execute if complete even if in the queue
     }
     finally
     {
         if (deleteResult != null)
         {
             deleteResult.Dispose();
         }
     }
 }
示例#6
0
        public override bool ExecuteJob(Job job)
        {
            if (job.ItemId == 0)
            {
                return true;
            }

            switch (job.Function)
            {
                case "notifyFriendRequest":
                    AccountFriendManage.NotifyFriendRequest(core, job);
                    return true;
                case "notifyStatusComment":
                    StatusMessage.NotifyStatusMessageComment(core, job);
                    return true;
            }

            return false;
        }
示例#7
0
        public static void NotifyUserComment(Core core, Job job)
        {
            Comment comment = new Comment(core, job.ItemId);
            core.LoadUserProfile(comment.CommentedItemKey.Id);
            User ev = core.PrimitiveCache[comment.CommentedItemKey.Id];

            if (ev.Owner is User && (!comment.OwnerKey.Equals(ev.ItemKey)))
            {
                core.CallingApplication.SendNotification(core, comment.User, (User)ev.Owner, ev.ItemKey, ev.ItemKey, "_COMMENTED_GUEST_BOOK", comment.BuildUri(ev));
            }

            //core.CallingApplication.SendNotification(core, comment.OwnerKey, ev.ItemKey, string.Format("[user]{0}[/user] commented on [user]{2}[/user] [iurl=\"{1}\"]blog post[/iurl]", comment.OwnerKey.Id, comment.BuildUri(ev), ev.OwnerKey.Id), string.Empty, emailTemplate);
        }
示例#8
0
 public override void PushJob(Job jobMessage)
 {
 }
示例#9
0
        public override bool ExecuteJob(Job job)
        {
            if (job.ItemId == 0)
            {
                return true;
            }

            switch (job.Function)
            {
                case "notifyGalleryComment":
                    Gallery.NotifyGalleryComment(core, job);
                    return true;
                case "notifyGalleryItemComment":
                    GalleryItem.NotifyGalleryItemComment(core, job);
                    return true;
                case "create_ultra":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.UltraExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Ultra || gi.ItemHeight > (int)PictureScale.Ultra)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.UltraPrefix, (int)PictureScale.Ultra, (int)PictureScale.Ultra))
                            {
                                gi.UltraExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_full":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.FullExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Full || gi.ItemHeight > (int)PictureScale.Full)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.FullPrefix, (int)PictureScale.Full, (int)PictureScale.Full))
                            {
                                gi.FullExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_display":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.DisplayExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Display || gi.ItemHeight > (int)PictureScale.Display)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.DisplayPrefix, (int)PictureScale.Display, (int)PictureScale.Display))
                            {
                                gi.DisplayExists = true;
                                gi.Update();
                            }
                        }
                        else
                        {
                            // This strips all uploaded images of EXIF data
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.DisplayPrefix, gi.ItemWidth, gi.ItemHeight))
                            {
                                gi.DisplayExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_mobile":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.MobileExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Mobile || gi.ItemHeight > (int)PictureScale.Mobile)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.MobilePrefix, (int)PictureScale.Mobile, (int)PictureScale.Mobile))
                            {
                                gi.MobileExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_thumb":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.ThumbnailExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Thumbnail || gi.ItemHeight > (int)PictureScale.Thumbnail)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.ThumbnailPrefix, (int)PictureScale.Thumbnail, (int)PictureScale.Thumbnail))
                            {
                                gi.ThumbnailExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_tiny":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.TinyExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Tiny || gi.ItemHeight > (int)PictureScale.Tiny)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.TinyPrefix, (int)PictureScale.Tiny, (int)PictureScale.Tiny))
                            {
                                gi.TinyExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_high":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.TinyExists) return true;

                        if (GalleryItem.CreateScaleWithSquareRatio(core, gi, gi.StoragePath, GalleryItem.HighPrefix, (int)PictureScale.High, (int)PictureScale.High))
                        {
                            gi.TinyExists = true;
                            gi.Update();
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_square":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.SquareExists) return true;

                        if (GalleryItem.CreateScaleWithSquareRatio(core, gi, gi.StoragePath, GalleryItem.SquarePrefix, (int)PictureScale.Square, (int)PictureScale.Square))
                        {
                            gi.SquareExists = true;
                            gi.Update();
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_tile":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.TileExists) return true;

                        if (GalleryItem.CreateScaleWithSquareRatio(core, gi, gi.StoragePath, GalleryItem.TilePrefix, (int)PictureScale.Tile, (int)PictureScale.Tile))
                        {
                            gi.TileExists = true;
                            gi.Update();
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_icon":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.IconExists) return true;

                        if (GalleryItem.CreateScaleWithSquareRatio(core, gi, gi.StoragePath, GalleryItem.IconPrefix, (int)PictureScale.Icon, (int)PictureScale.Icon))
                        {
                            gi.IconExists = true;
                            gi.Update();
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
            }

            return false;
        }
示例#10
0
        public static void NotifyMessage(Core core, Job job)
        {
            Message ev = new Message(core, job.ItemId);

            List<MessageRecipient> recipients = ev.GetRecipients();

            foreach (MessageRecipient recipient in recipients)
            {
                core.LoadUserProfile(recipient.UserId);
            }

            foreach (MessageRecipient recipient in recipients)
            {
                // TODO: notify everyone via push notifications

                if (ev.SenderId == recipient.UserId)
                {
                    // don't need to notify ourselves via e-mail
                    continue;
                }

                User receiver = core.PrimitiveCache[recipient.UserId];

                if (receiver.UserInfo.EmailNotifications)
                {
                    string notificationString = string.Format("[user]{0}[/user] [iurl=\"{1}\"]" + core.Prose.GetString("_SENT_YOU_A_MESSAGE") + "[/iurl]",
                        ev.SenderId, ev.Uri);

                    Template emailTemplate = new Template(core.TemplateEmailPath, "notification.html");

                    emailTemplate.Parse("SITE_TITLE", core.Settings.SiteTitle);
                    emailTemplate.Parse("U_SITE", core.Hyperlink.StripSid(core.Hyperlink.AppendAbsoluteSid(core.Hyperlink.BuildHomeUri())));
                    emailTemplate.Parse("TO_NAME", receiver.DisplayName);
                    core.Display.ParseBbcode(emailTemplate, "NOTIFICATION_MESSAGE", notificationString, receiver, false, string.Empty, string.Empty, true);
                    emailTemplate.Parse("NOTIFICATION_BODY", job.Body);

                    core.Email.SendEmail(receiver.UserInfo.PrimaryEmail, HttpUtility.HtmlDecode(core.Bbcode.Flatten(HttpUtility.HtmlEncode(notificationString))), emailTemplate);
                }
            }
        }
示例#11
0
        public bool InvokeJob(Job job)
        {
            if (job.ApplicationId == 0)
            {
                switch (job.Function)
                {
                    case "publishTweet":
                        return Twitter.PublishTweet(this, job);
                    case "publishTumblr":
                        return Tumblr.PublishPost(this, job);
                    case "publishFacebook":
                        return Facebook.PublishPost(this, job);
                }
            }
            else
            {
                ApplicationEntry ae = GetApplication(job.ApplicationId);

                Application jobApplication = Application.GetApplication(this, AppPrimitives.Any, ae);

                if (jobApplication != null)
                {
                    return jobApplication.ExecuteJob(job);
                }
            }

            return false;
        }
示例#12
0
 public virtual bool ExecuteJob(Job job)
 {
     return false;
 }
示例#13
0
        public override bool ExecuteJob(Job job)
        {
            if (job.ItemId == 0)
            {
                return true;
            }

            switch (job.Function)
            {
                case "notifyEventComment":
                    Event.NotifyEventComment(core, job);
                    return true;
                case "notifyEventInvite":
                    break;
            }

            return false;
        }
示例#14
0
        public static void NotifyGalleryItemComment(Core core, Job job)
        {
            try {
                Comment comment = new Comment(core, job.ItemId);
                GalleryItem ev = new GalleryItem(core, comment.CommentedItemKey.Id);

                if (ev.Owner is User && (!comment.OwnerKey.Equals(ev.OwnerKey)))
                {
                    core.CallingApplication.SendNotification(core, comment.User, (User)ev.Owner, ev.OwnerKey, ev.ItemKey, "_COMMENTED_GALLERY_ITEM", comment.BuildUri(ev));
                }

                core.CallingApplication.SendNotification(core, comment.OwnerKey, comment.User, ev.OwnerKey, ev.ItemKey, "_COMMENTED_GALLERY_ITEM", comment.BuildUri(ev));
            }
            catch (InvalidCommentException)
            {
            }
            catch (GalleryItemNotFoundException)
            {

            }
        }
示例#15
0
 public override void PushJob(TimeSpan ttl, Job jobMessage)
 {
     Task postResult = null;
     try
     {
         postResult = provider.PostMessagesAsync(new QueueName(SanitiseQueueName(jobMessage.QueueName)), CancellationToken.None, new Message<Job>(ttl, jobMessage));
         postResult.Wait();
     }
     catch (System.AggregateException)
     {
     }
     catch (System.Net.WebException)
     {
         // some jobs will eventually execute even if not in the queue
     }
     finally
     {
         if (postResult != null)
         {
             postResult.Dispose();
         }
     }
 }
示例#16
0
 public abstract void DeleteJob(Job job);
示例#17
0
        public override bool ExecuteJob(Job job)
        {
            if (job.ItemId == 0)
            {
                return true;
            }

            switch (job.Function)
            {
                case "notifyMessage":
                    Message.NotifyMessage(core, job);
                    return true;
            }

            return false;
        }
示例#18
0
 public abstract void PushJob(Job jobMessage);
示例#19
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public override bool ExecuteJob(Job job)
        {
            if (job.ItemId == 0)
            {
                return true;
            }

            switch (job.Function)
            {
                case "notifyBlogComment":
                    BlogEntry.NotifyBlogComment(core, job);
                    return true;
            }

            return false;
        }
示例#20
0
 public abstract void PushJob(TimeSpan ttl, Job jobMessage);
示例#21
0
 public override void DeleteJob(Job job)
 {
 }
示例#22
0
 public override void DeleteJob(Job job)
 {
     try
     {
         DeleteMessageRequest request = new DeleteMessageRequest();
         request.QueueUrl = GetQueueUrl(SanitiseQueueName(job.QueueName));
         request.ReceiptHandle = job.Handle;
         DeleteMessageResponse response = client.DeleteMessage(request);
     }
     catch (System.Net.WebException)
     {
         // some jobs won't execute if complete even if in the queue
     }
 }
示例#23
0
 public override void PushJob(TimeSpan ttl, Job jobMessage)
 {
 }
示例#24
0
 public override void PushJob(TimeSpan ttl, Job jobMessage)
 {
     try
     {
         SendMessageRequest request = new SendMessageRequest();
         //request.DelaySeconds = (int)(ttl.Ticks / TimeSpan.TicksPerSecond);
         request.QueueUrl = GetQueueUrl(SanitiseQueueName(jobMessage.QueueName));
         request.MessageBody = JsonConvert.SerializeObject(jobMessage);
         SendMessageResponse response = client.SendMessage(request);
     }
     catch (System.Net.WebException)
     {
     }
 }
示例#25
0
        public static void NotifyBlogComment(Core core, Job job)
        {
            Comment comment = new Comment(core, job.ItemId);
            BlogEntry ev = new BlogEntry(core, comment.CommentedItemKey.Id);

            if (ev.Owner is User && (!comment.OwnerKey.Equals(ev.OwnerKey)))
            {
                core.CallingApplication.SendNotification(core, comment.User, (User)ev.Owner, ev.OwnerKey, ev.ItemKey, "_COMMENTED_BLOG_POST", comment.BuildUri(ev));
            }

            core.CallingApplication.SendNotification(core, comment.OwnerKey, comment.User, ev.OwnerKey, ev.ItemKey, "_COMMENTED_BLOG_POST", comment.BuildUri(ev));
        }
示例#26
0
        public override bool ExecuteJob(Job job)
        {
            if (job.ItemId == 0)
            {
                return true;
            }

            switch (job.Function)
            {
                case "notifyUserComment":
                    UserGuestBook.NotifyUserComment(core, job);
                    return true;
            }

            return false;
        }