You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
5.0 KiB
127 lines
5.0 KiB
using CounsellorBL;
|
|
using CounsellorBL.Helper;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using OT.COM.SignalerMessage;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace EnterprizeV4.Controllers
|
|
{
|
|
public class HealthyController : Controller
|
|
{
|
|
// GET: Healthy
|
|
public ActionResult Index()
|
|
{
|
|
string sName = User.Identity.Name;
|
|
ViewBag.Identity = sName;
|
|
|
|
|
|
|
|
ConcurrentDictionary<string, string> dicSetting = TestService.GetSetting();
|
|
ViewBag.Setting = dicSetting;
|
|
|
|
AssemblyHelper.Load(Assembly.GetExecutingAssembly(), "CounsellorBL.*.dll");
|
|
string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase;
|
|
codeBase = codeBase.Substring(0, codeBase.LastIndexOf("/", StringComparison.OrdinalIgnoreCase));
|
|
|
|
Assembly[] assemblyArray = (from f in AppDomain.CurrentDomain.GetAssemblies()
|
|
where !f.IsDynamic
|
|
&& f.FullName.IndexOf("CounsellorBL", StringComparison.OrdinalIgnoreCase) != -1
|
|
&& f.CodeBase != null
|
|
&& f.CodeBase.StartsWith(codeBase, StringComparison.OrdinalIgnoreCase)
|
|
select f).ToArray<Assembly>();
|
|
|
|
Assembly abFirst = assemblyArray.FirstOrDefault();
|
|
string sVersion = null;
|
|
if (abFirst != null)
|
|
{
|
|
sVersion = FileVersionInfo.GetVersionInfo(abFirst.Location).FileVersion;
|
|
}
|
|
ViewBag.Version = sVersion;
|
|
|
|
|
|
return View();
|
|
}
|
|
|
|
protected string serviceString()
|
|
{
|
|
AssemblyHelper.Load(Assembly.GetExecutingAssembly(), "CounsellorBL.*.dll");
|
|
string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase;
|
|
codeBase = codeBase.Substring(0, codeBase.LastIndexOf("/", StringComparison.OrdinalIgnoreCase));
|
|
|
|
Assembly[] assemblyArray = (from f in AppDomain.CurrentDomain.GetAssemblies()
|
|
where !f.IsDynamic
|
|
&& f.FullName.IndexOf("CounsellorBL", StringComparison.OrdinalIgnoreCase) != -1
|
|
&& f.CodeBase != null
|
|
&& f.CodeBase.StartsWith(codeBase, StringComparison.OrdinalIgnoreCase)
|
|
select f).ToArray<Assembly>();
|
|
|
|
Type tBase = typeof(ServiceBase);
|
|
Type tReturn = typeof(CResponseMessage);
|
|
Type tRequestParam = typeof(CRequestMessage);
|
|
StringBuilder sbService = new StringBuilder();
|
|
|
|
foreach (Assembly assembly2 in assemblyArray)
|
|
{
|
|
IEnumerable<Type> ieType = assembly2.GetTypes().Where(x => x.IsClass && x.IsSubclassOf(tBase) && !x.IsGenericType);
|
|
|
|
|
|
string[] saModuleName = assembly2.ManifestModule.Name.Split(".".ToCharArray());
|
|
string sModuleName = saModuleName.Length == 3 ? saModuleName[1] + "." : "";
|
|
foreach (Type tService in ieType)
|
|
{
|
|
MethodInfo[] mis = tService.GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(
|
|
f => f.Name != "" && f.ReturnType == tReturn && f.GetParameters().Length == 1 && f.GetParameters()[0].ParameterType == tRequestParam)
|
|
.Distinct(new MethodInfoEq()).ToArray();
|
|
|
|
if (mis.Any())
|
|
{
|
|
sbService.AppendLine("// tslint:disable-next-line:class-name");
|
|
sbService.AppendLine($"export class {tService.Name}Meta {{");
|
|
sbService.AppendLine($" static SERVICENAME = '{sModuleName}{tService.Name}' ;");
|
|
|
|
foreach (MethodInfo mi in mis)
|
|
{
|
|
sbService.AppendLine($"\tstatic {mi.Name} = '{mi.Name}';");
|
|
}
|
|
sbService.AppendLine("}");
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return sbService.ToString();
|
|
}
|
|
|
|
// GET: Healthy/Details/5
|
|
public ActionResult ServiceString()
|
|
{
|
|
MemoryStream ms = new MemoryStream();
|
|
StreamWriter sw = new StreamWriter(ms, Encoding.UTF8);
|
|
sw.WriteLine(serviceString());
|
|
sw.Flush();
|
|
ms.Seek(0, SeekOrigin.Begin);
|
|
return File(ms, System.Net.Mime.MediaTypeNames.Application.Octet, "SupportService.ts");
|
|
}
|
|
|
|
}
|
|
|
|
public class MethodInfoEq : IEqualityComparer<MethodInfo>
|
|
{
|
|
public bool Equals(MethodInfo x, MethodInfo y)
|
|
{
|
|
return x.Name == y.Name;
|
|
}
|
|
|
|
public int GetHashCode(MethodInfo obj)
|
|
{
|
|
return obj.Name.GetHashCode();
|
|
}
|
|
}
|
|
}
|