Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public void Abort()
 {
     _tokenSource.Cancel(true);
     OnConvert?.Invoke(this, new ConvertEventArgs(ConvertEventType.Aborting, Properties.Resources.Convert_Aborting));
 }