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 static Comment Post(Core core) { long itemId = core.Functions.FormLong("item_id", 0); long itemTypeId = core.Functions.FormLong("item_type_id", 0); string comment = core.Http.Form["comment"]; ItemKey itemKey = new ItemKey(itemId, itemTypeId); ItemType itemType = new ItemType(core, itemTypeId); NumberedItem item = null; ICommentableItem thisItem = null; item = NumberedItem.Reflect(core, new ItemKey(itemId, itemTypeId)); if (item is ICommentableItem) { thisItem = (ICommentableItem)item; IPermissibleItem pItem = null; if (item is IPermissibleItem) { pItem = (IPermissibleItem)item; } else if (item is IPermissibleSubItem) { pItem = ((IPermissibleSubItem)item).PermissiveParent; } else { pItem = thisItem.Owner; } if (!pItem.Access.Can("COMMENT")) { throw new PermissionDeniedException("UNAUTHORISED_TO_COMMENT"); } } else { throw new InvalidItemException(); } Comment commentObject = null; commentObject = Comment.Create(core, itemKey, comment); if (item != null) { if (item is IActionableItem || item is IActionableSubItem) { // Touch Feed } else { ApplicationEntry ae = core.GetApplication(itemType.ApplicationId); ae.PublishToFeed(core, core.Session.LoggedInMember, commentObject, item, Functions.SingleLine(core.Bbcode.Flatten(commentObject.Body))); } ICommentableItem citem = (ICommentableItem)item; citem.CommentPosted(new CommentPostedEventArgs(commentObject, core.Session.LoggedInMember, new ItemKey(itemId, itemTypeId))); try { Subscription.SubscribeToItem(core, itemKey); } catch (AlreadySubscribedException) { // not a problem } return commentObject; } return null; }
public static OAuthApplication Create(Core core, string title, string slug, string description) { if (core == null) { throw new NullCoreException(); } core.Db.BeginTransaction(); InsertQuery iQuery = new InsertQuery(typeof(ApplicationEntry)); iQuery.AddField("application_name", slug); iQuery.AddField("user_id", core.LoggedInMemberId); iQuery.AddField("application_date_ut", UnixTime.UnixTimeStamp()); iQuery.AddField("application_title", title); iQuery.AddField("application_description", description); iQuery.AddField("application_primitive", false); iQuery.AddField("application_primitives", (byte)AppPrimitives.None); iQuery.AddField("application_comment", false); iQuery.AddField("application_rating", false); iQuery.AddField("application_style", false); iQuery.AddField("application_script", false); iQuery.AddField("application_type", (byte)ApplicationType.OAuth); iQuery.AddField("application_cron_enabled", false); iQuery.AddField("application_cron_frequency", 0); long applicationId = core.Db.Query(iQuery); ApplicationEntry newApplication = new ApplicationEntry(core, applicationId); iQuery = new InsertQuery(typeof(OAuthApplication)); iQuery.AddField("application_id", applicationId); iQuery.AddField("application_website", string.Empty); iQuery.AddField("application_api_key", OAuth.GeneratePublic()); iQuery.AddField("application_api_secret", OAuth.GenerateSecret()); iQuery.AddField("application_api_callback", string.Empty); core.Db.Query(iQuery); OAuthApplication newApp = new OAuthApplication(core, newApplication); ApplicationDeveloper developer = ApplicationDeveloper.Create(core, newApplication, core.Session.LoggedInMember); try { ApplicationEntry profileAe = core.GetApplication("Profile"); profileAe.Install(core, newApplication); } catch { } try { ApplicationEntry guestbookAe = core.GetApplication("GuestBook"); guestbookAe.Install(core, newApplication); } catch { } try { ApplicationEntry galleryAe = core.GetApplication("Gallery"); galleryAe.Install(core, newApplication); } catch { } return newApp; }
public static StatusMessage SaveMessage(Core core, string message) { if (core == null) { throw new NullCoreException(); } StatusMessage statusMessage = StatusMessage.Create(core, core.Session.LoggedInMember, message, core.Session.ApplicationId); AccessControlLists acl = new AccessControlLists(core, statusMessage); acl.SaveNewItemPermissions(); core.Search.Index(statusMessage); ApplicationEntry ae = core.GetApplication("Profile"); ae.PublishToFeed(core, core.Session.LoggedInMember, statusMessage, Functions.SingleLine(core.Bbcode.Flatten(statusMessage.Message))); return statusMessage; }
protected void worker_DoWork(object sender, DoWorkEventArgs e) { int wait = 15; for (int i = 0; i < wait * 100; i++) { // The sleep should happen on the worker thread rather than the application thread System.Threading.Thread.Sleep(10); if (e.Cancel) { // Poll the thread every [wait] seconds to work out if the worker should be cancelled return; } } //HttpContext.Current = (HttpContext)e.Argument; Mysql db = new Mysql(WebConfigurationManager.AppSettings["mysql-user"], WebConfigurationManager.AppSettings["mysql-password"], WebConfigurationManager.AppSettings["mysql-database"], WebConfigurationManager.AppSettings["mysql-host"]); Core core = new Core(db); string processViews = WebConfigurationManager.AppSettings["queue-process-views"]; if (!string.IsNullOrEmpty(processViews) && processViews.ToLower() == "true") { try { ItemView.ProcessViews(core); } catch (Exception ex) { InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "An Error occured at " + Hyperlink.Domain + " in global.asax"); iQuery.AddField("error_body", "EXCEPTION THROWN:\n" + ex.ToString()); core.Db.Query(iQuery); } } string cronApplication = WebConfigurationManager.AppSettings["queue-cron-application"]; if (!string.IsNullOrEmpty(cronApplication)) { List<ApplicationEntry> aes = new List<ApplicationEntry>(); if (cronApplication == "*") { aes.AddRange(core.GetCronApplications()); } else { ApplicationEntry ae = core.GetApplication(cronApplication); if (ae != null) { BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); aes.Add(ae); } } foreach (ApplicationEntry ae in aes) { if (UnixTime.UnixTimeStamp() % ae.CronFrequency < 15) { Application jobApplication = BoxSocial.Internals.Application.GetApplication(core, AppPrimitives.Any, ae); if (jobApplication != null) { try { if (!jobApplication.ExecuteCron()) { StringBuilder failedCronLog = new StringBuilder(); failedCronLog.AppendLine("Application Id: " + ae.ApplicationId); InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "Cron failed at " + Hyperlink.Domain); iQuery.AddField("error_body", "FAILED CRON:\n" + failedCronLog.ToString()); core.Db.Query(iQuery); } } catch (Exception ex) { InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "An Error occured at " + Hyperlink.Domain + " in global.asax"); iQuery.AddField("error_body", "EXCEPTION THROWN:\n" + ex.ToString() + "\n\n" + core.Console.ToString()); core.Db.Query(iQuery); } } } } } try { bool flag = false; lock (queueLock) { if (queue != null) { flag = true; } } if (flag) { int failedJobs = 0; // Retrieve Jobs Dictionary<string, int> queues = new Dictionary<string, int>(); queues.Add(WebConfigurationManager.AppSettings["queue-default-priority"], 10); StringBuilder failedJobsLog = new StringBuilder(); foreach (string queueName in queues.Keys) { List<Job> jobs = null; lock (queueLock) { try { jobs = Queue.ClaimJobs(queueName, queues[queueName]); } catch { return; } } foreach (Job job in jobs) { core.LoadUserProfile(job.UserId); } foreach (Job job in jobs) { core.CreateNewSession(core.PrimitiveCache[job.UserId]); // Load Application if (job.ApplicationId > 0) { ApplicationEntry ae = core.GetApplication(job.ApplicationId); BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); } // Execute Job if (core.InvokeJob(job)) { lock (queueLock) { Queue.DeleteJob(job); } } else { failedJobs++; //queue.ReleaseJob(job); #if DEBUG failedJobsLog.AppendLine("Application Id: " + job.ApplicationId); failedJobsLog.AppendLine("Item Id: " + job.ItemId); failedJobsLog.AppendLine("Item Type Id: " + job.ItemTypeId); failedJobsLog.AppendLine("Function: " + job.Function); failedJobsLog.AppendLine("Body: " + job.Body); failedJobsLog.AppendLine("Message: " + job.Message); failedJobsLog.AppendLine("Error: " + job.Error); failedJobsLog.AppendLine("===================="); #endif } } } if (failedJobs > 0) { InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "Jobs failed at " + Hyperlink.Domain); iQuery.AddField("error_body", "FAILED JOB COUNT:\n" + failedJobs.ToString() + "\n\n" + failedJobsLog.ToString()); core.Db.Query(iQuery); #if DEBUG core.Email.SendEmail(WebConfigurationManager.AppSettings["error-email"], "Jobs failed at " + Hyperlink.Domain, "FAILED JOB COUNT:\n" + failedJobs.ToString() + "\n\n" + failedJobsLog.ToString()); #endif } } } catch (Exception ex) { try { InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "An Error occured at " + Hyperlink.Domain + " in global.asax"); iQuery.AddField("error_body", "EXCEPTION THROWN:\n" + ex.ToString()); core.Db.Query(iQuery); core.Email.SendEmail(WebConfigurationManager.AppSettings["error-email"], "An Error occured at " + Hyperlink.Domain + " in global.asax", "EXCEPTION THROWN:\n" + ex.ToString()); } catch { try { core.Email.SendEmail(WebConfigurationManager.AppSettings["error-email"], "An Error occured at " + Hyperlink.Domain + " in global.asax", "EXCEPTION THROWN:\n" + ex.ToString()); } catch { } } } // Cleanup lock (queueLock) { if (queue != null) { Queue.CloseConnection(); Queue = null; } } core.CloseProse(); core.CloseSearch(); core.CloseCache(); core = null; db.CloseConnection(); db = null; }
public static ApplicationEntry GetExecutingApplication(Core core, Primitive installee) { return core.GetApplication(Assembly.GetCallingAssembly().GetName().Name); }
public static ApplicationEntry Create(Core core, string assembly, Application application, bool isPrimitive) { if (core == null) { throw new NullCoreException(); } InsertQuery iQuery = new InsertQuery(typeof(ApplicationEntry)); iQuery.AddField("application_name", assembly); iQuery.AddField("application_assembly_name", assembly); iQuery.AddField("user_id", core.LoggedInMemberId); iQuery.AddField("application_date_ut", UnixTime.UnixTimeStamp()); iQuery.AddField("application_title", application.Title); iQuery.AddField("application_description", application.Description); iQuery.AddField("application_primitive", isPrimitive); iQuery.AddField("application_primitives", (byte)application.GetAppPrimitiveSupport()); iQuery.AddField("application_comment", application.UsesComments); iQuery.AddField("application_rating", application.UsesRatings); iQuery.AddField("application_style", !string.IsNullOrEmpty(application.StyleSheet)); iQuery.AddField("application_script", !string.IsNullOrEmpty(application.JavaScript)); iQuery.AddField("application_icon", string.Format(@"/images/{0}/icon.png", assembly)); iQuery.AddField("application_thumb", string.Format(@"/images/{0}/thumb.png", assembly)); iQuery.AddField("application_tile", string.Format(@"/images/{0}/tile.png", assembly)); iQuery.AddField("application_type", (byte)ApplicationType.Native); iQuery.AddField("application_cron_enabled", application.CronEnabled); iQuery.AddField("application_cron_frequency", application.CronFrequency); long applicationId = core.Db.Query(iQuery); ApplicationEntry newApplication = new ApplicationEntry(core, applicationId); ApplicationDeveloper developer = ApplicationDeveloper.Create(core, newApplication, core.Session.LoggedInMember); try { ApplicationEntry guestbookAe = core.GetApplication("Profile"); guestbookAe.Install(core, newApplication); } catch { } try { ApplicationEntry guestbookAe = core.GetApplication("GuestBook"); guestbookAe.Install(core, newApplication); } catch { } return newApplication; }