code

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using TuWei.WebMVC.BLL;
using TuWei.WebMVC.Models;
using TuWei.WebMVC.OldTplant;

namespace TuWei.WebMVC.Controllers
{
//模型服务方法
public class TPlantController : BaseController
{

public readonly string SecretKey = System.Configuration.ConfigurationManager.AppSettings["TPlantSecretKey"];

#region TPlant模型服务方法

/// <summary>
/// 获取模型服务地址
/// </summary>
/// <returns></returns>
public string BeginSocket()
{
var result = string.Empty;

//modelServiceID 参数名不可修改,模型请求时发起的固定传参
var modelServiceID = Request["modelServiceID"].ToString();
EdgService_SoapClient service = new EdgService_SoapClient();
if (IsInner())//判断是否内网ta
{
result = service.BeginSocket_Loc(modelServiceID, 0);
}
else
{
result = service.BeginSocket(modelServiceID, 0);
}
return "\""+result+"\"";
}

/// <summary>
/// 获取颜色信息
/// </summary>
/// <returns></returns>
public string Color_ListOrderByLevel()
{
return string.Empty;
}

/// <summary>
/// 获取所有模型服务列表
/// </summary>
/// <returns></returns>
public string GetModelServiceList()
{
var result = string.Empty;
EdgService_SoapClient service = new EdgService_SoapClient();
result = Newtonsoft.Json.JsonConvert.SerializeObject(service.GetModelServiceListAsync());
return result;
}


//获取模型服务状态
public async Task<string> GetModelStatus()
{
var result = string.Empty;
bool bl = false;
var serviceName = Request["serviceName"].ToString();
EdgService_SoapClient service = new EdgService_SoapClient();
var re = await service.GetModelStatursAsync(0);
var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ModelListStatus>>(re);
if (list != null && list.Count > 0)
{
bl = list.FindAll(o => o.Key == "1" && o.Value.Contains(serviceName)).ToList().Count > 0;
}
return bl.ToString();
}

/// <summary>
/// 启动一个模型服务
/// </summary>
/// <returns></returns>
public async Task<string> StartInstanceProcess()
{
var serviceName = Request["serviceName"].ToString();
EdgService_SoapClient service = new EdgService_SoapClient();
await service.StartInstanceProcessAsync(serviceName, 0);
return true.ToString();
}

//判断是否内网IP
public bool IsInner()
{
IPAddress ip = null;
var ip4 = Request.UserHostAddress;
if (IPAddress.TryParse(ip4, out ip))
{
return ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork || ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6;
}
return false;

}

public T Deseralize<T>(string jsonstr)
{
return JsonConvert.DeserializeObject<T>(jsonstr);

}

#endregion

}
}

posted @ 2020-11-26 13:50  IDOER  阅读(182)  评论(0编辑  收藏  举报