/*
  * The contents of this file are subject to the Mozilla Public
  * License Version 1.1 (the "License"); you may not use this
  * file except in compliance with the License. You may obtain
  * a copy of the License at http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  * or implied. See the License for the specific language governing
  * rights and limitations under the License.
  *
  *
  * The Original Code is .NET RASP toolkit.
  *
  * The Initial Developer of the Original Code is Accenture and Avanade.
  * Portions created by Accenture and Avanade are Copyright (C) 2009
  * Danish National IT and Telecom Agency (http://www.itst.dk).
  * All Rights Reserved.
  *
  * Contributor(s):
  *   Gert Sylvest, Avanade
  *   Jesper Jensen, Avanade
  *   Ramzi Fadel, Avanade
  *   Patrik Johansson, Accenture
  *   Dennis Søgaard, Accenture
  *   Christian Pedersen, Accenture
  *   Martin Bentzen, Accenture
  *   Mikkel Hippe Brun, ITST
  *   Finn Hartmann Jordal, ITST
  *   Christian Lanng, ITST
  *
  */

using System;
using System.Collections.Generic;
using System.Text;

using dk.gov.oiosi.configuration;
using dk.gov.oiosi.uddi;

namespace dk.gov.oiosi.raspProfile
{
    /// <summary>
    /// Creates the default UDDI configuration
    /// </summary>
    public class DefaultUddiConfig
    {
        /// <summary>
        /// Sets the default UDDI lookup factory configuration
        /// </summary>
        public virtual void SetUddiLookupFactoryConfig()
        {
            UddiLookupClientFactoryConfig uddiFactoryConfig = ConfigurationHandler.GetConfigurationSection<UddiLookupClientFactoryConfig>();
            uddiFactoryConfig.ImplementationAssembly = "dk.gov.oiosi.library";
            uddiFactoryConfig.ImplementationNamespaceClass = "dk.gov.oiosi.uddi.UddiLookupClient";

            RegistryLookupClientFactoryConfig regFactoryConfig = ConfigurationHandler.GetConfigurationSection<RegistryLookupClientFactoryConfig>();
            regFactoryConfig.ImplementationAssembly = "dk.gov.oiosi.library";
            regFactoryConfig.ImplementationNamespaceClass = "dk.gov.oiosi.uddi.RegistryLookupClient";
        }

        /// <summary>
        /// Sets the test UDDI lookup factory configuration
        /// </summary>
        public virtual void SetTestUddiLookupFactoryConfig()
        {
            UddiLookupClientFactoryConfig uddiFactoryConfig = ConfigurationHandler.GetConfigurationSection<UddiLookupClientFactoryConfig>();
            uddiFactoryConfig.ImplementationAssembly = "dk.gov.oiosi.library";
            uddiFactoryConfig.ImplementationNamespaceClass = "dk.gov.oiosi.uddi.UddiLookupClientTest";

            RegistryLookupClientFactoryConfig regFactoryConfig = ConfigurationHandler.GetConfigurationSection<RegistryLookupClientFactoryConfig>();
            regFactoryConfig.ImplementationAssembly = "dk.gov.oiosi.library";
            uddiFactoryConfig.ImplementationNamespaceClass = "dk.gov.oiosi.uddi.RegistryLookupClient";
        }

        /// <summary>
        /// Sets the lookup factory configuration if it does not exist
        /// </summary>
        public virtual void SetIfNotExistsUddiLookupFactoryConfig()
        {
            if (ConfigurationHandler.HasConfigurationSection<UddiLookupClientFactoryConfig>())
                return;
            SetUddiLookupFactoryConfig();
        }

        /// <summary>
        /// Sets the test uddi lookup factory configuration if it does not exist
        /// </summary>
        public virtual void SetIfNotExistsTestUddiLookupFactoryConfig()
        {
            if (ConfigurationHandler.HasConfigurationSection<UddiLookupClientFactoryConfig>())
                return;
            SetTestUddiLookupFactoryConfig();
        }

        /// <summary>
        /// Sets the default uddi configuration
        /// </summary>
        public virtual void SetDefaultUddiConfig()
        {
            UddiConfig uddiConfig = ConfigurationHandler.GetConfigurationSection<UddiConfig>();
            uddiConfig.TryOtherHostsOnFailure = true;
            uddiConfig.FallbackTimeoutMinutes = 15;
            uddiConfig.LookupRegistryFallbackConfig = new LookupRegistryFallbackConfig();
            uddiConfig.LookupRegistryFallbackConfig.PrioritizedRegistryList.Add(new Registry(new List<string>() { "http://discoverypublic.uddi.ehandel.gov.dk/registry/uddi/inquiry", "http://discoverybackup.uddi.ehandel.gov.dk/registry/uddi/inquiry" }));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("cpr", "http://oio.dk/profiles/OIOSI/1.2/UDDI/Identifiers/cprNumber/"));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("cvr", "http://oio.dk/profiles/OWSA/modelT/1.0/UDDI/Identifiers/cvrNumber/"));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("duns", "http://oio.dk/profiles/OIOSI/1.1/UDDI/Identifiers/dunsNumber/"));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("ean", "http://oio.dk/profiles/OIOSI/1.0/UDDI/Identifiers/eanNumber/"));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("iban", "http://oio.dk/profiles/OIOSI/1.1/UDDI/Identifiers/ibanNumber/"));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("ovt", "http://oio.dk/profiles/OIOSI/1.0/UDDI/Identifiers/ovtNumber/"));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("p", "http://oio.dk/profiles/OIOSI/1.1/UDDI/Identifiers/pNumber/"));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("se", "http://oio.dk/profiles/OIOSI/1.1/UDDI/Identifiers/seNumber/"));
            ////uddiConfig.KeyTypeMappings.Add(new KeyType("vans", "http://oio.dk/profiles/OIOSI/1.1/UDDI/Identifiers/vansNumber/"));
            ///////uddiConfig.KeyTypeMappings.Add(new KeyType("", ""));
        }

        /// <summary>
        /// Setup default test
        /// </summary>
        public virtual void SetDefaultUddiConfigTest()
        {
            // Set UDDI test config:
            UddiLookupClientTestConfig uddiTestConfig = ConfigurationHandler.GetConfigurationSection<UddiLookupClientTestConfig>();
            // The oiosi test VOCES certificate:
            uddiTestConfig.CertificateSubjectSerialNumber =
               "CN=NemHandel Test 2 + SERIALNUMBER=CVR:26769388-DID:00000002, O=IT- og Telestyrelsen // CVR:26769388, C=DK";

            // Example of a revoked endpoint certificate:
            /*uddiTestConfig.CertificateSubjectSerialNumber =
               "OID.2.5.4.5=CVR:26769388-UID:1157365203353 + CN=IT- og Telestyrelsen - OIOSI-Test, O=IT- og Telestyrelsen // CVR:26769388, C=DK"; */

            uddiTestConfig.EndpointAddress = "http://oiositest.dk/interoptest/oiosiOmniEndpointB.svc";
            uddiTestConfig.ActivationDate = new DateTime(2007, 1, 1);
            uddiTestConfig.ExpirationDate = new DateTime(2012, 6, 1);
            uddiTestConfig.HasNewerVersion = false;
            uddiTestConfig.NewerVersionReference = "";
            uddiTestConfig.ServiceContactEmail = "test@test.com";
            uddiTestConfig.TermsOfUseUrl = "http://test.dk/termsOfUse.html";
            uddiTestConfig.Version = "1.0.3";
        }

        /// <summary>
        /// Sets the default uddi configuration if it does not exist
        /// </summary>
        public virtual void SetIfNotExistsDefaultUddiConfig()
        {
            if (ConfigurationHandler.HasConfigurationSection<UddiConfig>())
                return;
            SetDefaultUddiConfig();
        }

        /// <summary>
        /// Sets the default test uddi configuration if it does not exist
        /// </summary>
        public virtual void SetIfNotExistsDefaultUddiConfigTest()
        {
            if (ConfigurationHandler.HasConfigurationSection<UddiLookupClientTestConfig>())
                return;
            SetDefaultUddiConfigTest();
        }
    }
}