public void RequestItem(ItemKey itemKey) { if (itemKey.TypeId == 0) { return; } if (!typesAccessed.ContainsKey(itemKey.TypeId)) { // We need to make sure that the application is loaded if (itemKey.GetType(core).ApplicationId > 0) { core.ItemCache.RegisterType(typeof(ApplicationEntry)); ItemKey applicationKey = new ItemKey(itemKey.GetType(core).ApplicationId, ItemType.GetTypeId(core, typeof(ApplicationEntry))); core.ItemCache.RequestItem(applicationKey); ApplicationEntry ae = (ApplicationEntry)core.ItemCache[applicationKey]; typesAccessed.Add(itemKey.TypeId, ae.Assembly.GetType(itemKey.GetType(core).TypeNamespace)); } else { try { typesAccessed.Add(itemKey.TypeId, Type.GetType(itemKey.GetType(core).TypeNamespace)); } catch { HttpContext.Current.Response.Write(itemKey.ToString()); HttpContext.Current.Response.End(); } } } NumberedItemId loadedId = new NumberedItemId(itemKey.Id, itemKey.TypeId); if (!(batchedItemIds.Contains(loadedId) || itemsCached.ContainsKey(loadedId))) { batchedItemIds.Add(loadedId); } }
public void AdjustCommentCount(ItemKey itemKey, int adjustment) { ItemInfo ii = null; if (itemKey.GetType(this).Commentable) { try { ii = new ItemInfo(this, itemKey); } catch (InvalidIteminfoException) { ii = ItemInfo.Create(this, itemKey); } ii.AdjustComments(adjustment); ii.Update(); } else { throw new InvalidItemException(); } }
public static NumberedItem Reflect(Core core, ItemKey ik) { if (ik.GetType(core) != null) { if (ik.GetType(core).IsPrimitive) { core.PrimitiveCache.LoadPrimitiveProfile(ik); return core.PrimitiveCache[ik]; } } if (core.ItemCache.ContainsItem(ik)) { return core.ItemCache[ik]; } if (core == null) { throw new NullCoreException(); } Type tType = null; if (ik.GetType(core).ApplicationId > 0) { core.ItemCache.RegisterType(typeof(ApplicationEntry)); ItemKey applicationKey = new ItemKey(ik.GetType(core).ApplicationId, ItemKey.GetTypeId(core, typeof(ApplicationEntry))); core.ItemCache.RequestItem(applicationKey); ApplicationEntry ae = (ApplicationEntry)core.ItemCache[applicationKey]; tType = ae.Assembly.GetType(ik.GetType(core).TypeNamespace); } else { tType = Type.GetType(ik.GetType(core).TypeNamespace); } return (Activator.CreateInstance(tType, new object[] { core, ik.Id }) as NumberedItem); }
public void ItemUnsubscribed(ItemKey itemKey, User subscriber) { if (unsubscribeHandles.ContainsKey(itemKey.TypeId)) { unsubscribeHandles[itemKey.TypeId](new ItemUnsubscribedEventArgs(subscriber, itemKey)); } else { if (!itemKey.GetType(this).Subscribeable) { throw new InvalidItemException(); } } }
public void SendNotification(Core core, User actionBy, User receiver, ItemKey itemOwnerKey, ItemKey itemKey, string verb, string url, string action) { if (canNotify(core, receiver)) { Notification notification = Notification.Create(core, this, actionBy, receiver, itemOwnerKey, itemKey, verb, url, action); if (receiver.UserInfo.EmailNotifications) { // Header so we can use the same emailBody for multiple subscribers 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", notification.NotificationString, receiver, false, string.Empty, string.Empty, true); // TODO parse action links if (itemKey.GetType(core).Notifiable) { Dictionary<string, string> actions = notification.NotifiedItem.GetNotificationActions(action); foreach (string a in actions.Keys) { VariableCollection actionsVariableCollection = emailTemplate.CreateChild("actions_list"); actionsVariableCollection.Parse("ACTION", actions[a]); actionsVariableCollection.Parse("U_ACTION", core.Hyperlink.AppendAbsoluteSid(core.Hyperlink.AppendNvid(notification.NotifiedItem.GetNotificationActionUrl(a), notification.VerificationString))); } } core.Email.SendEmail(receiver.UserInfo.PrimaryEmail, HttpUtility.HtmlDecode(core.Bbcode.Flatten(HttpUtility.HtmlEncode(notification.NotificationString))), emailTemplate); } } }