public String GetExportResult(ICuesheetEntity cuesheetEntity) { String result = null; if (String.IsNullOrEmpty(Scheme) == false) { switch (SchemeType) { case SchemeType.Header: case SchemeType.Footer: var cuesheet = (Cuesheet)cuesheetEntity; result = Scheme.Replace(SchemeCuesheetArtist, cuesheet.Artist).Replace(SchemeCuesheetTitle, cuesheet.Title).Replace(SchemeCuesheeFile, cuesheet.AudioFile?.FileName); break; case SchemeType.Body: var track = (Track)cuesheetEntity; result = Scheme .Replace(SchemeTrackArtist, track.Artist) .Replace(SchemeTrackTitle, track.Title) .Replace(SchemeTrackPosition, track.Position != null ? track.Position.Value.ToString() : String.Empty) .Replace(SchemeTrackBegin, track.Begin != null ? track.Begin.Value.ToString() : String.Empty) .Replace(SchemeTrackEnd, track.End != null ? track.End.Value.ToString() : String.Empty) .Replace(SchemeTrackLength, track.Length != null ? track.Length.Value.ToString() : String.Empty); break; } } return(result); }
public String GetExportResult(ICuesheetEntity cuesheetEntity) { String result = null; if (String.IsNullOrEmpty(Scheme) == false) { switch (SchemeType) { case Schemetype.Header: case Schemetype.Footer: var cuesheet = (Cuesheet)cuesheetEntity; result = Scheme .Replace(SchemeCuesheetArtist, cuesheet.Artist) .Replace(SchemeCuesheetTitle, cuesheet.Title) .Replace(SchemeCuesheetAudiofile, cuesheet.Audiofile?.FileName) .Replace(SchemeCuesheetCDTextfile, cuesheet.CDTextfile?.FileName) .Replace(SchemeCuesheetCatalogueNumber, cuesheet.Cataloguenumber?.Value) .Replace(SchemeDate, DateTime.Now.ToShortDateString()) .Replace(SchemeDateTime, DateTime.Now.ToString()) .Replace(SchemeTime, DateTime.Now.ToLongTimeString()); break; case Schemetype.Body: var track = (Track)cuesheetEntity; result = Scheme .Replace(SchemeTrackArtist, track.Artist) .Replace(SchemeTrackTitle, track.Title) .Replace(SchemeTrackPosition, track.Position != null ? track.Position.Value.ToString() : String.Empty) .Replace(SchemeTrackBegin, track.Begin != null ? track.Begin.Value.ToString() : String.Empty) .Replace(SchemeTrackEnd, track.End != null ? track.End.Value.ToString() : String.Empty) .Replace(SchemeTrackLength, track.Length != null ? track.Length.Value.ToString() : String.Empty) .Replace(SchemeTrackFlags, String.Join(" ", track.Flags.Select(x => x.CuesheetLabel))) .Replace(SchemeTrackPreGap, track.PreGap != null ? track.PreGap.Value.ToString() : String.Empty) .Replace(SchemeTrackPostGap, track.PreGap != null ? track.PostGap.Value.ToString() : String.Empty) .Replace(SchemeDate, DateTime.Now.ToShortDateString()) .Replace(SchemeDateTime, DateTime.Now.ToString()) .Replace(SchemeTime, DateTime.Now.ToLongTimeString()); break; default: //Nothing to do break; } } return(result); }
/// <summary> /// Analyses a line and sets the properties on the entity /// </summary> /// <param name="line">Line to analyse</param> /// <param name="entity">Entity to set properties on</param> /// <param name="regices">Regular expressions for analysing</param> /// <returns>Analysed line with marking what has been matched</returns> private static String AnalyseLine(String line, ICuesheetEntity entity, IReadOnlyDictionary <Tuple <String, String>, Regex> regices) { String recognized = null; if ((String.IsNullOrEmpty(line) == false) && (entity != null) && (regices != null)) { var index = 0; foreach (var regexRelation in regices) { var match = regexRelation.Value.Match(line.Substring(index)); if (match.Success == true) { var propertyValueBefore = line.Substring(index, match.Index); var propertyBefore = entity.GetType().GetProperty(regexRelation.Key.Item1, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var propertyValueAfter = line.Substring(index + match.Index + match.Length); var propertyAfter = entity.GetType().GetProperty(regexRelation.Key.Item2, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); //Check if other regices might match the value after Boolean otherMatchRegEx = false; var elementIndex = regices.ToList().IndexOf(regexRelation); for (int i = elementIndex; i < regices.Count; i++) { var nextRegExRelation = regices.ElementAt(i); if (nextRegExRelation.Value.IsMatch(propertyValueAfter) == true) { otherMatchRegEx = true; i = regices.Count; } } SetValue(entity, propertyBefore, propertyValueBefore); //Set recognized recognized += String.Format("<Mark>{0}</Mark>{1}", line.Substring(index, match.Index), match.Value); if (otherMatchRegEx == false) { SetValue(entity, propertyAfter, propertyValueAfter); recognized += String.Format("<Mark>{0}</Mark>", line.Substring(index + match.Index + match.Length)); } index = index + match.Index + match.Length; } } } return(recognized); }
/// <summary> /// Set the value on the entity /// </summary> /// <param name="entity">Entity object to set the value on</param> /// <param name="property">Property to set</param> /// <param name="value">Value to set</param> private static void SetValue(ICuesheetEntity entity, PropertyInfo property, string value) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (property == null) { throw new ArgumentNullException(nameof(property)); } if (property.PropertyType == typeof(TimeSpan?)) { property.SetValue(entity, TimeSpan.Parse(value)); } if (property.PropertyType == typeof(uint?)) { property.SetValue(entity, Convert.ToUInt32(value)); } if (property.PropertyType == typeof(String)) { property.SetValue(entity, value); } if (property.PropertyType == typeof(IReadOnlyCollection <Flag>)) { var list = Flag.AvailableFlags.Where(x => value.Contains(x.CuesheetLabel)); ((ImportTrack)entity).SetFlags(list); } if (property.PropertyType == typeof(Audiofile)) { property.SetValue(entity, new Audiofile(value)); } if (property.PropertyType == typeof(Cataloguenumber)) { ((ImportCuesheet)entity).Cataloguenumber.Value = value; } if (property.PropertyType == typeof(CDTextfile)) { property.SetValue(entity, new CDTextfile(value)); } }