public static IDatabaseRepository <IHarvesterDataContext> CreateHarvesterRepository(RepositoryArgumentsBase arguments)
        {
            if (arguments.GetType() == typeof(SqlServerDatabaseRepositoryArguments))
            {
                LambdaFactory <IHarvesterDataContext, String> contextFactory = LambdaFactory.Wrap <IHarvesterDataContext, String>(s => new HarvesterDataContext(s));
                return(new SqlServerDatabaseRepository <IHarvesterDataContext>(arguments as SqlServerDatabaseRepositoryArguments, contextFactory));
            }

            throw new NotImplementedException();
        }
        public static IDatabaseRepository <IStatisticsDataContext> CreateStatisticsRepository(RepositoryArgumentsBase arguments)
        {
            if (arguments is SqlServerDatabaseRepositoryArguments repositoryArguments)
            {
                LambdaFactory <IStatisticsDataContext, String> contextFactory = LambdaFactory.Wrap <IStatisticsDataContext, String>(s => new StatisticsDataContext(s));
                return(new SqlServerDatabaseRepository <IStatisticsDataContext>(repositoryArguments, contextFactory));
            }

            throw new NotImplementedException();
        }
        public static ICounterRepository CreateCounterRepository(RepositoryArgumentsBase arguments)
        {
            switch (arguments)
            {
            case SushiCounterRepositoryArguments repositoryArguments:
            {
                BasicHttpBinding binding = new BasicHttpBinding
                {
                    MaxBufferPoolSize      = Int32.MaxValue,
                    MaxBufferSize          = Int32.MaxValue,
                    MaxReceivedMessageSize = Int32.MaxValue,
                    SendTimeout            = new TimeSpan(0, 6, 0),
                    ReceiveTimeout         = new TimeSpan(0, 6, 0)
                };

                LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress> factory;
                switch (repositoryArguments.Version)
                {
                case "3.0":
                case "3":
                    factory = new LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress>(address => new Journal.Sushi_3_0.SushiServiceInterfaceClient(binding, address));
                    break;

                case "4.0":
                case "4":
                    factory = new LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress>(address => new Journal.Sushi_4_0.SushiServiceInterfaceClient(binding, address));
                    break;

                case "4.1":
                case "":
                case null:
                    factory = new LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress>(address => new SushiServiceInterfaceClient(binding, address));
                    break;

                default:
                    throw new NotImplementedException(@"Sushi Version is not supported: {repositoryArguments.Version}. Try 4.1");
                }

                return(new SushiCounterRepository(repositoryArguments, factory));
            }

            case EbscoHostCounterRepositoryArguments ebscoRepositoryArguments:
            {
                BasicHttpBinding binding = new BasicHttpBinding
                {
                    MaxBufferPoolSize      = Int32.MaxValue,
                    MaxBufferSize          = Int32.MaxValue,
                    MaxReceivedMessageSize = Int32.MaxValue,
                    SendTimeout            = new TimeSpan(0, 6, 0),
                    ReceiveTimeout         = new TimeSpan(0, 6, 0),
                };

                var sushiFactory     = new LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress>(address => new SushiServiceInterfaceClient(binding, address));
                var sushiRepoFactory = LambdaFactory.Wrap <SushiCounterRepository, SushiCounterRepositoryArguments>(s => new SushiCounterRepository(s, sushiFactory));

                return(new EbscoHostCounterRepository(ebscoRepositoryArguments, sushiRepoFactory));
            }

            case EmailRepositoryArguments emailRepositoryArguments:
                return(new EmailRepository(emailRepositoryArguments));

            case SushiMuseCounterRepositoryArguments sushiArgs:
            {
                SushiCounterRepositoryArguments counterArgumentsnew = SushiCounterRepositoryArguments(sushiArgs);

                CustomBinding binding = new CustomBinding(
                    new CustomTextMessageBindingElement("iso-8859-1", "text/xml", MessageVersion.Soap11),
                    new HttpTransportBindingElement());

                var factory = new LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress>(address => new Journal.Sushi_3_0.SushiServiceInterfaceClient(binding, address));

                return(new SushiCounterRepository(counterArgumentsnew, factory));
            }

            case SushiMpsCounterRepositoryArguments sushiArgs:
            {
                SushiCounterRepositoryArguments counterArgumentsnew = SushiCounterRepositoryArguments(sushiArgs);

                BasicHttpBinding binding = new BasicHttpBinding
                {
                    MaxBufferPoolSize      = Int32.MaxValue,
                    MaxBufferSize          = Int32.MaxValue,
                    MaxReceivedMessageSize = Int32.MaxValue,
                    SendTimeout            = new TimeSpan(0, 6, 0),
                    ReceiveTimeout         = new TimeSpan(0, 6, 0),
                };

                var factory = new LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress>(address => new MPSInsight.SushiServiceInterfaceClient(binding, address));

                return(new SushiCounterRepository(counterArgumentsnew, factory));
            }

            case SushiGaleCounterRepositoryArguments sushiArgs:
            {
                SushiCounterRepositoryArguments counterArgumentsnew = SushiCounterRepositoryArguments(sushiArgs);

                var binding = new CustomBinding(new BasicHttpBinding("SushiService4"));
                binding.Elements.Remove <TextMessageEncodingBindingElement>();
                binding.Elements.Insert(0, new CustomTextMessageBindingElement(null, "text/html", MessageVersion.Soap11));

                var httpTransportBindingElement = binding.Elements.Find <HttpTransportBindingElement>();
                httpTransportBindingElement.MaxReceivedMessageSize = Int32.MaxValue;
                binding.Elements.Remove <HttpTransportBindingElement>();
                binding.Elements.Add(httpTransportBindingElement);

                var factory = new LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress>(address => new Gale.SushiServiceInterfaceClient(binding, address));

                return(new SushiCounterRepository(counterArgumentsnew, factory));
            }

            case SushiJstorCounterRepositoryArguments sushiArgs:
            {
                SushiCounterRepositoryArguments counterArgumentsnew = SushiCounterRepositoryArguments(sushiArgs);

                var binding = new CustomBinding(new BasicHttpBinding(BasicHttpSecurityMode.Transport)
                    {
                        MaxReceivedMessageSize = Int32.MaxValue, SendTimeout = TimeSpan.FromMinutes(4)
                    });

                binding.Elements.Remove <TextMessageEncodingBindingElement>();
                binding.Elements.Insert(0, new CustomTextMessageBindingElement(null, null, MessageVersion.Soap11));

                var factory = new LambdaFactory <ISushiServiceInterfaceClient, EndpointAddress>(address => new Journal.Sushi_4_0.SushiServiceInterfaceClient(binding, address));

                return(new SushiCounterRepository(counterArgumentsnew, factory));
            }

            default:
                throw new NotImplementedException();
            }
        }