/// <summary> /// Handles the ItemRemoved event of the libraryManager control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param> void libraryManager_ItemRemoved(object sender, ItemChangeEventArgs e) { if (!Helpers.FilterAndGetMediaType(e.Item, out var type)) { return; } lock (_libraryChangedSyncLock) { if (LibraryUpdateTimer == null) { LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, Timeout.Infinite); } else { LibraryUpdateTimer.Change(LibraryUpdateDuration, Timeout.Infinite); } var item = new LibItem { Id = e.Item.Id, SyncApiModified = DateTimeOffset.Now.ToUnixTimeSeconds(), ItemType = type }; _logger.LogDebug("ItemRemoved added for DB Saving {ItemId}", e.Item.Id); _itemsRemoved.Add(item); } }
public void SetUserInfoSync(List <MediaBrowser.Model.Dto.UserItemDataDto> dtos, List <LibItem> itemRefs, string userId) { var newRecs = new List <UserInfoRec>(); var upRecs = new List <UserInfoRec>(); var userInfoCollection = _liteDb.GetCollection <UserInfoRec>(UserInfoCollection); dtos.ForEach(dto => { _logger.LogDebug("Updating ItemId '{0}' for UserId: '{1}'", dto.ItemId, userId); Guid dtoItemId = Guid.Parse(dto.ItemId); LibItem itemref = itemRefs.FirstOrDefault(x => x.Id == dtoItemId); if (itemref != null) { var sJson = System.Text.Json.JsonSerializer.Serialize(dto, _jsonSerializerOptions); var oldRec = userInfoCollection.Find(u => u.ItemId == dto.ItemId && u.UserId == userId).FirstOrDefault(); var newRec = new UserInfoRec { ItemId = dto.ItemId, Json = sJson, UserId = userId, LastModified = DateTimeOffset.Now.ToUnixTimeSeconds(), MediaType = itemref.ItemType }; if (oldRec == null) { newRecs.Add(newRec); } else { newRec.Id = oldRec.Id; upRecs.Add(newRec); } } }); if (newRecs.Count > 0) { userInfoCollection.Insert(newRecs); } if (upRecs.Count > 0) { var data = userInfoCollection.FindAll().ToList(); foreach (var rec in upRecs) { data.Where(d => d.Id == rec.Id).ToList().ForEach(u => { u.ItemId = rec.ItemId; u.Json = rec.Json; u.UserId = rec.UserId; u.LastModified = rec.LastModified; u.MediaType = rec.MediaType; }); } userInfoCollection.Update(data); } }
/// <summary> /// Handles the ItemAdded event of the libraryManager control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param> void libraryManager_ItemAdded(object sender, ItemChangeEventArgs e) { if (!Helpers.FilterAndGetMediaType(e.Item, out var type)) { return; } lock (_libraryChangedSyncLock) { if (LibraryUpdateTimer == null) { LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, Timeout.Infinite); } else { LibraryUpdateTimer.Change(LibraryUpdateDuration, Timeout.Infinite); } var item = new LibItem { Id = e.Item.Id, SyncApiModified = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds), ItemType = type, }; _logger.LogDebug("ItemAdded added for DB Saving {ItemId}", e.Item.Id); _itemsAdded.Add(item); } }
public void SetUserInfoSync(List <MediaBrowser.Model.Dto.UserItemDataDto> dtos, List <LibItem> itemRefs, string userName, string userId, CancellationToken cancellationToken) { var newRecs = new List <UserInfoRec>(); var upRecs = new List <UserInfoRec>(); lock (_userLock) { dtos.ForEach(dto => { var sJson = json.SerializeToString(dto).ToString(); logger.LogDebug("Updating ItemId '{0}' for UserId: '{1}'", dto.ItemId, userId); LibItem itemref = itemRefs.Where(x => x.Id.ToString("N") == dto.ItemId).FirstOrDefault(); if (itemref != null) { var oldRec = userInfoRecs.Select(u => u.ItemId == dto.ItemId && u.UserId == userId).FirstOrDefault(); var newRec = new UserInfoRec() { ItemId = dto.ItemId, Json = sJson, UserId = userId, LastModified = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds), MediaType = itemref.ItemType, //LibraryName = itemref.CollectionName }; if (oldRec == null) { newRecs.Add(newRec); } else { newRec.Id = oldRec.Id; upRecs.Add(newRec); } } }); if (newRecs.Count > 0) { userInfoRecs.Insert(newRecs); } if (upRecs.Count > 0) { var data = userInfoRecs.Select(); foreach (var rec in upRecs) { data.Where(d => d.Id == rec.Id).ToList().ForEach(u => { u.ItemId = rec.ItemId; u.Json = rec.Json; u.UserId = rec.UserId; u.LastModified = rec.LastModified; u.MediaType = rec.MediaType; }); } userInfoRecs.Commit(data); } } }
private static void SetGeographyStatistic(LibItem libItem) { if (libItem.Affiliation != string.Empty) { List <string> affs = new List <string>(); if (libItem.Sourсe == "Web of Science") { affs = libItem.Affiliation .Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries) .Where(text => text[text.Length - 2] != ' ') .ToList(); } else { affs = libItem.Affiliation.Split(';').ToList(); } foreach (var aff in affs) { var infoArray = aff.Split(','); if (Geography.ContainsKey(infoArray.Last())) { Geography[infoArray.Last()]++; } else { Geography.Add(infoArray.Last(), 1); } } } }
private static void AffiliationComplement(LibItem savedItem, LibItem currItem) { if (savedItem.AffiliationIsEmpty && !currItem.AffiliationIsEmpty) { savedItem.Affiliation = currItem.Affiliation; } }
private static void AbstractComplement(LibItem savedItem, LibItem currItem) { if (savedItem.AbstractIsEmpty && !currItem.AbstractIsEmpty) { savedItem.Abstract = currItem.Abstract; } }
private static void KeywordsComplement(LibItem savedItem, LibItem currItem) { if (savedItem.KeywordsIsEmpty && !currItem.KeywordsIsEmpty) { savedItem.Keywords = currItem.Keywords; } }
private static void SetYearStatistic(LibItem libItem) { if (Years.ContainsKey(libItem.Year)) { Years[libItem.Year]++; } else { Years.Add(libItem.Year, 1); } }
private static void SetSourseRelevanceStatictic(LibItem libItem) { if (SourcesRelevance.ContainsKey(libItem.Sourсe)) { SourcesRelevance[libItem.Sourсe]++; } else { SourcesRelevance.Add(libItem.Sourсe, 1); } }
private static void SetTypesStatistic(LibItem libItem) { if (Types.ContainsKey(libItem.Type)) { Types[libItem.Type]++; } else { Types.Add(libItem.Type, 1); } }
private static void SetSourseUniqueStatictic(LibItem libItem) { if (SourcesUnique.ContainsKey(libItem.Sourсe)) { SourcesUnique[libItem.Sourсe]++; } else { SourcesUnique.Add(libItem.Sourсe, 1); } }
private static void SetJournalStatistic(LibItem libItem) { if (libItem.Type == "journal" && libItem.JournalName != string.Empty) { if (Journal.ContainsKey(libItem.JournalName)) { Journal[libItem.JournalName]++; } else { Journal.Add(libItem.JournalName, 1); } } }
private static void SetConferenceStatistic(LibItem libItem) { if (libItem.Type == "conference") { var title = libItem.JournalName; if (Conference.ContainsKey(title)) { Conference[title]++; } else { Conference.Add(title, 1); } } }
public Book(LibItem libItem) { Int32.TryParse(libItem.Year, out int year); Int32.TryParse(libItem.Volume, out int volume); Authors = AuthorsParser.ParseAuthors(libItem.Authors, libItem.Sourсe); Title = libItem.Title; Name = libItem.JournalName; City = string.Empty; Publisher = libItem.Publisher; Year = year; Pages = libItem.Pages; Volume = volume; Link = string.Empty; Date = DateTime.Parse(DateTime.Now.ToShortDateString()); }
public Journal(LibItem libItem) { Int32.TryParse(libItem.Volume, out int volume); Int32.TryParse(libItem.Number, out int number); Int32.TryParse(libItem.Year, out int year); Authors = AuthorsParser.ParseAuthors(libItem.Authors, libItem.Sourсe); Title = libItem.Title; JournalName = libItem.JournalName; Year = year; Pages = libItem.Pages; Number = number; Volume = volume; Link = string.Empty; Date = DateTime.Parse(DateTime.Now.ToShortDateString()); }
public Conference(LibItem libItem) { Int32.TryParse(libItem.Year, out int year); Int32.TryParse(libItem.Number, out int number); Int32.TryParse(libItem.Volume, out int volume); Authors = AuthorsParser.ParseAuthors(libItem.Authors, libItem.Sourсe); Title = libItem.Title; Publisher = libItem.Publisher; Pages = libItem.Pages; Year = year; City = libItem.Address; Number = number; Volume = volume; ConferenceName = libItem.JournalName; Doi = libItem.Doi; }
private int FindCopyPosition(LibItem item) { var title = Normalize(item.Title); string copy = null; if (IsUnique(title) && (copy = GetTitleCopy(title)) == null) { return(-1); } else { return (copy != null ? UniqueTitles[copy] : UniqueTitles[title]); } }
private List <LibItem> GetLibItems(StreamReader reader) { List <LibItem> Items = new List <LibItem>(); var template = @"\s?(.+?)\s?=\s?(""|{{|{)(.+?)(""|}}|}),"; var regex = new Regex(template); string tagString = "", newLine = ""; Tags.NewTags(); if (reader == null) { return(Items); } newLine = reader.ReadLine(); while (newLine == null || newLine == "" || newLine[0] != '@') { if (newLine == null) { return(Items); } newLine = reader.ReadLine(); } SetType(newLine); while (!reader.EndOfStream) { newLine = reader.ReadLine(); while (newLine == "" || IsEndOfLibItem(newLine)) { if (newLine != "") { if (newLine[0] != '@') { tagString += newLine; } else { SetType(newLine); } if (IsEndOfTag(newLine)) { var key = regex.Match(tagString).Groups[1].Value; var value = regex.Match(tagString).Groups[3].Value; SetSource(key, value, tagString); if (Tags.TagRework.ContainsKey(key)) { Tags.TagValues[Tags.TagRework[key]] = value; } tagString = ""; } } newLine = reader.ReadLine(); if (newLine == null) { break; } } if (tagString != string.Empty) { FixScienceDirect(tagString); } if (newLine == null) { break; } tagString = string.Empty; var newItem = new LibItem(Tags.TagValues); Items.Add(newItem); Tags.NewTags(); } reader.Close(); return(Items); }
// POST api/<controller> public LibItem Post(LibItem item) { return(repo.Add(item)); }
private static void FindImportantData(LibItem savedItem, LibItem currItem) { AbstractComplement(savedItem, currItem); KeywordsComplement(savedItem, currItem); AffiliationComplement(savedItem, currItem); }
// PUT api/<controller>/5 public long Put(LibItem item) { return(repo.Update(item).Result); }