using System;
using System.Web;
using System.Xml;
using Kreta.Framework;

namespace Kreta.KretaServer
{
    public class KretaConfiguration : Configuration
    {
        public KretaConfiguration(XmlNode confignode) : base(confignode)
        {
        }

        protected override void ReadConfig(XmlNode confignode)
        {
            string xpath = "";

            try
            {
                base.ReadConfig(confignode);

                if (!DBConnection.EndsWith(";", StringComparison.Ordinal))
                {
                    DBConnection += ";";
                }
                //if (DBConnection.IndexOf("Max Pool Size", StringComparison.OrdinalIgnoreCase) < 0)
                //    DBConnection += "Max Pool Size=" + (SessionLimit < 100 ? 100 : SessionLimit) + ";";

                XmlNode current = null;
                xpath = "/config/server/intezmenyconnectionstringfile";
                if ((current = confignode.SelectSingleNode(xpath)) != null)
                {
                    intezmenyConnectionStringFile = current.InnerText;
                    if (intezmenyConnectionStringFile.Contains("~") && (HttpContext.Current != null))
                    {
                        intezmenyConnectionStringFile = HttpContext.Current.Server.MapPath(intezmenyConnectionStringFile);
                    }
                }

                xpath = "/config/server/tesztintezmenyazonosito";
                if ((current = confignode.SelectSingleNode(xpath)) != null)
                {
                    tesztIntezmenyAzonosito = current.InnerText;
                }
                xpath = "/config/server/mkbbankszamlaigenylesconnectionstringfile";
                if ((current = confignode.SelectSingleNode(xpath)) != null)
                {
                    bankszamlaIgenylesConnectionStringFile = current.InnerText;
                    if (bankszamlaIgenylesConnectionStringFile.Contains("~") && (HttpContext.Current != null))
                    {
                        bankszamlaIgenylesConnectionStringFile = HttpContext.Current.Server.MapPath(bankszamlaIgenylesConnectionStringFile);
                    }
                }
            }
            catch (InvalidConfigurationException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new InvalidConfigurationException("Invalid configuration entry: " + xpath + ".", exception);
            }
        }

        private string intezmenyConnectionStringFile;
        private string tesztIntezmenyAzonosito;
        private string bankszamlaIgenylesConnectionStringFile;

        public string IntezmenyConnectionStringFile { get { return intezmenyConnectionStringFile; } }
        public string BankszamlaIgenylesConnectionStringFile { get { return bankszamlaIgenylesConnectionStringFile; } }

        public string TesztIntezmenyAzonosito { get { return tesztIntezmenyAzonosito; } }
    }
}