Ejemplo n.º 1
0
        public void InitTest()
        {
            _testTokenReplacer = new TokenReplacer();
            _testTokenReplacer.AddToken(new StringToken("Author", "Christophe"));
            _testTokenReplacer.AddToken(new StringToken("Title", "Lord of the Rings"));
            _testTokenReplacer.AddToken(new NumberToken("Counter", 23));
            _testTokenReplacer.AddToken(new DateToken("DateTime", _expectedDate.DateTimeInstance));
            _testTokenReplacer.AddToken(new ListToken("List", new[] { "filename1", "filename2" }));
            _testTokenReplacer.AddToken(new EnvironmentToken("Environment"));
            var userToken = new UserToken();

            userToken.AddKeyValuePair("TokenByUser", "User token value");
            userToken.AddKeyValuePair("TokenByUserWithEmptyValue", "");
            _testTokenReplacer.AddToken(userToken);
        }
        private SourceFileInfo BuildSourceFileInfo(JobType type)
        {
            var sfi = new SourceFileInfo();

            sfi.Filename           = "MyFileName";
            sfi.SessionId          = 321;
            sfi.WinStation         = "SomeStation";
            sfi.Author             = "Me";
            sfi.ClientComputer     = "MyComputer";
            sfi.PrinterName        = "SomePrinterName";
            sfi.JobCounter         = 4243;
            sfi.JobId              = 24;
            sfi.DocumentTitle      = "My awesome Document";
            sfi.Type               = type;
            sfi.TotalPages         = 341;
            sfi.Copies             = 3;
            sfi.UserTokenEvaluated = true;

            var userToken = new UserToken();

            userToken.AddKeyValuePair("testkey", "test value");
            sfi.UserToken = userToken;

            return(sfi);
        }
        private SourceFileInfo BuildSourceFileInfo(JobType type)
        {
            var userToken = new UserToken();

            userToken.AddKeyValuePair("testkey", "test value");

            _fixture.Freeze(userToken);

            return(_fixture.Create <SourceFileInfo>());
        }
Ejemplo n.º 4
0
        public void UserToken_Merge_MergeWithSameKeysContainsOlderKey()
        {
            var userToken1 = new UserToken();

            userToken1.AddKeyValuePair("samekey", "value old");
            var userToken2 = new UserToken();

            userToken2.AddKeyValuePair("samekey", "value new");

            userToken1.Merge(userToken2);

            Assert.AreEqual("value old", userToken1.KeyValueDict["samekey"]);
        }
Ejemplo n.º 5
0
        public void UserToken_Merge_MergedUserTokenContainsKeysAndValuesOfBothDicts()
        {
            var userToken1 = new UserToken();

            userToken1.AddKeyValuePair("key1", "value1");
            var userToken2 = new UserToken();

            userToken2.AddKeyValuePair("key2", "value2");

            userToken1.Merge(userToken2);

            Assert.AreEqual(2, userToken1.KeyValueDict.Count);
            Assert.AreEqual("value1", userToken1.KeyValueDict["key1"]);
            Assert.AreEqual("value2", userToken1.KeyValueDict["key2"]);
        }
Ejemplo n.º 6
0
        private TokenReplacer CreateTokenReplacerWithPlaceHolders()
        {
            var tr = new TokenReplacer();

            tr.AddToken(new StringToken("Author", Environment.UserName));
            tr.AddToken(new StringToken("PrintJobAuthor", Environment.UserName));
            tr.AddToken(new StringToken("ClientComputer", Environment.MachineName));
            tr.AddToken(new StringToken("ComputerName", Environment.MachineName));
            tr.AddToken(new NumberToken("Counter", 1234));
            tr.AddToken(new DateToken("DateTime", DateTime.Now));
            tr.AddToken(new StringToken("InputFilename", _translation.MyFileDocx));
            tr.AddToken(new StringToken("InputFilePath", @"C:\Temp"));
            tr.AddToken(new NumberToken("JobID", 1));
            tr.AddToken(new NumberToken("NumberOfCopies", 1));
            tr.AddToken(new NumberToken("NumberOfPages", 1));
            tr.AddToken(new ListToken("OutputFilenames",
                                      new[]
            {
                _translation.OutputFilename
                , _translation.OutputFilename2
                , _translation.OutputFilename3
            }));
            tr.AddToken(new StringToken("OutputFilePath", @"C:\Temp"));
            tr.AddToken(new StringToken("PrinterName", "PDFCreator"));
            tr.AddToken(new NumberToken("SessionID", 0));
            tr.AddToken(new StringToken("Title", _translation.TitleFromSettings));
            tr.AddToken(new StringToken("PrintJobName", _translation.TitleFromPrintJob));
            tr.AddToken(new StringToken("Username", Environment.UserName));
            tr.AddToken(new StringToken("Subject", _translation.SubjectFromSettings));
            tr.AddToken(new StringToken("Keywords", _translation.KeywordsFromSettings));
            tr.AddToken(new StringToken("DropboxHtmlLinks", "<a href=\"https://dropbox.com/link1\">File.pdf</a>"));
            tr.AddToken(new StringToken("DropboxFullLinks", "File.pdf ( https://dropbox.com/link1 )"));
            tr.AddToken(new EnvironmentToken());

            var userToken = new UserToken();

            userToken.AddKeyValuePair(UserTokenKey, "Value from UserToken");
            tr.AddToken(userToken);

            return(tr);
        }
Ejemplo n.º 7
0
        public UserToken ExtractUserTokenFromPsFile(string psFile, UserTokenSeperator seperator)
        {
            var psParser = BuildPsParser(psFile, seperator);

            psParser.Analyse();
            psParser.RemoveParameterLinesFromPSFile();
            psParser.CloseStream();

            var userToken = new UserToken();

            if (psParser.UserTokens == null)
            {
                return(userToken);
            }

            foreach (var ut in psParser.UserTokens)
            {
                userToken.AddKeyValuePair(ut.Key, ut.Value);
            }

            return(userToken);
        }