private static IEnumerable GetSupportedTypes(XmlDocument type, DocLoader loader)
        {
            yield return("System.Object");

            yield return(GetEscapedPath(type, "Type/@FullName"));

            Hashtable h = new Hashtable();

            GetInterfaces(h, type, loader);

            string s = GetEscapedPath(type, "Type/Base/BaseTypeName");

            if (s != null)
            {
                yield return(s);

                XmlDocument d;
                string      p = s;
                while (s != null && (d = loader(s)) != null)
                {
                    GetInterfaces(h, d, loader);
                    s = GetEscapedPath(d, "Type/Base/BaseTypeName");
                    if (p == s)
                    {
                        break;
                    }
                    yield return(s);
                }
            }

            foreach (object o in h.Keys)
            {
                yield return(o.ToString());
            }
        }
예제 #2
0
        private static DocLoader CreateDocLoader(XmlDocument overview)
        {
            Hashtable docs   = new Hashtable();
            DocLoader loader = delegate(string s) {
                XmlDocument d = null;
                if (!docs.ContainsKey(s))
                {
                    foreach (XmlNode n in overview.SelectNodes("//Type"))
                    {
                        string ns = n.ParentNode.Attributes ["Name"].Value;
                        string t  = n.Attributes ["Name"].Value;
                        string sd = n.Attributes ["SourceDirectory"].Value;
                        if (s == ns + "." + t.Replace("+", "."))
                        {
                            string f = CombinePath(sd, ns, t + ".xml");
                            if (File.Exists(f))
                            {
                                d = new XmlDocument();
                                d.Load(f);
                            }
                            docs.Add(s, d);
                            break;
                        }
                    }
                }
                else
                {
                    d = (XmlDocument)docs [s];
                }
                return(d);
            };

            return(loader);
        }
        public void CanTestFlatFileAssembling()
        {
            Stream input  = DocLoader.LoadStream("CSV_XML_SendInput.xml");
            Stream output = SchemaTester <Schema3_FF> .AssembleFF(input);

            String text = new StreamReader(output).ReadToEnd();

            Assert.IsTrue(text.Contains(","), "Output contains no commas");
        }
        public void CanTestFlatFileParsing()
        {
            Stream input  = DocLoader.LoadStream("CSV_FF_RecvInput.txt");
            Stream output = SchemaTester <Schema3_FF> .ParseFF(input);

            try {
                XmlDocument doc = new XmlDocument();
                doc.Load(output);
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
            }
        }
        public void CanTestXmlParsing()
        {
            Stream input  = DocLoader.LoadStream("SampleDocument.xml");
            Stream output = SchemaTester <Schema2_WPP> .ParseXml(input);

            try {
                XmlDocument doc = new XmlDocument();
                doc.Load(output);
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
            }
        }
        public void CanGetErrorInfoWhenFFParsingFails()
        {
            Stream input = DocLoader.LoadStream("CSV_FF_RecvInput_Bad.txt");

            try {
                Stream output = SchemaTester <Schema3_FF> .ParseFF(input);

                MessageHelper.ConsumeStream(output);
            } catch (Exception ex) {
                String msg = ErrorHelper.GetErrorMessage(ex);
                Assert.That(msg, new ContainsConstraint("Unexpected data"));
                return;
            }
            Assert.Fail("Parsing should've thrown an error");
        }
        public void CanGetErrorWhenXmlParsingFails()
        {
            Stream input = DocLoader.LoadStream("SampleDocument_Bad.xml");

            try {
                Stream output = SchemaTester <Schema2_WPP> .ParseXml(input);

                MessageHelper.ConsumeStream(output);
            } catch (Exception ex) {
                String msg = ErrorHelper.GetErrorMessage(ex);
                Assert.That(msg, new ContainsConstraint("incomplete content"));
                return;
            }
            Assert.Fail("Parsing should've thrown an error");
        }
예제 #8
0
        public void Receive_WithPromotedProps()
        {
            ReceivePipelineWrapper pipeline = Pipelines.Xml.Receive()
                                              .WithSpec <Schema2_WPP>();

            IBaseMessage input = MessageHelper.CreateFromStream(
                DocLoader.LoadStream("SampleDocument.xml")
                );
            MessageCollection output = pipeline.Execute(input);

            Property2 prop  = new Property2();
            object    value = output[0].Context.Read(prop.QName.Name, prop.QName.Namespace);

            Assert.AreEqual("Field2_0", value);
        }
예제 #9
0
        public void Receive_FullPipeline()
        {
            FFDisassembler ff = Disassembler.FlatFile()
                                .WithDocumentSpec <Schema3_FF>();
            ReceivePipelineWrapper pipeline = Pipelines.Receive()
                                              .WithDisassembler(ff);

            IBaseMessage input = MessageHelper.CreateFromStream(
                DocLoader.LoadStream("CSV_FF_RecvInput.txt")
                );

            MessageCollection output = pipeline.Execute(input);

            Assert.AreEqual(1, output.Count);
        }
예제 #10
0
 private static void GetInterfaces(Hashtable ifaces, XmlDocument doc, DocLoader loader)
 {
     foreach (XmlNode n in doc.SelectNodes("Type/Interfaces/Interface/InterfaceName"))
     {
         string t  = ToEscapedTypeName(n.InnerText);
         string tk = "T:" + t;
         if (!ifaces.ContainsKey(tk))
         {
             ifaces.Add(tk, null);
             XmlDocument d = loader(t);
             if (d != null)
             {
                 GetInterfaces(ifaces, d, loader);
             }
         }
     }
 }
예제 #11
0
        public void CanReadXmlAssemblerStream()
        {
            SendPipelineWrapper pipeline = Pipelines.Xml.Send()
                                           .WithSpec <Schema3_FF>();
            IBaseMessage input = MessageHelper.CreateFromStream(
                DocLoader.LoadStream("CSV_XML_SendInput.xml")
                );
            IBaseMessage output = pipeline.Execute(input);

            Assert.IsNotNull(output);
            // doc should load fine
            XmlDocument doc = new XmlDocument();

            doc.Load(output.BodyPart.Data);
            XmlNodeList fields = doc.SelectNodes("//*[local-name()='Field3']");

            Assert.Greater(fields.Count, 0);
        }
예제 #12
0
 private static void GetInterfaces(Hashtable ifaces, XmlDocument doc, DocLoader loader)
 {
     foreach (XmlNode n in doc.SelectNodes("Type/Interfaces/Interface/InterfaceName"))
     {
         string t  = ToEscapedTypeName(n.InnerText);
         string tk = "T:" + t;
         if (!ifaces.ContainsKey(tk))
         {
             ifaces.Add(tk, null);
             try {
                 XmlDocument d = loader(t);
                 if (d != null)
                 {
                     GetInterfaces(ifaces, d, loader);
                 }
             }
             catch (FileNotFoundException e) {
                 // ignore; interface documentation couldn't be found.
             }
         }
     }
 }
예제 #13
0
        public void CanApplyConfigToPipeline()
        {
            XmlTextReader reader = new XmlTextReader(
                DocLoader.LoadStream("PipelineInstanceConfig.xml")
                );
            SendPipelineWrapper pipeline = Pipelines.Xml.Send()
                                           .WithAssembler(Assembler.Xml())
                                           .WithEncoder(new MIME_SMIME_Encoder())
                                           .WithInstanceConfig(reader);

            XmlAsmComp xmlassm = (XmlAsmComp)
                                 pipeline.GetComponent(PipelineStage.Assemble, 0);

            Assert.IsFalse(xmlassm.AddXMLDeclaration);
            Assert.IsFalse(xmlassm.PreserveBom);

            MIME_SMIME_Encoder enc = (MIME_SMIME_Encoder)
                                     pipeline.GetComponent(PipelineStage.Encode, 0);

            Assert.IsTrue(enc.EnableEncryption);
            Assert.AreEqual(MIME_SMIME_Encoder.MIMETransferEncodingType.SevenBit,
                            enc.ContentTransferEncoding);
        }
예제 #14
0
        void ProcessDirectories(List <string> sourceDirectories)
        {
            if (sourceDirectories.Count == 0 || opts.dest == null || opts.dest == "")
            {
                throw new ApplicationException("The source and dest options must be specified.");
            }

            Directory.CreateDirectory(opts.dest);

            // Load the stylesheets, overview.xml, and resolver

            XslCompiledTransform overviewxsl = LoadTransform("overview.xsl", sourceDirectories);
            XslCompiledTransform stylesheet  = LoadTransform("stylesheet.xsl", sourceDirectories);
            XslCompiledTransform template;

            if (opts.template == null)
            {
                template = LoadTransform("defaulttemplate.xsl", sourceDirectories);
            }
            else
            {
                try {
                    XmlDocument templatexsl = new XmlDocument();
                    templatexsl.Load(opts.template);
                    template = new XslCompiledTransform(DebugOutput);
                    template.Load(templatexsl);
                } catch (Exception e) {
                    throw new ApplicationException("There was an error loading " + opts.template, e);
                }
            }

            XmlDocument overview = GetOverview(sourceDirectories);

            ArrayList extensions = GetExtensionMethods(overview);

            // Create the master page
            XsltArgumentList overviewargs = new XsltArgumentList();

            overviewargs.AddParam("Index", "", overview.CreateNavigator());

            var regenIndex = ShouldRegenIndexes(opts, overview, sourceDirectories);

            if (regenIndex)
            {
                overviewargs.AddParam("ext", "", opts.ext);
                overviewargs.AddParam("basepath", "", "./");
                Generate(overview, overviewxsl, overviewargs, opts.dest + "/index." + opts.ext, template, sourceDirectories);
                overviewargs.RemoveParam("basepath", "");
            }
            overviewargs.AddParam("basepath", "", "../");

            // Create the namespace & type pages

            XsltArgumentList typeargs = new XsltArgumentList();

            typeargs.AddParam("ext", "", opts.ext);
            typeargs.AddParam("basepath", "", "../");
            typeargs.AddParam("Index", "", overview.CreateNavigator());

            foreach (XmlElement ns in overview.SelectNodes("Overview/Types/Namespace"))
            {
                string nsname = ns.GetAttribute("Name");

                if (opts.onlytype != null && !opts.onlytype.StartsWith(nsname + "."))
                {
                    continue;
                }

                System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(opts.dest + "/" + nsname);
                if (!d.Exists)
                {
                    d.Create();
                }

                // Create the NS page
                string nsDest = opts.dest + "/" + nsname + "/index." + opts.ext;
                if (regenIndex)
                {
                    overviewargs.AddParam("namespace", "", nsname);
                    Generate(overview, overviewxsl, overviewargs, nsDest, template, sourceDirectories);
                    overviewargs.RemoveParam("namespace", "");
                }

                foreach (XmlElement ty in ns.SelectNodes("Type"))
                {
                    string typename, typefile, destfile;
                    GetTypePaths(opts, ty, out typename, out typefile, out destfile);

                    if (DestinationIsNewer(typefile, destfile))
                    {
                        // target already exists, and is newer.  why regenerate?
                        continue;
                    }

                    XmlDocument typexml = new XmlDocument();
                    typexml.Load(typefile);
                    PreserveMembersInVersions(typexml);
                    if (extensions != null)
                    {
                        DocLoader loader = CreateDocLoader(overview);
                        XmlDocUtils.AddExtensionMethods(typexml, extensions, loader);
                    }

                    Console.WriteLine(nsname + "." + typename);

                    Generate(typexml, stylesheet, typeargs, destfile, template, sourceDirectories);
                }
            }
        }
 private string SaveToTemp(String res)
 {
     DocLoader.ExtractToDir(res, Path.GetTempPath());
     return(Path.Combine(Path.GetTempPath(), res));
 }
        public static void AddExtensionMethods(XmlDocument typexml, ArrayList /*<XmlNode>*/ extensions, DocLoader loader)
        {
            // if no members (enum, delegate) don't add extensions
            XmlNode m = typexml.SelectSingleNode("/Type/Members");

            if (m == null)
            {
                return;
            }

            // static classes can't be targets:
            if (typexml.SelectSingleNode(
                    "/Type/TypeSignature[@Language='C#']/@Value")
                .Value.IndexOf(" static ") >= 0)
            {
                return;
            }

            foreach (string s in GetSupportedTypes(typexml, loader))
            {
                foreach (XmlNode extension in extensions)
                {
                    bool add = false;
                    foreach (XmlNode target in extension.SelectNodes("Targets/Target"))
                    {
                        if (target.Attributes ["Type"].Value == s)
                        {
                            add = true;
                            break;
                        }
                    }
                    if (!add)
                    {
                        continue;
                    }
                    foreach (XmlNode c in extension.SelectNodes("Member"))
                    {
                        XmlNode cm = typexml.ImportNode(c, true);
                        m.AppendChild(cm);
                    }
                }
            }
        }
예제 #17
0
		public static void AddExtensionMethods (XmlDocument typexml, ArrayList/*<XmlNode>*/ extensions, DocLoader loader)
		{
			// if no members (enum, delegate) don't add extensions
			XmlNode m = typexml.SelectSingleNode ("/Type/Members");
			if (m == null)
				return;

			// static classes can't be targets:
			if (typexml.SelectSingleNode (
						"/Type/TypeSignature[@Language='C#']/@Value")
					.Value.IndexOf (" static ") >= 0)
				return;

			foreach (string s in GetSupportedTypes (typexml, loader)) {
				foreach (XmlNode extension in extensions) {
					bool add = false;
					foreach (XmlNode target in extension.SelectNodes ("Targets/Target")) {
						if (target.Attributes ["Type"].Value == s) {
							add = true;
							break;
						}
					}
					if (!add) {
						continue;
					}
					foreach (XmlNode c in extension.SelectNodes ("Member")) {
						XmlNode cm = typexml.ImportNode (c, true);
						m.AppendChild (cm);
					}
				}
			}
		}
예제 #18
0
		private static void GetInterfaces (Hashtable ifaces, XmlDocument doc, DocLoader loader)
		{
			foreach (XmlNode n in doc.SelectNodes ("Type/Interfaces/Interface/InterfaceName")) {
				string t = ToEscapedTypeName (n.InnerText);
				string tk = "T:" + t;
				if (!ifaces.ContainsKey (tk)) {
					ifaces.Add (tk, null);
					XmlDocument d = loader (t);
					if (d != null)
						GetInterfaces (ifaces, d, loader);
				}
			}
		}
예제 #19
0
		private static void GetInterfaces (Hashtable ifaces, XmlDocument doc, DocLoader loader)
		{
			foreach (XmlNode n in doc.SelectNodes ("Type/Interfaces/Interface/InterfaceName")) {
				string t = ToEscapedTypeName (n.InnerText);
				string tk = "T:" + t;
				if (!ifaces.ContainsKey (tk)) {
					ifaces.Add (tk, null);
					try {
						XmlDocument d = loader (t);
						if (d != null)
							GetInterfaces (ifaces, d, loader);
					}
					catch (FileNotFoundException e) {
						// ignore; interface documentation couldn't be found.
					}
				}
			}
		}
예제 #20
0
		private static IEnumerable GetSupportedTypes (XmlDocument type, DocLoader loader)
		{
			yield return "System.Object";
			yield return GetEscapedPath (type, "Type/@FullName");
			string s = GetEscapedPath (type, "Type/Base/BaseTypeName");
			if (s != null) {
				yield return s;
				XmlDocument d;
				string p = s;
				while ((d = loader (s)) != null) {
					s = GetEscapedPath (d, "Type/Base/BaseTypeName");
					if (p == s)
						break;
					yield return s;
				}
			}

			Hashtable h = new Hashtable ();
			GetInterfaces (h, type, loader);
			foreach (object o in h.Keys)
				yield return o.ToString ();
		}
예제 #21
0
    private static void Main2()
    {
        if (opts.dumptemplate)
        {
            DumpTemplate();
            return;
        }

        if (opts.source == null || opts.source == "" || opts.dest == null || opts.dest == "")
        {
            throw new ApplicationException("The source and dest options must be specified.");
        }

        Directory.CreateDirectory(opts.dest);

        // Load the stylesheets, overview.xml, and resolver

        XslTransform overviewxsl = LoadTransform("overview.xsl");
        XslTransform stylesheet  = LoadTransform("stylesheet.xsl");
        XslTransform template;

        if (opts.template == null)
        {
            template = LoadTransform("defaulttemplate.xsl");
        }
        else
        {
            try {
                XmlDocument templatexsl = new XmlDocument();
                templatexsl.Load(opts.template);
                template = new XslTransform();
                template.Load(templatexsl);
            } catch (Exception e) {
                throw new ApplicationException("There was an error loading " + opts.template, e);
            }
        }

        XmlDocument overview = new XmlDocument();

        overview.Load(opts.source + "/index.xml");

        ArrayList extensions = GetExtensionMethods(overview);

        // Create the master page
        XsltArgumentList overviewargs = new XsltArgumentList();

        overviewargs.AddParam("ext", "", opts.ext);
        overviewargs.AddParam("basepath", "", "./");
        Generate(overview, overviewxsl, overviewargs, opts.dest + "/index." + opts.ext, template);
        overviewargs.RemoveParam("basepath", "");
        overviewargs.AddParam("basepath", "", "../");

        // Create the namespace & type pages

        XsltArgumentList typeargs = new XsltArgumentList();

        typeargs.AddParam("ext", "", opts.ext);
        typeargs.AddParam("basepath", "", "../");

        foreach (XmlElement ns in overview.SelectNodes("Overview/Types/Namespace"))
        {
            string nsname = ns.GetAttribute("Name");

            if (opts.onlytype != null && !opts.onlytype.StartsWith(nsname + "."))
            {
                continue;
            }

            System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(opts.dest + "/" + nsname);
            if (!d.Exists)
            {
                d.Create();
            }

            // Create the NS page
            overviewargs.AddParam("namespace", "", nsname);
            Generate(overview, overviewxsl, overviewargs, opts.dest + "/" + nsname + "/index." + opts.ext, template);
            overviewargs.RemoveParam("namespace", "");

            foreach (XmlElement ty in ns.SelectNodes("Type"))
            {
                string typefilebase = ty.GetAttribute("Name");
                string typename     = ty.GetAttribute("DisplayName");
                if (typename.Length == 0)
                {
                    typename = typefilebase;
                }

                if (opts.onlytype != null && !(nsname + "." + typename).StartsWith(opts.onlytype))
                {
                    continue;
                }

                string typefile = opts.source + "/" + nsname + "/" + typefilebase + ".xml";
                if (!File.Exists(typefile))
                {
                    continue;
                }

                XmlDocument typexml = new XmlDocument();
                typexml.Load(typefile);
                if (extensions != null)
                {
                    DocLoader loader = CreateDocLoader(overview);
                    XmlDocUtils.AddExtensionMethods(typexml, extensions, loader);
                }

                Console.WriteLine(nsname + "." + typename);

                Generate(typexml, stylesheet, typeargs, opts.dest + "/" + nsname + "/" + typefilebase + "." + opts.ext, template);
            }
        }
    }