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 static List <NippsSite> ListNippsSite(string hostName) { string deploymentServiceUrl = BuildDeploymentServiceUrl(hostName) + "ListNippsSite"; NippsSiteResponse response = RestHelper.RestGet <NippsSiteResponse>(deploymentServiceUrl); if (response.Result == Result.OK) { return(response.NippsSites); } foreach (string em in response.ResultMessages) { NLog.LogManager.GetCurrentClassLogger().Error(em); } return(new List <NippsSite>()); }
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); }
public virtual void LogCriticalError(string logMessage) { NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); try { Regex hostRegex = new Regex("://(.*)/Netas\\.Nipps\\."); Regex appRegex = new Regex("(/Netas\\.Nipps\\.)([\\.\\w]*)(/)"); string absoluteUri = Request.RequestUri.AbsoluteUri; string application = appRegex.Match(absoluteUri).Value; string host = hostRegex.Match(absoluteUri).Value.Replace("://", "").Replace("/Netas.Nipps.", ""); string port = Regex.IsMatch(host, ":[0-9]*") ? Regex.Match(host, ":[0-9]*").Value.Replace(":", "") : "80"; host = host.Replace(":" + port, ""); string uri = ConfigurationManager.AppSettings["DeployManagerServiceUrl"]; if (string.IsNullOrEmpty(uri)) { logger.Error("DeployManagerServiceUrl is not defined in the config."); return; } NippsSiteResponse siteResponse = RestHelper.RestGet <NippsSiteResponse>(uri + "DeploymentService/ListNippsSite"); if (siteResponse.Result != Result.OK) { foreach (string m in siteResponse.ResultMessages) { logger.Error(m); } return; } uri = ConfigurationManager.AppSettings["LogManagerServiceUrl"]; if (string.IsNullOrEmpty(uri)) { logger.Error("LogManagerServiceUrl is not defined in the config."); return; } NippsSite nippsSite = siteResponse.NippsSites.Where(ns => ns.Port.Equals(port)).Single(); string moduleName = host + ">" + nippsSite.Name + ">/" + application.Replace("/", ""); NippsLogRequest logRequest = new NippsLogRequest { NippsLogs = new List <NippsLog> { new NippsLog { LogLevelId = NippsLogLevel.Fatal, LogModuleName = moduleName, LogMessage = logMessage } } }; NippsLogResponse logResponse = RestHelper.RestPostObject <NippsLogResponse, NippsLogRequest>(uri + "NippsLogService/Add", logRequest); if (logResponse.Result != Result.OK) { foreach (string m in logResponse.ResultMessages) { logger.Error(m); } } } catch (Exception ex) { logger.Error(ex.ToString()); } }