using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DesiredContractLibrary;
using System.Runtime.Serialization;

namespace DesiredClassLibrary
{
    [Serializable]
    public class DesiredClass : DesiredContract
    {
        private string _name;

        public static bool IsWeb()
        {
            try
            {
                return ((HttpContext.Current != null) && (HttpRuntime.AppDomainAppId != null));
            }
            catch
            {
                //exception due to inexistence of HttpContext
                return false;
            }
        }
        
        public virtual string Name 
        { 
            get
            {
                return IsWeb()?System.Web.HttpContext.Current.Session["Name"].ToString():_name;
            }
            set
            {
                if (IsWeb())
                {
                    System.Web.HttpContext.Current.Session.Add("Name", value);
                }
                else
                {
                    _name = value;
                }
            }
        }

        public virtual string GetHello()
        {
            return "Hello world, " + Name + "!";
        }
    }
}