Exemple #1
0
 public SemanticError(string message, TreePathStreamedBlob item, int lineNumber, int linePosition)
     : base(message)
 {
     this.Item = item;
     this.LineNumber = lineNumber;
     this.LinePosition = linePosition;
 }
 public SemanticWarning(string message, TreePathStreamedBlob item, int lineNumber, int linePosition)
 {
     this.Message = message;
     this.Item = item;
     this.LineNumber = lineNumber;
     this.LinePosition = linePosition;
 }
Exemple #3
0
        public RenderState(RenderState copy, TreePathStreamedBlob item = null)
        {
            this.engine = copy.engine;

            this.item = item ?? copy.item;
            this.readFrom = copy.readFrom;
            this.writeTo = copy.writeTo;
            this.earlyExit = copy.earlyExit;
            this.processElements = copy.processElements;

            this.previous = copy;
        }
        public async Task<Errorable<TreePathStreamedBlob>[]> GetBlobsByTreePaths(params TreeBlobPath[] treePaths)
        {
#if false
            var blobs =
                from tp in treePaths
                let tr = await trrepo.GetTreeIDByPath(new TreeTreePath(tp.RootTreeID, tp.Path.Tree))
            // await operator cannot currently be used in query expressions.
#else
            // Estimated size:
            var blobs = new Errorable<TreePathStreamedBlob>[treePaths.Length];
            
            for (int i = 0; i < treePaths.Length; ++i)
            {
                var tp = treePaths[i];

                var etrm = await trrepo.GetTreeIDByPath(new TreeTreePath(tp.RootTreeID, tp.Path.Tree)).ConfigureAwait(continueOnCapturedContext: false);
                if (etrm.HasErrors) blobs[i] = etrm.Errors;

                var trm = etrm.Value;
                if (!trm.TreeID.HasValue)
                {
                    blobs[i] = null;
                    continue;
                }

                // Get the tree:
                var etr = await trrepo.GetTree(trm.TreeID.Value).ConfigureAwait(continueOnCapturedContext: false);
                if (etr.HasErrors) blobs[i] = etr.Errors;

                TreeNode tr = etr.Value;

                // Get the blob out of this tree:
                // TODO: standardize name comparison semantics:
                var trbl = tr.Blobs.SingleOrDefault(x => x.Name == tp.Path.Name);
                if (trbl == null)
                {
                    blobs[i] = null;
                    continue;
                }
                
                // Finally return the streamed blob:
                // TODO: unknown length of blob; is it a problem?
                blobs[i] = new TreePathStreamedBlob(tp, new StreamedBlob(blrepo, trbl.BlobID));
            }

            return blobs;
#endif
        }
Exemple #5
0
        protected void assertTranslated(TestContext tc, TreePathStreamedBlob item, string expected, params SemanticWarning[] expectedWarnings)
        {
            output(item);

            var fragTask = tc.ce.RenderBlob(item);
            fragTask.Wait();

            var efrag = fragTask.Result;
            Assert.IsFalse(efrag.HasErrors);

            var frag = efrag.Value;
            output(frag);

            var errors = tc.ce.GetErrors();
            if (errors.Count > 0)
            {
                Console.Error.WriteLine("Error(s):");
                foreach (var err in errors)
                {
                    Console.Error.WriteLine("  {0} ({1}:{2}): {3}", err.Item.TreeBlobPath.Path, err.LineNumber, err.LinePosition, err.Message);
                }
            }

            var warns = tc.ce.GetWarnings();
            if (warns.Count > 0)
            {
                Console.Error.WriteLine("Warning(s):");
                foreach (var warn in warns)
                {
                    Console.Error.WriteLine("  {0} ({1}:{2}): {3}", warn.Item.TreeBlobPath.Path, warn.LineNumber, warn.LinePosition, warn.Message);
                }
            }

            Assert.AreEqual(expected, (string)frag);

            Assert.AreEqual(expectedWarnings.Length, warns.Count);
            CollectionAssert.AreEqual(expectedWarnings, warns, new SemanticWarningMessageComparer());
        }
Exemple #6
0
        public RenderState(ContentEngine engine, TreePathStreamedBlob item, XmlTextReader readFrom = null, StringBuilder writeTo = null, Func<RenderState, bool> earlyExit = null, Func<RenderState, Task<Errorable<bool>>> processElements = null, RenderState previous = null)
        {
            this.engine = engine;

            this.item = item;
            this.readFrom = readFrom;
            this.writeTo = writeTo;
            this.earlyExit = earlyExit ?? DefaultEarlyExit;
            this.processElements = processElements ?? DefaultProcessElements;

            this.previous = previous;
        }
Exemple #7
0
 protected void assertTranslated(TestContext tc, IStreamedBlob bl, TreeID rootid, string expected, params SemanticWarning[] expectedWarnings)
 {
     var item = new TreePathStreamedBlob(rootid, (CanonicalBlobPath)"/test", bl);
     assertTranslated(tc, item, expected, expectedWarnings);
 }
Exemple #8
0
 protected void output(TreePathStreamedBlob item)
 {
     output((HtmlFragment)(item.TreeBlobPath.Path.ToString() + ":"));
     output((HtmlFragment)Encoding.UTF8.GetString(
         item.StreamedBlob.ReadStream( (Func<System.IO.Stream, Errorable<byte[]>>) (sr =>
         {
             byte[] tmp = new byte[sr.Length];
             sr.Read(tmp, 0, (int)sr.Length);
             return tmp;
         })).Value
     ));
     output((HtmlFragment)"-----------------------------------------");
 }
Exemple #9
0
 protected void assumeFail(TestContext tc, IStreamedBlob bl, TreeID rootid, IVO.CMS.SemanticError[] expectedErrors, SemanticWarning[] expectedWarnings)
 {
     var item = new TreePathStreamedBlob(rootid, (CanonicalBlobPath)"/test", bl);
     assumeFail(tc, item, expectedErrors, expectedWarnings);
 }