|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
- u! i7 j: h! Z( Fzhangandma 发表于 2013-1-25 10:16 
, G" F+ ^* ~, E- G" r) u发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
& U8 F! h: X) w( S因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。/ y- @# d) F3 ] A7 }
( E/ r9 a$ O8 q |/ ~% Y2 s8 Ostring txt = Conversions.ToString(EasyHttp.Send("http://thebestspinner.com/api.php", "action=rewriteText&inapp=1&session=" + g_uniq + "&protectedterms=" + HttpUtility.UrlEncode(str) + "&text=" + HttpUtility.UrlEncode(selectedText), EasyHttp.HTTPMethod.HTTP_POST, ""));- internal static void AutoRewrite(ref OpenSpinDocument osd)
+ P( i7 p7 F* A9 K5 S7 E" J/ | - {& N5 `, q" B0 F4 s
- string selectedText;0 F5 o8 `& L, W9 ~1 [
- IEnumerator enumerator;
7 D& R; l, i) d1 [! ] o6 |% A - string str = "";8 f+ B# K- |5 ~1 ?; D$ _
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];
3 b9 ^- r, t. H) C' [ E) x+ } - try
. t4 S& H6 D2 ~% s- G2 n - {3 ~8 z* e; S/ X# D0 n$ }; e
- enumerator = list.GetEnumerator();
, N& x8 m0 G9 f& ?% C( _ - while (enumerator.MoveNext())
3 b: j1 [; c4 p0 Z, P: ]6 O: U3 @ - {
1 L; w; _4 B* t2 G- w4 J - string str4 = Conversions.ToString(enumerator.Current);
$ z. q* O2 y) i: r; p - str = str + str4.Trim().ToLower() + ",";
" B( p r+ u/ ? V6 ~. W - }
: u3 I, d; r0 B& E, [6 @" I - }
! o! w0 `* f. d% Q - finally
1 t1 M+ L7 H( b4 w! U M7 J- ] - {
, w& D, j, [6 D4 t - if (enumerator is IDisposable)4 f5 E! U$ h/ @ C: V* I
- {
4 k9 F" c4 D M2 l - (enumerator as IDisposable).Dispose();$ I$ L% N: Q6 E" g. P
- }
. [& a% S0 ^) c, S( b# m! b - }
% g" i5 d/ |8 d9 k- i - if (str.Length > 0)" d/ L) Z2 d" ~- ^) J0 J8 ^
- {/ E) j# }$ [; g, {: S( @ @* b
- str = str.Substring(0, str.Length - 1);
; }# v, j" ~ k! j W; y - }+ e' Q4 j ^6 n& h6 g
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
- O7 a2 j$ W) e. x2 Y8 _5 R - {! l, R# g; |* k4 d+ z! Y+ a
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;
" U, a$ i+ d" R" c. a - }3 s) c$ X6 t5 Z) E8 B
- else
/ a/ h5 d0 H" d* k' y) y& g - {
P+ {/ ~) H; |4 U - selectedText = osd.spinTab.spinDoc.artf.Text;
2 f8 N0 L% |. J' A' m% R U - }( W. v& G! H9 f5 ?/ H* K
- string txt = Conversions.ToString(EasyHttp.Send("http://thebestspinner.com/api.php", "action=rewriteText&inapp=1&session=" + g_uniq + "&protectedterms=" + HttpUtility.UrlEncode(str) + "&text=" + HttpUtility.UrlEncode(selectedText), EasyHttp.HTTPMethod.HTTP_POST, ""));* t1 ]" _* I4 H( B5 X1 A- i# K+ w
- if (txt.IndexOf("<success>true</success>") > -1)/ q. Q/ ~+ a- {4 B, x; i" Q5 y& x
- {9 ]# G8 p: U6 M u
- txt = txt.Substring(txt.IndexOf("<output>") + 8);( k+ ?: b p8 x
- txt = txt.Substring(0, txt.IndexOf("</output>"));9 N6 g( T* f) @6 |
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)+ }* ~; G D Q
- {
' P) y0 ~% S: e: F/ h - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);* L6 T6 S# }4 E% h; @
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
% _/ ?# T0 w4 K, H - }
( L$ F. h) Z8 f& Q3 P, }" m - else) }: M8 e* k: b& p
- {
/ f _0 ]3 f1 ^4 o! T4 l - osd.spinTab.spinDoc.artf.Text = "";* G: ?; \* c0 e% Q+ |
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
* J' d# a/ o2 B. A5 x" m - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";/ A( o( i2 J5 p' z0 v; Y/ z
- } c9 A8 S8 u2 G! `4 X6 ~8 a
- }$ u/ q0 m+ A6 C j' b4 A
- else if (txt.IndexOf("<error>") > -1)
$ u+ N. ^+ l \, s - {/ C1 ^4 |% }- g- o
- txt = txt.Substring(txt.IndexOf("<error>") + 7);
( `+ V. w$ e% R1 E% u& Y' | - txt = txt.Substring(0, txt.IndexOf("</error>"));
4 J1 I+ t& A/ V - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);1 ~( n C% C( A, l8 R. y* p
- }
& d8 G( ?6 f- L - else, {1 ]9 y6 n" O0 e* }( j* X
- {: Y2 ^; B# p* ^6 G9 F* U! J9 M
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); t6 N0 o" l3 r- ]/ a
- txt = Conversions.ToString(EasyHttp.Send("http://thebestspinner.com/", "action=app_rewrite_error&uniq=" + g_uniq + "&protectedterms=" + HttpUtility.UrlEncode(str) + "&text=" + HttpUtility.UrlEncode(selectedText), EasyHttp.HTTPMethod.HTTP_POST, ""));
# P& `1 x, h" B7 { - }1 }$ g9 }. N5 H1 c
- }
7 O+ F1 \7 `1 \* l - - r9 n& Z; A! Q5 v" a0 x& K
- * ?( m! s* p$ E/ L+ f% E
9 J# m! T0 K4 R' j5 S4 ?! `4 b-
5 d1 `% V" ?4 ]; L7 O1 a - B# B% g6 _- h! K8 [
- ) [- s: e$ r7 h: Z9 X" p' K
复制代码 |
|