/// <summary> /// Reads a URI. /// </summary> /// <param name="node">The node containing the URI.</param> /// <param name="table">The serialiser table.</param> /// <returns>A new instance of a <see cref="Uri"/> if the node is valid; null otherwise.</returns> public override object Read(XmlNode node, NetReflectorTypeTable table) { if (node == null) { // NetReflector should do this check, but doesn't if (this.Attribute.Required) { throw new NetReflectorItemRequiredException(Attribute.Name + " is required"); } else { return(null); } } Uri ret; if (node is XmlAttribute) { ret = new Uri(node.Value); } else { ret = new Uri(node.InnerText); } return(ret); }
public void ShouldUseInstantiatorThatHasBeenSet() { TestInstantiator instantiator = new TestInstantiator(); table = NetReflectorTypeTable.CreateDefault(instantiator); ReadTestHashClassContainingElements(); Assert.AreEqual(4, instantiator.instantiateCallCount); }
public void ShouldUseInstantiatorThatHasBeenSet() { TestInstantiator instantiator = new TestInstantiator(); table = NetReflectorTypeTable.CreateDefault(instantiator); ReadCollectionTestClass(); Assert.AreEqual(4, instantiator.instantiateCallCount); }
/// <summary> /// Reads the specified node. /// </summary> /// <param name="node">The node to read.</param> /// <param name="table">The underlying serialiser table.</param> /// <returns>The deserialised network credentials.</returns> public override object Read(XmlNode node, NetReflectorTypeTable table) { NetworkCredential ret = null; XmlElement elem = (XmlElement)node; if (elem != null) { if (!elem.HasAttribute("userName") || String.IsNullOrEmpty(elem.GetAttribute("userName").Trim())) { Log.Warning("No 'userName' specified!"); return(ret); } if (!elem.HasAttribute("password")) { Log.Warning("No 'password' specified!"); return(ret); } if (elem.HasAttribute("domain") && !String.IsNullOrEmpty(elem.GetAttribute("domain").Trim())) { ret = new NetworkCredential(elem.GetAttribute("userName").Trim(), elem.GetAttribute("password").Trim(), elem.GetAttribute("domain").Trim()); } else { ret = new NetworkCredential(elem.GetAttribute("userName").Trim(), elem.GetAttribute("password").Trim()); } } return(ret); }
public void AddAssemblyFromFilename() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add("NetReflectorPlugin.Test.dll"); Assert.AreEqual(1, table.Count); Assert.IsNotNull(table["plugin"], "Plugin type not found"); }
public override object Read(XmlNode node, NetReflectorTypeTable table) { IList <TqBinding> bindins = new List <TqBinding>(); var str = node.InnerText; if (!string.IsNullOrEmpty(str)) { string[] lines = str.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); var tqBindings = lines.Select(t => t.Split(':')) .Where(t => t.Length >= 3) .Select(t => new TqBinding { Ip = t[0].Trim(), Port = Convert.ToInt32(t[1].Trim()), Host = t[2].Trim(), SSL = t.Length == 4 ? t[3].Trim() : string.Empty }); tqBindings.ToList().ForEach(t => { bindins.Add(t); }); } return(bindins.ToArray()); }
public void ShouldGenerateASchemaToValidateTestSubClassXml() { NetReflectorTypeTable table = new NetReflectorTypeTable { typeof (TestClass), typeof (TestInnerClass), typeof (TestSubClass) }; XsdGenerator generator = new XsdGenerator(table); XmlSchema schema = generator.Generate(true); #if DEBUG schema.Write(Console.Out); #endif string xmlToValidate = TestClass.GetXmlWithSubClass(DateTime.Today); #if DEBUG Console.Out.WriteLine("xmlToValidate = {0}", xmlToValidate); #endif XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(new StringReader(xmlToValidate))); reader.Schemas.Add(schema); reader.ValidationType = ValidationType.Schema; while (reader.Read()) {} }
public void PreprocessParametersAddsDirectValueForValidDoublyNestedNodesDynamicValueWithoutDefaultWithComment() { var document = new XmlDocument(); var xml = "<item attrib=\"value\"><subItems><subItem><subSubItems><subSubItem><value>$[value]</value></subSubItem><!-- this is a comment --><subSubItem><value>$[value2]</value></subSubItem></subSubItems></subItem></subItems></item>"; document.LoadXml(xml); var task = new TestTask(); NetReflectorTypeTable typeTable = new NetReflectorTypeTable(); typeTable.Add(typeof(Item)); typeTable.Add(typeof(SubItem)); typeTable.Add(typeof(subSubItem)); var actual = task.PreprocessParameters(typeTable, document.DocumentElement); var expected = "<item attrib=\"value\"><subItems><subItem><subSubItems><subSubItem><value></value></subSubItem><!-- this is a comment --><subSubItem><value></value></subSubItem></subSubItems></subItem></subItems>" + "<dynamicValues>" + "<directValue>" + "<parameter>value</parameter>" + "<property>subItems[0].subSubItems[0].value</property>" + "</directValue>" + "<directValue>" + "<parameter>value2</parameter>" + "<property>subItems[0].subSubItems[1].value</property>" + "</directValue>" + "</dynamicValues></item>"; Assert.AreEqual(expected, actual.OuterXml); }
public override object Read(XmlNode node, NetReflectorTypeTable types) { var files = new List <BuildReportXslFilename>(); foreach (XmlNode fileNode in node.SelectNodes("xslFile")) { var newFile = new BuildReportXslFilename(); foreach (XmlNode childNode in fileNode.ChildNodes) { if (childNode.NodeType == XmlNodeType.Text) { newFile.Filename = childNode.InnerText.Trim(); } else if (childNode.LocalName == "includedProjects") { foreach (XmlNode projectNode in childNode.ChildNodes) { newFile.IncludedProjects.Add(projectNode.InnerText.Trim()); } } else if (childNode.LocalName == "excludedProjects") { foreach (XmlNode projectNode in childNode.ChildNodes) { newFile.ExcludedProjects.Add(projectNode.InnerText.Trim()); } } } files.Add(newFile); } return(files.ToArray()); }
/// <summary> /// Reads a URI. /// </summary> /// <param name="node">The node containing the URI.</param> /// <param name="table">The serialiser table.</param> /// <returns>A new instance of a <see cref="Uri"/> if the node is valid; null otherwise.</returns> public override object Read(XmlNode node, NetReflectorTypeTable table) { if (node == null) { // NetReflector should do this check, but doesn't if (this.Attribute.Required) { throw new NetReflectorItemRequiredException(Attribute.Name + " is required"); } else { return(null); } } // Get the actual private value PrivateString value; if (node is XmlAttribute) { value = node.Value; } else { value = node.InnerText; } return(value); }
private NetReflectorTypeTable NetReflectorTypeTable() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(Assembly.GetExecutingAssembly()); return(table); }
public void AddAllAssembliesInAppDomain() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(AppDomain.CurrentDomain); Assert.IsTrue(table.Count > 0); }
/// <summary> /// Initialise the security manager. /// </summary> public override void Initialise() { if (!isInitialised) { // Initialise the reader typeTable = new NetReflectorTypeTable(); typeTable.Add(AppDomain.CurrentDomain); typeTable.Add(Directory.GetCurrentDirectory(), CONFIG_ASSEMBLY_PATTERN); typeTable.InvalidNode += delegate(InvalidNodeEventArgs args) { throw new CruiseControlException(args.Message); }; reflectionReader = new NetReflectorReader(typeTable); // Initialise the local caches SessionCache.Initialise(); loadedUsers = new Dictionary <string, IAuthentication>(); wildCardUsers = new List <IAuthentication>(); loadedPermissions = new Dictionary <string, IPermission>(); // Load each file settingFileMap = new Dictionary <string, string>(); foreach (string fileName in files) { LoadFile(fileName); } } isInitialised = true; }
private static NetReflectorTypeTable MakeTypeTable() { NetReflectorTypeTable t = new NetReflectorTypeTable(); t.Add(typeof(WritingSystemCollection_V1)); t.Add(typeof(WritingSystem_V1)); return(t); }
public void AddAssemblyTwice() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(Assembly.GetExecutingAssembly()); table.Add(Assembly.GetExecutingAssembly()); Assert.AreEqual(NumberOfReflectorTypesInAssembly, table.Count); }
public NetReflectorConfigurationReader() { typeTable = new NetReflectorTypeTable(); typeTable.Add(AppDomain.CurrentDomain); typeTable.Add(Directory.GetCurrentDirectory(), CONFIG_ASSEMBLY_PATTERN); typeTable.InvalidNode += new InvalidNodeEventHandler(HandleUnusedNode); reader = new NetReflectorReader(typeTable); }
public void AddTypeToTypeTable() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(typeof (TestClass)); Assert.AreEqual(1, table.Count); Assert.AreEqual(typeof (TestClass), table["reflectTest"].Type); }
public void LoadReflectorTypesByFilenameFilter() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(Directory.GetCurrentDirectory(), "*Test.dll"); Assert.AreEqual(NumberOfReflectorTypesInAssembly + 1, table.Count); Assert.IsNotNull(table["plugin"], "Plugin type not found"); Assert.IsNotNull(table["array-test"], "Array-test type not found"); }
public void AddTypeToTypeTable() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(typeof(TestClass)); Assert.AreEqual(1, table.Count); Assert.AreEqual(typeof(TestClass), table["reflectTest"].Type); }
public void ShouldUseCustomInstantiatorIfUsed() { TestInstantiator instantiator = new TestInstantiator(); NetReflectorTypeTable table = new NetReflectorTypeTable(instantiator); table.Add(typeof(TestClass)); Assert.AreEqual(instantiator, ((XmlTypeSerialiser)table["reflectTest"]).Instantiator); }
private static NetReflectorTypeTable MakeTypeTable() { NetReflectorTypeTable t = new NetReflectorTypeTable(); t.Add(typeof(ViewTemplate)); t.Add(typeof(Field)); // t.Add(typeof(Field.WritingSystemId)); return(t); }
private static NetReflectorWriter NetReflectorWriter(XmlWriter writer) { NetReflectorTypeTable t = new NetReflectorTypeTable(); t.Add(typeof(WritingSystemCollection_V1)); t.Add(typeof(WritingSystem_V1)); return(new NetReflectorWriter(writer)); }
public override object Read(XmlNode node, NetReflectorTypeTable table) { Debug.Assert(node.Name == "writingSystems"); Debug.Assert(node != null); var l = new List<string>(); foreach (XmlNode n in node.SelectNodes("id")) { l.Add(n.InnerText); } return l; }
public override object Read(XmlNode node, NetReflectorTypeTable table) { if (node == null) { return(null); } else { return(JToken.Parse(node.InnerText)); } }
private NetReflectorTypeTable GetTypeTable() { NetReflectorTypeTable newTypeTable = NetReflectorTypeTable.CreateDefault(instantiator); // split the relative search path only by ';', thats also valid with Mono on Unix foreach (string searchPathDir in AppDomain.CurrentDomain.RelativeSearchPath.Split(';')) { newTypeTable.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, searchPathDir), CONFIG_ASSEMBLY_PATTERN); } newTypeTable.Add(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), CONFIG_ASSEMBLY_PATTERN); return(newTypeTable); }
public void ShouldProduceXmlDocumentationOfReflectorTypesButNotIncludeEmptyDescriptions() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(typeof (TestSubClass)); StringWriter writer = new StringWriter(); XmlDocumentationGenerator generator = new XmlDocumentationGenerator(table, new XmlMemberDocumentationGeneratorExtension()); generator.Write(writer); string expectedXml = @"<?xml version=""1.0"" encoding=""utf-16""?><netreflector><reflectortype><name>TestSubClass</name><namespace>Exortech.NetReflector.Test</namespace><reflectorName>sub</reflectorName></reflectortype></netreflector>"; Assert.AreEqual(expectedXml, writer.ToString()); }
public void DeserializeInventoryFromXmlString() { NetReflectorTypeTable t = new NetReflectorTypeTable(); t.Add(typeof(Field)); t.Add(typeof(ViewTemplate)); ViewTemplate f = new ViewTemplate(); f.LoadFromString(TestResources.viewTemplate); CheckInventoryMatchesDefinitionInResource(f); }
public void AddMismatchingTypes() { AssemblyBuilder tempAssembly = CreateTemporaryAssembly(); ModuleBuilder moduleBuilder = tempAssembly.DefineDynamicModule("tempModule"); CreateTypeWithReflectorTypeAttribute(moduleBuilder, "Foo", "foo"); CreateTypeWithReflectorTypeAttribute(moduleBuilder, "Bar", "bar"); NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(tempAssembly); }
/// <summary> /// Read a node. /// </summary> /// <param name="node"></param> /// <param name="table"></param> /// <returns></returns> public override object Read(XmlNode node, NetReflectorTypeTable table) { if (isList) { return(ReadList(node)); } else { var value = ReadValue(node as XmlElement); return(value); } }
/// <summary> /// Reads the specified node. /// </summary> /// <param name="node">The node.</param> /// <param name="types">The types.</param> /// <returns></returns> /// <remarks></remarks> public override object Read(XmlNode node, NetReflectorTypeTable types) { if (node == null) { // NetReflector should do this check, but doesn't if (this.Attribute.Required) { throw new NetReflectorItemRequiredException(Attribute.Name + " is required"); } else { return(null); } } Timeout timeout = Timeout.DefaultTimeout; XmlAttribute a = node as XmlAttribute; if (a != null) { try { timeout = new Timeout(Int32.Parse(a.Value, CultureInfo.CurrentCulture)); } catch (Exception) { Log.Warning("Could not parse timeout string. Using default timeout."); } } else { var e = node as XmlElement; if (e != null) { try { TimeUnits units = TimeUnits.MILLIS; string unitsString = e.GetAttribute("units"); if (unitsString != null && !(unitsString != null && unitsString.Length == 0)) { units = TimeUnits.Parse(unitsString); } timeout = new Timeout(Int32.Parse(e.InnerText, CultureInfo.CurrentCulture), units); } catch (Exception) { Log.Warning("Could not parse timeout string. Using default timeout."); } } } return(timeout); }
public override object Read(XmlNode node, NetReflectorTypeTable table) { Dictionary <string, string> dic = new Dictionary <string, string>(); if (node != null) { foreach (XmlNode child in node.ChildNodes) { dic[child.Name] = child.InnerText; } } return(dic); }
protected override void ExecuteTask() { Log(Level.Info, "Loading assembly {0}.", assembly); NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(assembly); Log(Level.Info, "Loaded {0} types.", table.Count); Log(Level.Info, "Generating documentation. The output will be written to {0}", outfile); using (StreamWriter writer = new StreamWriter(outfile)) { new XmlDocumentationGenerator(table).WriteIndented(writer); } }
public void AddAssemblyToTypeTable() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(Assembly.GetExecutingAssembly()); Assert.AreEqual(NumberOfReflectorTypesInAssembly, table.Count); Assert.AreEqual(typeof (TestClass), table["reflectTest"].Type); Assert.AreEqual(typeof (TestInnerClass), table["inner"].Type); Assert.AreEqual(typeof (TestSubClass), table["sub"].Type); Assert.AreEqual(typeof (ArrayTestClass), table["array-test"].Type); Assert.AreEqual(typeof (ElementTestClass), table["element"].Type); Assert.AreEqual(typeof (HashTestClass), table["hashtest"].Type); Assert.AreEqual(typeof (CollectionTestClass), table["collectiontest"].Type); }
public void LoadsFromXml() { NetReflectorTypeTable typeTable = new NetReflectorTypeTable(); typeTable.Add(AppDomain.CurrentDomain); NetReflectorReader reader = new NetReflectorReader(typeTable); object result = reader.Read("<fileBasedCache duration=\"5\" mode=\"Fixed\"/>"); Assert.IsInstanceOfType(typeof(FileBasedSessionCache), result); FileBasedSessionCache cache = result as FileBasedSessionCache; Assert.AreEqual(5, cache.Duration); Assert.AreEqual(SessionExpiryMode.Fixed, cache.ExpiryMode); }
public override object Read(XmlNode node, NetReflectorTypeTable table) { return 2; }
public XmlDocumentationGenerator(NetReflectorTypeTable table, XmlMemberDocumentationGenerator memberGenerator) { this.table = table; this.memberGenerator = memberGenerator; }
public XmlDocumentationGenerator(NetReflectorTypeTable table) : this(table, new XmlMemberDocumentationGenerator()) { }
protected void SetUp() { nodes = new ArrayList(); serialiser = new XmlTypeSerialiser(typeof(TestClass), ReflectorTypeAttribute.GetAttribute(typeof(TestClass))); table = NetReflectorTypeTable(); }
public object Read(XmlNode node, NetReflectorTypeTable table) { throw new NotImplementedException(); }
private NetReflectorTypeTable NetReflectorTypeTable() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(Assembly.GetExecutingAssembly()); return table; }
public void Setup() { table = NetReflectorTypeTable.CreateDefault(); }
public XsdGenerator(NetReflectorTypeTable table) { this.table = table; }
public void ShouldUseCustomInstantiatorIfUsed() { TestInstantiator instantiator = new TestInstantiator(); NetReflectorTypeTable table = new NetReflectorTypeTable(instantiator); table.Add(typeof (TestClass)); Assert.AreEqual(instantiator, ((XmlTypeSerialiser) table["reflectTest"]).Instantiator); }
public void LoadReflectorTypesByFilename_UnknownAssembly() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add("UnknownAssembly.Test.dll"); }