/// <summary> /// Find first file in the specified group /// </summary> /// <param name="grp"></param> /// <returns></returns> public FileDsc FindFirstFileForTheGroup(FileGroupDsc grp) { if (this.Files != null) { return(this.EnumerateGroupFiles(grp).FirstOrDefault()); } return(null); }
/// <summary> /// Find first image file in the specified group /// </summary> /// <param name="grp"></param> /// <returns></returns> public FileDsc FindFirstImageForTheGroup(FileGroupDsc grp) { if (this.Files != null) { return(this.EnumerateGroupFiles(grp).FirstOrDefault((fl) => _imgExtensions.Contains(fl.Extension))); } return(null); }
public List <FileGroupDsc> RecalcGroups(double intervalM, Func <int, string> grpNameGenerator = null) { List <FileGroupDsc> rz = new List <FileGroupDsc>(); DateTime dt = DateTime.MinValue; Func <int, string> namer = grpNameGenerator ?? ((n) => string.Format("Group #{0}", n)); FileGroupDsc tmp = null; int ix = 1; if (this.Files.Count > 0) { var q = from t in this.Files orderby t.FileTime select t; foreach (var t in q) { if (tmp == null) { tmp = new FileGroupDsc() { GrpName = namer(ix++), StartTime = new DateTimeRef(t.FileTime), EndTime = new DateTimeRef(DateTime.MaxValue), Count = 1 }; dt = t.FileTime; t.Group = tmp; rz.Add(tmp); } else { if (dt.AddMinutes(intervalM) < t.FileTime) { tmp.EndTime.Value = dt; tmp = new FileGroupDsc() { GrpName = namer(ix++), StartTime = new DateTimeRef(t.FileTime), EndTime = new DateTimeRef(DateTime.MaxValue), Count = 1 }; dt = t.FileTime; t.Group = tmp; rz.Add(tmp); } else { tmp.Count += 1; t.Group = tmp; dt = t.FileTime; } } } tmp.EndTime.Value = dt; } return(this.FileGroups = rz); }
public FileGroupDsc CreateNextGroup(string grpName, DateTime endTime) { var rz = new FileGroupDsc() { GrpName = grpName, StartTime = this.EndTime, EndTime = new DateTimeRef(endTime) }; return(rz); }
void DoStartGroup() { var cfl = this.CurrentFileDsc; if (cfl != null) { var cgrp = cfl.Group; int ix = this.FileGroups.IndexOf(cgrp); var ngrp = new FileGroupDsc() { GrpName = GetNextGrpName(cgrp), StartTime = new DateTimeRef(cfl.FileTime), EndTime = new DateTimeRef(cgrp.EndTime.Value), IsManual = true }; this.FileGroups.Insert(ix + 1, ngrp); cgrp.EndTime = new DateTimeRef(cfl.FileTime.AddMilliseconds(-1)); var qg = from f in this.Files where object.ReferenceEquals(f.Group, cgrp) select f; var cgMaxTm = cgrp.StartTime.Value; //need get more accurate endtime for the old group int cgn = 0, ngn = 0; foreach (var f in qg) { if (f.FileTime < cgrp.EndTime.Value) { cgn++; if (cgMaxTm < f.FileTime) { cgMaxTm = f.FileTime; } } else { ngn++; f.Group = ngrp; } } cgrp.Count = cgn; cgrp.EndTime.Value = cgMaxTm; ngrp.Count = ngn; PrepareNames(); this.CurrentGroup = ngrp; } }
/// <summary> /// Converts collection of DateTimes into groups ordered by time. /// </summary> /// <param name="times">Collection of DateTimes. May contain duplicates and may not be ordered.</param> /// <param name="grpNameGenerator">Group name generator. If <c>null</c> then default generator is used.</param> /// <returns></returns> public static IEnumerable <FileGroupDsc> GenerateSequence(IEnumerable <DateTime> times, Func <int, string> grpNameGenerator = null) { HashSet <DateTime> dths = new HashSet <DateTime>(times); var tml = (from t in dths orderby t select t).ToArray(); Func <int, string> namer = grpNameGenerator ?? ((x) => string.Format("Group #{0}", x)); if (tml.Length > 0) { if (tml.Length == 1) { yield return(new FileGroupDsc() { GrpName = namer(1), StartTime = new DateTimeRef(tml[0]), EndTime = new DateTimeRef(DateTime.MaxValue) }); } else { FileGroupDsc fg = new FileGroupDsc() { GrpName = namer(1), StartTime = new DateTimeRef(tml[0]), EndTime = new DateTimeRef(tml[1]) }; yield return(fg); for (int i = 2; i < tml.Length; i++) { fg = fg.CreateNextGroup(namer(i), tml[i]); yield return(fg); } fg = fg.CreateNextGroup(namer(tml.Length), DateTime.MaxValue); yield return(fg); } } }
IEnumerable <FileDsc> EnumerateGroupFiles(FileGroupDsc fgrp) { return(from f in this.Files where object.ReferenceEquals(f.Group, fgrp) select f); }
string GetNextGrpName(FileGroupDsc grp) { return(grp.GrpName + ".a"); }