public NippsSiteResponse ListSite()
        {
            NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
            NippsSiteResponse response = new NippsSiteResponse();
            response.ResultMessages = new List<string>();

            try
            {
                using (ServerManager serverManager = ServerManager.OpenRemote("localhost"))
                {
                    
                    List<NippsSite> sites = new List<NippsSite>();

                    foreach (Site site in serverManager.Sites)
                    {
                        
                        NippsSite nippsSite = new NippsSite();
                        nippsSite.Name = site.Name;
                        nippsSite.NippsApplications = new List<NippsApplication>();

                        foreach (Application application in site.Applications)
                        {
                        
                            try
                            {
                                nippsSite.NippsApplications.Add(new NippsApplication
                                {
                                    ApplicationPoolName = application.ApplicationPoolName,
                                    Path = application.Path,
                                    PhysicalPath = ServerManagerHelper.PutEnvVarValue(application.VirtualDirectories[0].PhysicalPath),
                                    ApplicationPoolState = serverManager.ApplicationPools[application.ApplicationPoolName].State,
                                    Version = GetVersion(application)
                                });

                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.ToString());
                                response.ResultMessages.Add(ex.ToString());
                            }

                        }

                        try
                        {
                            nippsSite.State = site.State;
                            nippsSite.Protocol = site.Bindings[0].Protocol;
                            nippsSite.Port = site.Bindings[0].EndPoint.Port.ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.ToString());
                            response.ResultMessages.Add(ex.ToString());
                        }

                        sites.Add(nippsSite);

                    }

                    response.NippsSites = sites;
                    response.Result = Result.OK;
                    logger.Debug(sites);
                }

            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                response.Result = Result.FAIL;
                response.ResultMessages.Add(ex.ToString());
            }
       
            return response;

        }
        public NippsSiteResponse RemoveNippsSite(NippsSiteRequest nippsSiteRequest)
        {
            bool isRemoved;
            bool isSucceededOne = false;
            Logger logger = NLog.LogManager.GetCurrentClassLogger();
            NippsSiteResponse response = new NippsSiteResponse();
            response.ResultMessages = new List<string>();
            response.Result = Result.OK;

            try
            {
                using (ServerManager serverManager = ServerManager.OpenRemote("localhost"))
                {
                    foreach (NippsSite nippsSite in nippsSiteRequest.NippsSites)
                        if (nippsSite.NippsApplications.Count > 0)
                            foreach (Site site in serverManager.Sites)
                                if (site.Name.Equals(nippsSite.Name))
                                {

                                    isRemoved = false;
                                    
                                    foreach (NippsApplication nippsApplication in nippsSite.NippsApplications)
                                    {
                                        try
                                        {
                                            //remove application
                                            logger.Debug("the app we remove -> " + nippsApplication.Path);
                                            Application application = FindApplication(site.Applications, nippsApplication.Path); 
                                            site.Applications.Remove(application);
                                            
                                            //then folder
                                            string removeFolder = application
                                                .VirtualDirectories
                                                    .Where(v => v.Path.Equals("/"))
                                                    .Single()
                                                    .PhysicalPath;

                                            removeFolder = ServerManagerHelper.PutEnvVarValue(removeFolder);

                                            logger.Debug("the path we remove -> " + removeFolder);
                                            if (Directory.Exists(removeFolder))
                                                Directory.Delete(removeFolder, true);
                                            else
                                                logger.Error(removeFolder + " not found.");

                                            isSucceededOne = true;
                                            isRemoved = true;

                                            //response.ResultMessages.Add(
                                    //string.Format("[{0} - {1} - {2}]", nippsPackage.SiteName, nippsPackage.ApplicationPoolName, nippsPackage.ApplicationName));

                                            break;
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex.ToString());
                                            if (isSucceededOne)
                                                response.Result = Result.SUCCESSWITHWARN;
                                            response.ResultMessages.Add(ex.ToString());
                                        }
                                    }

                                    if (isRemoved)
                                    {
                                        serverManager.CommitChanges(); 
                                        break;
                                    }
                                        
                                }
                }

            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                response.Result = Result.FAIL;
                response.ResultMessages.Add(ex.ToString());
            }

            return response;

        }