using System.Reflection.Metadata;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Collections;
using System.Reflection;
using UMC.Web;
using UMC.Data.Entities;
using UMC.Web.UI;
using UMC.ITME.Entities;
using UMC.Net;
using UMC.Data;
namespace UMC.ITME.Activities
{
///
/// 邮箱账户
///
[UMC.Web.Apiumc("Proxy", "Setup", Auth = WebAuthType.Admin)]
class SiteSetupActivity : WebActivity
{
public override void ProcessActivity(WebRequest request, WebResponse response)
{
var ConfKey = this.AsyncDialog("ConfKey", r =>
{
return new Web.UISheetDialog() { Title = "新发布类型" }
.Put("Web应用", "Proxy").Put("文件应用", "File");
});
if (ConfKey.StartsWith("https://") || ConfKey.StartsWith("http://"))
{
var url = new Uri(ConfKey);
request.Arguments.Put("Domain", new Uri(url, "/").AbsoluteUri);
ConfKey = url.LocalPath.Trim('/');
if (String.IsNullOrEmpty(ConfKey))
{
ConfKey = "Proxy";
}
else if (ConfKey == "UMC")
{
var str = new Uri(url, "/UMC.Conf").WebRequest().Put(new WebMeta().Put("domain", $"{Web.WebResource.Instance().WebDomain()}")).ReadAsString();
var data = JSON.Deserialize(str);
if (data?.ContainsKey("appConf") == true)
{
var appConf = data["appConf"] as Hashtable;
if (appConf.ContainsKey("IconSrc"))
{
this.Context.Request.Arguments.Put("IconSrc", data["IconSrc"]);
}
if (appConf.ContainsKey("Open"))
{
this.Context.Request.Arguments.Put("Open", data["Open"]);
}
if (appConf.ContainsKey("Menu"))
{
this.Context.Request.Arguments.Put("Menu", JSON.Serialize(data["Menu"]));
}
if (appConf.ContainsKey("Home"))
{
this.Context.Request.Arguments.Put("Home", data["Home"]);
}
if (appConf.ContainsKey("Mobile"))
{
this.Context.Request.Arguments.Put("Mobile", data["Mobile"]);
}
if (appConf.ContainsKey("Caption"))
{
this.Context.Request.Arguments.Put("Caption", data["Caption"]);
}
}
}
}
var appId = WebResource.Instance().Provider["appId"];
var secret = UMC.Data.WebResource.Instance().Provider["appSecret"];
var config = this.AsyncDialog("Settings", g =>
{
var from = new Web.UIFormDialog() { Title = "发布新应用" };
var sDomain = this.AsyncDialog("Domain", "none");
var Caption = this.Context.Request.Arguments["Caption"];
this.Context.Request.Arguments.Remove("Caption");
switch (ConfKey)
{
case "UMC":
case "Proxy":
case "Bridge":
if (String.Equals(sDomain, "none"))
{
from.AddText("应用网址", "Domain", String.Empty);
this.Context.Request.Arguments.Remove("Domain");
}
else
{
from.AddTextValue().Put("应用网址", sDomain);
}
from.AddText("发布标识", "Root", String.Empty).PlaceHolder("[a-z0-9]全小写字符").Put("tip", "");// $"将以[标识]为前缀合成域名来访问");
from.AddText("发布名称", "Caption", Caption);
break;
case "File":
this.Context.Request.Arguments.Remove("Domain");
from.Title = "发布文件应用";
from.AddOption("所在目录", "Domain", String.Empty, String.Empty).Command("System", "Dir", new WebMeta().Put("type", "Dir"));
from.AddText("发布标识", "Root", String.Empty).PlaceHolder("[a-z0-9]全小写字符").Put("tip", "");//$"将以[标识]为前缀合成域名来访问");
from.AddText("发布名称", "Caption", Caption);
from.AddCheckBox("", "AuthConf", "none").Put("支持目录浏览", "*", true);
break;
case "Developer":
if (String.IsNullOrEmpty(secret))
{
this.Context.Response.Redirect("System", "License", new UIConfirmDialog("当前版本未登记注册") { DefaultValue = "Select" });
}
from.Title = "开发者发布";
from.Add(UICell.Create("QRCode", new WebMeta().Put("value", $"https://api.apiumc.com/UMC/Platform/EditCert/{appId}")));
from.AddConfirm("请开发者用ITME App扫一扫,生成开发者证书,再点击下一步", "Settings", "YES");
from.Submit("下一步", $"{request.Model}.{request.Command}");
return from;
default:
if (String.IsNullOrEmpty(secret))
{
this.Context.Response.Redirect("System", "License", new UIConfirmDialog("当前版本未登记注册") { DefaultValue = "Select" });
}
var webr2 = new Uri(APIProxy.Uri, "Transfer").WebRequest();
UMC.ITME.Utility.Sign(webr2, secret);
var data = JSON.Deserialize(webr2.Post(new WebMeta().Put("type", "Market", "ProductCode", ConfKey)).ReadAsString());
if (data == null)
{
this.Prompt("网络异常");
}
if (data.ContainsKey("success"))
{
from.Title = "发布市场应用";
if (data.ContainsKey("Domain"))
{
sDomain = data["Domain"] as string;
this.Context.Request.Arguments.Put("Domain", sDomain);
from.AddTextValue().Put("服务网址", sDomain);
}
else if (String.Equals(sDomain, "none"))
{
from.AddText("应用网址", "Domain", String.Empty);
this.Context.Request.Arguments.Remove("Domain");
}
else
{
from.AddTextValue().Put("应用网址", sDomain);
}
if (data.ContainsKey("IconSrc"))
{
this.Context.Request.Arguments.Put("IconSrc", data["IconSrc"]);
}
from.AddText("发布标识", "Root", String.Empty).PlaceHolder("[a-z0-9]全小写字符").Put("tip", "");//$"将以[标识]为前缀合成域名来访问");
from.AddText("发布名称", "Caption", data["Caption"] as string);
from.AddRadio("服务条款", "Price", new ListItemCollection().Put(String.Format("{0}", data["Price"]), "1"));
from.Submit("确认发布", "Site.Config");
from.Add(UICell.UI('\uf085', "开发者", data["Seller"] as string));
from.Add(UICell.UI('\ue94d', "服务电话", data["Tel"] as string, UIClick.Tel(data["Tel"] as string)));
return from;
}
else
{
this.Prompt((data["msg"] as string) ?? "参数不正确");
}
break;
}
from.Submit("确认发布", "Site.Config");
return from;
});
if (ConfKey == "Developer")
{
var content = new Uri($"https://wdk.oss-accelerate.aliyuncs.com/TEMP/EditCert/{appId}.lic").WebRequest().Get().ReadAsString();
if (String.IsNullOrEmpty(content))
{
this.Prompt("获取证书失败");
}
var s = content.IndexOf(":");
if (s == -1)
{
this.Prompt("获取证书失败");
}
var Seller = content.Substring(0, s);
if (License.GetLicense(Seller).ExpireTime > 0 || License.Put(Seller, content.Substring(s + 1)))
{
this.Context.Send(false);
response.Redirect(request.Model, request.Command, Seller);
this.Prompt("证书导入成功");
}
else
{
this.Prompt("获取导入失败,请确认证书是否一致");
}
}
var site = new Site
{
Root = config["Root"].ToLower()
};
if (System.Text.RegularExpressions.Regex.IsMatch(site.Root, "^[a-z0-9]+$") == false)
{
this.Prompt("应用标识只支持【a-z0-9】字符");
}
site.Caption = config["Caption"];
try
{
var Domain = config["Domain"];
if (String.IsNullOrEmpty(Domain))
{
this.Prompt("请输入正确的网址");
}
switch (Domain.Substring(0, Domain.IndexOf("://")))
{
case "http":
case "https":
if (Domain.Contains("*."))
{
var l = Domain.IndexOf('/', 8);
if (l == -1)
{
site.Domain = Domain + "/";
}
else
{
site.Domain = Domain.Substring(0, l + 1);
}
}
else
{
site.Domain = new Uri(new Uri(Domain), "/").AbsoluteUri;
}
break;
case "file":
site.Domain = Domain.TrimEnd('/');
if (config["AuthConf"].Contains("*"))
{
site.Domain += "/";
}
break;
case "unix":
site.Domain = Domain;
break;
default:
this.Prompt("网址格式不支持");
break;
}
}
catch
{
this.Prompt("网址格式不支持");
}
if (config.ContainsKey("Home"))
{
site.Home = config["Home"];
}
if (config.ContainsKey("Mobile"))
{
site.MobileHome = config["Mobile"];
}
if (config.ContainsKey("Open"))
{
switch (config["Open"].ToLower())
{
default:
case "new":
site.OpenModel = 0;
break;
case "win":
site.OpenModel = 1;
break;
case "mac":
site.OpenModel = 2;
break;
case "link":
site.OpenModel = 3;
break;
}
}
if (config.ContainsKey("Menu"))
{
var lis = new List