import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import com.esri.arcgis.server.ServerConnection;
import com.esri.arcgis.system.ServerInitializer;
import com.esri.arcgis.carto.IImageDescription;
import com.esri.arcgis.carto.IImageDisplay;
import com.esri.arcgis.carto.IImageResult;
import com.esri.arcgis.carto.IImageType;
import com.esri.arcgis.carto.IMapDescription;
import com.esri.arcgis.carto.IMapServer;
import com.esri.arcgis.carto.IMapServerInfo;
import com.esri.arcgis.carto.ImageDescription;
import com.esri.arcgis.carto.ImageDisplay;
import com.esri.arcgis.carto.MapServer;
import com.esri.arcgis.carto.esriImageFormat;
import com.esri.arcgis.carto.esriImageReturnType;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.server.IEnumServerDirectoryInfo;
import com.esri.arcgis.server.IEnumServerObjectConfiguration;
import com.esri.arcgis.server.IServerContext;
import com.esri.arcgis.server.IServerObjectAdmin;
import com.esri.arcgis.server.IServerObjectConfiguration2;
import com.esri.arcgis.server.IServerObjectConfigurationStatus;
import com.esri.arcgis.server.IServerObjectManager;
import com.esri.arcgis.server.ServerConnection;
import com.esri.arcgis.server.esriConfigurationStatus;
import com.esri.arcgis.server.esriServerIsolationLevel;
import com.esri.arcgis.server.esriStartupType;
import com.esri.arcgis.system.IPropertySet;
import com.esri.arcgis.system.ServerInitializer;
import com.esri.arcgis.carto.ImageType;
import com.esri.arcgis.geometry.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import javax.imageio.ImageIO;
public class MapServiceOper {
private String ip;
private String user;
private String password;
private Map serverInfo;
private ServerConnection conn=null;
private String filePath;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Map getServerInfo() {
return serverInfo;
}
public void setServerInfo(Map serverInfo) {
this.serverInfo = serverInfo;
}
public void MapServiceOper(String ip,String user,String password ){
this.ip = ip;
this.user = user;
this.password =password;
}
public Boolean reStartMapService(){
//IServerObjectManager som= conn.getServerObjectManager();
//IEnumServerDirectoryInfo directoryInfo = som.getServerDirectoryInfos();
//System.out.println(directoryInfo.getCount());
try {
IServerObjectAdmin pServerObjectAdmin =conn.getServerObjectAdmin();
//获得server服务器列表,判断发布的服务是否存在
IEnumServerObjectConfiguration ss = pServerObjectAdmin.getConfigurations();
IServerObjectConfiguration2 pp;
boolean isExist=false;
for (int i = 0; i < ss.getCount();i++ )
{
pp = (IServerObjectConfiguration2)ss.next();
String name = pp.getName();
String type=pp.getTypeName();
System.out .println ("服务名:"+name);
if(serverInfo.containsKey(name))
{
if(serverInfo.get(name).toString().equals(type))
{
System.out .println ("找到服务!"+name);
pServerObjectAdmin.startConfiguration(pp.getName(), pp.getTypeName());
isExist=true;
System.out .println (name+"服务启动成功!");
}
}
}
if(isExist)
{
return true;
}
else
{
System.out .println ("不存在服务!");
return false;
}
}catch (AutomationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
public Boolean stopMapService(){
try {
IServerObjectAdmin pServerObjectAdmin =conn.getServerObjectAdmin();
//获得server服务器列表,判断发布的服务是否存在
IEnumServerObjectConfiguration ss = pServerObjectAdmin.getConfigurations();
IServerObjectConfiguration2 pp;
boolean isExist=false;
for (int i = 0; i < ss.getCount();i++ )
{
pp = (IServerObjectConfiguration2)ss.next();
String name = pp.getName();
String type=pp.getTypeName();
System.out .println ("服务名:"+name);
if(serverInfo.containsKey(name))
{
if(serverInfo.get(name).toString().equals(type))
{
System.out .println ("找到服务!"+name);
pServerObjectAdmin.stopConfiguration(pp.getName(), pp.getTypeName());
isExist=true;
System.out .println (name+"服务关闭成功!");
}
}
}
if(isExist)
{
return true;
}
else
{
System.out .println ("不存在服务!");
return false;
}
}catch (AutomationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
public Boolean deleteMapService(){
try {
IServerObjectAdmin pServerObjectAdmin =conn.getServerObjectAdmin();
//获得server服务器列表,判断发布的服务是否存在
IEnumServerObjectConfiguration ss = pServerObjectAdmin.getConfigurations();
IServerObjectConfiguration2 pp;
boolean isExist=false;
for (int i = 0; i < ss.getCount();i++ )
{
pp = (IServerObjectConfiguration2)ss.next();
String name = pp.getName();
String type=pp.getTypeName();
System.out .println ("服务名:"+name);
if(serverInfo.containsKey(name))
{
if(serverInfo.get(name).toString().equals(type))
{
System.out .println ("找到服务!"+name);
pServerObjectAdmin.deleteConfiguration(pp.getName(), pp.getTypeName());
isExist=true;
System.out .println (name+"服务删除成功!");
}
}
}
if(isExist)
{
return true;
}
else
{
System.out .println ("不存在服务!");
return false;
}
}catch (AutomationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
public boolean publishMapService(){
try
{
IServerObjectAdmin pServerObjectAdmin = conn.getServerObjectAdmin();
//获得server服务器列表,判断发布的服务是否存在
IEnumServerObjectConfiguration ss = pServerObjectAdmin.getConfigurations();
IServerObjectConfiguration2 pp;
for (int i = 0; i < ss.getCount();i++ )
{
pp = (IServerObjectConfiguration2)ss.next();
String name = pp.getName();
System.out .println (name);
String type=pp.getTypeName();