public async Task <ICommandResult> Handle(LanguageAddCommand mesage) { try { Language language = new Language(); language.Add(mesage); await _languageService.AddToDb(language); ICommandResult result = new CommandResult() { Message = "", ObjectId = language.Id, Status = CommandResult.StatusEnum.Sucess }; return(result); } catch (Exception e) { e.Data["Param"] = mesage; ICommandResult result = new CommandResult() { Message = e.Message, Status = CommandResult.StatusEnum.Fail }; return(result); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return(null); } var intermediate = new Dictionary <string, string>(); serializer.Populate(reader, intermediate); var language = new Language(); foreach (var kvp in intermediate) { var culture = (CultureInfo)null; try { culture = new CultureInfo(kvp.Key); } catch { culture = CultureInfo.CurrentCulture; } language.Add(culture, kvp.Value); } return(language); }
private Language CreateDefaultLanguage(string fileName, Insert insertStatement) { if (insertStatement.Values.Count != 3) { throw new ArgumentNullException(nameof(insertStatement)); } var language = new Language(Language.Default, insertStatement.Values[0], fileName); language.Add(CreateWord(insertStatement)); return(language); }
public Language Transform(string fileName, List <ISqlStatement> statements) { if (statements == null) { return(null); } Language language = null; bool first = true; foreach (var statement in statements) { if (!(statement is Insert insertStatement)) { continue; } if (first) { if (insertStatement.Values.Count == 2) { language = CreateLanguage(fileName, insertStatement); } else { language = CreateDefaultLanguage(fileName, insertStatement); } first = false; } else if (insertStatement.Values.Count() == 3) { language.Add(CreateWord(insertStatement)); } } return(language); }
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); }
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 the information of a book from an online source /// </summary> public Book AutoLoadDNB(string isbn) { Book book = new Book(); book.BookIsbn = isbn; if (IsbnValidated(isbn)) { htmlData = Regex.Replace(htmlData, @"\t|\n|\r", ""); htmlData = Regex.Replace(htmlData, "<a href=.*?>", ""); var genreName = GetGenreNeu().Replace("[", "(").Replace("]", ")"); if (!genreName.Equals("")) { GenreHelper helper = new GenreHelper(); Genre genre = new Genre(); if (helper.FindIdByName(genreName) < 0) { genre.GenreName = genreName; genre.Add(); } genre = new Genre(helper.FindIdByName(genreName)); book.BookGenre = genre; } var titel = GetTitelNeu().Replace("[", "(").Replace("]", ")"); if (!titel.Equals("")) { book.BookTitle = titel; } var authors = GetAutorNeu(); foreach (string s in authors) { Author author = new Author(); AuthorHelper helper = new AuthorHelper(); if (helper.FindIdByName(s) < 0) { author.AuthorName = s; author.Add(); } author = new Author(helper.FindIdByName(s)); book.BookAuthors.Add(author); } var ausgabe = GetAusgabeNeu().Replace("[", "(").Replace("]", ")"); if (!ausgabe.Equals("")) { book.BookEdition = ausgabe; } var publisherName = GetVerlagNeu().Replace("[", "(").Replace("]", ")"); if (!publisherName.Equals("")) { PublisherHelper helper = new PublisherHelper(); Publisher publisher = new Publisher(); if (helper.FindIdByName(publisherName) < 0) { publisher.PublisherName = publisherName; publisher.Add(); } publisher = new Publisher(helper.FindIdByName(publisherName)); book.BookPublisher = publisher; } var jahr = GetDatumNeu(); if (!jahr.Equals("")) { try { DateTime date = new DateTime(int.Parse(jahr), 1, 1); book.BookDatePublication = date; } catch { book.BookDatePublication = DateTime.UtcNow; } } var preis = GetPreisNeu().Replace('.', ','); if (!preis.Equals("")) { book.BookPrice = decimal.Parse(preis); } var languageName = GetSpracheNeu().Replace("[", "(").Replace("]", ")"); if (!languageName.Equals("")) { LanguageHelper helper = new LanguageHelper(); Language language = new Language(); if (helper.FindIdByName(languageName) < 0) { language.LanguageName = languageName; language.Add(); } language = new Language(helper.FindIdByName(languageName)); book.BookLanguage = language; } var image = GetPictureNeu(isbn); if (image != null) { book.BookImage = image; } return(book); //MetroMessageBox.Show(this, "Das Buch \"" + tb_Titel.Text + "\" wurde erfolgreich geladen!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { return(book); //AutoLoadBuecherNachISBN(); } }
public void TestAddException3() { Language.Add(EmptyDict <int, int>(), 1, null); }
public void TestAddException2() { Language.Add(EmptyDict <int, int>(), null, 1); }
public void TestAddException1() { Language.Add(null, Int(1), Int(1)); }
public HttpResponseMessage PostID(Languages lang) //POSTMAN ile pointer kullanarak verilen geldiğini görebiliriz. { var createdLanguages = _language.Add(lang); return(Request.CreateResponse(HttpStatusCode.Created, createdLanguages)); }