private static XElement ParseDescription(XElement xElement, RssItem newItem, XElement subElement) { subElement = xElement.Element("description"); if (subElement != null) { newItem.Description = subElement.Value; int indexOfComment = newItem.Description.IndexOf("<!--"); if (indexOfComment != -1) { string commentSection = newItem.Description.Substring(indexOfComment); int indexOfLinkStart = commentSection.IndexOf("/><a href=\"http://www.gluevault.com/system/files/"); if (indexOfLinkStart != -1) { indexOfLinkStart = indexOfLinkStart + "/><a href=\"".Length; string stringContainingFileAtStart = commentSection.Substring(indexOfLinkStart); int endOfFile = stringContainingFileAtStart.IndexOf("\""); string file = stringContainingFileAtStart.Substring(0, endOfFile); newItem.DirectLink = file; } } } return subElement; }
public static RssItem FromXElement(XElement xElement) { RssItem newItem = new RssItem(); var subElement = xElement.Element("title"); if (subElement != null) { newItem.Title = subElement.Value; } subElement = ParseDescription(xElement, newItem, subElement); subElement = xElement.Element("comments"); if (subElement != null) { newItem.Comments = subElement.Value; } subElement = xElement.Element("pubDate"); if (subElement != null) { newItem.PublishedDate = xElement.Element("pubDate").Value; } return newItem; }
private static XElement ParseDescription(XElement xElement, RssItem newItem, XElement subElement) { subElement = xElement.Element("description"); if (subElement != null) { newItem.Description = subElement.Value; int indexOfComment = newItem.Description.IndexOf("<!--"); if (indexOfComment != -1) { string commentSection = newItem.Description.Substring(indexOfComment); int indexOfLinkStart = commentSection.IndexOf("/><a href=\"http://www.gluevault.com/system/files/"); if (indexOfLinkStart != -1) { indexOfLinkStart = indexOfLinkStart + "/><a href=\"".Length; string stringContainingFileAtStart = commentSection.Substring(indexOfLinkStart); int endOfFile = stringContainingFileAtStart.IndexOf("\""); string file = stringContainingFileAtStart.Substring(0, endOfFile); newItem.DirectLink = file; } } } return(subElement); }
public static RssItem FromXElement(XElement xElement) { RssItem newItem = new RssItem(); var subElement = xElement.Element("title"); if (subElement != null) { newItem.Title = subElement.Value; } subElement = ParseDescription(xElement, newItem, subElement); subElement = xElement.Element("comments"); if (subElement != null) { newItem.Comments = subElement.Value; } subElement = xElement.Element("pubDate"); if (subElement != null) { newItem.PublishedDate = xElement.Element("pubDate").Value; } return(newItem); }
public static void StartDownloadingInformation(string url, Action <AllFeed, DownloadState> callback) { Thread thread = new Thread(() => { AllFeed toReturn = null; DownloadState result = DownloadState.Error; try { // Create a request for the URL. WebRequest request = WebRequest.Create(url); // If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials; // Get the response. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream dataStream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(dataStream)) { // Read the content. string responseFromServer = reader.ReadToEnd(); toReturn = new AllFeed(); //toReturn = FileManager.XmlDeserializeFromString<AllFeed>(responseFromServer); XDocument doc = XDocument.Parse(responseFromServer); foreach (var xElement in doc.Element("rss").Element("channel").Elements("item")) { RssItem newItem = RssItem.FromXElement(xElement); toReturn.Items.Add(newItem); } } result = DownloadState.InformationDownloaded; } catch (Exception e) { result = DownloadState.Error; } callback(toReturn, result); }); thread.Start(); }
private void ShowSelectedPluginInformation() { object selectedItem = ListBox.SelectedItem; if (selectedItem == null) { LastUpdatedTitleLabel.Text = "Select an item to view update information"; LastUpdatedTitleLabel.Visible = true; LastUpdatedValueLabel.Visible = false; RemoteActionButton.Visible = false; } else if(AllFeed != null) { RssItem item = GetItemFor(AllFeed, SelectedPlugin); SelectedRssItem = item; if (item != null) { string glueLink = item.GlueLink; SelectedPlugin.RemoteLocation = glueLink; if (SelectedPlugin.DownloadState == DownloadState.InformationDownloaded) { LastUpdatedTitleLabel.Text = "Last Update: "; LastUpdatedValueLabel.Visible = true; LastUpdatedValueLabel.Text = SelectedPlugin.LastUpdate.ToString(); RemoteActionButton.Visible = true; RemoteActionButton.Text = "Go to GlueVault"; RemoteActionButton2.Visible = true; RemoteActionButton2.Text = "Install Latest Plugin"; } else if(SelectedPlugin.DownloadState == DownloadState.NotStarted) { LastUpdatedTitleLabel.Text = "Downloading information for " + item.Title; SelectedPlugin.TryStartDownload((arg)=> { // The window may have been closed already if (this.Visible) { try { this.Invoke((MethodInvoker)delegate { ShowSelectedPluginInformation(); }); } catch { // no big deal, it's disposed most likely because the user closed the window. } } }); } else if (SelectedPlugin.DownloadState == DownloadState.Error) { LastUpdatedTitleLabel.Text = "Error getting information about plugin"; RemoteActionButton.Visible = true; RemoteActionButton2.Visible = false; RemoteActionButton.Text = "Try again"; } } else { LastUpdatedTitleLabel.Text = "Plugin not found on GlueVault.com:"; LastUpdatedValueLabel.Visible = false; RemoteActionButton.Visible = false; RemoteActionButton2.Visible = false; } //LastUpdatedTitleLabel.Text = "Last Updated:"; //LastUpdatedValueLabel.Text = "12 34 5678"; //LastUpdatedTitleLabel.Visible = true; //LastUpdatedValueLabel.Visible = true; //RemoteActionButton.Visible = true; //RemoteActionButton.Text = "Refresh"; } }