// Test-controller för Wos-Mods-överföring // Filnamn: article.txt savedrecs.txt testsearch.txt WoS_SU_2011_ar-re_1-88_new_120227.txt public ActionResult WosToMods(string id) { var filePath = Server.MapPath(path + "\\" + (string.IsNullOrWhiteSpace(id) ? "testsearch4.txt" : id + ".txt")); var f = new FileInfo(filePath); Dictionary <string, string>[] wosRecords = null; using (var sr = new StreamReader(filePath)) { wosRecords = MatchWoSToDiva.PrepareWosFile(sr).ToArray(); } XNamespace xmlns = "http://www.loc.gov/mods/v3"; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; XNamespace xlink = "http://www.w3.org/1999/xlink"; XNamespace schemaLocation = "http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd"; // Konverterar postvis, resultatet ska bäddas in i ModsCollection. var modsCollection = new XElement(xmlns + "modsCollection", new XAttribute("xmlns", "http://www.loc.gov/mods/v3"), new XAttribute("version", "3.2"), new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"), new XAttribute(XNamespace.Xmlns + "xlink", "http://www.w3.org/1999/xlink"), new XAttribute(xsi + "schemaLocation", "http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")); foreach (var wosRecord in wosRecords) { modsCollection.Add(WoSRecordWriter.ModsRecord(wosRecord, int.Parse(ConfigurationManager.AppSettings["MaxAuthorCount"]), ConfigurationManager.AppSettings["OnlyFirstLastAndLocalAuthors"] == "1")); } return(new XmlActionResult(modsCollection)); }
public FileContentResult DownLoadWoSRecords(int batch, int matchLevel, string format = null) { int batchSize = int.Parse(ConfigurationManager.AppSettings["DownloadBatchSize"]); var wosRecords = (Dictionary <string, string>[])Session["WosRecords"]; var divaRecords = (Dictionary <string, string>[])Session["DivaRecords"]; var matchResult = (Tuple <Dictionary <string, string>, Dictionary <string, string>, int>[])Session["MatchResult"]; var matchedWosIds = matchResult.Select(a => a.Item2["UT"]).ToArray(); var matchedDivaIds = matchResult.Select(a => a.Item1["PID"]).ToArray(); //Get List of unmatched WoS records var unmatchedWos = wosRecords.Where(a => !matchedWosIds.Contains(a["UT"])); //Get List of unmatched DiVA records var unmatchedDivas = divaRecords.Where(a => !matchedDivaIds.Contains(a["PID"])); var downloadLevel = false; IEnumerable <Dictionary <string, string> > postsToDownload; if (matchLevel > 0) { postsToDownload = matchResult.Where(a => a.Item3 == matchLevel).Select(a => a.Item2); downloadLevel = true; } else { postsToDownload = unmatchedWos; } var posts = postsToDownload.Skip(batch * batchSize); if (posts.Count() >= batchSize) { posts = posts.Take(batchSize); } if (format == "MODS") { XNamespace xmlns = "http://www.loc.gov/mods/v3"; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; XNamespace xlink = "http://www.w3.org/1999/xlink"; XNamespace schemaLocation = "http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd"; // Konverterar postvis, resultatet ska bäddas in i ModsCollection. var modsCollection = new XElement(xmlns + "modsCollection", new XAttribute("xmlns", "http://www.loc.gov/mods/v3"), new XAttribute("version", "3.2"), new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"), new XAttribute(XNamespace.Xmlns + "xlink", "http://www.w3.org/1999/xlink"), new XAttribute(xsi + "schemaLocation", "http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")); foreach (var wospost in posts) { modsCollection.Add( WoSRecordWriter.ModsRecord( wospost.Where(a => !a.Key.StartsWith("new") && a.Key != "FA").ToDictionary(a => a.Key, a => a.Value), int.Parse(ConfigurationManager.AppSettings["MaxAuthorCount"]), ConfigurationManager.AppSettings["OnlyFirstLastAndLocalAuthors"] == "1") ); } return(File(new UTF8Encoding().GetBytes(modsCollection.ToString()), "text/XML", "Unmatched-" + (downloadLevel ? "level" + matchLevel + "-" : string.Empty) + DateTime.Now.ToShortDateString() + ".xml")); } else { var s = new StringBuilder(); foreach (var wospost in posts) { s.Append( WoSRecordWriter.WoSRecordString( wospost.Where(a => !a.Key.StartsWith("new") && a.Key != "FA").ToDictionary(a => a.Key, a => a.Value), int.Parse(ConfigurationManager.AppSettings["MaxAuthorCount"]), ConfigurationManager.AppSettings["OnlyFirstLastAndLocalAuthors"] == "1") ); } s.Append("\nEF"); return(File(new UTF8Encoding().GetBytes(s.ToString()), "text/csv", "Unmatched-" + (downloadLevel ? "level" + matchLevel + "-" : string.Empty) + DateTime.Now.ToShortDateString() + ".csv")); } }