예제 #1
0
        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));
        }
예제 #2
0
        public static string ServiceBaseUrl(string hostName, string siteName, string appName)
        {
            //find site from given host
            NippsSite nippsSite = NippsSiteHelper.ListNippsSite(hostName)
                                  .Where(s => s.Name.Equals(siteName))
                                  .Single();

            //build url from site bindings
            string baseUrl = nippsSite.Protocol
                             + "://" + hostName
                             + ":" + nippsSite.Port + appName;

            return(baseUrl);
        }
        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);
        }
예제 #4
0
        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());
            }
        }