예제 #1
0
        /// <summary>
        /// Loads all the settings from a file.
        /// </summary>
        /// <param name="fileName"></param>
        private void LoadFile(string fileName)
        {
            XmlDocument sourceDocument = new XmlDocument();

            sourceDocument.Load(executionEnvironment.EnsurePathIsRooted(fileName));

            foreach (XmlElement setting in sourceDocument.DocumentElement.SelectNodes("*"))
            {
                object loadedItem = reflectionReader.Read(setting);

                IPermission permission = loadedItem as IPermission;
                if (permission != null)
                {
                    permission.Manager = this;
                    string identifier = permission.Identifier.ToLower(CultureInfo.InvariantCulture);
                    if (loadedPermissions.ContainsKey(identifier))
                    {
                        loadedPermissions.Remove(identifier);
                    }
                    loadedPermissions.Add(identifier, permission);
                    LinkIdentifierWithFile(fileName, identifier);
                }
                else
                {
                    IAuthentication authentication = loadedItem as IAuthentication;
                    if (authentication != null)
                    {
                        authentication.Manager = this;
                        string identifier = authentication.Identifier.ToLower(CultureInfo.InvariantCulture);
                        if (loadedUsers.ContainsKey(identifier))
                        {
                            loadedUsers.Remove(identifier);
                        }
                        if (authentication.Identifier.Contains("*"))
                        {
                            wildCardUsers.Add(authentication);
                        }
                        else
                        {
                            loadedUsers.Add(identifier, authentication);
                        }
                        LinkIdentifierWithFile(fileName, identifier);
                    }
                    else
                    {
                        throw new CruiseControlException("Unknown security item: " + setting.OuterXml);
                    }
                }
            }
        }
예제 #2
0
        public void LoadFromString(string xml)
        {
            NetReflectorReader r      = new NetReflectorReader(MakeTypeTable());
            XmlReader          reader = XmlReader.Create(new StringReader(xml));

            try
            {
                r.Read(reader, this);
            }
            finally
            {
                reader.Close();
            }
        }
예제 #3
0
        public void Load(string path)
        {
            NetReflectorReader r      = new NetReflectorReader(MakeTypeTable());
            XmlReader          reader = XmlReader.Create(path);

            try
            {
                r.Read(reader, this);
            }
            finally
            {
                reader.Close();
            }
        }
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
 public IConfiguration Read(XmlDocument document)
 {
     VerifyDocumentHasValidRootElement(document);
     try
     {
         Configuration configuration = new Configuration();
         foreach (XmlNode node in document.DocumentElement)
         {
             if (!(node is XmlComment))
             {
                 IProject project = reader.Read(node) as IProject;                               // could this be null?  should check
                 configuration.AddProject(project);
             }
         }
         return(configuration);
     }
     catch (NetReflectorException ex)
     {
         throw new ConfigurationException("Unable to instantiate CruiseControl projects from configuration document. " +
                                          "Configuration document is likely missing Xml nodes required for properly populating CruiseControl configuration." + ex.Message, ex);
     }
 }
예제 #10
0
 public void LoadFromLegacyWeSayFile(string PathToWritingSystemPrefsFile)
 {
     if (WeSayWritingSystemsPrefsExist(PathToWritingSystemPrefsFile))
     {
         NetReflectorReader r      = new NetReflectorReader(MakeTypeTable());
         XmlReader          reader = XmlReader.Create(PathToWritingSystemPrefsFile);
         var wesayWsFileCollection = new WritingSystemCollection_V1();
         try
         {
             r.Read(reader, wesayWsFileCollection);
         }
         finally
         {
             reader.Close();
         }
         foreach (KeyValuePair <string, WritingSystem_V1> pair in wesayWsFileCollection)
         {
             if (!ContainsKey(pair.Key))
             {
                 Add(pair.Key, pair.Value);
             }
         }
     }
 }
예제 #11
0
        private object ValidateElement(HtmlElement tableEl, XmlNode node, int row, Configuration configuration)
        {
            HtmlAttribute rowClass   = new HtmlAttribute("class", (row % 2) == 1 ? "even" : "odd");
            object        loadedItem = null;

            try
            {
                loadedItem = myConfigReader.Read(node);
                this.configurationHierarchy.Add(loadedItem);
                if (loadedItem is IProject)
                {
                    IProject project = loadedItem as IProject;
                    configuration.AddProject(project);
                    tableEl.AppendChild(
                        GenerateElement("tr",
                                        rowClass,
                                        GenerateElement("td", project.Name),
                                        GenerateElement("td", "Project"),
                                        GenerateElement("td", "Yes")));
                    LogMessage(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Loaded project '{0}'", project.Name));
                }
                else if (loadedItem is IQueueConfiguration)
                {
                    IQueueConfiguration queueConfig = loadedItem as IQueueConfiguration;
                    configuration.QueueConfigurations.Add(queueConfig);
                    tableEl.AppendChild(
                        GenerateElement("tr",
                                        rowClass,
                                        GenerateElement("td", queueConfig.Name),
                                        GenerateElement("td", "Queue"),
                                        GenerateElement("td", "Yes")));
                    LogMessage(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Loaded queue '{0}'", queueConfig.Name));
                }
                else if (loadedItem is ISecurityManager)
                {
                    ISecurityManager securityManager = loadedItem as ISecurityManager;
                    configuration.SecurityManager = securityManager as ISecurityManager;
                    LogMessage("Loaded security manager");
                }
                else
                {
                    tableEl.AppendChild(
                        GenerateElement("tr",
                                        rowClass,
                                        GenerateElement("td", (node as XmlElement).GetAttribute("name")),
                                        GenerateElement("td", node.Name),
                                        GenerateElement("td", "No")));
                    var message = "Unknown configuration type: " + loadedItem.GetType().Name;
                    tableEl.AppendChild(
                        GenerateElement("tr",
                                        rowClass,
                                        GenerateElement("td",
                                                        new HtmlAttribute("colspan", "3"),
                                                        GenerateElement("div",
                                                                        new HtmlAttribute("class", "error"),
                                                                        message))));
                    LogMessage(message);
                    isConfigValid = false;
                }
            }
            catch (Exception error)
            {
                string errorMsg = error.Message;
                int    index    = errorMsg.IndexOf("Xml Source");
                if (index >= 0)
                {
                    errorMsg = errorMsg.Substring(0, index - 1);
                }
                tableEl.AppendChild(
                    GenerateElement("tr",
                                    rowClass,
                                    GenerateElement("td", (node as XmlElement).GetAttribute("name")),
                                    GenerateElement("td", node.Name),
                                    GenerateElement("td", "No")));
                tableEl.AppendChild(
                    GenerateElement("tr",
                                    rowClass,
                                    GenerateElement("td",
                                                    new HtmlAttribute("colspan", "3"),
                                                    GenerateElement("div",
                                                                    new HtmlAttribute("class", "error"),
                                                                    errorMsg))));
                isConfigValid = false;
                LogMessage(error.Message);
            }

            return(loadedItem);
        }