//---------------------------------------------------------------------------------
// Microsoft (R) .NET Services
// Software Development Kit
// 
// Copyright (c) Microsoft Corporation. All rights reserved.  
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 
//---------------------------------------------------------------------------------

namespace Microsoft.ServiceBus.Samples
{
    using System;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    using Microsoft.ServiceBus;
    using System.ServiceModel.Web;

    class Program
    {
        static void Main(string[] args)
        {
            // create the credentials object for the endpoint
            TransportClientEndpointBehavior userNamePasswordServiceBusCredential =
                new TransportClientEndpointBehavior();
            userNamePasswordServiceBusCredential.CredentialType =
                TransportClientCredentialType.SharedSecret;
            userNamePasswordServiceBusCredential.Credentials.SharedSecret.IssuerName = "owner";
            userNamePasswordServiceBusCredential.Credentials.SharedSecret.IssuerSecret = "Ctq3JKN+rBxpcsQxEE2Rk4H5kGFt44+MhMwyx5sdc50=";

            Console.WriteLine("You can download a feed that describes this talk at:");
            Uri address = new Uri(
                "https://pluralsight.servicebus.windows.net/techedme");
            WebServiceHost host = new WebServiceHost(typeof(SyndicationService), 
                address);

            // add the Service Bus credentials to all endpoints specified in configuration
            foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
            {
                Console.WriteLine(endpoint.Address);
                endpoint.Behaviors.Add(userNamePasswordServiceBusCredential);
            }
            
            host.Open();

            Console.WriteLine("Press [Enter] to exit");
            Console.WriteLine();
            Console.ReadLine();

            host.Close();
        }

        #region SDK Utilities
        static string GetServiceBusSolutionName()
        {
            string serviceBusSolutionName = Environment.GetEnvironmentVariable("RELAYSAMPLESOLUTION");
            while (string.IsNullOrEmpty(serviceBusSolutionName))
            {
                Console.Write("Please enter the Solution name to use for this sample:");
                serviceBusSolutionName = Console.ReadLine();
            }
            return serviceBusSolutionName;
        }
        #endregion

    }
}