/// <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; }
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); }
private static NetReflectorTypeTable MakeTypeTable() { NetReflectorTypeTable t = new NetReflectorTypeTable(); t.Add(typeof(WritingSystemCollection_V1)); t.Add(typeof(WritingSystem_V1)); return(t); }
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 AddAssemblyTwice() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(Assembly.GetExecutingAssembly()); table.Add(Assembly.GetExecutingAssembly()); Assert.AreEqual(NumberOfReflectorTypesInAssembly, table.Count); }
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)); }
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 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 AddAssemblyFromFilename() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add("NetReflectorPlugin.Test.dll"); Assert.AreEqual(1, table.Count); Assert.IsNotNull(table["plugin"], "Plugin type not found"); }
public void AddAllAssembliesInAppDomain() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(AppDomain.CurrentDomain); Assert.IsTrue(table.Count > 0); }
private NetReflectorTypeTable NetReflectorTypeTable() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(Assembly.GetExecutingAssembly()); return(table); }
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 object Load(string xpath) { string dashboardConfig = ""; using (StreamReader sr = new StreamReader(CalculateDashboardConfigPath())) { dashboardConfig = sr.ReadToEnd(); } XmlNode node = XmlUtil.SelectNode(dashboardConfig, xpath); NetReflectorTypeTable typeTable = NetReflectorTypeTable.CreateDefault(instantiator); typeTable.Add(Path.GetDirectoryName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.RelativeSearchPath)), "ccnet.*.plugin.dll"); typeTable.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ccnet.*.plugin.dll"); return(NetReflector.Read(node, 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 ShouldGenerateASchemaToValidateTestClassXml() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(typeof(TestClass)); table.Add(typeof(TestInnerClass)); XsdGenerator generator = new XsdGenerator(table); XmlSchema schema = generator.Generate(true); // schema.Write(Console.Out); string xmlToValidate = TestClass.GetXml(DateTime.Today); // Console.Out.WriteLine("xmlToValidate = {0}", xmlToValidate); XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(new StringReader(xmlToValidate))); reader.Schemas.Add(schema); reader.ValidationType = ValidationType.Schema; while (reader.Read()) {} }
/// <summary> /// Initializes a new instance of the <see cref="NetReflectorConfigurationReader" /> class. /// </summary> /// <remarks></remarks> public NetReflectorConfigurationReader() { typeTable = new NetReflectorTypeTable(); typeTable.Add(AppDomain.CurrentDomain); string pluginLocation = ConfigurationManager.AppSettings["PluginLocation"]; if (!string.IsNullOrEmpty(pluginLocation)) { if (Directory.Exists(pluginLocation)) { typeTable.Add(pluginLocation, CONFIG_ASSEMBLY_PATTERN); } else { throw new CruiseControlException("Unable to find plugin directory: " + pluginLocation); } } typeTable.Add(Directory.GetCurrentDirectory(), CONFIG_ASSEMBLY_PATTERN); reader = new NetReflectorReader(typeTable); }
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); }
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()); }
private void InitialiseConfigReader() { myTypeTable = new NetReflectorTypeTable(); Assembly thisAssembly = typeof(IProject).Assembly; myTypeTable.Add(thisAssembly); foreach (AssemblyName referencedAssembly in thisAssembly.GetReferencedAssemblies()) { myTypeTable.Add(Assembly.Load(referencedAssembly)); } var pluginLocation = System.Configuration.ConfigurationManager.AppSettings["PluginLocation"]; if (!string.IsNullOrEmpty(pluginLocation)) { if (Directory.Exists(pluginLocation)) { myTypeTable.Add(pluginLocation, CONFIG_ASSEMBLY_PATTERN); } } try { myTypeTable.Add(Directory.GetCurrentDirectory(), CONFIG_ASSEMBLY_PATTERN); } catch (Exception error) { MessageBox.Show( "Unable to load one or more plug-ins: " + error.Message, "Plug-in Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } myTypeTable.InvalidNode += delegate(InvalidNodeEventArgs args) { throw new NetReflectorException(args.Message); }; myConfigReader = new NetReflectorReader(myTypeTable); }
public void PreprocessParametersAddsDirectValueForValidDoublyNestedDynamicValuesNodes() { var document = new XmlDocument(); var xml = "<item attrib=\"value\"><subItems><subItem><subSubItemsDV><subSubItemDV><prop>$[value]</prop></subSubItemDV><subSubItemDV><prop>$[value2]</prop></subSubItemDV></subSubItemsDV></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(SubItemDV)); typeTable.Add(typeof(subSubItemDV)); var actual = task.PreprocessParameters(typeTable, document.DocumentElement); var expected = "<item attrib=\"value\"><subItems><subItem><subSubItemsDV>" + "<subSubItemDV>" + "<prop></prop>" + "<dynamicValues>" + "<directValue>" + "<parameter>value</parameter>" + "<property>prop</property>" + "</directValue>" + "</dynamicValues>" + "</subSubItemDV>" + "<subSubItemDV>" + "<prop></prop>" + "<dynamicValues>" + "<directValue>" + "<parameter>value2</parameter>" + "<property>prop</property>" + "</directValue>" + "</dynamicValues>" + "</subSubItemDV>" + "</subSubItemsDV>" + "</subItem></subItems></item>"; Assert.AreEqual(expected, actual.OuterXml); }
public void ShouldGenerateASchemaToValidateTestClassXml() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(typeof(TestClass)); table.Add(typeof(TestInnerClass)); XsdGenerator generator = new XsdGenerator(table); XmlSchema schema = generator.Generate(true); // schema.Write(Console.Out); string xmlToValidate = TestClass.GetXml(DateTime.Today); // Console.Out.WriteLine("xmlToValidate = {0}", xmlToValidate); XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(new StringReader(xmlToValidate))); reader.Schemas.Add(schema); reader.ValidationType = ValidationType.Schema; while (reader.Read()) { } }
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 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 DeserializeOne_CustomSortRules_Before_SortUsing() { NetReflectorTypeTable t = new NetReflectorTypeTable(); t.Add(typeof(WritingSystem_V1)); NetReflectorReader r = new NetReflectorReader(t); WritingSystem_V1 ws = (WritingSystem_V1) r.Read( "<WritingSystem><CustomSortRules>test</CustomSortRules><SortUsing>CustomSimple</SortUsing><FontName>Tahoma</FontName><FontSize>99</FontSize><Id>one</Id></WritingSystem>"); Assert.IsNotNull(ws); Assert.AreEqual("test", ws.CustomSortRules); Assert.AreEqual(WritingSystem_V1.CustomSortRulesType.CustomSimple.ToString(), ws.SortUsing); }
public void LoadsFromXml() { NetReflectorTypeTable typeTable = new NetReflectorTypeTable(); typeTable.Add(AppDomain.CurrentDomain); NetReflectorReader reader = new NetReflectorReader(typeTable); object result = reader.Read("<inMemoryCache duration=\"5\" mode=\"Fixed\"/>"); Assert.That(result, Is.InstanceOf <InMemorySessionCache>()); InMemorySessionCache cache = result as InMemorySessionCache; Assert.AreEqual(5, cache.Duration); Assert.AreEqual(SessionExpiryMode.Fixed, cache.ExpiryMode); }
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 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 void DeserializeOne() { NetReflectorTypeTable t = new NetReflectorTypeTable(); t.Add(typeof(WritingSystem_V1)); NetReflectorReader r = new NetReflectorReader(t); WritingSystem_V1 ws = (WritingSystem_V1) r.Read( @"<WritingSystem> <Abbreviation>xx</Abbreviation> <CustomSortRules>B c d R</CustomSortRules> <FontName>Tahoma</FontName> <FontSize>99</FontSize> <Id>one</Id> <IsAudio>False</IsAudio> <IsUnicode>True</IsUnicode> <WindowsKeyman>IPA Unicode 5.1(ver 1.2 US) MSK</WindowsKeyman> <RightToLeft>False</RightToLeft> <SortUsing>one</SortUsing> <SpellCheckingId>xx</SpellCheckingId> </WritingSystem>"); // since Linux may not have Tahoma, we // need to test against the font mapping Font font = new Font("Tahoma", 99); Assert.IsNotNull(ws); Assert.AreEqual("xx", ws.Abbreviation); Assert.AreEqual("B c d R", ws.CustomSortRules); #if __MonoCS__ // Tahoma should not be available on Linux // Checking that what you asked for is in the ws // and what you get is the standard DejaVu Sans font Assert.AreEqual(font.OriginalFontName, ws.FontName); Assert.AreEqual(font.Name, "DejaVu Sans"); #else Assert.AreEqual(font.Name, ws.FontName); #endif Assert.AreEqual(font.Size, ws.FontSize); Assert.AreEqual("one", ws.ISO); Assert.AreEqual(false, ws.IsAudio); Assert.AreEqual(true, ws.IsUnicode); Assert.AreEqual("IPA Unicode 5.1(ver 1.2 US) MSK", ws.KeyboardName); Assert.AreEqual(false, ws.RightToLeft); Assert.AreEqual("one", ws.SortUsing); Assert.AreEqual("xx", ws.SpellCheckingId); }
public void CustomSortRules_SerializeAndDeserialize() { WritingSystem_V1 ws = new WritingSystem_V1("one", new Font("Arial", 99)); ws.SortUsing = WritingSystem_V1.CustomSortRulesType.CustomICU.ToString(); string rules = "&n < ng <<< Ng <<< NG"; ws.CustomSortRules = rules; string s = NetReflector.Write(ws); NetReflectorTypeTable t = new NetReflectorTypeTable(); t.Add(typeof(WritingSystem_V1)); NetReflectorReader r = new NetReflectorReader(t); WritingSystem_V1 wsRead = (WritingSystem_V1)r.Read(s); Assert.IsNotNull(wsRead); Assert.AreEqual(rules, ws.CustomSortRules); }
public void ShouldUseCustomInstantiatorIfUsed() { TestInstantiator instantiator = new TestInstantiator(); NetReflectorTypeTable table = new NetReflectorTypeTable(instantiator); table.Add(typeof (TestClass)); Assert.AreEqual(instantiator, ((XmlTypeSerialiser) table["reflectTest"]).Instantiator); }
private NetReflectorTypeTable NetReflectorTypeTable() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(Assembly.GetExecutingAssembly()); return table; }
public void LoadReflectorTypesByFilename_UnknownAssembly() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add("UnknownAssembly.Test.dll"); }