Пример #1
0
        /*
        public Dictionary<string, string> metadict
        { get { return _metadict; } }
        private Dictionary<string, string> _metadict;
         */
        public Calinfo(string id)
        {
            var metadict = Metadata.LoadMetadataForIdFromAzureTable(id);
            try
            {

                this._id = id;

                if (metadict.ContainsKey("type") == false)
                {
                    GenUtils.PriorityLogMsg("exception", "new calinfo: no hub type for id (" + id + ")", null);
                    return;
                }

                this._contact = Configurator.GetStrSetting(metadict, Configurator.usersettings, "contact");

                this._css = Configurator.GetUriSetting(metadict, Configurator.usersettings, "css").ToString();

                this._default_image_html = Configurator.GetStrSetting(metadict, Configurator.usersettings, "default_img_html");

                //this._has_descriptions = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "descriptions");
                this._has_descriptions = true;

                //this._has_locations = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "locations");
                this._has_locations = true;

                this._display_width = Configurator.GetStrSetting(metadict, Configurator.usersettings, "display_width"); // todo: obsolete this

                this._feed_count = Configurator.GetMetadictValueOrSettingsValue(metadict, Configurator.usersettings, "feed_count");

                this._has_img = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "header_image");

                this._icalendar_horizon_days = Configurator.GetIntSetting(metadict, Configurator.usersettings, "icalendar_horizon_days");

                this._img_url = Configurator.GetUriSetting(metadict, Configurator.usersettings, "img");

                this._title = Configurator.GetTitleSetting(metadict, Configurator.usersettings, "title");

                this._template_url = Configurator.GetUriSetting(metadict, Configurator.usersettings, "template");
                //this._template_url = new Uri(Configurator.settings["template"]);

                this._twitter_account = Configurator.GetStrSetting(metadict, Configurator.usersettings, "twitter");

                this._tzname = Configurator.GetStrSetting(metadict, Configurator.usersettings, "tz");
                this._tzinfo = Utils.TzinfoFromName(this._tzname);

                this._use_rdfa = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "use_rdfa");

                this._use_x_wr_timezone = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "use_x_wr_timezone");

                //if (metadict.ContainsKey("where"))
                if (metadict["type"] == "where")
                {
                    this._hub_enum = HubType.where;
                    this._where = metadict[this.hub_enum.ToString()];
                    this._what = Configurator.nothing;

                    //this._radius = metadict.ContainsKey("radius") ? Convert.ToInt16(metadict["radius"]) : Configurator.default_radius;
                    this._radius = Configurator.GetIntSetting(metadict, Configurator.usersettings, "radius");

                    // enforce the default max radius
                    if (this._radius > Configurator.max_radius)
                        this._radius = Configurator.max_radius;

                    this._population = Configurator.GetPopSetting(this.id, metadict, Configurator.usersettings, "population");
                    this._eventful = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "eventful");
                    this._upcoming = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "upcoming");
                    this._eventbrite = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "eventbrite");
                    this._facebook = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "facebook");

                    // curator gets to override the lat/lon that will otherwise be looked up based on the location

                    // if (!metadict.ContainsKey("lat") && !metadict.ContainsKey("lon"))
                    if ( GenUtils.KeyExistsAndHasValue(metadict, "lat") && GenUtils.KeyExistsAndHasValue(metadict, "lon") )
                    {
                        this._lat = metadict["lat"];
                        this._lon = metadict["lon"];
                    }
                    else
                    {
                        var apikeys = new Apikeys();
                        var lookup_lat = Utils.LookupLatLon(apikeys.bing_maps_key, this.where)[0];
                        var lookup_lon = Utils.LookupLatLon(apikeys.bing_maps_key, this.where)[1];

                        if (!String.IsNullOrEmpty(lookup_lat) && !String.IsNullOrEmpty(lookup_lon))
                        {
                            this._lat = metadict["lat"] = lookup_lat;
                            this._lon = metadict["lon"] = lookup_lon;
                            Utils.UpdateLatLonToAzureForId(id, lookup_lat, lookup_lon);
                        }
                    }

                    if (String.IsNullOrEmpty(this.lat) && String.IsNullOrEmpty(this.lon))
                    {
                        GenUtils.PriorityLogMsg("warning", "Configurator: no lat and/or lon for " + id, null);
                    }

                }

                // if (metadict.ContainsKey("what"))
                if (metadict["type"] == "what")
                {
                    this._hub_enum = HubType.what;
                    this._what = metadict[this.hub_enum.ToString()];
                    this._where = Configurator.nowhere;
                }

                if (metadict["type"] == "region")
                {
                    this._hub_enum = HubType.region;
                    this._what = Configurator.nothing;
                    this._where = Configurator.nowhere;
                }
            }

            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "new Calinfo: " + id, e.Message + e.StackTrace);
            }
        }
Пример #2
0
        /*
         * public Dictionary<string, string> metadict
         * { get { return _metadict; } }
         * private Dictionary<string, string> _metadict;
         */

        public Calinfo(string id)
        {
            this.timestamp = DateTime.UtcNow;

            var metadict = Metadata.LoadMetadataForIdFromAzureTable(id);

            try
            {
                this._id = id;

                if (metadict.ContainsKey("type") == false)
                {
                    GenUtils.PriorityLogMsg("exception", "new calinfo: no hub type for id (" + id + ")", null);
                    return;
                }

                this._contact = Configurator.GetStrSetting(metadict, Configurator.usersettings, "contact");

                this._css = Configurator.GetUriSetting(metadict, Configurator.usersettings, "css").ToString();

                this._default_image_html = Configurator.GetStrSetting(metadict, Configurator.usersettings, "default_img_html");

                //this._has_descriptions = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "descriptions");
                this._has_descriptions = true;

                //this._has_locations = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "locations");
                this._has_locations = true;

                this._display_width = Configurator.GetStrSetting(metadict, Configurator.usersettings, "display_width");                 // todo: obsolete this

                this._feed_count = Configurator.GetMetadictValueOrSettingsValue(metadict, Configurator.usersettings, "feed_count");

                this._has_img = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "header_image");

                this._icalendar_horizon_days = Configurator.GetIntSetting(metadict, Configurator.usersettings, "icalendar_horizon_days");

                this._img_url = Configurator.GetUriSetting(metadict, Configurator.usersettings, "img");

                this._title = Configurator.GetTitleSetting(metadict, Configurator.usersettings, "title");

                this._template_url = Configurator.GetUriSetting(metadict, Configurator.usersettings, "template");
                //this._template_url = new Uri(Configurator.settings["template"]);

                this._twitter_account = Configurator.GetStrSetting(metadict, Configurator.usersettings, "twitter");

                this._tzname = Configurator.GetStrSetting(metadict, Configurator.usersettings, "tz");
                this._tzinfo = Utils.TzinfoFromName(this._tzname);

                this._use_rdfa = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "use_rdfa");

                this._use_x_wr_timezone = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "use_x_wr_timezone");

                //if (metadict.ContainsKey("where"))
                if (metadict["type"] == "where")
                {
                    this._hub_enum = HubType.where;
                    this._where    = metadict[this.hub_enum.ToString()];
                    this._what     = Configurator.nothing;

                    //this._radius = metadict.ContainsKey("radius") ? Convert.ToInt16(metadict["radius"]) : Configurator.default_radius;
                    this._radius = Configurator.GetIntSetting(metadict, Configurator.usersettings, "radius");

                    // enforce the default max radius
                    if (this._radius > Configurator.max_radius)
                    {
                        this._radius = Configurator.max_radius;
                    }

                    this._population = Configurator.GetPopSetting(this.id, metadict, Configurator.usersettings, "population");
                    this._eventful   = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "eventful");
                    this._eventbrite = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "eventbrite");
                    this._facebook   = Configurator.GetBoolSetting(metadict, Configurator.usersettings, "facebook");

                    // curator gets to override the lat/lon that will otherwise be looked up based on the location

                    // if (!metadict.ContainsKey("lat") && !metadict.ContainsKey("lon"))
                    if (GenUtils.KeyExistsAndHasValue(metadict, "lat") && GenUtils.KeyExistsAndHasValue(metadict, "lon"))
                    {
                        this._lat = metadict["lat"];
                        this._lon = metadict["lon"];
                    }
                    else
                    {
                        var apikeys    = new Apikeys();
                        var lookup_lat = Utils.LookupLatLon(apikeys.bing_maps_key, this.where)[0];
                        var lookup_lon = Utils.LookupLatLon(apikeys.bing_maps_key, this.where)[1];

                        if (!String.IsNullOrEmpty(lookup_lat) && !String.IsNullOrEmpty(lookup_lon))
                        {
                            this._lat = metadict["lat"] = lookup_lat;
                            this._lon = metadict["lon"] = lookup_lon;
                            Utils.UpdateLatLonToAzureForId(id, lookup_lat, lookup_lon);
                        }
                    }

                    if (String.IsNullOrEmpty(this.lat) && String.IsNullOrEmpty(this.lon))
                    {
                        GenUtils.PriorityLogMsg("warning", "Configurator: no lat and/or lon for " + id, null);
                    }

                    this.SetShowBadgesForHub();
                }

                // if (metadict.ContainsKey("what"))
                if (metadict["type"] == "what")
                {
                    this._hub_enum = HubType.what;
                    this._what     = metadict[this.hub_enum.ToString()];
                    this._where    = Configurator.nowhere;
                    this.SetShowBadgesForHub();
                }

                if (metadict["type"] == "region")
                {
                    this._hub_enum = HubType.region;
                    this._what     = Configurator.nothing;
                    this._where    = Configurator.nowhere;
                    this.SetShowBadgesForRegion();
                }
            }

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