// Use this for initialization void Start() { serverManager = this; Commands = new Queue <string>(); //OnMatchInfoReceived; SetConnection(); }
private string SavePackage(NippsPackage nippsPackage, Site site) { NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); logger.Debug(nippsPackage); //decode zip-file byte[] packageZipBuffer = Convert.FromBase64String(nippsPackage.PackageZIP); //calculate physical-path of the / -default- app&virtualpath string basePath = site.Applications .Where(a => a.Path.Equals("/")) .Single() .VirtualDirectories .Where(v => v.Path.Equals("/")) .Single() .PhysicalPath; basePath += "\\"; basePath = ServerManagerHelper.PutEnvVarValue(basePath); logger.Debug(basePath); NippsZipHelper.Unzip(basePath, packageZipBuffer); return(basePath); }
private static string ApplicationRestore(NippsPackage np) { string currentAppFolder = AppDomain.CurrentDomain.BaseDirectory; string applicationFolder = ServerManagerHelper.PutEnvVarValue( ServerManagerHelper.GetApplicationPhysicalPath( np.SiteName, np.ApplicationName )); string BackupTargetPath = GetBackupTargetPath(); string zipName = BackupTargetPath + np.PackageZIP; _Logger.Debug("{0}, {1}, {2}", currentAppFolder, applicationFolder, zipName); if (applicationFolder.StartsWith(currentAppFolder) || currentAppFolder.StartsWith(applicationFolder)) { return("[ErrorCode: RESTORE_COULD_NOT_EXTRACT_OVER_SELF]"); } applicationFolder = applicationFolder.EndsWith("\\") ? applicationFolder : applicationFolder + "\\"; NippsZipHelper.Unzip(applicationFolder, zipName); return(zipName.Substring(BackupTargetPath.Length)); }
private static string ApplicationBackup(NippsPackage np) { string applicationFolder = ServerManagerHelper.PutEnvVarValue( ServerManagerHelper.GetApplicationPhysicalPath( np.SiteName, np.ApplicationName )); string BackupTargetPath = GetBackupTargetPath(); string zipName = BackupTargetPath + (np.ApplicationName.Equals("/") ? "Site_" : "Appl_") + ZipFileName(np); _Logger.Debug("{0}, {1}", applicationFolder, zipName); NippsZipHelper.ZipFolder(applicationFolder, zipName); return(zipName.Substring(BackupTargetPath.Length)); }
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); }