|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 & p2 q$ y/ `( z, K) k, d7 A% q
zhangandma 发表于 2013-1-25 10:16 ! p" C8 N5 b+ l9 z& z
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
2 F( W, r- M6 {6 a+ P7 ]因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
' j9 _& c! } t! G( R4 O( Z' I5 [' X
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)
3 I% D$ N9 d5 P( v* T4 a/ P+ f - {
s( J4 p. ^* q9 F+ B9 H - string selectedText;0 {) @& u5 W0 y* {
- IEnumerator enumerator;2 d, ]" \ o1 v( o
- string str = "";
" t( }9 d; d4 ?( t) c% M! ^& G1 n - ArrayList list = (ArrayList) g_protected[g_projectedCategory];0 V) x2 L5 E6 E" [+ b
- try7 _, @# g+ i$ S% ?% E" U
- {) s' h( U( [7 w9 M* c- _
- enumerator = list.GetEnumerator();- G) [1 ~4 _5 L' V4 C( X
- while (enumerator.MoveNext())
, o" l7 @5 U4 {; L0 \1 \ - {7 ?- P7 ~8 c9 i; `! x: [2 E
- string str4 = Conversions.ToString(enumerator.Current);
; C- ]/ a0 W/ w& Y4 F& e. F - str = str + str4.Trim().ToLower() + ",";2 m" Y$ ^7 r4 J4 [
- }
+ [' s, E4 g: R' N - }
+ K( N6 {! C% q# R4 n* _ - finally% Q0 ?% E# Q- ]: [7 d" M# [1 x
- {4 m( x' B7 }: y8 g" L9 f( e) p
- if (enumerator is IDisposable)5 d2 R+ u& f9 |" S5 B- w& s3 k
- {
4 N! ]: q+ {9 v6 ?* C% H8 Y. a& u - (enumerator as IDisposable).Dispose();9 p, d k$ w! m) M
- }
) E; G: ], {0 U) b - }3 [( G1 W/ J: W y( O3 r
- if (str.Length > 0)- a k. t9 Q M( q; H" j2 y
- {# x6 q) ]/ z' |3 z. T3 K5 z! F
- str = str.Substring(0, str.Length - 1);
& T# x8 q1 F+ d$ ]- R - }5 q! u+ Y4 l9 s+ T, E* L
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0), @- ?' [% b1 a1 N1 Q, P
- {5 a9 q R- w! W
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;
% }" m3 t( s0 Q8 C# j' m$ f! W - } U5 h- o1 D4 s' ~0 a
- else
7 l7 z8 s( }3 w3 d/ u" E4 j* w - {
2 C5 [$ k6 H! M. S6 s% h9 l2 L - selectedText = osd.spinTab.spinDoc.artf.Text;
" v3 `: {; |. _ - }- p8 h! W+ k \) c( r5 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, "")); u, V$ T5 L9 M) F, b+ S
- if (txt.IndexOf("<success>true</success>") > -1)
1 _ e& s7 t9 w" b - {
2 R" B* i+ R! M6 I - txt = txt.Substring(txt.IndexOf("<output>") + 8);
: c. Y6 Z7 D5 h2 g2 j - txt = txt.Substring(0, txt.IndexOf("</output>"));; y p/ D5 U+ h* _$ V+ R2 ^$ r
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
+ Y. Z# r3 X& Y2 C2 ^; ^* e1 |1 L6 n - {
6 t% W+ ]# a: p( k0 s: f9 c, f - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);2 q( d+ ~) N! N9 \/ \1 F
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
& y) r1 G6 a; S7 a% q8 z0 ~( C% J5 r - } q- ^( c: B' `6 d \4 Q7 @+ A
- else
3 |3 U" y2 @* _( }, s$ ~ - {
& g0 n3 q9 R2 l* {" ^9 ^ - osd.spinTab.spinDoc.artf.Text = "";( C) N% Y" h( c% b2 V
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
; f; Q$ T, M# L& A4 g" F$ t' g - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";$ `+ q7 w7 w1 I- T
- }; ]0 O' B/ E) G' w- V( c6 `
- }9 J9 N7 C- B9 U
- else if (txt.IndexOf("<error>") > -1)
: c) q+ j* J' ?! T0 s; v - {* ~: U# R2 w# H0 i2 M" v% [, J. f
- txt = txt.Substring(txt.IndexOf("<error>") + 7);/ C9 N9 F. A$ d
- txt = txt.Substring(0, txt.IndexOf("</error>"));
9 `1 a# ^& o+ `. A, r0 s - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
6 ?9 ^" b( i2 A! {# [+ Y) n+ ? - }6 }+ N1 R2 L3 b; W
- else
$ v, P! g" _1 ^% m6 r. R - {
: j. v/ p6 B; s! g; K - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
* r! I9 M3 F" @8 V - 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, ""));
6 \& _6 ^2 x8 x9 E8 ]8 ^ - }; O; G+ I% ^* g( m) A
- }( {% N6 d2 M/ v8 j9 o9 D& J7 M7 d
! u7 s0 k$ }4 `, s" ^-
0 |% u t r! O3 _2 L# L
: f9 _1 T' m2 Y) |8 }4 k-
. e( O' ]9 @% A' G2 ^" T
3 a7 }0 y6 ~. j( L2 ?0 d" i: g. f* c- . _6 t# H9 P% \: i
复制代码 |
|