// used by the service in both WorkerRole and WebRole
        // in WorkerRole: when saving renderings
        // in WebRole: when serving renderings
        public CalendarRenderer(string id)
        {
            this.calinfo = Utils.AcquireCalinfo(id);
            this.cache = null;
            this.ResetCounters();
            this.es_getter = new EventStoreGetter(GetEventStoreWithCaching);
            try
            {
                this.id = id;

                try
                {
                    this.template_html = HttpUtils.FetchUrl(calinfo.template_url).DataAsString();
                }
                catch (Exception e)
                {
                    GenUtils.PriorityLogMsg("exception", "CalendarRenderer: cannot fetch template", e.InnerException.Message);
                    throw (e);
                }

                this.xmlfile = this.id + ".xml";
                this.jsonfile = this.id + ".json";
                this.htmlfile = this.id + ".html";

                //  this.ical_sources = Collector.GetIcalSources(this.id);
            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "CalenderRenderer.CalendarRenderer: " + id, e.Message + e.StackTrace);
            }
        }
Example #2
0
        public CalendarRenderer(string id)
        {
            this.timestamp = DateTime.UtcNow;
            this.calinfo = Utils.AcquireCalinfo(id);
            this.cache = null;
            this.ResetCounters();
            this.es_getter = new EventStoreGetter(GetEventStoreWithCaching);
            this.category_images = new Dictionary<string, string>();
            this.source_images = new Dictionary<string, string>();
            this.is_region = Utils.IsRegion(id);
            this.default_js_url = "http://elmcity.blob.core.windows.net/admin/elmcity-1.17.js";
            this.default_args = new Dictionary<string, object>();

            try
            {
                this.id = id;

                try
                {
                    var metadict = Metadata.LoadMetadataForIdFromAzureTable(id);
                    if (metadict.ContainsKey("args"))
                    {
                        this.default_args_json = metadict["args"];
                        this.default_args = JsonConvert.DeserializeObject<Dictionary<string, object>>(this.default_args_json);
                    }
                    else
                    {
                        this.default_args = new Dictionary<string, object>();
                    }
                }
                catch (Exception e)
                {
                    GenUtils.LogMsg("exception", "CalendarRenderer: acquiring args", e.Message);
                }

                try
                {
                    this.template_html = HttpUtils.FetchUrl(calinfo.template_url).DataAsString();
                    this.default_template_html = this.template_html;
                }
                catch (Exception e)
                {
                    GenUtils.PriorityLogMsg("exception", "CalendarRenderer: cannot fetch template", e.Message);
                    throw (e);
                }

                try
                {
                    GetImages("category");
                }
                catch (Exception e)
                {
                    GenUtils.PriorityLogMsg("exception", "CalendarRenderer: loading category images", e.Message);
                    throw (e);
                }

                try
                {
                    GetImages("source");
                }
                catch (Exception e)
                {
                    GenUtils.PriorityLogMsg("exception", "CalendarRenderer: loading source images", e.Message);
                    throw (e);
                }

                var settings = GenUtils.GetSettingsFromAzureTable();
                try
                {
                    this.max_events = Convert.ToInt32(settings["max_html_events_default"]);  // start with service-wide setting

                    if (this.default_args.ContainsKey("max_events"))			 // look for hub setting
                        this.max_events = Convert.ToInt32( default_args["max_events"] );
                }
                catch (Exception e)
                {
                    GenUtils.PriorityLogMsg("exception", "CalendarRenderer: setting max events", e.Message);
                    this.max_events = 1000;
                    throw (e);
                }
                finally
                {
                    settings = null;
                }

            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "CalenderRenderer.CalendarRenderer: " + id, e.Message + e.StackTrace);
            }
        }