|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 ( a: p: `! |% g- K; l
zhangandma 发表于 2013-1-25 10:16 
8 b$ h8 u5 f3 M, o/ B0 C1 l发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的 0 w" m3 l3 i5 G- F, w
因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。) @' T( }" f% [& Z7 W0 i0 Z; u0 c! m
4 z0 P7 [' R9 f) c. \/ c9 {! ]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, ""));- internal static void AutoRewrite(ref OpenSpinDocument osd)/ X1 i% U0 a0 ?* K
- {( x, Q7 \8 _$ Z6 w& A3 {! o/ G
- string selectedText;6 C4 C1 R* h, R% j2 @* D1 i% ^
- IEnumerator enumerator; u- p: d- w& d! t: B6 I
- string str = "";
2 Y+ S8 u6 p( Z' \: h - ArrayList list = (ArrayList) g_protected[g_projectedCategory];( d& b# \; |1 |7 [& W3 o& e3 B
- try
( ~9 ~( E# T- a* t - {2 ?; |$ ]& R# S/ I
- enumerator = list.GetEnumerator();
5 i/ @1 z9 \& P - while (enumerator.MoveNext())
+ `! X; _' R( S/ ~; R+ N8 p3 m% |( V - {8 j- r) ~9 @3 u+ ]7 O& D
- string str4 = Conversions.ToString(enumerator.Current);3 w7 h" j' A4 i1 R- R
- str = str + str4.Trim().ToLower() + ",";
/ b- E8 [: [+ A3 _) B3 U - }
: ^4 F9 B# O; r' L - }7 l! T; |) `0 u9 }
- finally
2 |& L: v; F7 Y# @- X: }' W - {. v) f# g+ r5 D: ]
- if (enumerator is IDisposable)
0 L7 H6 j* z$ i4 N. M' l - {9 s1 H. C/ w* s, A; W+ u3 O$ ^5 Z
- (enumerator as IDisposable).Dispose();
W7 D& H# [8 z& v4 p# Y3 H0 a- G - }
0 x' L- V9 b+ T9 ^ - }$ Z8 Y2 _( N7 p: S5 d: t
- if (str.Length > 0)
4 s2 Y4 ]" v, a - {
( R. g$ _ Y$ n1 V# a" V+ h - str = str.Substring(0, str.Length - 1);# j- u1 n2 j9 C5 R* w8 G+ K3 t# z
- }
1 ?$ L7 O. k0 F - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)% B, W3 t1 Y" N1 k# M4 S
- {
2 E) F: z) l) c+ k3 N - selectedText = osd.spinTab.spinDoc.artf.SelectedText;& K" {( g5 b. @
- }
8 s" k+ z+ k0 l \: e - else2 A1 E; `* J5 A3 Z. M
- {% P$ k. q& S/ |: Q9 v
- selectedText = osd.spinTab.spinDoc.artf.Text;8 a4 e. D8 x" k$ E' |! {2 F5 }
- }
& h7 ^, V- D/ `8 _, c f - 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, ""));
8 A2 k- ?0 Y0 c" P# U1 l/ v - if (txt.IndexOf("<success>true</success>") > -1)
. d$ Q0 Z, g# ]1 f* X8 j6 T - {+ l" e0 i- b; _% q! f
- txt = txt.Substring(txt.IndexOf("<output>") + 8);; b7 K. g$ ^/ h. S
- txt = txt.Substring(0, txt.IndexOf("</output>"));! m* G6 |% I! j0 g0 F1 T' y p
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)4 k; v% i( ~7 T2 \+ L; C: d
- {! h: O& M% T8 D; W8 p
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
5 a) t; h. c( O' |1 b2 H$ d* \1 X - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";" `* Z/ t! u+ a& j0 {1 u7 |
- }
$ B( h, j0 P! H$ ? - else
5 k+ B/ ^+ I" ? - {7 ^/ c/ R) m6 d: N7 G: c2 u. u
- osd.spinTab.spinDoc.artf.Text = "";% G* ]# W5 r9 Z9 a/ \
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
& o' x8 F* v, O7 R: y. K - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
1 @# T, O6 ]% G6 D! n( |$ a# ? - }
0 r6 K$ i- P4 } - }! V5 S1 I7 g5 q$ K
- else if (txt.IndexOf("<error>") > -1)( q- {. |/ j0 R: Q1 y" ^
- {/ C% ^! V; [1 S) W7 x {
- txt = txt.Substring(txt.IndexOf("<error>") + 7);
5 t6 J+ z9 f2 [8 n; N* x- P- ?, ? - txt = txt.Substring(0, txt.IndexOf("</error>"));
9 d* P& r* }: j7 e' @1 l1 f - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
; q5 A z. _# z8 d R, E - } R" R, C) N3 z" G2 ~0 v
- else
3 y8 H3 V- m/ Q2 l: o - {% d2 s7 V8 p2 T/ D
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
, U) d* t! E5 E! J2 Y' g8 z - 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, ""));- q9 O: @: Y9 n; P2 P# R) b2 I2 ^1 b
- }
0 v" I" V4 E2 P7 \& @ - }
% t1 C2 x% P8 P! Z! [ - ( y ]. z, m0 u! E% W+ P6 D' Z
-
. U) V# ~( i8 ^0 K @1 H) t0 z - ) f" c+ }% W" Y& O) H# s
-
8 x8 i/ J2 H/ F0 }7 e - O9 X! r5 C- X e0 b
- 3 B* o5 O( {( k2 Q$ S# C; ~ P; B, ]. s
复制代码 |
|