using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CLIP.eForm.Consent.Web
{
    public partial class Deploy : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string opCode =  Request.QueryString["OP"];

            if (string.IsNullOrEmpty(opCode))
            {
                
            }
            else
            {
                if (opCode.Equals("GetClientUIFiles"))
                {
                    string clientUIFiles = Server.MapPath("~/App_Data/ClientUIFiles.xml");
                    string clientUIFilesXml = File.ReadAllText(clientUIFiles);
                    Response.Write(clientUIFilesXml);
                    Response.End();
                }
                else if (opCode.Equals("GetClientUIFilesBasePath"))
                {
                    Response.Write(GetBaseUrl()+"DeployFiles/");
                    Response.End();
                }
            }
        }

        public string GetBaseUrl()
        {
            var request = HttpContext.Current.Request;
            var appUrl = HttpRuntime.AppDomainAppVirtualPath;

            if (appUrl != "/") appUrl += "/";

            var baseUrl = string.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Authority, appUrl);

            return baseUrl;
        }
    }
}