internal static void CreateInterface(string Directory, string Domain, string Namespace, IList List, Func<string, string> WriteFunc = null) { json arr = new json(Post(Domain, EncryptString(new json(new { Name = "interface_info", List = List }).ToString(), Interface_Data_Key))); if (arr.GetType() == "array") { for (int i = 0; i < arr.length; i++) { _ClassInfo info = (_ClassInfo)arr[i]; string sNamespace = info.Namespace; string ClassName = info.ClassName; string FileName = ClassName + ".cs"; IList<_MethodInfo> Methods = info.Methods; if (WriteFunc != null) FileName = WriteFunc(FileName); using (FileStream fs = File.Open(Directory + FileName, FileMode.Create, FileAccess.Write, FileShare.Read)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine("//Domain"); sw.WriteLine("//" + Domain); sw.WriteLine("//Namespace"); sw.WriteLine("//" + Namespace); sw.WriteLine("//ClassName"); sw.WriteLine("//" + sNamespace + "." + ClassName); sw.WriteLine("//请勿修改上述接口信息"); sw.WriteLine("namespace " + Namespace); sw.WriteLine("{"); sw.WriteLine(" public class " + ClassName + " : wnxd.Web.InterfaceBase"); sw.WriteLine(" {"); sw.WriteLine(" public " + ClassName + "()"); sw.WriteLine(" {"); sw.WriteLine(" this.Domain = \"" + Domain + "\";"); sw.WriteLine(" this.Namespace = \"" + sNamespace + "\";"); sw.WriteLine(" this.ClassName = \"" + ClassName + "\";"); sw.WriteLine(" }"); for (int n = 0; n < Methods.Count; n++) { _MethodInfo MethodInfo = Methods[n]; string MethodToken = MethodInfo.MethodToken; string MethodName = MethodInfo.MethodName; string ReturnType = MethodInfo.ReturnType; IList<_ParameterInfo> Parameters = MethodInfo.Parameters; string summary = MethodInfo.Summary; if (!string.IsNullOrEmpty(summary)) { sw.WriteLine(" /// <summary>"); sw.WriteLine(" /// " + summary); sw.WriteLine(" /// </summary>"); } bool isvoid = false; if (ReturnType == "System.Void") isvoid = true; string args = string.Empty; sw.Write(" public " + (isvoid ? "void" : ReturnType) + " " + MethodName + "("); IDictionary<string, string> outparams = new Dictionary<string, string>(); for (int x = 0; x < Parameters.Count; x++) { _ParameterInfo ParameterInfo = Parameters[x]; string ParameterName = ParameterInfo.ParameterName; _ParameterType Type = ParameterInfo.Type; bool IsOptional = ParameterInfo.IsOptional; string ParameterType = ParameterInfo.ParameterType; if (x > 0) sw.Write(", "); switch (Type) { case _ParameterType.In: args += ", " + ParameterName; break; case _ParameterType.Out: sw.Write("out "); outparams.Add(ParameterName, ParameterType); args += ", null"; break; case _ParameterType.Retval: sw.Write("ref "); outparams.Add(ParameterName, ParameterType); args += ", " + ParameterName; break; } sw.Write(ParameterType + " " + ParameterName); if (IsOptional) sw.Write(" = " + ParameterInfo.DefaultValue.ToString()); } sw.WriteLine(")"); sw.WriteLine(" {"); sw.Write(" wnxd.javascript.json r = this."); if (MethodInfo.CacheTime == null) sw.Write("Run("); else sw.Write("GetCache(" + MethodInfo.CacheTime.Value + ", "); sw.WriteLine("\"" + (string.IsNullOrEmpty(MethodToken) ? MethodName : MethodToken) + "\"" + args + ");"); if (outparams.Count > 0) { sw.WriteLine(" wnxd.javascript.json outparams = r[\"OutParams\"];"); sw.WriteLine(" r = r[\"Data\"];"); int y = 0; foreach (KeyValuePair<string, string> item in outparams) { sw.WriteLine(" " + item.Key + " = " + "(" + item.Value + ")outparams[" + y + "]" + ".TryConvert(typeof(" + item.Value + "));"); y++; } } if (!isvoid) { if (ReturnType == "wnxd.javascript.json") sw.WriteLine(" return r;"); else sw.WriteLine(" return (" + ReturnType + ")r.TryConvert(typeof(" + ReturnType + "));"); } sw.WriteLine(" }"); } sw.WriteLine(" }"); sw.Write("}"); sw.Flush(); } } } }
private void query_Click(object sender, RoutedEventArgs e) { this.list.Items.Clear(); if (string.IsNullOrEmpty(this.textbox.Text)) { } else { if (this.textbox.Text.Substring(0, 4) != "http") this.textbox.Text = "http://" + this.textbox.Text; if (this.textbox.Text.Last() != '/') this.textbox.Text += "/"; json arr = new json(Post(this.textbox.Text, interface_name)); if (arr.GetType() == "array") for (int i = 0; i < arr.length; i++) this.list.Items.Add((string)arr[i]); } }