コード例 #1
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		private static TaskType StartTask(string id, Calinfo calinfo, TaskType type)
		{
			Scheduler.EnsureTaskRecord(id, type);

			if (Scheduler.IsAbandoned(id, type))           // abandoned?
				Scheduler.UnlockId(id, type);                 // unlock

			if (Scheduler.IsLockedId(id, type))          // locked?
				return TaskType.none;                       // skip

			if (AcquireLock(id, type) == false)            // can't lock?
				return TaskType.none;                        // skip

			var now = System.DateTime.Now.ToUniversalTime();

			TaskType started = TaskType.none;

			/*
			if (todo.start_requests.HasItem(id))
			{
				GenUtils.LogMsg("status", "Received start message from " + id, null);
				//TwitterApi.SendTwitterDirectMessage(calinfo.twitter_account, "elmcity received your start message");
				started = type;
			}
			else */

			started = Scheduler.MaybeStartTaskForId(now, calinfo, type);

			if (started == TaskType.none)
				Scheduler.UnlockId(id, type);

			return started;
		}
コード例 #2
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		public static void DoFacebook(Calinfo calinfo)
		{
			if (settings["use_facebook"] == "true" && calinfo.facebook)
			{
				var facebook = new ZonedEventStore(calinfo, SourceType.facebook);
				Collector coll = new Collector(calinfo, settings);
				coll.CollectFacebook(facebook, testing);
			}
		}
コード例 #3
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		public static void DoEventBrite(Calinfo calinfo)
		{
			if (settings["use_eventbrite"] == "true" && calinfo.eventbrite)
			{
				var eventbrite = new ZonedEventStore(calinfo, SourceType.eventbrite);
				Collector coll = new Collector(calinfo, settings);
				coll.CollectEventBrite(eventbrite);
			}
		}
コード例 #4
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		public static void DoEventful(Calinfo calinfo)
		{
			if (settings["use_eventful"] == "true" && calinfo.eventful)
			{
				var eventful = new ZonedEventStore(calinfo, SourceType.eventful);
				Collector coll = new Collector(calinfo, settings);
				coll.CollectEventful(eventful, testing);
			}
		}
コード例 #5
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		public static void SaveWhereStats(FeedRegistry fr, Calinfo calinfo)
		{
			var id = calinfo.id;
			GenUtils.LogMsg("status", "SaveWhereStats: " + id, null);
			NonIcalStats estats = GetNonIcalStats(NonIcalType.eventful, id, calinfo, settings);
			NonIcalStats ustats = GetNonIcalStats(NonIcalType.upcoming, id, calinfo, settings);
			NonIcalStats ebstats = GetNonIcalStats(NonIcalType.eventbrite, id, calinfo, settings);
			NonIcalStats fbstats = GetNonIcalStats(NonIcalType.facebook, id, calinfo, settings);
			Dictionary<string, IcalStats> istats = GetIcalStats(id);

			var where = calinfo.where;
			string[] response = Utils.FindCityOrTownAndStateAbbrev(where);
			var city_or_town = response[0];
			var state_abbrev = response[1];
			int pop = Utils.FindPop(id, city_or_town, state_abbrev);
			var futurecount = 0;
			futurecount += estats.eventcount;
			futurecount += ustats.eventcount;
			futurecount += ebstats.eventcount;

			var sb_report = new StringBuilder();
			sb_report.Append(MakeTableHeader());

			var options = new ParallelOptions();

			Parallel.ForEach(source: fr.feeds.Keys, parallelOptions: options, body: (feedurl) =>
			//		foreach (var feedurl in fr.feeds.Keys)
			{
				StatsRow(id, istats, sb_report, ref futurecount, feedurl);
			}
			);

			sb_report.Append("</table>\n");

			var events_per_person = Convert.ToInt32(futurecount) / (float)pop;
			var report = Utils.EmbedHtmlSnippetInDefaultPageWrapper(calinfo, sb_report.ToString());
			bs.PutBlob(id, id + ".stats.html", new Hashtable(), Encoding.UTF8.GetBytes(report), "text/html");

			var dict = new Dictionary<string, object>();
			dict.Add("events", futurecount.ToString());
			dict.Add("events_per_person", string.Format("{0:f}", events_per_person));
			TableStorage.UpmergeDictToTableStore(dict, "metadata", id, id);
		}
コード例 #6
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		public static void TestRunnerAdmin(object o, ElapsedEventArgs args)
		{
			GenUtils.LogMsg("status", "TestRunnerAdmin", null);
			var calinfo = new Calinfo(ElmcityUtils.Configurator.azure_compute_account);
			try
			{
				var ca_failed = GenUtils.RunTests("CalendarAggregator");
				var eu_failed = GenUtils.RunTests("ElmcityUtils");
				//failed += GenUtils.RunTests("WorkerRole");
				//failed += GenUtils.RunTests("WebRole");
				var clean = (ca_failed == "" && eu_failed == "");
				var msg = clean ? "clean at " : "failures at ";
				bs.PutBlob("admin", "testrunner", msg + "\n" + ca_failed + "\n" + eu_failed + "\n" + System.DateTime.UtcNow.ToString(), "text/plain");
			}
			catch (Exception e)
			{
				GenUtils.PriorityLogMsg("exception", "TestRunnerAdmin", e.Message + e.StackTrace);
			}
		}
コード例 #7
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		public static void MergeIcs(Calinfo calinfo)
		{
			var id = calinfo.id;
			GenUtils.LogMsg("status", "MergeIcs: " + id, null);
			List<string> suffixes = new List<string>() { "ical" };
			if (calinfo.hub_enum == HubType.where)
				foreach (NonIcalType type in Enum.GetValues(typeof(CalendarAggregator.NonIcalType)))
				{
					if (Utils.UseNonIcalService(type, settings, calinfo) == true)
						suffixes.Add(type.ToString());
				}
			try
			{
				var all_ical = new iCalendar();
				Collector.AddTimezoneToDDayICal(all_ical, calinfo.tzinfo);

				foreach (var suffix in suffixes)  // todo: skip if disabled in settings
				{
					var url = MakeIcsUrl(id, suffix);
					try
					{
						var feedtext = HttpUtils.FetchUrl(url).DataAsString();
						var sr = new StringReader(feedtext);
						var ical = iCalendar.LoadFromStream(sr).First().Calendar;
						all_ical.MergeWith(ical);
					}
					catch (Exception e)
					{
						GenUtils.LogMsg("warning", "MergeICS: " + url, e.Message);
					}
				}

				var serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer(all_ical);
				var icsbytes = Encoding.UTF8.GetBytes(serializer.SerializeToString(all_ical));
				bs.PutBlob(id, id + ".ics", new Hashtable(), icsbytes, "text/calendar");
			}
			catch (Exception e)
			{
				GenUtils.LogMsg("exception", "MergeIcs: " + id, e.Message + e.StackTrace);
			}
		}
コード例 #8
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		private static NonIcalStats GetNonIcalStats(NonIcalType type, string id, Calinfo calinfo, Dictionary<string, string> settings)
		{
			var name = type.ToString() + "_stats.json";
			var stats = new NonIcalStats();
			if (settings["use_" + type.ToString()] != "true" || Utils.UseNonIcalService(type, settings, calinfo) != true)
			{
				stats.venuecount = 0;
				stats.eventcount = 0;
				stats.whenchecked = DateTime.MinValue;
				return stats;
			}
			try
			{
				if (BlobStorage.ExistsBlob(id, name))
					stats = Utils.DeserializeObjectFromJson<NonIcalStats>(id, name);
			}
			catch (Exception e)
			{
				GenUtils.LogMsg("exception", "GetEventAndVenueStats: " + id + " " + name, e.Message + e.StackTrace);
			}
			return stats;
		}
コード例 #9
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		public static void SaveWhatStats(FeedRegistry fr, Calinfo calinfo)
		{
			var id = calinfo.id;
			GenUtils.LogMsg("status", "SaveWhatStats: " + id, null);
			Dictionary<string, IcalStats> istats = GetIcalStats(id);
			var sb_report = new StringBuilder();
			sb_report.Append(MakeTableHeader());
			var futurecount = 0;

			var options = new ParallelOptions();
			Parallel.ForEach(source: fr.feeds.Keys, parallelOptions: options, body: (feedurl) =>
			//		foreach (var feedurl in fr.feeds.Keys)
			{
				StatsRow(id, istats, sb_report, ref futurecount, feedurl);
			}
			);

			sb_report.Append("</table>\n");
			string preamble = MakeWhatPreamble(futurecount);
			var report = preamble + sb_report.ToString();
			report = Utils.EmbedHtmlSnippetInDefaultPageWrapper(calinfo, report);
			bs.PutBlob(id, id + ".stats.html", new Hashtable(), Encoding.UTF8.GetBytes(report), null);
		}
コード例 #10
0
ファイル: WorkerRole.cs プロジェクト: mikesavior/elmcity
		public static void DoIcal(FeedRegistry fr, Calinfo calinfo)
		{
			if (testfeeds.Count > 0)
				foreach (var testfeed in testfeeds)
					fr.AddFeed(testfeed, "testing: " + testfeed);
			else
				fr.LoadFeedsFromAzure(FeedLoadOption.all);

			var id = calinfo.id;

			ZonedEventStore ical = new ZonedEventStore(calinfo, SourceType.ical);
			try
			{

				GenUtils.LogMsg("status", "DoIcal: " + id, null);
				Collector coll = new Collector(calinfo, settings);
				coll.CollectIcal(fr, ical, test: testing);
			}
			catch (Exception e)
			{
				GenUtils.LogMsg("exception", "DoIcal: " + id, e.Message + e.StackTrace);
			}
		}