Пример #1
0
        private void AddAuthorAndTitleTokens(Metadata metadata)
        {
            var author = _tokenReplacer.ReplaceTokens(metadata.Author);
            var title  = _tokenReplacer.ReplaceTokens(metadata.Title);

            _tokenReplacer.AddStringToken("Author", author);
            _tokenReplacer.AddStringToken("Title", title);
        }
        private string ReplaceTokens(string s)
        {
            if (s == null)
            {
                return(string.Empty);
            }

            return(_tokenReplacer.ReplaceTokens(s));
        }
Пример #3
0
        public void SubjectTokenViewModel_ReplaceTokensFunction_TextIsToken_PokenIsReplacedInPreview()
        {
            var tokenName  = _tokenHelper.GetTokenListForEmail()[0];
            var tokenValue = _tokenReplacer.ReplaceTokens(tokenName);

            _viewModel.SubjectTokenViewModel.Text = tokenName;

            Assert.AreEqual(tokenValue, _viewModel.SubjectTokenViewModel.Preview);
        }
        public void SingReasonTokenViewModel_Preview_IsTextWithReplacedTokens()
        {
            var tokenName  = _tokenHelper.GetTokenListWithFormatting()[0];
            var tokenValue = _tokenReplacer.ReplaceTokens(tokenName);

            _viewModel.SignReasonTokenViewModel.Text = tokenName;

            Assert.AreEqual(tokenValue, _viewModel.SignReasonTokenViewModel.Preview);
        }
Пример #5
0
 public void ReplaceTokensInMetadata()
 {
     JobInfo.Metadata.Author   = TokenReplacer.ReplaceTokens(JobInfo.Metadata.Author);
     JobInfo.Metadata.Title    = TokenReplacer.ReplaceTokens(JobInfo.Metadata.Title);
     JobInfo.Metadata.Subject  = TokenReplacer.ReplaceTokens(JobInfo.Metadata.Subject);
     JobInfo.Metadata.Keywords = TokenReplacer.ReplaceTokens(JobInfo.Metadata.Keywords);
 }
        private string TokenReplace(string text)
        {
            var textWithTokens = _tokenReplacer.ReplaceTokens(text);
            var bytes          = Encoding.GetEncoding("ISO-8859-1").GetBytes(textWithTokens); // Remove illegal characters (e.g. chinese characters).

            return(Encoding.GetEncoding("ISO-8859-1").GetString(bytes));
        }
Пример #7
0
        private async Task ProcessResultInternalAsync(VideoFrame frame)
        {
            var urlTemplate = frame.Metadata.Info.CallbackUrl;

            if (urlTemplate != null)
            {
                _logger.LogInformation("Webhook notify for {streamId}", frame.Metadata.Info.Id);

                var replacedUrl = TokenReplacer.ReplaceTokens(urlTemplate, frame);
                try
                {
                    var uri = new Uri(replacedUrl);

                    using var client = _clientFactory.CreateClient();
                    await client.GetAsync(uri).ConfigureAwait(false);
                }
                catch (UriFormatException ex)
                {
                    _logger.LogError(ex, "Invalid CallbackUrl for {streamId}:{callbackUrl}",
                                     frame.Metadata.Info.Id, replacedUrl);
                }
                catch (HttpRequestException hre)
                {
                    _logger.LogError(hre, "Error in http call for {streamId}:{callbackUrl}",
                                     frame.Metadata.Info.Id, replacedUrl);
                }
            }
        }
Пример #8
0
        public static string ComposeScriptPath(string path, TokenReplacer tokenReplacer)
        {
            string composedPath = tokenReplacer.ReplaceTokens(path);

            composedPath = FileUtil.Instance.MakeValidFolderName(composedPath);

            return(composedPath);
        }
Пример #9
0
        public string ComposeScriptParameters(string parameterString, IList <string> outputFiles, TokenReplacer tokenReplacer)
        {
            var composedParameters = new StringBuilder();

            composedParameters.Append(tokenReplacer.ReplaceTokens(parameterString) + " ");
            composedParameters.Append(string.Join(" ", outputFiles.Select(s => "\"" + _path.GetFullPath(s) + "\"")));

            return(composedParameters.ToString());
        }
Пример #10
0
        public string ComposeScriptPath(string path, TokenReplacer tokenReplacer)
        {
            var validName    = new ValidName();
            var composedPath = tokenReplacer.ReplaceTokens(path);

            composedPath = validName.MakeValidFolderName(composedPath);

            return(composedPath);
        }
        public void RecipientsTokenViewModel_Preview_IsTextWithReplacedTokens()
        {
            var tokenName  = _tokenHelper.GetTokenListForEmailRecipients()[0];
            var tokenValue = _tokenReplacer.ReplaceTokens(tokenName);

            _viewModel.RecipientsTokenViewModel.Text = tokenName;

            Assert.AreEqual(tokenValue, _viewModel.RecipientsTokenViewModel.Preview);
        }
        public void TokenReplacer_TokenWithParameter_ReturnsPlaceholder()
        {
            const string tokenName = "MyToken";

            var tr = new TokenReplacer();

            tr.AddToken(BuildToken(tokenName));

            var str = tr.ReplaceTokens("<MyToken:Test>");

            Assert.AreEqual("Value for 'Test'", str);
        }
Пример #13
0
        private string GetRecipientsString(EmailSmtpSettings smtpSettings, TokenReplacer tokenReplacer)
        {
            var recipientsTo  = tokenReplacer.ReplaceTokens(smtpSettings.Recipients);
            var recipientsCc  = tokenReplacer.ReplaceTokens(smtpSettings.RecipientsCc);
            var recipientsBcc = tokenReplacer.ReplaceTokens(smtpSettings.RecipientsBcc);

            var sb = new StringBuilder();

            sb.AppendLine($"{_translation.RecipientsToText} {recipientsTo}");

            if (!string.IsNullOrWhiteSpace(recipientsCc))
            {
                sb.AppendLine($"{_translation.RecipientsCcText} {recipientsCc}");
            }

            if (!string.IsNullOrWhiteSpace(recipientsBcc))
            {
                sb.AppendLine($"{_translation.RecipientsBccText} {recipientsBcc}");
            }

            return(sb.ToString());
        }
Пример #14
0
        private void AddMetaDataTokens(Metadata metadata)
        {
            _tokenReplacer.AddStringToken("PrintJobAuthor", metadata.PrintJobAuthor);
            _tokenReplacer.AddStringToken("PrintJobName", metadata.PrintJobName);

            var subject = _tokenReplacer.ReplaceTokens(metadata.Subject);

            _tokenReplacer.AddStringToken("Subject", subject);

            var keywords = _tokenReplacer.ReplaceTokens(metadata.Keywords);

            _tokenReplacer.AddStringToken("Keywords", keywords);

            // Author and title token have to be created last,
            // as they can contain other tokens that might need replacing
            var author = _tokenReplacer.ReplaceTokens(metadata.Author);

            _tokenReplacer.AddStringToken("Author", author);

            var title = _tokenReplacer.ReplaceTokens(metadata.Title);

            _tokenReplacer.AddStringToken("Title", title);
        }
Пример #15
0
        private void CreateStampFile(string filename, ConversionProfile profile, TokenReplacer tokenReplacer)
        {
            // Create a resource manager to retrieve resources.
            var rm = new ResourceManager(typeof(Resources));

            var stampString = rm.GetString("PostScriptStamp");

            if (stampString == null)
            {
                throw new InvalidOperationException("Error while fetching stamp template");
            }

            var outlineWidth  = 0;
            var outlineString = "show";

            if (profile.Stamping.FontAsOutline)
            {
                outlineWidth  = profile.Stamping.FontOutlineWidth;
                outlineString = "true charpath stroke";
            }

            var textWithTokens = tokenReplacer.ReplaceTokens(profile.Stamping.StampText);
            var stampText      = RemoveIllegalCharacters(textWithTokens);

            // Only Latin1 chars are allowed here
            stampString = stampString.Replace("[STAMPSTRING]",
                                              EncodeGhostscriptParametersOctal(stampText));
            stampString = stampString.Replace("[FONTNAME]", profile.Stamping.PostScriptFontName);
            stampString = stampString.Replace("[FONTSIZE]", profile.Stamping.FontSize.ToString(_numberFormat));
            stampString = stampString.Replace("[STAMPOUTLINEFONTTHICKNESS]", outlineWidth.ToString(CultureInfo.InvariantCulture));
            stampString = stampString.Replace("[USEOUTLINEFONT]", outlineString); // true charpath stroke OR show

            if (profile.OutputFormat == OutputFormat.PdfX ||
                profile.PdfSettings.ColorModel == ColorModel.Cmyk)
            {
                var colorString = RgbToCmykColorString(profile.Stamping.Color);
                stampString = stampString.Replace("[FONTCOLOR]", colorString);
                stampString = stampString.Replace("setrgbcolor", "setcmykcolor");
            }
            else
            {
                var colorString = (profile.Stamping.Color.R / 255.0).ToString("0.00", _numberFormat) + " " +
                                  (profile.Stamping.Color.G / 255.0).ToString("0.00", _numberFormat) + " " +
                                  (profile.Stamping.Color.B / 255.0).ToString("0.00", _numberFormat);
                stampString = stampString.Replace("[FONTCOLOR]", colorString);
            }

            FileWrap.WriteAllText(filename, stampString);
        }
Пример #16
0
        public string ComposeScriptPath(string path, TokenReplacer tokenReplacer)
        {
            var scriptPath = tokenReplacer.ReplaceTokens(path);

            try
            {
                scriptPath = _path.GetFullPath(scriptPath);
            }
            catch
            {
                //Check will deal with it later
            }

            return(scriptPath);
        }
Пример #17
0
        public Task ProcessResultAsync(VideoFrame frame)
        {
            //If not enabled, skip this processor.
            if (!_isEnabled)
            {
                return(Task.CompletedTask);
            }
            if (frame is null)
            {
                throw new ArgumentNullException(nameof(frame));
            }
            var results = frame.Metadata.AnalysisResult;

            if (results is null)
            {
                throw new InvalidOperationException("An analysis result is expected");
            }

            Logger.LogInformation("New result received for frame acquired at {timestamp}. {detectionCount} objects detected",
                                  frame.Metadata.Timestamp, results.Count);

            var labelStats = from r in results
                             group r by r.Label into g
                             select $"#{g.Key}:{g.Count()}";

            var stats = String.Join("; ", labelStats);

            Logger.LogInformation("Detected: {detectionstats}", stats);


            var filename = TokenReplacer.ReplaceTokens(Options.CapturePattern, frame);

            var filePath = Path.Combine(_captureRootPath, filename);

            EnsureDirectoryPath(filePath);

            using var result = Visualizer.AnnotateImage(frame.Image, results.ToArray());

            if (Cv2.ImWrite(filePath, result))
            {
                Logger.LogInformation("Interesting Detection Saved: {filename}", filename);
            }
            else
            {
                Logger.LogError("Error during write of file {filePath}", filePath);
            }
            return(Task.CompletedTask);
        }
Пример #18
0
        private string ReplaceTokensAddSignature(string s)
        {
            if (s == null)
            {
                return(string.Empty);
            }

            var contentString = _tokenReplacer.ReplaceTokens(s);

            if (AddSignature)
            {
                contentString += _signatureText;
            }

            return(contentString);
        }
Пример #19
0
        public void ReplaceTokens()
        {
            Assert.AreEqual("C:\\Temp\\a.out", "{RootFolder}\\a.out".ReplaceTokens(new { RootFolder = "C:\\Temp" }));
            Assert.AreEqual("1 + 2", "{x} + {y}".ReplaceTokens(new { x = 1, y = 2 }));
            Assert.AreEqual("20180131", "{Date: yyyyMMdd}".ReplaceTokens(new { Date = new DateTime(2018, 01, 31) }));
            Assert.AreEqual("1", "{Params[1]}".ReplaceTokens(new { Params = new int[] { 0, 1, 2 } }));
            Assert.AreEqual("C:\\Temp\\a.out", "{Params[Folder2]}\\a.out".ReplaceTokens(new { Params = new Dictionary <string, string>()
                                                                                              {
                                                                                                  { "Folder1", "C:\\User" }, { "Folder2", "C:\\Temp" }
                                                                                              } }));
            Assert.AreEqual("1 + {y}", "{x} + {y}".ReplaceTokens(false, new { x = 1 }));

            var tokenReplacer = new TokenReplacer(new[] { new { Date = new DateTime(2018, 01, 31) } }, true, '%', '%');

            Assert.AreEqual("20180131", tokenReplacer.ReplaceTokens("%Date:yyyyMMdd%"));
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var stringValue = value as string;

            if (stringValue == null)
            {
                throw new NotImplementedException();
            }

            stringValue = TokenReplacer.ReplaceTokens(stringValue);

            if (Footer != null)
            {
                stringValue += Footer;
            }

            return(FileUtil.Instance.MakeValidFileName(stringValue));
        }
Пример #21
0
        /// <summary>
        ///     Compose the output filename based on settings, output format etc.
        /// </summary>
        /// <returns>composed output filename</returns>
        public string ComposeOutputFilename()
        {
            var outputFilename =
                FileUtil.Instance.MakeValidFileName(TokenReplacer.ReplaceTokens(Profile.FileNameTemplate));

            switch (Profile.OutputFormat)
            {
            case OutputFormat.Pdf:
            case OutputFormat.PdfA1B:
            case OutputFormat.PdfA2B:
            case OutputFormat.PdfX:
                outputFilename += ".pdf";
                break;

            case OutputFormat.Jpeg:
                outputFilename += ".jpg";
                break;

            case OutputFormat.Png:
                outputFilename += ".png";
                break;

            case OutputFormat.Tif:
                outputFilename += ".tif";
                break;

            case OutputFormat.Txt:
                outputFilename += ".txt";
                break;

            default:
                Logger.Warn("Can't find a supported Output format! File format is defaulted to .pdf");
                outputFilename += ".pdf";
                break;
            }

            if (outputFilename.Length > FileUtil.MAX_PATH)
            {
                outputFilename = FileUtil.Instance.EllipsisForPath(outputFilename, 250);
            }

            return(outputFilename);
        }
Пример #22
0
        protected override void QueryTargetFile()
        {
            TokenReplacer tr = Job.TokenReplacer;

            string outputFolder = FileUtil.Instance.MakeValidFolderName(tr.ReplaceTokens(Job.Profile.AutoSave.TargetDirectory));
            string filePath     = Path.Combine(outputFolder, Job.ComposeOutputFilename());

            try
            {
                filePath = FileUtil.Instance.EllipsisForTooLongPath(filePath);
                Logger.Debug("FilePath after ellipsis: " + filePath);
            }
            catch (ArgumentException)
            {
                Logger.Error("Autosave filepath is only a directory or the directory itself is already too long to append a filename under the limits of Windows (max "
                             + FileUtil.MAX_PATH + " characters): " + filePath);
                Cancel = true;
                return;
            }

            Job.OutputFilenameTemplate = filePath;
        }
Пример #23
0
 private string PreviewForFileName(string s)
 {
     return(ValidName.MakeValidFileName(_tokenReplacer.ReplaceTokens(s)));
 }
Пример #24
0
        private string PreviewForFileName(string s)
        {
            var validName = new ValidName();

            return(validName.MakeValidFileName(_tokenReplacer.ReplaceTokens(s)));
        }
Пример #25
0
 private void AuthorTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
 {
     AuthorPreviewText.Text = _tokenReplacer.ReplaceTokens(AuthorTextBox.Text);
 }
Пример #26
0
 /// <summary>
 ///     Applies Metadata to the current job
 /// </summary>
 public void ApplyMetadata()
 {
     TokenReplacer           = GetTokenReplacer();
     JobInfo.Metadata.Author = TokenReplacer.ReplaceTokens(JobInfo.Metadata.Author);
     JobInfo.Metadata.Title  = TokenReplacer.ReplaceTokens(JobInfo.Metadata.Title);
 }
Пример #27
0
 private string ReplaceTokens(string s)
 {
     return(_tokenReplacer.ReplaceTokens(s));
 }
Пример #28
0
        public void Test()
        {
            Assert.AreEqual("No angel-brakets in this String...",
                            _testTokenReplacer.ReplaceTokens("No angel-brakets in this String..."));
            Assert.AreEqual("Only Open < no Close", _testTokenReplacer.ReplaceTokens("Only Open < no Close"));
            Assert.AreEqual("Only Close > no Open", _testTokenReplacer.ReplaceTokens("Only Close > no Open"));
            Assert.AreEqual("An <Unknown> Token", _testTokenReplacer.ReplaceTokens("An <Unknown> Token"));
            Assert.AreEqual("An Christophe becomes Christophe",
                            _testTokenReplacer.ReplaceTokens("An <Author> becomes Christophe"));
            Assert.AreEqual("Christophe", _testTokenReplacer.ReplaceTokens("<Author>"));
            Assert.AreEqual("Christophe", _testTokenReplacer.ReplaceTokens("<AuTHOR>"));
            Assert.AreEqual("A 23 becomes 23", _testTokenReplacer.ReplaceTokens("A <Counter> becomes 23"));
            Assert.AreEqual("<BLA<>BLA>", _testTokenReplacer.ReplaceTokens("<BLA<>BLA>"));

            Assert.AreEqual("<<NoToken>ChristopheSomethingBehind>",
                            _testTokenReplacer.ReplaceTokens("<<NoToken><Author>SomethingBehind>"));

            Assert.AreEqual("NumberToken with Format 0023",
                            _testTokenReplacer.ReplaceTokens("NumberToken with Format <Counter:0000>"));

            Assert.AreEqual("NumberToken with wrong Format BLA",
                            _testTokenReplacer.ReplaceTokens("NumberToken with wrong Format <Counter:BLA>"));

            Assert.AreEqual("DateToken without Format 24.07.2012 04:36:06",
                            _testTokenReplacer.ReplaceTokens("DateToken without Format <DateTime>"));

            Assert.AreEqual("DateToken with Format 20120724043606",
                            _testTokenReplacer.ReplaceTokens("DateToken with Format <DateTime:yyyyMMddHHmmss>"));

            Assert.AreEqual("DateToken with Format 24 07 2012",
                            _testTokenReplacer.ReplaceTokens("DateToken with Format <DateTime:dd MM yyyy>"));

            Assert.AreEqual("DateToken with wrong Format 24.07.2012 04:36:06",
                            _testTokenReplacer.ReplaceTokens("DateToken with wrong Format <DateTime:1>"));

            Assert.AreEqual("Token without Format with: Format Christophe",
                            _testTokenReplacer.ReplaceTokens("Token without Format with: Format <Author: 500>"));

            Assert.AreEqual("Unknown Token with: Format:<Christophe: Bla>",
                            _testTokenReplacer.ReplaceTokens("Unknown Token with: Format:<Christophe: Bla>"));

            Assert.AreEqual("--Christophe-Christophe1234Christophe--",
                            _testTokenReplacer.ReplaceTokens("--<Author>-<Author>1234<Author>--"));

            Assert.AreEqual("Christophe>Christophe<Christophe",
                            _testTokenReplacer.ReplaceTokens("<Author>><Author><<Author>"));

            Assert.AreEqual("This is a real special case > this should not be doublicated < ",
                            _testTokenReplacer.ReplaceTokens("This is a real special case > this should not be doublicated < "));

            Assert.AreEqual("This is a real special case > this Christophe should not be doublicated < something",
                            _testTokenReplacer.ReplaceTokens("This is a real special case > this <Author> should not be doublicated < something"));

            Assert.AreEqual("Futher test of last case Christophe > this should not be doublicated <",
                            _testTokenReplacer.ReplaceTokens("Futher test of last case <Author> > this should not be doublicated <"));

            Assert.AreEqual("And to be sure: Christophe > this Christophe should not be doublicated < Christophe",
                            _testTokenReplacer.ReplaceTokens("And to be sure: <Author> > this <Author> should not be doublicated < <Author>"));

            Assert.AreEqual("filename1, filename2", _testTokenReplacer.ReplaceTokens("<List>"));
            Assert.AreEqual("filename1 - filename2", _testTokenReplacer.ReplaceTokens("<List: - >"));
            Assert.AreEqual("filename1\nfilename2", _testTokenReplacer.ReplaceTokens("<List:\\n>"));
        }
Пример #29
0
 private void FtpTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
 {
     DirectoryPreviewTextBox.Text = FtpAction.MakeValidPath(_tokenReplacer.ReplaceTokens(DirectoryTextBox.Text));
 }
Пример #30
0
 public void Test(string expected, string tokenizedString)
 {
     Assert.AreEqual(expected, _testTokenReplacer.ReplaceTokens(tokenizedString));
 }