public void ParserError ()
		{
			StringWriter writer = new StringWriter ();
			writer.WriteLine ("[Nini Thing");
			writer.WriteLine (" my key = something");
			IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));
		}
 private static void SetExtensions(IniDocument doc, IEnumerable<KeyValuePair<string, string>> extensionDeclarations)
 {
     var section = doc.Sections.GetOrCreate("extensions");
     foreach (var pair in extensionDeclarations)
     {
         section.Set(pair.Key, pair.Value);
     }
 }
 public ConfigurationFile(TextReader tr)
 {
     this.ini = new IniDocument(tr, IniFileType.WindowsStyle);
     if (ini.Sections["ApplicationLauncher"].GetValue("ConfigVersion") != "1")
     {
         throw new ConfigurationFileFormatException("ApplicationLauncher.ConfigVersion is not 1");
     }
 }
Пример #4
0
 public void Setup()
 {
     var iniDoc = new IniDocument();
     var configSource = new IniConfigSource(iniDoc);
     configSource.AddConfig("InWorldz.Phlox");
     var world = SceneHelper.CreateScene(9000, 1000, 1000);
     var engine = new MockScriptEngine(world, configSource);
     lslSystemApi = new LSLSystemAPI(engine, null, 0, UUID.Zero);
 }
		public void GetKey ()
		{
			StringWriter writer = new StringWriter ();
			writer.WriteLine ("[Nini]");
			writer.WriteLine (" my key = something");
			IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));
			
			IniSection section = doc.Sections["Nini"];
			Assert.IsTrue (section.Contains ("my key"));
			Assert.AreEqual ("something", section.GetValue ("my key"));
			Assert.IsFalse (section.Contains ("not here"));
		}
		public void SetKey ()
		{
			IniDocument doc = new IniDocument ();
			
			IniSection section = new IniSection ("new section");
			doc.Sections.Add (section);

			section.Set ("new key", "some value");
			
			Assert.IsTrue (section.Contains ("new key"));
			Assert.AreEqual ("some value", section.GetValue ("new key"));
		}
		public void GetSection ()
		{
			StringWriter writer = new StringWriter ();
			writer.WriteLine ("; Test");
			writer.WriteLine ("[Nini Thing]");
			IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));
			
			Assert.AreEqual (1, doc.Sections.Count);
			Assert.AreEqual ("Nini Thing", doc.Sections["Nini Thing"].Name);
			Assert.AreEqual ("Nini Thing", doc.Sections[0].Name);
			Assert.IsNull (doc.Sections["Non Existant"]);
		}
		public void SetSection ()
		{
			IniDocument doc = new IniDocument ();

			IniSection section = new IniSection ("new section");
			doc.Sections.Add (section);
			Assert.AreEqual ("new section", doc.Sections[0].Name);
			Assert.AreEqual ("new section", doc.Sections["new section"].Name);
			
			section = new IniSection ("a section", "a comment");
			doc.Sections.Add (section);
			Assert.AreEqual ("a comment", doc.Sections[1].Comment);
		}
Пример #9
0
        public void DuplicateKeys()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("[Test]");
            writer.WriteLine (" a value = something 0");
            writer.WriteLine (" a value = something 1");
            writer.WriteLine (" a value = something 2");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));

            Assert.IsNotNull (doc.Sections["Test"]);
            Assert.AreEqual (1, doc.Sections.Count);
            Assert.AreEqual (1, doc.Sections["Test"].ItemCount);
            Assert.IsNotNull (doc.Sections["Test"].GetValue ("a value"));
            Assert.AreEqual ("something 0", doc.Sections["Test"].GetValue ("a value"));
        }
Пример #10
0
        public void GetAllKeys()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("[Nini]");
            writer.WriteLine (" ; a comment");
            writer.WriteLine (" my key = something");
            writer.WriteLine (" dog = rover");
            writer.WriteLine (" cat = muffy");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));

            IniSection section = doc.Sections["Nini"];

            Assert.AreEqual (4, section.ItemCount);
            Assert.AreEqual (3, section.GetKeys ().Length);
            Assert.AreEqual ("my key", section.GetKeys ()[0]);
            Assert.AreEqual ("dog", section.GetKeys ()[1]);
            Assert.AreEqual ("cat", section.GetKeys ()[2]);
        }
Пример #11
0
        public FrontendConfig(string uiName)
            : base()
        {
            _UIName = uiName;
            _Prefix = "Frontend/";

            #if CONFIG_NINI
            m_IniFilename = m_ConfigPath+"/smuxi-frontend.ini";
            if (!File.Exists(m_IniFilename)) {
            #if LOG4NET
                _Logger.Debug("creating file: "+m_IniFilename);
            #endif
                File.Create(m_IniFilename).Close();
                m_IsCleanConfig = true;
            }

            m_IniDocument = new IniDocument(m_IniFilename);
            #endif
        }
Пример #12
0
        public void DuplicateSections()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("[Test]");
            writer.WriteLine (" my key = something");
            writer.WriteLine ("[Test]");
            writer.WriteLine (" another key = something else");
            writer.WriteLine ("[Test]");
            writer.WriteLine (" value 0 = something 0");
            writer.WriteLine (" value 1 = something 1");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));

            Assert.IsNotNull (doc.Sections["Test"]);
            Assert.AreEqual (1, doc.Sections.Count);
            Assert.AreEqual (2, doc.Sections["Test"].ItemCount);
            Assert.IsNull (doc.Sections["Test"].GetValue ("my key"));
            Assert.IsNotNull (doc.Sections["Test"].GetValue ("value 0"));
            Assert.IsNotNull (doc.Sections["Test"].GetValue ("value 1"));
        }
Пример #13
0
        public void MysqlStyleDocument()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("# another comment"); // empty line
            writer.WriteLine ("[test]");
            writer.WriteLine (" quick ");
            writer.WriteLine (" cat = cats are not tall animals ");
            writer.WriteLine (" dog : dogs bark");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()),
                                                IniFileType.MysqlStyle);

            Assert.IsTrue (doc.Sections["test"].Contains ("quick"));
            Assert.AreEqual ("", doc.Sections["test"].GetValue ("quick"));
            Assert.AreEqual ("cats are not tall animals",
                            doc.Sections["test"].GetValue ("cat"));
            Assert.AreEqual ("dogs bark", doc.Sections["test"].GetValue ("dog"));
        }
Пример #14
0
        public void WindowsStyleDocument()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("; another comment"); // empty line
            writer.WriteLine ("[test]");
            writer.WriteLine (" cat = cats are not ; tall ");
            writer.WriteLine (" dog = dogs \"bark\"");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()),
                                                IniFileType.WindowsStyle);

            IniSection section = doc.Sections["test"];
            Assert.AreEqual ("cats are not ; tall", section.GetValue ("cat"));
            Assert.AreEqual ("dogs \"bark\"", section.GetValue ("dog"));
        }
Пример #15
0
        public void SaveToStream()
        {
            string filePath = "SaveToStream.ini";
            FileStream stream = new FileStream (filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument ();
            IniSection section = new IniSection ("Pets");
            section.Set ("dog", "rover");
            section.Set ("cat", "muffy");
            doc.Sections.Add (section);
            doc.Save (stream);
            stream.Close ();

            IniDocument newDoc = new IniDocument (new FileStream (filePath,
                                                                  FileMode.Open));
            section = newDoc.Sections["Pets"];
            Assert.IsNotNull (section);
            Assert.AreEqual (2, section.GetKeys ().Length);
            Assert.AreEqual ("rover", section.GetValue ("dog"));
            Assert.AreEqual ("muffy", section.GetValue ("cat"));

            stream.Close ();

            File.Delete (filePath);
        }
Пример #16
0
        public void SaveDocumentWithComments()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("; some comment");
            writer.WriteLine (""); // empty line
            writer.WriteLine ("[new section]");
            writer.WriteLine (" dog = rover");
            writer.WriteLine (""); // Empty line
            writer.WriteLine ("; a comment");
            writer.WriteLine (" cat = muffy");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));

            StringWriter newWriter = new StringWriter ();
            doc.Save (newWriter);

            StringReader reader = new StringReader (newWriter.ToString ());
            Assert.AreEqual ("; some comment", reader.ReadLine ());
            Assert.AreEqual ("", reader.ReadLine ());
            Assert.AreEqual ("[new section]", reader.ReadLine ());
            Assert.AreEqual ("dog = rover", reader.ReadLine ());
            Assert.AreEqual ("", reader.ReadLine ());
            Assert.AreEqual ("; a comment", reader.ReadLine ());
            Assert.AreEqual ("cat = muffy", reader.ReadLine ());

            writer.Close ();
        }
Пример #17
0
        private static void StartConnect()
        {
            // reading the servers.ini for server configuration
            var ConfigFile = string.Format("{0}/{1}", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Data\\servers.ini"); // the config file's location.
            var Parser = new IniDocument(ConfigFile);
            Dictionary<string, Service> serviceList = new Dictionary<string, Service>();
            foreach (DictionaryEntry de in Parser.Sections)
            {
                IniSection section = (IniSection)de.Value;
                Service s = new Service();
                s.Name = de.Key.ToString();
                s.IP = section.GetValue("ip");
                s.Port = Convert.ToInt32(section.GetValue("port"));
                s.PasswordEncrypt = Convert.ToBoolean(section.GetValue("passwordencrypt"));
                serviceList.Add(de.Key.ToString(), s);
            }

            // if config.ini contains a valid server skip choosing a new one
            string service = Config.Server.Config.Instance.Name;
            if (string.IsNullOrEmpty(service) || !serviceList.ContainsKey(service))
            {
                var selectedService = ConsoleHelper.GetConsoleMenu<Service>("Select your service", serviceList);
                _currentService = selectedService;
                Config.Server.Config.Instance.Name = selectedService.Name;
                Config.Server.Config.Instance.Save();
            }
            else
            {
                _currentService = serviceList[service];
            }

            // if config.ini contains a username skip asking for a new one
            string username = Config.Authentication.Config.Instance.Username;
            if (string.IsNullOrEmpty(username))
            {
                username = ConsoleHelper.GetConsoleString("Please enter the username");
                Config.Authentication.Config.Instance.Username = username;
                Config.Authentication.Config.Instance.Save();
            }

            // if config.ini contains a password skip asking for a new one
            string password = Config.Authentication.Config.Instance.Password;
            if (string.IsNullOrEmpty(password))
            {
                password = ConsoleHelper.GetConsoleString("Please enter the password");
                Config.Authentication.Config.Instance.Password = password.Encrypt(PasswordEncryptionKey);
                Config.Authentication.Config.Instance.Save();
            }
            else
            {
                // decrypting password
                password = password.Decrypt(PasswordEncryptionKey);
            }

            // creating login packet and enqueue so it will get sent once we are connected
            // might change this later to support password_encrypt from clientinfo.xml
            _packetQueue = new Queue<Net.Protocol.Methods.IMethodOut>();
            _packetQueue.Enqueue(Net.Protocol.Methods.CA.Login.CreateBuilder()
                .SetVersion(20)
                .SetId(username.ToCharArray())
                .SetPasswd(password.ToCharArray())
                .SetClienttype(Static.ClientType.CLIENTTYPE_FRANCE)
                .Build());

            // creating the buffer for the ragnarok packets
            _buffer = new Net.RoNetBuffer();

            // start connection
            _connectThread = new Thread(Connect);
            _connectThread.Start();
        }
Пример #18
0
        public void SaveAsPythonStyle()
        {
            string filePath = "Save.ini";
            FileStream stream = new FileStream (filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument ();
            doc.FileType = IniFileType.PythonStyle;
            IniSection section = new IniSection ("Pets");
            section.Set ("my comment");
            section.Set ("dog", "rover");
            doc.Sections.Add (section);
            doc.Save (stream);
            stream.Close ();

            StringWriter writer = new StringWriter ();
            writer.WriteLine ("[Pets]");
            writer.WriteLine ("# my comment");
            writer.WriteLine ("dog : rover");

            StreamReader reader = new StreamReader (filePath);
            Assert.AreEqual (writer.ToString (), reader.ReadToEnd ());
            reader.Close ();

            File.Delete (filePath);
        }
Пример #19
0
        public void SambaStyleDocument()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("; some comment");
            writer.WriteLine ("# another comment"); // empty line
            writer.WriteLine ("[test]");
            writer.WriteLine (" cat = cats are not tall\\ ");
            writer.WriteLine (" animals ");
            writer.WriteLine (" dog = dogs \\ ");
            writer.WriteLine ("        do not eat cats ");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()),
                                                IniFileType.SambaStyle);

            Assert.AreEqual ("cats are not tall animals",
                            doc.Sections["test"].GetValue ("cat"));
            Assert.AreEqual ("dogs         do not eat cats",
                            doc.Sections["test"].GetValue ("dog"));
        }
Пример #20
0
        public void SambaLoadAsStandard()
        {
            string filePath = "Save.ini";
            FileStream stream = new FileStream (filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument ();
            doc.FileType = IniFileType.SambaStyle;
            IniSection section = new IniSection ("Pets");
            section.Set ("my comment");
            section.Set ("dog", "rover");
            doc.Sections.Add (section);
            doc.Save (stream);
            stream.Close ();

            IniDocument iniDoc = new IniDocument ();
            iniDoc.FileType = IniFileType.Standard;
            iniDoc.Load (filePath);

            File.Delete (filePath);
        }
Пример #21
0
        public void RemoveSection()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("[Nini Thing]");
            writer.WriteLine (" my key = something");
            writer.WriteLine ("[Parser]");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));

            Assert.IsNotNull (doc.Sections["Nini Thing"]);
            doc.Sections.Remove ("Nini Thing");
            Assert.IsNull (doc.Sections["Nini Thing"]);
        }
Пример #22
0
        static void Main(String[] args)
        {
            Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
            Console.Title = "Fortitude Server Prototype";
            _sActive = true;

            Cache.MaxInteractionDistance = 30d;
            Cache.PlacementCost = 5;
            Cache.MinPlacementDistance = 300d;

            Player.PayoutInterval = 3.0 * 60.0 * 60.0;
            Player.UnitsPerCache = 1.0;

            String iniPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "config.ini");
            String[] ownerEmails = null;

            if (!File.Exists(iniPath)) {
                Console.WriteLine("WARNING: config.ini not found, some features may not function");
            } else {
                IniDocument ini = new IniDocument(iniPath);
                IniSection general = ini.Sections["general"];

                ServerAddress = general.GetValue("address");
                int.TryParse(general.GetValue("localport"), out LocalPort);

                ownerEmails = general.GetValue("owners").Split(new char[] { ',' },
                    StringSplitOptions.RemoveEmptyEntries);

                DatabaseManager.FileName = general.GetValue("database") ?? DatabaseManager.FileName;
                EmailManager.CreateClient(ini.Sections["smtp"]);
                ContentManager.Initialize(ini.Sections["webserver"]);
            }

            DatabaseManager.ConnectLocal();

            if (ownerEmails != null) {
                Account.AddOwnerEmails(ownerEmails);
            }

            Thread clientThread = new Thread(async () => {
                HttpListener listener = new HttpListener();
                listener.Prefixes.Add("http://+:" + LocalPort + "/");
                listener.Start();

                Console.WriteLine("Http server started and ready for requests");

                Stopwatch timeout = new Stopwatch();

                while (_sActive) {
                    timeout.Restart();
                    Task<HttpListenerContext> ctxTask = listener.GetContextAsync();

                    while (!ctxTask.IsCompleted && _sActive) { 
                        Thread.Sleep(10);
                        if (Player.PayoutInterval > 1.0 && Player.PayoutDue) {
                            Player.Payout();
                        }
                        //if (timeout.Elapsed.TotalSeconds >= RequestTimeout) {
                        //    break;
                        //}
                    }

                    if (!_sActive)
                        break;

                    //if (timeout.Elapsed.TotalSeconds >= RequestTimeout) {
                    //    continue;
                    //}

                    ProcessRequest(await ctxTask);
                }

                listener.Stop();
            });

            clientThread.Start();

            while (_sActive) {
#if DEBUG
                ProcessCommand(Console.ReadLine());
#else
                Thread.Sleep(10);
#endif
            }

            clientThread.Abort();

            while (clientThread.IsAlive)
                Thread.Sleep(10);

            DatabaseManager.Disconnect();
        }
Пример #23
0
		/// <include file='IniConfigSource.xml' path='//Constructor[@name="ConstructorIniDocument"]/docs/*' />
		public IniConfigSource (IniDocument document)
		{
			Load (document);
		}
Пример #24
0
		/// <include file='IConfigSource.xml' path='//Method[@name="Reload"]/docs/*' />
		public override void Reload ()
		{
			if (savePath == null) {
				throw new ArgumentException ("Error reloading: You must have "
							+ "the loaded the source from a file");
			}

			iniDocument = new IniDocument (savePath);
			MergeDocumentIntoConfigs ();
			base.Reload ();
		}
Пример #25
0
        public Config()
        {
            #if CONFIG_NINI
            m_ConfigPath = Path.Combine(Environment.GetFolderPath(
                Environment.SpecialFolder.ApplicationData), "smuxi");

            if (!Directory.Exists(m_ConfigPath)) {
                Directory.CreateDirectory(m_ConfigPath);
            }

            m_IniFilename = Path.Combine(m_ConfigPath, "smuxi-engine.ini");
            if (!File.Exists(m_IniFilename)) {
            #if LOG4NET
                _Logger.Debug("creating file: "+m_IniFilename);
            #endif
                File.Create(m_IniFilename).Close();
                m_IsCleanConfig = true;
            }

            m_IniDocument = new IniDocument(m_IniFilename);
            //m_IniConfigSource = new IniConfigSource(m_IniFilename);
            #endif
        }
 /// <include file='IniConfigSource.xml' path='//Constructor[@name="ConstructorTextReader"]/docs/*' />
 public IniConfigSource(TextReader reader)
 {
     this.Merge (this); // required for SaveAll
     iniDocument = new IniDocument (reader);
     Load ();
 }
Пример #27
0
		/// <include file='IniConfigSource.xml' path='//Constructor[@name="Constructor"]/docs/*' />
		public IniConfigSource ()
		{
			iniDocument = new IniDocument ();
		}
Пример #28
0
        public void PythonStyleDocument()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("; some comment");
            writer.WriteLine ("# another comment"); // empty line
            writer.WriteLine ("[test]");
            writer.WriteLine (" cat: cats are not tall animals ");
            writer.WriteLine (" dog : dogs bark");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()),
                                                IniFileType.PythonStyle);

            Assert.AreEqual ("cats are not tall animals",
                            doc.Sections["test"].GetValue ("cat"));
            Assert.AreEqual ("dogs bark", doc.Sections["test"].GetValue ("dog"));
        }
Пример #29
0
		/// <include file='IniConfigSource.xml' path='//Method[@name="LoadIniDocument"]/docs/*' />
		public void Load (IniDocument document)
		{
			this.Configs.Clear ();

			this.Merge (this); // required for SaveAll
			iniDocument = document;
			Load ();
		}
Пример #30
0
        public void RemoveKey()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("[Nini]");
            writer.WriteLine (" my key = something");
            IniDocument doc = new IniDocument (new StringReader (writer.ToString ()));

            Assert.IsTrue (doc.Sections["Nini"].Contains ("my key"));
            doc.Sections["Nini"].Remove ("my key");
            Assert.IsFalse (doc.Sections["Nini"].Contains ("my key"));
        }