|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
5 l# r. n6 X/ J# szhangandma 发表于 2013-1-25 10:16 
! F# G. Q% f+ V, m: W发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
5 a6 |% C- [' K因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
" N; g7 a& S! Z
: Y* @0 {4 g! ]1 G C9 ustring 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)! U; K5 Z% M3 l, v$ G
- {6 b" j# Y- N8 F, z- P$ o
- string selectedText;
0 u8 X) a3 s3 @; F& e- U - IEnumerator enumerator;* H; _; h6 T" I/ G! {/ c! |; p* \
- string str = "";; [% X8 I+ X. W/ Y! v3 e4 c
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];6 P' ?4 B# m8 W! q, F/ G- ^
- try( s, i) [1 q {5 w N$ u, y
- {8 Y. ?: F5 v6 I7 c
- enumerator = list.GetEnumerator();1 W2 V T; C& D& o! A
- while (enumerator.MoveNext())
2 @% X7 {) x4 ]$ a& m2 t - {
# F) l4 e, V& C. q4 J# { - string str4 = Conversions.ToString(enumerator.Current);
2 Q/ f" k" g5 a" ]- L. D - str = str + str4.Trim().ToLower() + ",";2 L! [9 A3 @$ c
- }
q/ F' P% R( z% G - }7 D3 X- }& ^! O
- finally' v, F# z* H. Y( O
- {
' }7 h, T e& K: h) ` - if (enumerator is IDisposable) y9 O7 k1 |* e
- {8 ^' Z6 }% E' k! I- V
- (enumerator as IDisposable).Dispose();
3 h6 L# X8 ~: Z - }: X m; q ?7 s" j$ m0 F
- }
& o) M# e9 g) Q [4 u - if (str.Length > 0)
1 b+ j7 ?' @( B: k" k/ N1 y - {% }0 {8 A5 @+ B
- str = str.Substring(0, str.Length - 1);$ v$ `8 g) W J5 O3 R9 S0 S5 {1 v
- }2 p4 S4 s- x+ g$ C( D* f
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
9 ^! L* Y5 w: ^) A9 a - {
' t/ ]6 r2 ^: n; b1 n - selectedText = osd.spinTab.spinDoc.artf.SelectedText;
6 S O3 {# w' j - }
) k4 `/ _ v4 C' F! |/ b7 F - else
6 T0 V) ]! X: Y Z - {
6 r) |( F! q$ D - selectedText = osd.spinTab.spinDoc.artf.Text;
6 C: r; |& A8 E" A& z - }! R% R0 J- v3 g6 B" D5 {: R. p5 j. Y
- 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, ""));3 e" b0 i* ^2 k2 [: t8 O2 d
- if (txt.IndexOf("<success>true</success>") > -1)
. W1 c# E) r+ }2 K1 T3 y - {) P1 Q7 m2 n5 y3 [% d2 b
- txt = txt.Substring(txt.IndexOf("<output>") + 8);
9 _/ Z) p3 @- p2 T: h4 } - txt = txt.Substring(0, txt.IndexOf("</output>"));' Q; @& ~- ]5 i6 \' E
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
& {8 i- s2 l: I, O p0 x. V0 S5 D - {& t7 N" y( U) \& k
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);. h1 ~. Z, X$ L8 m$ ~$ i9 `9 y
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";4 A/ X" b- P }5 s! _( N/ p' |
- }
* h9 K$ K8 M* z2 V: ]0 C; i5 O - else& w2 ?9 i$ u W/ e3 n( A
- {: w( o' [2 f% { ]
- osd.spinTab.spinDoc.artf.Text = "";
% X- }8 X2 U9 h: C - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
! I% @; O$ S8 I/ y, e7 ?4 W$ ]# v! \/ o - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";1 N* K) w4 q) n* R
- }
7 P% f8 R7 M& E! M - }
* f. s' @0 W' X" d2 T6 Z1 k - else if (txt.IndexOf("<error>") > -1)
8 W: f6 t" F9 |1 \3 P9 ?" @# v7 O - {
( a& \+ Q6 _, u& n4 x - txt = txt.Substring(txt.IndexOf("<error>") + 7);
4 @. Q7 C% E- V! R - txt = txt.Substring(0, txt.IndexOf("</error>"));
' E, I3 x( N G' L* i - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
. w3 D+ a6 W! w( w8 i5 x0 ?. N# G - }
. `6 }9 B% o( k' Z; h3 _+ u - else
w. l' t7 `2 T) J+ K" R - {* J/ p6 b2 {9 B7 m# W8 y. p
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);5 K ~ P/ I, [2 H: H% T6 K
- 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, ""));
" e+ s5 K' d* W/ C - }
; y0 f* ]1 c3 i - }
! x! P- m+ a% F4 ? - % s, M! O7 m* q! ~. u
- ( p7 R+ V& F) {
( I( g, }% z$ W7 \" S# `0 }- 9 }& G( P* D. L8 q1 d4 N1 u4 R" K
- ! l+ C3 S$ |" Y' c6 [1 Q( l
! C; @* P8 ^0 L+ |
复制代码 |
|