public static List <T> StaticConvert(string value, OnConvert convert) { List <T> results = new List <T>(); if (!string.IsNullOrEmpty(value)) { foreach (string val in value.Split(',')) { if (string.IsNullOrEmpty(val)) { continue; } List <T> values = convert(val); if (values == null) { return(null); } results.AddRange(values); } } return(results); }
public static List <T> StaticConvert(string value, OnConvert convert) { List <T> results = new List <T>(); if (!string.IsNullOrEmpty(value)) { foreach (string val in value.Split(',')) { if (string.IsNullOrEmpty(val)) { continue; } T result; if (!convert(val, out result)) { continue; } results.Add(result); } } return(results); }
public void Convert(ICollection <InputFileItem> fileItems) { _tokenSource = new CancellationTokenSource(); Task.Run(() => { try { OnConvert?.Invoke(this, new ConvertEventArgs(ConvertEventType.BeginConvert, $"{Properties.Resources.Convert_Start} {fileItems.Count()} {Properties.Resources.files}")); foreach (var item in fileItems) { if (_tokenSource.IsCancellationRequested) { _tokenSource.Token.ThrowIfCancellationRequested(); } if (!item.Path.EndsWith("m4a") && !item.Path.EndsWith(".m4b")) { OnConvert?.Invoke(this, new ConvertEventArgs(ConvertEventType.ConvertToAAC, $"{Properties.Resources.Converting}: {item.FileName}")); using (var filestream = new MediaFoundationReader(item.Path)) { item.WorkingPath = Path.GetTempFileName(); MediaFoundationEncoder.EncodeToAac(filestream, item.WorkingPath); } } } OnConvert?.Invoke(this, new ConvertEventArgs(ConvertEventType.EndConvert)); } catch (OperationCanceledException oe) { OnConvert?.Invoke(this, new ConvertEventArgs(ConvertEventType.Cancelled, oe.Message)); } catch (Exception e) { OnConvert?.Invoke(this, new ConvertEventArgs(ConvertEventType.Error, e.Message)); } finally { foreach (var item in fileItems) { File.Delete(item.WorkingPath); } } }, _tokenSource.Token); }
public static string StaticConvert(IEnumerable <T> list, OnConvert convert) { if (list == null) { return(""); // Must return a non-null } string results = ""; // Must return a non-null foreach (T key in list) { if (!string.IsNullOrEmpty(results)) { results += ","; } results += convert(key); } return(results); }
public void Abort() { _tokenSource.Cancel(true); OnConvert?.Invoke(this, new ConvertEventArgs(ConvertEventType.Aborting, Properties.Resources.Convert_Aborting)); }