init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal interface IListControl {
|
||||
|
||||
String[] Options { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class IntDroplist : ParamControl, IListControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach (String str in this.Options) {
|
||||
if (str.Equals( base.Value )) {
|
||||
builder.AppendFormat( "<option value=\"{0}\" selected=\"selected\">{0}</option>", str );
|
||||
}
|
||||
else {
|
||||
builder.AppendFormat( "<option value=\"{0}\">{0}</option>", str );
|
||||
}
|
||||
}
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><select name=\"{1}\" class=\"IntDroplist\">{2}</select></span>", base.Label, base.Name, builder.ToString() );
|
||||
}
|
||||
}
|
||||
|
||||
public String[] Options { get; set; }
|
||||
|
||||
public override System.Type Type {
|
||||
get { return typeof( int ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class IntTextbox : ParamControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><input name=\"{1}\" type=\"text\" value=\"{2}\" class=\"IntTextbox\" /></span>", base.Label, base.Name, base.Value );
|
||||
}
|
||||
}
|
||||
|
||||
public override System.Type Type {
|
||||
get { return typeof( int ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class LongTextbox : ParamControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><textarea name=\"{1}\" class=\"LongTextbox\">{2}</textarea></span>", base.Label, base.Name, base.Value );
|
||||
}
|
||||
}
|
||||
|
||||
public override System.Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using Zhaizj.Framework;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
/// <summary>
|
||||
/// 参数在 html 表单中对应的控件
|
||||
/// </summary>
|
||||
public abstract class ParamControl {
|
||||
|
||||
/// <summary>
|
||||
/// web界面中显示用的字符
|
||||
/// </summary>
|
||||
public String Label { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数名称,从0开始:param0, param1, param2, .... paramN
|
||||
/// </summary>
|
||||
public String Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数的值,用于传递
|
||||
/// </summary>
|
||||
public String Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 控件的 Html
|
||||
/// </summary>
|
||||
public abstract String Html { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数的类型
|
||||
/// </summary>
|
||||
public abstract Type Type { get; }
|
||||
|
||||
protected ParamControl() { }
|
||||
|
||||
/// <summary>
|
||||
/// 将参数值转换为正确的参数类型
|
||||
/// </summary>
|
||||
/// <param name="val"></param>
|
||||
/// <returns></returns>
|
||||
public Object ChangeType( Object val ) {
|
||||
|
||||
if (val == null) return getNullValue( val );
|
||||
|
||||
try {
|
||||
return Convert.ChangeType( val, this.Type );
|
||||
}
|
||||
catch {
|
||||
return getNullValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
private Object getNullValue( Object val ) {
|
||||
if (this.Type == typeof( int )) return 0;
|
||||
if (this.Type == typeof( DateTime )) return DateTime.Now;
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取参数对应的控件
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <param name="paramIndex"></param>
|
||||
/// <returns></returns>
|
||||
public static ParamControl GetControl( String param, int paramIndex ) {
|
||||
return GetControl( param, paramIndex, "" );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取参数对应的控件
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <param name="paramIndex"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static ParamControl GetControl( String param, int paramIndex, String value ) {
|
||||
|
||||
if (strUtil.IsNullOrEmpty( param )) return null;
|
||||
|
||||
String[] strArray = param.Split( new char[] { '=' } );
|
||||
String itemName = strArray[0];
|
||||
String itemValue = strArray[1];
|
||||
|
||||
if (itemValue.StartsWith( "IntTextbox" )) {
|
||||
IntTextbox intBox = new IntTextbox();
|
||||
init( intBox, itemName, paramIndex, value );
|
||||
return intBox;
|
||||
}
|
||||
if (itemValue.StartsWith( "IntDroplist" )) {
|
||||
IntDroplist droplist = new IntDroplist();
|
||||
initList( droplist, itemName, paramIndex, value, itemValue );
|
||||
return droplist;
|
||||
}
|
||||
if (itemValue.StartsWith( "StringTextbox" )) {
|
||||
StringTextbox strBox = new StringTextbox();
|
||||
init( strBox, itemName, paramIndex, value );
|
||||
return strBox;
|
||||
}
|
||||
if (itemValue.StartsWith( "StringDroplist" )) {
|
||||
StringDroplist droplist = new StringDroplist();
|
||||
initList( droplist, itemName, paramIndex, value, itemValue );
|
||||
return droplist;
|
||||
}
|
||||
if (itemValue.StartsWith( "StringRadio" )) {
|
||||
StringRadio radio = new StringRadio();
|
||||
initList( radio, itemName, paramIndex, value, itemValue );
|
||||
return radio;
|
||||
}
|
||||
if (itemValue.StartsWith( "StringCheckbox" )) {
|
||||
StringCheckbox checkbox = new StringCheckbox();
|
||||
initList( checkbox, itemName, paramIndex, value, itemValue );
|
||||
return checkbox;
|
||||
}
|
||||
if (itemValue.StartsWith( "LongTextbox" )) {
|
||||
LongTextbox longBox = new LongTextbox();
|
||||
init( longBox, itemName, paramIndex, value );
|
||||
return longBox;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void init( ParamControl ctl, String itemName, int paramIndex, String value ) {
|
||||
ctl.Label = itemName;
|
||||
|
||||
// 参数从0开始:param0, param1, param2, .... paramN
|
||||
ctl.Name = "param" + paramIndex;
|
||||
ctl.Value = value;
|
||||
}
|
||||
|
||||
private static void initList( ParamControl ctl, String itemName, int paramIndex, String value, String itemValue ) {
|
||||
ctl.Label = itemName;
|
||||
ctl.Name = "param" + paramIndex;
|
||||
ctl.Value = value;
|
||||
((IListControl)ctl).Options = getOptions( itemValue );
|
||||
}
|
||||
|
||||
private static String[] getOptions( String itemValue ) {
|
||||
String str = itemValue.TrimEnd( ')' ).Split( '(' )[1];
|
||||
return str.Split( '/' );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class StringCheckbox : ParamControl, IListControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append( "<span class=\"paramLabel\">" );
|
||||
builder.Append( base.Label );
|
||||
builder.Append( "</span> <span class=\"paramControl\">" );
|
||||
foreach (String str in this.Options) {
|
||||
builder.AppendFormat( "<input name=\"{0}\" value=\"{1}\" type=\"checkbox\" class=\"StringCheckbox\"", base.Name, str );
|
||||
if (str.Equals( base.Value )) {
|
||||
builder.AppendFormat( "checked=\"checked\" />{0} ", str );
|
||||
}
|
||||
else {
|
||||
builder.AppendFormat( "/>{0} ", str );
|
||||
}
|
||||
}
|
||||
builder.Append( "</span>" );
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public String[] Options { get; set; }
|
||||
|
||||
public override Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class StringDroplist : ParamControl, IListControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach (String str in this.Options) {
|
||||
if (str.Equals( base.Value )) {
|
||||
builder.AppendFormat( "<option value=\"{0}\" selected=\"selected\">{0}</option>", str );
|
||||
}
|
||||
else {
|
||||
builder.AppendFormat( "<option value=\"{0}\">{0}</option>", str );
|
||||
}
|
||||
}
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><select name=\"{1}\" class=\"StringDroplist\">{2}</select></span>", base.Label, base.Name, builder.ToString() );
|
||||
}
|
||||
}
|
||||
|
||||
public String[] Options { get; set; }
|
||||
|
||||
public override Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class StringRadio : ParamControl, IListControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append( "<span class=\"paramLabel\">" );
|
||||
builder.Append( base.Label );
|
||||
builder.Append( "</span> <span class=\"paramControl\">" );
|
||||
foreach (String str in this.Options) {
|
||||
builder.AppendFormat( "<input name=\"{0}\" value=\"{1}\" type=\"radio\" class=\"StringRadio\"", base.Name, str );
|
||||
if (str.Equals( base.Value )) {
|
||||
builder.AppendFormat( "checked=\"checked\" />{0} ", str );
|
||||
}
|
||||
else {
|
||||
builder.AppendFormat( "/>{0} ", str );
|
||||
}
|
||||
}
|
||||
builder.Append( "</span>" );
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public String[] Options { get; set; }
|
||||
|
||||
public override Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class StringTextbox : ParamControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><input name=\"{1}\" type=\"text\" value=\"{2}\" class=\"StringTextbox\"/></span>", base.Label, base.Name, base.Value );
|
||||
}
|
||||
}
|
||||
|
||||
public override Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Zhaizj.Framework.Data;
|
||||
using Zhaizj.Framework.SOA.Controls;
|
||||
|
||||
namespace Zhaizj.Framework.SOA {
|
||||
|
||||
/// <summary>
|
||||
/// 服务的状态
|
||||
/// </summary>
|
||||
public class ServiceStatus {
|
||||
|
||||
/// <summary>
|
||||
/// 禁止在服务列表中查看
|
||||
/// </summary>
|
||||
public static readonly int ListForbidden = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 系统中各类服务
|
||||
/// </summary>
|
||||
public class Service : CacheObject {
|
||||
|
||||
/// <summary>
|
||||
/// 服务的全名,比如 Zhaizj.Framework.Apps.Forum.Service.ForumTopicService
|
||||
/// </summary>
|
||||
public String Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 服务公开的方法名称,比如 GetRecentTopic
|
||||
/// </summary>
|
||||
public String Method { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数类型,包括在web页面中显示的名称和控件类型(比如:显示数量=IntTextbox;性别=StringDroplist(男/女/保密);名称=StringTextBox;)
|
||||
/// </summary>
|
||||
public String Params { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数的默认值(可选)
|
||||
/// </summary>
|
||||
public String ParamsDefault { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取参数的默认值
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<String, String> GetParamDefault() {
|
||||
Dictionary<String, String> result = new Dictionary<String, String>();
|
||||
if (strUtil.IsNullOrEmpty( this.ParamsDefault )) return result;
|
||||
String[] arrPair = this.ParamsDefault.Split( ';' );
|
||||
foreach (String pair in arrPair) {
|
||||
if (strUtil.IsNullOrEmpty( pair )) continue;
|
||||
String[] arrItem = pair.Split( '=' );
|
||||
if (arrItem.Length != 2) continue;
|
||||
result.Add( arrItem[0].Trim(), arrItem[1].Trim() );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分类:可以通过 GetBy(String tag) 获得某类别的所有服务
|
||||
/// </summary>
|
||||
public String Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 预留的自定义的筛选条件(通常指出对应的模板名称)
|
||||
/// </summary>
|
||||
public String Note { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 预留的服务状态:启用、停用、禁止等
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 只有允许的 owner 才可以使用本服务。留空表示不限制。多个owner可以用英文分号隔开
|
||||
/// </summary>
|
||||
public String Owner { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 服务简介。用于可视化界面中
|
||||
/// </summary>
|
||||
public String Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 此服务对应的链接
|
||||
/// </summary>
|
||||
public String Link { get; set; }
|
||||
|
||||
private ArrayList _controls;
|
||||
|
||||
/// <summary>
|
||||
/// 获得所有参数所对应的控件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ArrayList GetParams() {
|
||||
if (_controls == null) {
|
||||
_controls = getParamsList( Params );
|
||||
}
|
||||
return _controls;
|
||||
}
|
||||
|
||||
private ArrayList getParamsList( String paramString ) {
|
||||
ArrayList list = new ArrayList();
|
||||
if (strUtil.IsNullOrEmpty( paramString )) return list;
|
||||
|
||||
String[] arrItem = paramString.Split( ';' );
|
||||
for (int i = 0; i < arrItem.Length; i++) {
|
||||
String item = arrItem[i];
|
||||
if (strUtil.HasText( item )) {
|
||||
list.Add( ParamControl.GetControl( item, i ) );
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得所有允许的 Owner 数组
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public String[] GetOwnerTypes() {
|
||||
return this.Owner.Split( ';' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Zhaizj.Framework.DI;
|
||||
using Zhaizj.Framework.Reflection;
|
||||
using Zhaizj.Framework.SOA.Controls;
|
||||
|
||||
namespace Zhaizj.Framework.SOA {
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务的工具类
|
||||
/// </summary>
|
||||
public class ServiceContext {
|
||||
|
||||
/// <summary>
|
||||
/// 根据 id 获取服务
|
||||
/// </summary>
|
||||
/// <param name="serviceId"></param>
|
||||
/// <returns></returns>
|
||||
public static Service Get( int serviceId ) {
|
||||
return (new Service().findById( serviceId ) as Service);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有服务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IList GetAll() {
|
||||
return new Service().findAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得某分类下的所有服务(tag当做分类法使用)
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="ownerType"></param>
|
||||
/// <returns></returns>
|
||||
public static IList GetByTag( String tag, String ownerType ) {
|
||||
IList list = new ArrayList();
|
||||
IList all = GetAll();
|
||||
foreach (Service service in all) {
|
||||
if (hasTag( service.Tags, tag ) && isOwner( ownerType, service.GetOwnerTypes() ) && service.Status != ServiceStatus.ListForbidden) {
|
||||
list.Add( service );
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static Boolean isOwner( String ownerType, String[] ownerTypes ) {
|
||||
foreach (String o in ownerTypes) {
|
||||
if (ownerType.Equals( o )) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据服务 id 和参数,调用服务,返回服务运行的结果
|
||||
/// </summary>
|
||||
/// <param name="serviceId"></param>
|
||||
/// <param name="serviceParamValues">服务的参数</param>
|
||||
/// <param name="defaultValues">默认参数</param>
|
||||
/// <returns></returns>
|
||||
public static IList GetData( int serviceId, Dictionary<String, String> serviceParamValues, Dictionary<String, String> defaultValues ) {
|
||||
|
||||
ArrayList argList = new ArrayList();
|
||||
|
||||
Service service = Get( serviceId );
|
||||
IList parms = service.GetParams();
|
||||
for (int i = 0; i < parms.Count; i++) {
|
||||
|
||||
String pkey = "param" + i;
|
||||
String val = serviceParamValues.ContainsKey( pkey ) ? serviceParamValues[pkey] : null;
|
||||
|
||||
Object argValue = ((ParamControl)parms[i]).ChangeType( val );
|
||||
argList.Add( argValue );
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<String, String> pair in defaultValues) {
|
||||
Object argValue = getValue( service, pair );
|
||||
argList.Add( argValue );
|
||||
}
|
||||
|
||||
object[] args = argList.ToArray();
|
||||
|
||||
Object objService = ObjectContext.GetByType( service.Type );
|
||||
return (ReflectionUtil.CallMethod( objService, service.Method, args ) as IList);
|
||||
}
|
||||
|
||||
private static Object getValue( Service service, KeyValuePair<String, String> pair ) {
|
||||
Dictionary<String, String> pd = service.GetParamDefault();
|
||||
String valueType = pd[pair.Key];
|
||||
if (valueType.Equals( "int" ))
|
||||
return cvt.ToInt( pair.Value );
|
||||
return pair.Value;
|
||||
}
|
||||
|
||||
private static Boolean hasTag( String svcTag, String tag ) {
|
||||
if (strUtil.HasText( svcTag )) {
|
||||
tag = tag.Trim();
|
||||
String[] strArray = svcTag.Split( new[] { ',', '/', ' ', '|' } );
|
||||
foreach (String str in strArray) {
|
||||
if (str.Trim() == tag) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user