Esempio n. 1
0
        public MarkdownConverter(IConversionOptions options, HttpClient?httpClient = null, ILogger?logger = null)
        {
            this.options    = options;
            this.logger     = logger ?? NullLogger.Instance;
            this.httpClient = httpClient ?? new HttpClient();

            this.includeXPaths = this.options.IncludeTags.Where(t => t.StartsWith("/")).ToList();
            this.includeTags   = this.options.IncludeTags.Except(this.includeXPaths).ToHashSet();

            this.excludeXPaths = this.options.ExcludeTags.Where(t => t.StartsWith("/")).ToList();
            this.excludeTags   = this.options.ExcludeTags.Except(this.includeXPaths).ToHashSet();
        }
        public string ConvertToWords(double number, IConversionOptions options = null)
        {
            var dictionary             = new EnglishDictionary();
            var groupsToWordsConverter = new EnglishTripletToWordsConverter(dictionary);

            var converter = new NumberToWordsConverterBuilder()
                            .WithDictionary(dictionary)
                            .WithTripletConverter(groupsToWordsConverter)
                            .Build();

            return(converter.ConvertToWords(number, options));
        }
Esempio n. 3
0
        public void Convert(string inputFile, string outputFile, IConversionOptions options)
        {
            if (string.IsNullOrWhiteSpace(Controller.FFmpegPath))
            {
                throw new FFmpegException("Engine is not initialized yet");
            }

            string additionalArgs = Path.DirectorySeparatorChar == '\\' ? "-nostdin -y -loglevel info " : "-y -loglevel info ";

            var startInfo = new ProcessStartInfo
            {
                FileName               = Controller.FFmpegPath,
                Arguments              = $"{additionalArgs}-i \"{inputFile}\" {options}\"{outputFile}\"",
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true,
                WindowStyle            = ProcessWindowStyle.Hidden
            };

            using (var process = new Process())
            {
                List <string> receivedMessagesLog = new List <string>();
                TimeSpan      totalMediaDuration  = new TimeSpan();
                Exception     caughtException     = null;

                process.StartInfo          = startInfo;
                process.ErrorDataReceived += (sender, received) =>
                {
                    if (received.Data == null)
                    {
                        return;
                    }

                    try
                    {
                        receivedMessagesLog.Insert(0, received.Data);

                        Match matchDuration = RegexEngine.Index[RegexEngine.Find.Duration].Match(received.Data);
                        if (matchDuration.Success)
                        {
                            TimeSpan.TryParse(matchDuration.Groups[1].Value, out totalMediaDuration);
                        }

                        if (RegexEngine.IsProgressData(received.Data, out ConvertProgressEventArgs progressEvent))
                        {
                            progressEvent.TotalDuration = totalMediaDuration;
                            OnProgressChanged(progressEvent);
                        }
                        else if (RegexEngine.IsConvertCompleteData(received.Data, out ConversionCompleteEventArgs convertCompleteEvent))
                        {
                            convertCompleteEvent.TotalDuration = totalMediaDuration;
                            OnConversionComplete(convertCompleteEvent);
                        }
                    }
                    catch (Exception ex)
                    {
                        caughtException = ex;
                    }
                };
                process.Start();

                process.BeginErrorReadLine();
                process.WaitForExit();

                if (process.ExitCode != 0 || caughtException != null)
                {
                    throw new Exception(
                              process.ExitCode + ": " + receivedMessagesLog[0],
                              caughtException);
                }
            }
        }
Esempio n. 4
0
 public MarkdownConverter(IConversionOptions options, ILogger?logger = null)
     : this(options, null, logger)
 {
 }
        public virtual string ConvertToWords(double number, IConversionOptions options = null)
        {
            var wordsBuilder = new StringBuilder();
            var tempNumber   = number;

            var opt = options ?? ConversionOptions.Default;

            var currencyInfo = _converterDictionary.GetCurrencyInfo(opt.CurrencyCode);

            if (number < 0)
            {
                wordsBuilder.Append(_converterDictionary.GetMinus());
                wordsBuilder.Append(opt.WordSeparator);
                tempNumber = Math.Abs(number);
            }

            (int IntegerValue, int decimalValue) = GetDecimalPartValue(number);

            string decimalString = ProcessGroup(decimalValue, -1, 0);

            string retVal = string.Empty;

            int group = 0;

            if (tempNumber < 1)
            {
                retVal = $"{_converterDictionary.GetZero()}";
            }
            else
            {
                while (tempNumber >= 1)
                {
                    int numberToProcess = (int)(tempNumber % 1000);

                    tempNumber /= 1000;

                    string groupDescription = ProcessGroup(numberToProcess, group, Math.Floor(tempNumber));

                    if (groupDescription != string.Empty)
                    {
                        if (group > 0)
                        {
                            var separator = retVal == string.Empty ? string.Empty : opt.WordSeparator;
                            retVal = $"{_converterDictionary.GetGroup(group)}{separator}{retVal.TrimStart()}";
                        }

                        retVal = $"{groupDescription.Trim()}{opt.WordSeparator}{retVal.TrimStart()}";
                    }

                    group++;
                }
            }

            if (!string.IsNullOrEmpty(retVal))
            {
                wordsBuilder.Append(retVal.Trim());
                var currencyName = (IntegerValue == 1 ? currencyInfo.Name : currencyInfo.PluralName);
                wordsBuilder.Append(opt.WordSeparator);
                wordsBuilder.Append(currencyName.Trim());
            }

            if (!string.IsNullOrEmpty(decimalString))
            {
                wordsBuilder.Append(opt.WordSeparator);
                wordsBuilder.Append($"{_converterDictionary.GetAnd()}");
                wordsBuilder.Append(opt.WordSeparator);

                wordsBuilder.Append(decimalString.Trim());
                wordsBuilder.Append(opt.WordSeparator);

                var currencyPartName = (decimalValue == 1 ? currencyInfo.PartName : currencyInfo.PluralPartName);
                wordsBuilder.Append(currencyPartName.Trim());
            }
            var result = wordsBuilder.ToString();

            return(LetterCaseHelper.ConvertLetterCaseTo(result, opt.LanguageCode, opt.LetterCase));
        }