|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
% O a% v( d" d6 I4 u; azhangandma 发表于 2013-1-25 10:16 
* c9 L2 a Q- N3 O/ m s( g4 B* H发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的 $ z0 a" T, Q" V
因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。7 H( h' C' w6 F! j. z
& V/ K w9 {/ j$ A4 L! B8 Kstring 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)' f( t k; u: d, O! i* M6 h
- {* C& R+ I$ F' X' K' w5 X
- string selectedText;- A7 Q, m& L7 b; @7 \
- IEnumerator enumerator;( K+ Q* u' M+ ?7 O
- string str = "";
, H% [. r$ B) S8 @6 B' A; t - ArrayList list = (ArrayList) g_protected[g_projectedCategory];
/ ^# w" q: Y! H& M - try( c$ c5 X9 ^4 z6 R) I- r9 Q* V
- {0 U% p9 [ K) K0 Z
- enumerator = list.GetEnumerator();# O: B% E$ L r$ `; W+ v- ?
- while (enumerator.MoveNext())
! Y) V: G( a# l/ [ - {+ N! c x( t& K/ Y
- string str4 = Conversions.ToString(enumerator.Current);
. n: X n* H; ~6 e, v - str = str + str4.Trim().ToLower() + ",";0 b3 P8 e1 J0 ~. K2 K
- }- @4 U: v9 b* h
- }. P W9 i: |- T$ q& _$ V& D
- finally; X8 I, j' ^7 r8 }, Q
- {+ I& M" s+ G7 ~, _) K! O b
- if (enumerator is IDisposable)
6 I- e' k' l9 t7 B+ m: ^+ j2 C9 |% s$ I - {
2 b6 j) O% T- m" W( ^3 [ - (enumerator as IDisposable).Dispose();- j% R- Y& s4 R# m
- }- U0 x1 E O# R$ e% ~
- }
7 @+ f+ w& |3 M& `. _+ \1 C. ` - if (str.Length > 0)9 k7 ?$ {1 ?/ l* \2 m7 a3 v
- {6 X2 U8 X0 x' p4 A) _
- str = str.Substring(0, str.Length - 1);
* @7 x2 @- u3 ?. B" c: S - }! v" e3 ^8 _$ v5 k
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0). U6 _0 b: V& |) e+ @) a
- {: {' C& u8 T |) V& E0 t
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;
Z }, V% C2 V' D& `4 ` - }
/ q% V" y" v e) R5 T; v% @; d - else
+ ` C( ?1 n8 x% Q$ k - {9 P& {" Z0 `* X
- selectedText = osd.spinTab.spinDoc.artf.Text;
7 f D3 ?! G6 Q$ {: G4 d5 B$ P - }2 v# [5 j6 l9 r. P
- 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, ""));) D# p3 o/ Z7 p. n* u( ^
- if (txt.IndexOf("<success>true</success>") > -1)
) T7 d$ }2 I8 l- t* d N; s4 @ - {# ?1 n9 n7 L1 Y% f8 o
- txt = txt.Substring(txt.IndexOf("<output>") + 8);
# Z3 T+ W, L/ h5 ^ - txt = txt.Substring(0, txt.IndexOf("</output>"));5 `& h( o' k9 ^6 g$ ?1 S
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)2 `# I; z1 Q# m# o( R
- {
+ L1 | s4 e6 t0 s' |7 p E0 `" N - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
8 X) a I- ~0 D8 X$ e+ G4 F - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";# l9 j3 I% y& N6 n3 z: |
- }
+ Y: @' A/ @1 G+ t - else
0 [( F5 _& x# L - {
' {/ F" y2 n. z% p' G - osd.spinTab.spinDoc.artf.Text = "";
& T4 D" }: y. i! Y0 o - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);+ f2 m$ M4 _& }+ F- O# z! u, {
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";0 `+ A7 D! x; g1 C' |( d7 P
- }
9 ?3 q7 O, ]/ U, r& V& }* K: o - }
4 I( w/ ~4 S2 f' t, Y5 D - else if (txt.IndexOf("<error>") > -1)# j, u' E0 `4 _0 b$ a8 |3 s1 `
- {3 ~8 S1 T- @7 V5 b9 i
- txt = txt.Substring(txt.IndexOf("<error>") + 7);
# d+ N+ m) b; L. A+ g - txt = txt.Substring(0, txt.IndexOf("</error>"));
) U3 A4 B5 I3 h/ Y0 y% y, M - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
" R$ W, P0 i) e, Y0 C6 R6 ~ - }
" D) i! M5 g" ^7 F+ h* Z1 \$ R; l! ~ - else
- _, j2 H, N7 a1 _ - {- u; X) {0 O K+ \' 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- M. E/ m7 }9 d1 p# n - 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, ""));! o" d5 e5 g* u' @3 `
- }3 `1 U# l, `: j1 b4 C- h2 F
- }
- b' y* n6 H( Z5 s. a% t - 0 \6 v" T H1 C6 h
- # R9 l U1 Y) L ] u, }7 T
- : E/ }6 a: e: n
-
! ~& c1 J$ w% }/ K" G
' [6 b5 T/ f' Y1 {4 W* I
: B7 C8 Q( \. H0 R
复制代码 |
|