/// <summary> /// Adds a collection of working years to serialized data /// </summary> /// <param name="items">Collection of items to add</param> /// <param name="fileFormat"> <see cref="OwlSerializer.FileFormats"/> of the items</param> /// <returns>Id of item</returns> public IEnumerable<int> AddWorkingYears(IEnumerable<IWorkingYear> items, OwlSerializer.FileFormats fileFormat) { List<int> ids = new List<int>(); foreach (WorkingYear year in items.Select(item => new WorkingYear(item))) { if (!yearsCollection.ContainsKey(year.YearCount)) { AddWorkingYear(year, fileFormat); ids.Add(year.YearCount); yearsCollection.Add(year.YearCount,year); } } return ids; }
/// <summary> /// Adds a working year to serialized data /// </summary> /// <param name="item">Item to add</param> /// <param name="fileFormat"> <see cref="OwlSerializer.FileFormats"/> of the item</param> /// <returns>Id of item</returns> public int AddWorkingYear(IWorkingYear item, OwlSerializer.FileFormats fileFormat) { if (!yearsCollection.ContainsKey(item.YearCount)) { WorkingYear year = new WorkingYear(item); switch (fileFormat) { case OwlSerializer.FileFormats.Cfg: case OwlSerializer.FileFormats.Xml: OwlSerializer.Save(year, typeof(WorkingYear), yearFolder + year.YearCount, OwlSerializer.FileFormats.Xml); break; case OwlSerializer.FileFormats.Json: OwlSerializer.Save(year, typeof(WorkingYear), yearFolder + year.YearCount, OwlSerializer.FileFormats.Json); break; } yearsCollection.Add(year.YearCount,year); return year.YearCount; } return -1; }
/// <summary> /// Updates the given item /// </summary> /// <param name="items">Items to update</param> /// <param name="fileFormat"> <see cref="OwlSerializer.FileFormats"/> of the items</param> public bool UpdateWorkingYears(IEnumerable<IWorkingYear> items, OwlSerializer.FileFormats fileFormat) { return items.Aggregate(true, (current, item) => current & UpdateWorkingYear(item, fileFormat)); }
/// <summary> /// Updates the given item /// </summary> /// <param name="item">Item to update</param> /// <param name="fileFormat"> <see cref="OwlSerializer.FileFormats"/> of the item</param> public bool UpdateWorkingYear(IWorkingYear item, OwlSerializer.FileFormats fileFormat) { WorkingYear year = new WorkingYear(item); if (yearsCollection.ContainsKey(year.YearCount)) { yearsCollection[year.YearCount] = year; switch (fileFormat) { case OwlSerializer.FileFormats.Cfg: case OwlSerializer.FileFormats.Xml: OwlSerializer.Save(year, typeof(WorkingYear), yearFolder + year.YearCount, OwlSerializer.FileFormats.Xml); break; case OwlSerializer.FileFormats.Json: OwlSerializer.Save(year, typeof(WorkingYear), yearFolder + year.YearCount, OwlSerializer.FileFormats.Json); break; } return true; } return false; }
/// <summary> /// Removes a collection of working years from serialized data specified by the given function /// </summary> /// <param name="func">Function to evaluate</param> /// <param name="fileFormat"> <see cref="OwlSerializer.FileFormats"/> of the items</param> public bool RemoveWorkingYears(Func<IWorkingYear, bool> func, OwlSerializer.FileFormats fileFormat) { IEnumerable<IWorkingYear> remove = GetWorkingYears(func); var workingYears = remove as IWorkingYear[] ?? remove.ToArray(); return workingYears.Any() && RemoveWorkingYears(workingYears, fileFormat); }
/// <summary> /// Removes a collection of working years from serialized data /// </summary> /// <param name="items">Collection of items to remove</param> /// <param name="fileFormat"> <see cref="OwlSerializer.FileFormats"/> of the items</param> public bool RemoveWorkingYears(IEnumerable<IWorkingYear> items, OwlSerializer.FileFormats fileFormat) { bool res = true; foreach (IWorkingYear item in items) { if (yearsCollection.ContainsKey(item.YearCount)) { res &= RemoveWorkingYear(item, fileFormat); } else { res = false; } } return res; }
/// <summary> /// Removes a working year from serialized data /// </summary> /// <param name="item">Item to remove</param> /// <param name="fileFormat"> <see cref="OwlSerializer.FileFormats"/> of the item</param> public bool RemoveWorkingYear(IWorkingYear item, OwlSerializer.FileFormats fileFormat) { if (yearsCollection.ContainsKey(item.YearCount)) { OwlSerializer.Delete(yearFolder + item.YearCount, fileFormat); yearsCollection.Remove(item.YearCount); return true; } return false; }