using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using C1.C1Zip;
using System.IO;

namespace EsriMapSamples.Web
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string DestinationPath = HttpContext.Current.Request.PhysicalApplicationPath;
            string sourcePath = DestinationPath.Substring(0, DestinationPath.LastIndexOf('\\'));
            sourcePath = sourcePath.Substring(0, sourcePath.LastIndexOf('\\'));
            sourcePath = sourcePath + "\\EsriMapSamples\\Samples";

            C1ZipFile zip = new C1ZipFile();
            try
            {
                zip.Create(DestinationPath + "SourceCode.zip");

                foreach (string fileName in Directory.GetFiles(sourcePath, "*.cs"))
                {
                    zip.Entries.Add(fileName);
                }
                foreach (string fileName in Directory.GetFiles(sourcePath, "*.xaml"))
                {
                    zip.Entries.Add(fileName);
                }
            }
            catch (UnauthorizedAccessException)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Unable to zip latest source code. Will use cached source code instead. Run sample from permissible folder to generate latest source code.');", true);
            }
        }

    }
}