/// <summary> /// دریافت یک فایل xml و نمایش اطلاعات اولیه آن /// </summary> /// <param name="url"></param> /// <param name="Name"></param> /// <param name="Description"></param> /// <param name="MoreInfoUrl"></param> /// <returns></returns> public static bool RetrieveProperties(string url, out string Name, out string Description, out string MoreInfoUrl) { Name = Description = MoreInfoUrl = ""; try { WebRequest req = WebRequest.Create(url); GConnectionManager.ConfigureProxy(ref req); using (WebResponse response = req.GetResponse()) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); //Should Redirect? XmlNodeList ndListRedirect = doc.GetElementsByTagName("RedirectInfo"); if (ndListRedirect.Count > 0) { XmlNode redirectNode = ndListRedirect[0]; foreach (XmlNode Node in redirectNode.ChildNodes) { if (Node.Name == "Url") { if (!string.IsNullOrEmpty(Node.InnerText)) { return(RetrieveProperties(Node.InnerText, out Name, out Description, out MoreInfoUrl)); } } } } XmlNodeList nameNodeList = doc.GetElementsByTagName("Name"); if (nameNodeList != null && nameNodeList.Count == 1) { Name = nameNodeList[0].InnerText; } XmlNodeList descNodeList = doc.GetElementsByTagName("Description"); if (descNodeList != null && descNodeList.Count == 1) { Description = descNodeList[0].InnerText; } XmlNodeList urlNodeList = doc.GetElementsByTagName("MoreInfoUrl"); if (urlNodeList != null && urlNodeList.Count == 1) { MoreInfoUrl = urlNodeList[0].InnerText; } return(true); } } } } catch { return(false); } }
/// <summary> /// دریافت فایل xml خوانش /// </summary> /// <param name="url"></param> /// <param name="targetFilePath"></param> /// <param name="overwrite"></param> /// <param name="Exception"></param> /// <returns></returns> public static bool DownloadAudioXml(string url, string targetDir, bool overwrite, out string Exception) { Exception = string.Empty; Uri uri = new Uri(url); string targetFilePath = Path.Combine(targetDir, Path.GetFileName(uri.LocalPath)); try { if (File.Exists(targetFilePath)) { if (!overwrite) { return(true); } else { File.Delete(targetFilePath); } } WebRequest req = WebRequest.Create(url); GConnectionManager.ConfigureProxy(ref req); using (WebResponse response = req.GetResponse()) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { XmlDocument doc = new XmlDocument(); //this is unnecessary, but at least does some kind of verification doc.LoadXml(reader.ReadToEnd()); doc.Save(targetFilePath); } } } return(true); } catch (Exception exp) { Exception = exp.Message; return(false); } }
/// <summary> /// دریافت کننده لیست خوانشها /// </summary> /// <param name="url"></param> /// <param name="Exception"></param> /// <returns></returns> public static List <Dictionary <string, string> > RetrieveList(string url, out string Exception) { List <Dictionary <string, string> > lst = new List <Dictionary <string, string> >(); try { WebRequest req = WebRequest.Create(url); GConnectionManager.ConfigureProxy(ref req); using (WebResponse response = req.GetResponse()) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); //Collect List: XmlNodeList paudioNodes = doc.GetElementsByTagName("PoemAudio"); foreach (XmlNode gdbNode in paudioNodes) { Dictionary <string, string> audioInfo = new Dictionary <string, string>(); foreach (XmlNode Node in gdbNode.ChildNodes) { audioInfo.Add(Node.Name, Node.InnerText); } lst.Add(audioInfo); } } } } Exception = string.Empty; return(lst); } catch (Exception exp) { Exception = exp.Message; return(null); } }
private void CheckForUpdate(bool Prompt) { try { WebRequest req = WebRequest.Create("http://dg.ganjoor.net/version.xml"); GConnectionManager.ConfigureProxy(ref req); using (WebResponse response = req.GetResponse()) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); int MyVersionMajor = Assembly.GetExecutingAssembly().GetName().Version.Major; int MyVersionMinor = Assembly.GetExecutingAssembly().GetName().Version.Minor; int VersionMajor = 0; int VersionMinor = 0; string updateUrl = string.Empty; XmlNode versionNode = doc.GetElementsByTagName("Version")[0]; foreach (XmlNode Node in versionNode.ChildNodes) { if (Node.Name == "Major") { VersionMajor = Convert.ToInt32(Node.InnerText); } else if (Node.Name == "Minor") { VersionMinor = Convert.ToInt32(Node.InnerText); } else if (Node.Name == "UpdateUrl") { if (string.IsNullOrEmpty(updateUrl)) { updateUrl = Node.InnerText; } } else if (Node.Name == "UpdateUrl162Plus") { updateUrl = Node.InnerText; } } if (VersionMajor == MyVersionMajor && VersionMinor == MyVersionMinor) { if (Prompt) { MessageBox.Show("شما آخرین ویرایش گنجور رومیزی را در اختیار دارید.", "تبریک", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign); } } else { if ( MessageBox.Show("ویرایش جدیدتر " + VersionMajor.ToString() + "." + VersionMinor.ToString() + " از نرمافزار ارائه شده است. صفحهٔ دریافت باز شود؟ ", "ویرایش جدید", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign) == DialogResult.Yes ) { System.Diagnostics.Process.Start(updateUrl); if (!Prompt)//check for new gdbs { return; } } } } } } if (!Prompt)//check for new gdbs { string strException; List <GDBInfo> Lst = GDBListProcessor.RetrieveList("http://i.ganjoor.net/android/androidgdbs.xml", out strException); if (Lst != null && string.IsNullOrEmpty(strException)) { List <GDBInfo> finalList = new List <GDBInfo>(); DbBrowser db = new DbBrowser(); foreach (GDBInfo gdb in Lst) { if ( !db.IsInGDBIgnoreList(gdb.CatID) && db.GetCategory(gdb.CatID) == null ) { finalList.Add(gdb); } } if (finalList.Count > 0) { using (NewGDBFound dlg = new NewGDBFound(finalList)) { if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { using (DownloadingGdbList dwnDlg = new DownloadingGdbList(dlg.dwnldList)) if (dwnDlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { foreach (string DownloadedFile in dwnDlg.DownloadedFiles) { ImportGdb(DownloadedFile); if (Settings.Default.DeleteDownloadedFiles) { File.Delete(DownloadedFile); } } } } foreach (int CatID in dlg.IgnoreList) { db.AddToGDBIgnoreList(CatID); } } } } } } catch (Exception exp) { if (Prompt) { MessageBox.Show(exp.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// دریافت یک فایل xml و تبدیل آن به لیستی از GDBInfoها /// </summary> /// <param name="url"></param> /// <param name="Exception"></param> /// <returns></returns> public static List <GDBInfo> RetrieveList(string url, out string Exception) { List <GDBInfo> lstGDBs = new List <GDBInfo>(); try { WebRequest req = WebRequest.Create(url); GConnectionManager.ConfigureProxy(ref req); using (WebResponse response = req.GetResponse()) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); //Should Redirect? XmlNodeList ndListRedirect = doc.GetElementsByTagName("RedirectInfo"); if (ndListRedirect.Count > 0) { XmlNode redirectNode = ndListRedirect[0]; foreach (XmlNode Node in redirectNode.ChildNodes) { if (Node.Name == "Url") { if (!string.IsNullOrEmpty(Node.InnerText)) { return(RetrieveList(Node.InnerText, out Exception)); } } } } //Collect List: lstGDBs.Clear(); XmlNodeList gdbNodes = doc.GetElementsByTagName("gdb"); foreach (XmlNode gdbNode in gdbNodes) { GDBInfo gdbInfo = new GDBInfo(); foreach (XmlNode Node in gdbNode.ChildNodes) { switch (Node.Name) { case "CatName": gdbInfo.CatName = Node.InnerText; break; case "PoetID": gdbInfo.PoetID = Convert.ToInt32(Node.InnerText); break; case "CatID": gdbInfo.CatID = Convert.ToInt32(Node.InnerText); break; case "DownloadUrl": gdbInfo.DownloadUrl = Node.InnerText; break; case "BlogUrl": gdbInfo.BlogUrl = Node.InnerText; break; case "FileExt": gdbInfo.FileExt = Node.InnerText; break; case "ImageUrl": gdbInfo.ImageUrl = Node.InnerText; break; case "FileSizeInByte": gdbInfo.FileSizeInByte = Convert.ToInt32(Node.InnerText); break; case "LowestPoemID": gdbInfo.LowestPoemID = Convert.ToInt32(Node.InnerText); break; case "PubDate": { string[] dateParts = Node.InnerText.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); int Year = Convert.ToInt32(dateParts[0]); int Month = Convert.ToInt32(dateParts[1]); int Day = Convert.ToInt32(dateParts[2]); gdbInfo.PubDate = new DateTime(Year, Month, Day); } break; } } lstGDBs.Add(gdbInfo); } } } } Exception = string.Empty; return(lstGDBs); } catch (Exception exp) { Exception = exp.Message; return(null); } }