public ActionResult NippsUndeploy(Models.Nipps nipps)
        {

            ViewBag.ReturnToAction = ReturnToAction;
            ViewBag.ReturnToController = ReturnToController;
            ViewBag.Title = Resources.Global.UndeployTitle;
            ViewBag.Name = Resources.Global.Undeploy;

            try
            {
                //first, get and remove nippsmodule, do not care weather exist or not
                RemoveNippsModule(GetNippsModule(nipps));
                
                //then remove application
                NippsSite nippsSite = new NippsSite
                {
                    Name = nipps.SiteName,
                    NippsApplications = new List<NippsApplication> { new NippsApplication { Path = nipps.ApplicationName, PhysicalPath = nipps.PhysicalPath } }
                };

                string svcUrl = NippsSiteHelper.BuildDeploymentServiceUrl(nipps.HostName) + "RemoveNippsSite";
                NippsSiteRequest nippsSiteRequest = new NippsSiteRequest { NippsSites = new List<NippsSite> { nippsSite } };
                NippsSiteResponse response = RestHelper.RestPostObject<NippsSiteResponse, NippsSiteRequest>(svcUrl, nippsSiteRequest);

                if (response.Result == Result.OK)
                    return RedirectToAction("NippsServiceList");

                SetViewBagResult(response, ViewBag);

            }
            catch (Exception ex)
            {
                Logger.Error("{0}: {1}", nipps, ex.ToString());
                SetViewBagResult(new NippsSiteResponse { Result = Result.FAIL, ResultMessages = new List<string> { ex.ToString() } }, ViewBag);
            }

            return View(NippsSiteHelper.ResultMessageView);
        }
        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;

        }