private void AddFeed() { BTBWeatherFeedInfo objBTBYahooWeather = new BTBWeatherFeedInfo(); BTBWeatherFeedController objCtlBTBYahooWeather = new BTBWeatherFeedController(); //load info object with relavent data objBTBYahooWeather.WeatherId = ItemId; objBTBYahooWeather.ModuleId = ModuleId; BTBWeatherFeedController.TemperatureScale tempScale; if (rbTempC.Checked) { tempScale = BTBWeatherFeedController.TemperatureScale.Celsius; } else { tempScale = BTBWeatherFeedController.TemperatureScale.Fahrenheit; } objBTBYahooWeather.Url = objCtlBTBYahooWeather.CreateFeedUrl(txtFeedCode.Text, tempScale); objBTBYahooWeather.WeatherId = DataProvider.AddBTBWeatherFeed(objBTBYahooWeather); objCtlBTBYahooWeather.UpdateWeatherFeed(objBTBYahooWeather, this.PortalSettings, this.ModuleConfiguration); }
private void ddlLocations_SelectedIndexChanged(object sender, System.EventArgs e) { int weatherId = Int32.Parse(ddlLocations.SelectedValue); BTBWeatherFeedInfo info = DataProvider.GetBTBWeatherFeed(weatherId); //determine if user persistance is enabled //and store the selection if (ModuleSettings.AllowUserPersonialisation && HttpContext.Current.User.Identity.IsAuthenticated) { DotNetNuke.Entities.Users.UserInfo curUser = UserController.GetUserById(PortalId, UserId); curUser.Profile.SetProfileProperty(USER_PERSONIALISATION, ddlLocations.SelectedValue); UserController.UpdateUser(this.PortalId, curUser); } DisplayFeed(info); }
protected void DisplayFeed(BTBWeatherFeedInfo info) { //check if we have a transformed feed or the item has expired from cache if (info != null) { if (string.IsNullOrEmpty(info.TransformedFeed) | info.CachedDate < DateTime.Now | string.IsNullOrEmpty(info.LocationName)) { BTBWeatherFeedController controller = new BTBWeatherFeedController(); controller.UpdateWeatherFeed(info, this.PortalSettings, this.ModuleConfiguration); } else if (ModuleSettings.RenderEngine == BTBYahooWeatherSettings.TemplateEngine.Razor) { //if we are usig razor always update the html since we may have logic in the //cshtml which is doing something and needs to render the html different and //not just display the cached version BTBWeatherFeedController controller = new BTBWeatherFeedController(); controller.RenderRssData(info, this.ModuleConfiguration); } litOutput.Text = info.TransformedFeed; } }
/// <summary> /// sets up the edit page /// </summary> private void LoadExistingData() { var list = DataProvider.GetBTBWeatherFeedByModule(this.ModuleId); var controller = new BTBWeatherFeedController(); //sort the list by location name lstLocations.DataSource = list.OrderBy(w => w.LocationName); lstLocations.DataBind(); //if we have one or more feed get the current temperature unit //we need this to set the correct radio button checked if (list.Count() > 0) { BTBWeatherFeedInfo info = (BTBWeatherFeedInfo)list.First(); BTBWeatherFeedController.TemperatureScale tempScale = controller.ExtractTemperatureScaleFromUrl(info.Url); if (tempScale == BTBWeatherFeedController.TemperatureScale.Celsius) { rbTempC.Checked = true; } else { rbTempF.Checked = true; } ViewState[VIEWSTATE_TEMPERATURE_SCALE] = tempScale; //setup the default weather feed ddlDefaultFeed.DataValueField = "WeatherId"; ddlDefaultFeed.DataTextField = "LocationName"; ddlDefaultFeed.DataSource = list; ddlDefaultFeed.DataBind(); //set the default feed BTBWeatherFeedInfo defaultWeatherFeed = controller.GetDefaultFeed(list); if (defaultWeatherFeed != null) { ddlDefaultFeed.Enabled = true; ddlDefaultFeed.SelectedValue = defaultWeatherFeed.WeatherId.ToString(); } } else { ddlDefaultFeed.Enabled = false; } //load all the xlst templates LoadTemplateFiles("Xslt", ddlXsltTemplates); //load all the razor templates LoadTemplateFiles("Razor", ddlRazorTemplates); if (ModuleSettings.RenderEngine == BTBYahooWeatherSettings.TemplateEngine.Xlst) { rbXlst.Checked = true; var item = ddlXsltTemplates.Items.FindByText(ModuleSettings.TemplateName); if (item != null) { item.Selected = true; } } else { rbRazor.Checked = true; var item = ddlRazorTemplates.Items.FindByText(ModuleSettings.TemplateName); if (item != null) { item.Selected = true; } } //load the flag to determine if we allow the user to persist the selected //weather location chkUserPersist.Checked = ModuleSettings.AllowUserPersonialisation; }
private void Page_Load(object sender, System.EventArgs e) { try { jQuery.RequestRegistration(); BTBWeatherFeedController controller = new BTBWeatherFeedController(); BTBWeatherFeedInfo info; if (!Page.IsPostBack) { var weatherFeeds = DataProvider.GetBTBWeatherFeedByModule(ModuleId); if ((weatherFeeds == null)) { //this module does not have a configured //weather feed, info the user DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("FeedNotSet.Text", this.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError); return; } if (weatherFeeds.Count() > 1) { ValidateFeedsHaveLocationName(weatherFeeds); pnlDropDown.Visible = true; ddlLocations.DataTextField = "LocationName"; ddlLocations.DataValueField = "WeatherId"; ddlLocations.DataSource = weatherFeeds.OrderBy(w => w.LocationName); ddlLocations.DataBind(); } //check if we should load the users selected weather feed if (ModuleSettings.AllowUserPersonialisation && HttpContext.Current.User.Identity.IsAuthenticated) { //check if the user has selected otherwise just let the //default location pick the selection DotNetNuke.Entities.Users.UserInfo curUser = UserController.GetUserById(PortalId, UserId); string location = curUser.Profile.GetPropertyValue(USER_PERSONIALISATION); if (location != null) { BTBWeatherFeedInfo userSelectWFI = null; int locationId = -1; int.TryParse(location, out locationId); foreach (BTBWeatherFeedInfo item in weatherFeeds) { if (item.WeatherId == locationId) { userSelectWFI = item; break; } } if (userSelectWFI != null) { ddlLocations.SelectedValue = userSelectWFI.WeatherId.ToString(); DisplayFeed(userSelectWFI); return; } } } //check if we have a default feed, overwise show the first time BTBWeatherFeedInfo defaultInfo = controller.GetDefaultFeed(weatherFeeds); if (defaultInfo != null) { info = defaultInfo; ddlLocations.SelectedValue = defaultInfo.WeatherId.ToString(); } else { info = weatherFeeds.FirstOrDefault(); } DisplayFeed(info); } } catch (System.Net.WebException exc) { //this will bubble up from the call to the update feed if we have a connection //problem to the remote RSS feed //output something to the user control to tell the user we have a problem DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("WebException.Text", this.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError); //log the details in the event log for the admin to see Exceptions.LogException(exc); } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } }