public static XmltvSource[] ImportFromNextPvr() { var db = DbHelper.GetDatabase(); List<string> existing = db.Fetch<string>("select lower([filename]) from xmltvsource"); string[] sourceFiles = NUtility.Channel.LoadAll().Where(x => x.EPGSource == "XMLTV").Select(x => { return Regex.Match(x.EPGMapping, "(?<=(<file>))[^<]+").Value; }) .Distinct() .Where(x => !String.IsNullOrWhiteSpace(x) && !existing.Contains(x.ToLower())).ToArray(); // insert new files List<XmltvSource> newSources = new List<XmltvSource>(); foreach (string file in sourceFiles) { XmltvSource source = new XmltvSource(); source.Filename = file; source.Scan(false); source.Save(); newSources.Add(source); } return newSources.ToArray(); }
internal static bool Save(XmltvSource[] Sources) { var db = DbHelper.GetDatabase(); var toDelete = Models.XmltvSource.LoadAll().Where(x => !Sources.Select(y => y.Oid).Contains(x.Oid)).ToArray(); try { db.BeginTransaction(); foreach (var source in Sources) source.Save(db); foreach (var source in toDelete) source.Delete(db); db.CompleteTransaction(); return true; } catch (Exception) { db.AbortTransaction(); return false; } }