Event Calendar

Topics: Feature requests, General, XSLT
Aug 4, 2011 at 8:54 PM

Using the standard event calendar is there a way to delete the event when it hit the end date.  Our calendar will have many events monthly and this would be a great feature to manage the event dataset.  Otherwise, I see the records getting hard to manage for a event calendar that has a large amount of data records.

 

thanks

Rob

Aug 4, 2011 at 8:58 PM

You can a workflow that is scheduled to run once a day... in there you'll delete expired events. Here is the article for creating scheduled tasks in C1 http://docs.composite.net/C1/Console/ConsoleFAQ.aspx?q=How+to+create+scheduled+tasks+in+C1%3F

Aug 5, 2011 at 10:18 AM

If you are okay with just having your clean up job run when when the site web app restart you can keep the logic in the start up handler.

Oct 9, 2011 at 7:30 PM

After reviewing the documents posted, I have tried to figure out how to create a workflow to remove expired data from my event calendar dataset without luck.  I am new to .net, is there somewhere I can get more documentation to accomplish this task?  Thanks for any information you could pass along.

Oct 10, 2011 at 10:31 AM

Hello

Below are some articles which also can be helpful:

http://docs.composite.net/C1/ASP-NET/Composite-C1-API/ApplicationStartup.aspx - how to perform specific operations on the application startup

http://docs.composite.net/C1/ASP-NET/Composite-C1-API.aspx - how to use C1 API, for example How to Delete Data

Also, below is some code example how you can delete old Composite.List.EventCalendar items on  Application Stratup(create DeleteOldEvents.cs file in App_Code folder with next code):

using Composite.Core.Application;
using Composite.Core;
using Composite.Data;
using Composite.Lists;
using System.Linq;
using System;

[ApplicationStartup]
public class DeleteOldEvents
{
	public static void OnBeforeInitialize()
	{
	}

	public static void OnInitialized()
	{
		foreach (PublicationScope scope in Enum.GetValues(typeof(PublicationScope)))
		{
			using (DataConnection conn = new DataConnection(scope))
			{
				var eventsDoBeDeleted = conn.Get<EventCalendar>().Where(e => e.EndDate < DateTime.Today.AddDays(-1)).ToList();
				if (eventsDoBeDeleted.Count() > 0)
				{
					Log.LogInformation("DeleteOldEvents", "Start deleting...");
					conn.Delete<EventCalendar>(eventsDoBeDeleted);
				}
			}
		}
	}
}

Oct 10, 2011 at 10:36 AM

use

if (eventsDoBeDeleted.Any())

instead of .Count() since its clearer in expressing your intent and has theoretical performance gains. Say, you have a list of 132432 entries, and the ONLY way to find its count, is to do 132432 loops and incrementing a counter each time, it would be far more efficient to just do one loop, and return true right away.

 

Oct 10, 2011 at 12:46 PM

If people are doing some code optimization, I cannot stay away :) 

In this case Count() won't do actual counting, because the method Enumerable.Count() includes check for the case the enumeration is an ICollection.

Another way to optimize would be to calculate the date beforehand. The reason for this is: if the EventCaledar collection is loaded into memory, it will be calculated before each comparison.

Final version:

 

DateTime yesterday = DateTime.Today.AddDays(-1);

var eventsToBeDeleted = conn.Get<EventCalendar>().Where(e => e.EndDate < yesterday).ToList();

if (eventsToBeDeleted.Any() { /* ... */ }

but it's more like "optimization for optimization's sake", you wouldn't feel the difference if you won't do it :)



Oct 10, 2011 at 12:57 PM
Edited Oct 10, 2011 at 12:58 PM

whether count() is doing a count/loop, or its a O(1) operation is an implementation detail that you should never take for granted. I must admit that i overlooked the .ToList() method call, which means that you should actually check for count with the .Count property. The .Count() method will work on any IEnumerable<T> object, and what might perform fine in this context can perform horrible when copy-pasting the code and reusing it somewhere else.

aaanyway, as a i wrote, the performance optimization is a theoretically beneficial side effect, the important thing here is that .Any() is a more precise expression of your intent, than .Count() > 0 is. We're never interested in the count, we're not using it for anything... so don't ask for it.