Beispiel #1
0
        public void TooLongStringsTest(string variable)
        {
            var    sb = new StringBuilder();
            string input;

            // Add some variables in the text to test a use case where we don't have only text
            if (!string.IsNullOrEmpty(variable))
            {
                sb.Append(variable);
            }

            sb.Append('a', 45000);

            // Add some variables in the text to test a use case where we don't have only text
            if (!string.IsNullOrEmpty(variable))
            {
                sb.Append(variable);
            }

            input = sb.ToString();
            IStore store = new SimpleStore();

            store["foo"] = "{foo}";
            var doc = new SimpleDocument(input);
            var res = doc.Render(store);

            Assert.AreEqual(input, res);
        }
 public void TestTemplateOneOf()
 {
     Random random = new Random();
     var document = new SimpleDocument("The letter is {OneOf(\"a\", \"b\", \"c\", \"d\", null)}.");
     var store = new BuiltinStore();
     store["OneOf"] = new NativeFunction((values) =>
     {
         return values[random.Next(values.Count)];
     });
     store["system"] = "Alrai";
     List<string> results = new List<string>();
     for (int i = 0; i < 1000; i++)
     {
         results.Add(document.Render(store));
     }
     Assert.IsTrue(results.Contains(@"The letter is a."));
     results.RemoveAll(result => result == @"The letter is a.");
     Assert.IsTrue(results.Contains(@"The letter is b."));
     results.RemoveAll(result => result == @"The letter is b.");
     Assert.IsTrue(results.Contains(@"The letter is c."));
     results.RemoveAll(result => result == @"The letter is c.");
     Assert.IsTrue(results.Contains(@"The letter is d."));
     results.RemoveAll(result => result == @"The letter is d.");
     Assert.IsTrue(results.Contains(@"The letter is ."));
     results.RemoveAll(result => result == @"The letter is .");
     Assert.IsTrue(results.Count == 0);
 }
Beispiel #3
0
        private IDocument CreateDocumentFromFile(string file)
        {
            string[] lines;
            try
            {
                lines = File.ReadAllLines(file);
            }
            catch (Exception ex)
            {
                Errors = string.Format("Error pre-parsing file: {0}.{1}{2}", file, Environment.NewLine, ex.Message);
                return(null);
            }

            StringBuilder text = new StringBuilder();

            foreach (string line in lines)
            {
                string textLine;
                if (line.Contains("@project"))
                {
                    textLine = line.Replace("@project", Name);
                }
                else
                {
                    textLine = line;
                }
                if (textLine.Contains("@machine"))
                {
                    foreach (BasicObjectsTree tree in Data.Trees)
                    {
                        text.AppendLine(textLine.Replace("@machine", tree.Name));
                    }
                }
                else
                {
                    text.AppendLine(textLine);
                }
            }
            IDocument document;

            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(text.ToString())))
            {
                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    try
                    {
                        document = new SimpleDocument(reader, pjSetting); // throws ParseException on error
                    }
                    catch (ParseException ex)
                    {
                        Errors      = string.Format("Error parsing {3}:\r\nLine {0}, pos {1}: {2}", ex.Line, ex.Column, ex.Message, file);
                        ErrorLine   = ex.Line;
                        ErrorColumn = ex.Column;
                        stream.Dispose();
                        return(null);
                    }
                }
            }
            return(document);
        }
Beispiel #4
0
        public void TextTooLong(string variable, int characters)
        {
            var    builder = new StringBuilder();
            var    store   = new SimpleStore();
            string input;

            // Add some variables in the text to test a use case where we don't have only text
            if (!string.IsNullOrEmpty(variable))
            {
                builder.Append(variable);
            }

            builder.Append('a', characters);

            // Add some variables in the text to test a use case where we don't have only text
            if (!string.IsNullOrEmpty(variable))
            {
                builder.Append(variable);
            }

            input = builder.ToString();

            store["foo"] = "{foo}";

            var document = new SimpleDocument(input);
            var output   = document.Render(store);

            Assert.AreEqual(input, output);
        }
Beispiel #5
0
        protected override async Task <List <string> > Deserialize(string obj)
        {
            var simpleDocument = new SimpleDocument <List <string> >(obj);
            var document       = (List <string>)simpleDocument.Document;

            return(await Task.FromResult(document));
        }
Beispiel #6
0
        public async Task Dispose_Blocks()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            SearchClient client = resources.GetSearchClient();

            SimpleDocument[] data = SimpleDocument.GetDocuments((int)(BatchSize * 1.5));

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender(
                                new SearchIndexingBufferedSenderOptions <SimpleDocument>()
            {
                AutoFlush = false
            });
            AssertNoFailures(indexer);
            ConcurrentDictionary <int, IndexDocumentsAction <SimpleDocument> > pending = TrackPending(indexer);

            await indexer.UploadDocumentsAsync(data);

            await DelayAsync(EventDelay, EventDelay);

            Assert.AreEqual(data.Length, pending.Count);

            await((IAsyncDisposable)indexer).DisposeAsync();
            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
        }
        public void TestTemplateOneOf()
        {
            Random random   = new Random();
            var    document = new SimpleDocument("The letter is {OneOf(\"a\", \"b\", \"c\", \"d\", null)}.");
            var    store    = new BuiltinStore();

            store["OneOf"] = new NativeFunction((values) =>
            {
                return(values[random.Next(values.Count)]);
            });
            store["system"] = "Alrai";
            List <string> results = new List <string>();

            for (int i = 0; i < 1000; i++)
            {
                results.Add(document.Render(store));
            }
            Assert.IsTrue(results.Contains(@"The letter is a."));
            results.RemoveAll(result => result == @"The letter is a.");
            Assert.IsTrue(results.Contains(@"The letter is b."));
            results.RemoveAll(result => result == @"The letter is b.");
            Assert.IsTrue(results.Contains(@"The letter is c."));
            results.RemoveAll(result => result == @"The letter is c.");
            Assert.IsTrue(results.Contains(@"The letter is d."));
            results.RemoveAll(result => result == @"The letter is d.");
            Assert.IsTrue(results.Contains(@"The letter is ."));
            results.RemoveAll(result => result == @"The letter is .");
            Assert.IsTrue(results.Count == 0);
        }
Beispiel #8
0
        private void buttonEvaluate_Click(object sender, EventArgs e)
        {
            SimpleDocument document;
            ISetting       setting;
            IStore         store;

            setting = this.SettingCreate();

            try
            {
                document = new SimpleDocument(this.textBoxInput.Text, setting);
                store    = new BuiltinStore();

                foreach (TreeNode root in this.treeViewValue.Nodes)
                {
                    foreach (KeyValuePair <Value, Value> pair in this.ValuesBuild(root.Nodes))
                    {
                        store.Set(pair.Key, pair.Value, StoreMode.Global);
                    }
                }

                this.DisplayText(document.Render(store));
            }
            catch (ParseException exception)
            {
                this.DisplayError(exception);
            }
        }
Beispiel #9
0
        private void buttonEvaluate_Click(object sender, EventArgs e)
        {
            SimpleDocument	document;
            ISetting		setting;
            IStore			store;

            setting = this.SettingCreate ();

            try
            {
                document = new SimpleDocument (this.textBoxInput.Text, setting);
                store = new BuiltinStore ();

                foreach (TreeNode root in this.treeViewValue.Nodes)
                {
                    foreach (KeyValuePair<Value, Value> pair in this.ValuesBuild (root.Nodes))
                        store.Set (pair.Key, pair.Value, StoreMode.Global);
                }

                this.DisplayText (document.Render (store));
            }
            catch (ParseException exception)
            {
                this.DisplayError (exception);
            }
        }
Beispiel #10
0
        public async Task AutoFlush_PartialBatch()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            SearchClient client = resources.GetSearchClient();

            SimpleDocument[] data = SimpleDocument.GetDocuments(BatchSize / 2);

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender(
                                new SearchIndexingBufferedSenderOptions <SimpleDocument>()
            {
                AutoFlushInterval = null
            });
            AssertNoFailures(indexer);
            await indexer.UploadDocumentsAsync(data);

            await DelayAsync(TimeSpan.FromSeconds(5), EventDelay);

            Assert.Zero((int)await resources.GetSearchClient().GetDocumentCountAsync());

            await indexer.FlushAsync();

            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
        }
Beispiel #11
0
        public async Task AutoFlush_MultipleBatches()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            SearchClient client = resources.GetSearchClient();

            SimpleDocument[] data = SimpleDocument.GetDocuments((int)(BatchSize * 3.5));

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender(
                                new SearchIndexingBufferedSenderOptions <SimpleDocument>()
            {
                AutoFlushInterval = null
            });
            AssertNoFailures(indexer);
            await indexer.UploadDocumentsAsync(data);

            await DelayAsync(TimeSpan.FromSeconds(10), EventDelay);
            await WaitForDocumentCountAsync(resources.GetSearchClient(), 3 *BatchSize, delay : TimeSpan.FromSeconds(5));

            // Check that we have the correct number of documents
            await indexer.FlushAsync();

            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
        }
        private static void AssertEqual(string expression, string expected)
        {
            IDocument document = new SimpleDocument("{eq(" + expression + ", " + expected + ")}");
            IStore    store    = new BuiltinStore();

            Assert.AreEqual("true", document.Render(store), "'{0}' doesn't evaluate to '{1}'", expression, expected);
        }
Beispiel #13
0
        public async Task KeyFieldAccessor_Custom()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            SearchClient client = resources.GetSearchClient();

            SimpleDocument[] data = SimpleDocument.GetDocuments(10);

            bool customAccessorInvoked = false;

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender <SimpleDocument>(
                                new SearchIndexingBufferedSenderOptions <SimpleDocument>
            {
                KeyFieldAccessor = (SimpleDocument doc) =>
                {
                    customAccessorInvoked = true;
                    return(doc.Id);
                }
            });
            AssertNoFailures(indexer);
            await indexer.UploadDocumentsAsync(data);

            await indexer.FlushAsync();

            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);

            Assert.IsTrue(customAccessorInvoked);
        }
Beispiel #14
0
        public async Task Champion_ContinueAddingWhileSending()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            SearchClient client = resources.GetSearchClient();

            SimpleDocument[] data = SimpleDocument.GetDocuments(1000);

            // Wrap in a block so we DisposeAsync before getting the Count below
            {
                await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                                client.CreateIndexingBufferedSender <SimpleDocument>();
                AssertNoFailures(indexer);

                // Trickle documents in
                for (int i = 0; i < data.Length; i++)
                {
                    await indexer.UploadDocumentsAsync(new[] { data[i] });
                    await DelayAsync(TimeSpan.FromMilliseconds(5));
                }
            }

            // Check that we have the correct number of documents
            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
        }
Beispiel #15
0
        public async Task Behavior_Retry(int status)
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            BatchingSearchClient client = GetBatchingSearchClient(resources);

            SimpleDocument[] data = SimpleDocument.GetDocuments(1);

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender <SimpleDocument>();
            client.ResponseTransformer = (IndexingResult result) =>
            {
                client.ResponseTransformer = null;
                return(new IndexingResult(result.Key, false, status));
            };
            AssertNoFailures(indexer);
            int sent = 0;

            indexer.ActionSentAsync += (a, c) => { sent++; return(Task.CompletedTask); };
            await indexer.UploadDocumentsAsync(data);

            await indexer.FlushAsync();

            Assert.Less(1, sent);
        }
        private static void AssertPrint(string expression, string expected)
        {
            IDocument document = new SimpleDocument("{echo " + expression + "}");
            IStore    store    = new BuiltinStore();

            Assert.AreEqual(expected, document.Render(store), "'{0}' doesn't render to '{1}'", expression, expected);
        }
        protected override string Serialize(Token accessToken)
        {
            var tokenHandle = accessToken.ToTokenHandle();
            var document    = new SimpleDocument <TokenHandle>(tokenHandle).DocumentJson;

            return(document);
        }
Beispiel #18
0
        public async Task AutoFlushInterval_FullBatch()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            BatchingSearchClient client = GetBatchingSearchClient(resources);

            SimpleDocument[] data = SimpleDocument.GetDocuments((int)(BatchSize * 1.5));

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender(
                                new SearchIndexingBufferedSenderOptions <SimpleDocument>
            {
                AutoFlushInterval = TimeSpan.FromMilliseconds(500)
            });
            AssertNoFailures(indexer);
            ConcurrentDictionary <int, IndexDocumentsAction <SimpleDocument> > pending = TrackPending(indexer);

            Task <object> submitted = client.BatchSubmitted;
            await indexer.UploadDocumentsAsync(data);

            await submitted;

            await DelayAsync(EventDelay, EventDelay);

            Assert.AreEqual(data.Length - BatchSize, pending.Count);

            await DelayAsync(TimeSpan.FromSeconds(5), EventDelay);
            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
        }
Beispiel #19
0
        public virtual string GetHtml()
        {
            if (HtmlTemplate == null)
            {
                return(null);
            }

            var document = new SimpleDocument(HtmlTemplate);
            var store    = new BuiltinStore();

            foreach (var prop in TemplateModel.GetType().GetProperties())
            {
                store[prop.Name] = prop.GetValue(TemplateModel).ToString();
            }

            var body         = document.Render(store);
            var baseDocument = new SimpleDocument(BaseHtmlTemplate);

            store = new BuiltinStore
            {
                ["Body"] = body
            };
            var result = baseDocument.Render(store);

            return(result);
        }
        private static void AssertResult(string expression, bool expected)
        {
            IDocument document = new SimpleDocument("{" + (expected ? "" : "!") + "(" + expression + ")}");
            IStore    store    = new BuiltinStore();

            Assert.AreEqual("true", document.Render(store));
        }
Beispiel #21
0
        private IDocument CreateDocument(string templateText, RenderingContext context)
        {
            // Render cottle
            IDocument document;

            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(templateText)))
            {
                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    try
                    {
                        document = new SimpleDocument(reader, pjSetting); // throws ParseException on error
                    }
                    catch (ParseException ex)
                    {
                        Errors      = string.Format("Error parsing:\r\nLine {0}, pos {1}: {2}", ex.Line, ex.Column, ex.Message);
                        ErrorLine   = ex.Line;
                        ErrorColumn = ex.Column;
                        stream.Dispose();
                        return(null);
                    }
                }
            }
            return(document);
        }
Beispiel #22
0
        public override string ProcessData(string data)
        {
            string         targetFileName = base.GetParam((int)ConfigurationEnum.DestinationPath).Value;
            XDocument      xdoc           = null;
            string         serializedDoc  = null;
            SimpleDocument doc            = null;

            try
            {
                xdoc = XDocument.Parse(data);

                List <XNode> list = new List <XNode>(xdoc.Root.Nodes());

                Predicate <XNode> titleFinder = (XNode p) => { return(((System.Xml.Linq.XElement)p).Name == "title"); };
                Predicate <XNode> textFinder  = (XNode p) => { return(((System.Xml.Linq.XElement)p).Name == "text"); };

                if (!(list.Exists(titleFinder) && list.Exists(textFinder)))
                {
                    throw new ParseDataExceptionJW(new Exception("JsonWriterProvider: node 'title'or node 'text'  not exists."));
                }

                doc = new SimpleDocument
                {
                    Title = xdoc.Root.Element("title").Value,
                    Text  = xdoc.Root.Element("text").Value
                };
            }
            catch (Exception ex)
            {
                throw new ParseDataExceptionJW(ex);
            }


            try
            {
                serializedDoc = JsonConvert.SerializeObject(doc);
            }
            catch (Exception ex)
            {
                throw new SerializeExceptionJW(ex);
            }

            try
            {
                using (var targetStream = File.Open(targetFileName, FileMode.Create, FileAccess.Write))
                {
                    var sw = new StreamWriter(targetStream);
                    sw.Write(serializedDoc);
                    sw.Flush();
                }
            }
            catch (Exception ex)
            {
                throw new StreamExceptionJW(ex);
            }

            return(string.Empty);
            //            sw.Write(serializedDoc);
        }
        public override IEnumerable <string> DeserializeScopes(string obj)
        {
            obj = string.IsNullOrEmpty(obj) ? "[]" : obj;
            var simpleDocument = new SimpleDocument <List <string> >(obj);
            var document       = (List <string>)simpleDocument.Document;

            return(document);
        }
 public void TestTemplateSimple()
 {
     var document = new SimpleDocument(@"Hello {name}!");
     var store = new BuiltinStore();
     store["name"] = "world";
     var result = document.Render(store);
     Assert.AreEqual("Hello world!", result);
 }
Beispiel #25
0
        public override async Task <List <Secret> > DeserializeSecretsAsync(string obj)
        {
            obj = string.IsNullOrEmpty(obj) ? "[]" : obj;
            var simpleDocument = new SimpleDocument <List <Secret> >(obj);
            var document       = (List <Secret>)simpleDocument.Document;

            return(await Task.FromResult(document));
        }
        public override async Task <Token> DeserializeTokenHandleAsync(string obj, IClientStore clientStore)
        {
            var simpleDocument = new SimpleDocument <TokenHandle>(obj);
            var document       = (TokenHandle)simpleDocument.Document;
            var result         = await document.MakeIdentityServerTokenAsync(clientStore);

            return(result);
        }
Beispiel #27
0
        public async Task Champion_BasicCheckpointing()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            SearchClient client = resources.GetSearchClient();

            SimpleDocument[] data = SimpleDocument.GetDocuments(1000);

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender(
                                new SearchIndexingBufferedSenderOptions <SimpleDocument>
            {
                AutoFlush         = true,
                AutoFlushInterval = null
            });

            List <IndexDocumentsAction <SimpleDocument> > pending = new List <IndexDocumentsAction <SimpleDocument> >();

            indexer.ActionAddedAsync +=
                (IndexDocumentsAction <SimpleDocument> doc, CancellationToken cancellationToken) =>
            {
                pending.Add(doc);
                return(Task.CompletedTask);
            };
            indexer.ActionCompletedAsync +=
                (IndexDocumentsAction <SimpleDocument> doc,
                 IndexingResult result,
                 CancellationToken cancellationToken) =>
            {
                pending.Remove(doc);
                return(Task.CompletedTask);
            };
            indexer.ActionFailedAsync +=
                (IndexDocumentsAction <SimpleDocument> doc,
                 IndexingResult result,
                 Exception ex,
                 CancellationToken cancellationToken) =>
            {
                pending.Remove(doc);
                return(Task.CompletedTask);
            };

            await indexer.UploadDocumentsAsync(data.Take(500));

            await indexer.MergeDocumentsAsync(new[] { new SimpleDocument {
                                                          Id = "Fake"
                                                      } });

            await indexer.UploadDocumentsAsync(data.Skip(500));

            await DelayAsync(TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(250));

            Assert.AreEqual(1001 - BatchSize, pending.Count);

            await indexer.FlushAsync();

            Assert.AreEqual(0, pending.Count);
        }
Beispiel #28
0
        public override async Task <List <Claim> > DeserializeClaimsAsync(string obj)
        {
            obj = string.IsNullOrEmpty(obj) ? "[]" : obj;
            var simpleDocument = new SimpleDocument <List <ClaimTypeRecord> >(obj);
            var document       = (List <ClaimTypeRecord>)simpleDocument.Document;
            var result         = document.ToClaims();

            return(await Task.FromResult(result));
        }
        public override ClaimsPrincipal DeserializeSubject(string obj)
        {
            obj = string.IsNullOrEmpty(obj) ? "[]" : obj;
            var simpleDocument  = new SimpleDocument <List <ClaimIdentityRecord> >(obj);
            var document        = (List <ClaimIdentityRecord>)simpleDocument.Document;
            var claimsPrincipal = new ClaimsPrincipal();

            claimsPrincipal.AddIdentities(document.ToClaimsIdentitys());
            return(claimsPrincipal);
        }
        public override string Serialize(IEnumerable <string> scopes)
        {
            if (scopes == null)
            {
                return("[]");
            }
            var simpleDocument = new SimpleDocument <IEnumerable <string> >(scopes).DocumentJson;

            return(simpleDocument);
        }
        public void TestTemplateSimple()
        {
            var document = new SimpleDocument(@"Hello {name}!");
            var store    = new BuiltinStore();

            store["name"] = "world";
            var result = document.Render(store);

            Assert.AreEqual("Hello world!", result);
        }
        public override string SerializeClaimsIdentityRecords(List <ClaimIdentityRecord> claimIdentityRecords)
        {
            if (claimIdentityRecords == null)
            {
                return("[]");
            }
            var simpleDocument = new SimpleDocument <List <ClaimIdentityRecord> >(claimIdentityRecords).DocumentJson;

            return(simpleDocument);
        }
        public override string SerializeRequestScopes(List <string> scopeNames)
        {
            if (scopeNames == null)
            {
                return("[]");
            }
            var simpleDocument = new SimpleDocument <List <string> >(scopeNames).DocumentJson;

            return(simpleDocument);
        }
 public void TestTemplateFunctional()
 {
     var document = new SimpleDocument(@"You are entering the {System(system)} system.");
     var store = new BuiltinStore();
     store["System"] = new NativeFunction((values) =>
     {
         return Translations.StarSystem(values[0].AsString);
     }, 1);
     store["system"] = "Alrai";
     var result = document.Render(store);
     Assert.AreEqual("You are entering the <phoneme alphabet=\"ipa\" ph=\"ˈalraɪ\">Alrai</phoneme> system.", result);
 }
 public void TestTemplateConditional()
 {
     var document = new SimpleDocument("{if value = 1:foo|else:{if value = 2:bar|else:baz}}");
     var store = new BuiltinStore();
     store["value"] = 1;
     var result = document.Render(store);
     Assert.AreEqual("foo", result);
     store["value"] = 2;
     result = document.Render(store);
     Assert.AreEqual("bar", result);
     store["value"] = 3;
     result = document.Render(store);
     Assert.AreEqual("baz", result);
 }
 /// <summary>
 /// Resolve a script with an existing store
 /// </summary>
 public string resolveScript(string script, BuiltinStore store)
 {
     try
     {
         var document = new SimpleDocument(script, setting);
         var result = document.Render(store);
         Logging.Debug("Turned script " + script + " in to speech " + result);
         return result.Trim() == "" ? null : result.Trim();
     }
     catch (Exception e)
     {
         Logging.Warn("Failed to resolve script: " + e.ToString());
         return "There is a problem with the script: " + e.Message.Replace("'", "");
     }
 }
Beispiel #37
0
        private void buttonClean_Click(object sender, EventArgs e)
        {
            SimpleDocument	document;
            ISetting	    setting;

            setting = this.SettingCreate ();

            try
            {
                document = new SimpleDocument (this.textBoxInput.Text, setting);

                this.DisplayText (document.Source ());
            }
            catch (ParseException exception)
            {
                this.DisplayError (exception);
            }
        }
Beispiel #38
0
        private static void AssertEqual(string expression, string expected)
        {
            IDocument	document = new SimpleDocument ("{eq(" + expression + ", " + expected + ")}");
            IStore		store = new BuiltinStore ();

            Assert.AreEqual ("true", document.Render (store), "'{0}' doesn't evaluate to '{1}'", expression, expected);
        }
Beispiel #39
0
        private static void AssertPrint(string expression, string expected)
        {
            IDocument	document = new SimpleDocument ("{echo " + expression + "}");
            IStore		store = new BuiltinStore ();

            Assert.AreEqual (expected, document.Render (store), "'{0}' doesn't render to '{1}'", expression, expected);
        }
Beispiel #40
0
        public string CreateDocument()
        {
            IDocument document;
            IScope scope;

            using (StreamReader template = new StreamReader(new FileStream("template.html", FileMode.Open), Encoding.UTF8))
            {
                document = new SimpleDocument(template);
            }

            scope = new DefaultScope();

            scope["slideTitle"] = titleTextBox.Text;

            int numExts = extensionsListBox.SelectedItems.Count;

            var stylesheets = new Value[numExts];
            var scripts = new Value[numExts];
            var extSnippets = new Dictionary<Value, Value>();
            int i = 0;
            foreach (string extName in extensionsListBox.SelectedItems)
            {
                stylesheets[i] = extensions[extName] + ".css";
                scripts[i] = extensions[extName] + ".js";

                var snippetName = "deck." + extName;

                if (snippets.ContainsKey(snippetName))
                    extSnippets.Add(snippetName, snippets[snippetName]);

                i++;
            }

            scope["extensionStylesheets"] = stylesheets;
            scope["extensionScripts"] = scripts;
            scope["extensionSnippets"] = extSnippets;
            scope["styleTheme"] = styles[(string)stylesListBox.SelectedItem];
            scope["transitionTheme"] = transitions[(string)transitionsListBox.SelectedItem];

            return document.Render(scope);
        }
Beispiel #41
0
        private static void AssertResult(string expression, bool expected)
        {
            IDocument	document = new SimpleDocument ("{" + (expected ? "" : "!") + "(" + expression + ")}");
            IStore		store = new BuiltinStore ();

            Assert.AreEqual ("true", document.Render (store));
        }