using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace IronIntel.Contractor
{
    public class Common
    {
        public Common()
        {
        }

        private static string _LoginSessionCookieName;
        public static string LoginSessionCookieName
        {
            get
            {
                if (_LoginSessionCookieName == null)
                {
                    _LoginSessionCookieName = Site.IronIntelBasePage.LOGINSESSION_COOKIENAME;
                }
                return _LoginSessionCookieName;
            }
        }

        private static string _LanguageCookieName;
        public static string LanguageCookieName
        {
            get
            {
                if (_LanguageCookieName == null)
                {
                    _LanguageCookieName = LoginSessionCookieName + "language";
                }
                return _LanguageCookieName;
            }
        }

        private static string _RememberCookieName;
        public static string RememberCookieName
        {
            get
            {
                if (_RememberCookieName == null)
                {
                    _RememberCookieName = LoginSessionCookieName + "RemberUser";
                }
                return _RememberCookieName;
            }
        }

        private static string _FrsPeriodCookieName;
        public static string FrsPeriodCookieName
        {
            get
            {
                if (_FrsPeriodCookieName == null)
                {
                    _FrsPeriodCookieName = LoginSessionCookieName + "Period";
                }
                return _FrsPeriodCookieName;
            }
        }

        private static string _FrsThemeCookieName;
        public static string FrsThemeCookieName
        {
            get
            {
                if (_FrsThemeCookieName == null)
                {
                    _FrsThemeCookieName = LoginSessionCookieName + "FrsTheme";
                }
                return _FrsThemeCookieName;
            }
        }

        /// <summary>
        /// 此方法只有FIC的的页面,其他页面也是会出错
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static string GenerateUrl(string file)
        {
            string url;
            System.Web.UI.Page page = HttpContext.Current.Handler as System.Web.UI.Page;
            if (page != null)
            {
                // Use page instance.
                url = page.ResolveUrl("~/") + "fic/" + file;
            }
            else
            {
                // avoid duplicate operation
                url = HttpContext.Current.Request.ApplicationPath + "/fic/" + file;
            }
            try
            {
                var path = System.IO.Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "fic/" + file);
                if (System.IO.File.Exists(path))
                {
                    url += "?t=" + System.IO.File.GetLastWriteTimeUtc(path).Ticks;
                }
            }
            catch (Exception)
            {
                // cant read file
            }
            return url;
        }
    }
}