public ActionResult Add(AddTitleViewModel model, FormCollection formInfo) { model.CategoryId = int.Parse(formInfo["category"]); model.UserId = User.Identity.GetUserId(); if (!string.IsNullOrEmpty(model.Name) && !string.IsNullOrEmpty(model.Description)) { //model.Description = model.Description.Replace("\r\n", "<br>"); title = title.Add(model); if (title.Result.Type != ResultType.Success) { TempData["result"] = title.Result; return(RedirectToAction("Index", "Home", new { area = "" })); } return(RedirectToAction("Index", "Title", new { TitleId = title.Id, CategoryId = title.CategoryId })); } TempData["result"] = new Result(ResultType.Error, "Başlık Eklenemedi. Gerekli alanları doldurunuz."); return(RedirectToAction("Index", "Home", new { area = "" })); }
/* * 小説のダウンロードを行う。 * * * */ public void DownloadNovel() { var urls = getNovelUrl(); var text = new List <string>(); var title = new List <string>(); foreach (string url in urls) { string html = getHtml(url); text.Add(analysisHtml(html)); if (Juge) { title.Add(analysisHtmTitlel(html)); } } NovelText.Add(Ncode, text); if (Juge) { Title.Add(Ncode, title); } return; }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.GetEntry(opfFilePath); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (Stream zipStream = _EpubFile.GetInputStream(zipEntry)) { using (MemoryStream memoryStream = new MemoryStream()) { byte[] buffer = new byte[4096]; // 4K is optimum StreamUtils.Copy(zipStream, memoryStream, buffer); memoryStream.Position = 0; contentOpf = XElement.Load(memoryStream); } } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null ? contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; UUID = contentOpf.Elements(xNamespace + "metadata").Elements() .FirstOrDefault(e => e.Name.LocalName == "identifier" && e.HasAttributes && e.Attribute("id") != null && e.Attribute("id").Value == uniqueIdentifier ).Value; foreach ( var metadataElement in contentOpf.Element(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase)); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (MemoryStream memoryStream = new MemoryStream()) { zipEntry.Extract(memoryStream); // Fix buggy "<?xml verison="1.1"?> // See http://stackoverflow.com/questions/912440/xdocument-cant-load-xml-with-version-1-1-in-c-sharp-linq byte[] b = memoryStream.ToArray(); for (int i = 0; i < 50; i++) { // Check for version="1.1" and replace if found if (b[i] == 0x76 && b[i + 1] == 0x65 && b[i + 2] == 0x72 && b[i + 3] == 0x73 && b[i + 4] == 0x69 && b[i + 5] == 0x6F && b[i + 6] == 0x6E && b[i + 7] == 0x3D && b[i + 8] == 0x22 && b[i + 9] == 0x31 && b[i + 10] == 0x2E && b[i + 11] == 0x31) { b[i + 11] = 0x30; } } using (MemoryStream fixedStream = new MemoryStream(b)) { contentOpf = XElement.Load(fixedStream); } b = null; } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attributes("id").FirstOrDefault() != null && e.Attribute("id").Value == uniqueIdentifier).Value; } catch { } foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
public void Add(IDictionary <string, object> properties) { Title.Add(properties); Body.Add(properties); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase)); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (MemoryStream memoryStream = new MemoryStream()) { zipEntry.Extract(memoryStream); memoryStream.Position = 0; contentOpf = XElement.Load(memoryStream); } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attribute("id").Value == uniqueIdentifier).Value; } catch { } foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
/// <summary> /// Loads or reload data from disk. /// </summary> protected override void DoReLoad(string filePath) { if (filePath.IsNullOrEmpty()) { return; } try { Title.Clear(); Items.Clear(); var lines = File.ReadAllLines(filePath); for (int index = 0; index < lines.Length; index++) { void showError() { string message = SysTranslations.ErrorInFile.GetLang(filePath, index + 1, lines[index]); DisplayManager.ShowError(message); } string line = lines[index].Trim(); if (line.Length == 0) { continue; } if (line.StartsWith(";")) { continue; } if (line.StartsWith("FOLDER-SEPARATOR")) { SeparatorBeforeFolder = true; } else if (line.StartsWith("-")) { Items.Add(new OnlineProviderItem("-")); } else if (line.StartsWith("Lang/")) { var parts = line.Split('/', '='); if (parts.Length == 3) { Title.Add(Languages.Values[parts[1].Trim().ToLower()], parts[2].Trim()); } else { showError(); } } else if (line.StartsWith(TagName)) { string name = line.Substring(TagName.Length); if (++index >= lines.Length) { showError(); break; } line = lines[index].Trim(); if (line.StartsWith(TagURL)) { Items.Add(new OnlineProviderItem(name, line.Substring(TagURL.Length))); } else { showError(); } } else { showError(); } } SortByLanguage(); } catch (FileNotFoundException) { string msg = SysTranslations.FileNotFound.GetLang(filePath); DisplayManager.ShowError(msg); } catch (Exception ex) { string msg = SysTranslations.LoadFileError.GetLang(filePath, ex.Message); DisplayManager.ShowError(msg); } }