0
|
1 using System;
|
|
2 using System.Text;
|
|
3 using System.Collections;
|
|
4
|
|
5 namespace Demo.WebServices.Client.WebClient
|
|
6 {
|
|
7 public class WebOperationCancelledEventArgs : EventArgs
|
|
8 {
|
|
9 private readonly string _url;
|
|
10 public string Url
|
|
11 {
|
|
12 get { return _url; }
|
|
13 }
|
|
14
|
|
15 private readonly string _methodName;
|
|
16 public string MethodName
|
|
17 {
|
|
18 get { return _methodName; }
|
|
19 }
|
|
20
|
|
21 private readonly object[] _parameters;
|
|
22 public object[] Parameters
|
|
23 {
|
|
24 get { return _parameters; }
|
|
25 }
|
|
26
|
|
27 public WebOperationCancelledEventArgs(string url, string methodName, object[] parameters)
|
|
28 {
|
|
29 _url = url;
|
|
30 _methodName = methodName;
|
|
31 _parameters = parameters;
|
|
32 }
|
|
33
|
|
34 public string Format()
|
|
35 {
|
|
36 StringBuilder sb = new StringBuilder();
|
|
37 sb
|
|
38 .Append(Url)
|
|
39 .Append('/')
|
|
40 .Append(MethodName)
|
|
41 .Append('(')
|
|
42 ;
|
|
43
|
|
44 if (Parameters != null)
|
|
45 {
|
|
46 bool first = true;
|
|
47
|
|
48 foreach (object parameter in Parameters)
|
|
49 {
|
|
50 if (first)
|
|
51 first = false;
|
|
52 else
|
|
53 sb.Append(", ");
|
|
54
|
|
55 try
|
|
56 {
|
|
57 FormatParameter(parameter, sb);
|
|
58 }
|
|
59 catch (Exception ex)
|
|
60 {
|
|
61 sb.Append(ex.ToString());
|
|
62 }
|
|
63 }
|
|
64 }
|
|
65
|
|
66 return sb.Append(')').ToString();
|
|
67 }
|
|
68
|
|
69 private static void FormatParameter(object parameter, StringBuilder sb)
|
|
70 {
|
|
71 if (parameter == null)
|
|
72 sb.Append("null");
|
|
73 else if (parameter is string)
|
|
74 sb.Append('"').Append((string)parameter).Append('"');
|
|
75 else if (parameter is char)
|
|
76 sb.Append('\'').Append((char)parameter).Append('\'');
|
|
77 else if (parameter is IEnumerable)
|
|
78 {
|
|
79 sb.Append('[');
|
|
80 bool first = true;
|
|
81 foreach (object item in (IEnumerable)parameter)
|
|
82 {
|
|
83 FormatParameter(item, first? sb: sb.Append(','));
|
|
84 first = false;
|
|
85 }
|
|
86 sb.Append(']');
|
|
87 }
|
|
88 else
|
|
89 sb.Append(parameter.ToString());
|
|
90 }
|
|
91 }
|
|
92 } |