public virtual IISResultInfo ReStartSite(IISStartInfo info) { var result = StopSite(info); if (result.Success) { result = StartSite(info); } return(result); }
private DirectoryEntry GetByPath(IISStartInfo info) { if (info.ParentID < 1) { return(null); } var webPath = IISWebPath + "/" + info.ParentID.ToString(); var root = new DirectoryEntry(webPath); return(root); }
public override IISResultInfo StopSite(IISStartInfo info) { var ret = new IISResultInfo(); try { var siteEntry = GetByPath(info); if (siteEntry == null) { return(ret.SetError("站点不存在", 404)); } siteEntry.Invoke("Stop", null); siteEntry.Dispose(); } catch (Exception e) { ret.SetError(e.Message, 500); } return(ret); }
public override IISResultInfo StartSite(IISStartInfo info) { var data = new IISResultInfo(); try { using (var iisManager = new ServerManager()) { var site = iisManager.Sites.FirstOrDefault(p => p.Id == info.ParentID); if (site == null) { return(data.SetError("site not found", 404)); } switch (site.State) { case ObjectState.Starting: break; case ObjectState.Started: break; case ObjectState.Stopping: case ObjectState.Stopped: case ObjectState.Unknown: site.Start(); break; default: throw new ArgumentOutOfRangeException(); } } } catch (Exception e) { data.SetError(e); } return(data); }
public abstract IISResultInfo StopSite(IISStartInfo info);