|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
) {' u! R8 L& D2 D B8 H+ x4 i* tzhangandma 发表于 2013-1-25 10:16 
8 e( }3 o4 _9 D8 L发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的 " }8 ]+ G" U3 Q$ e
因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。' A6 H9 `" i5 z' e5 M9 d
9 F! |( ` y4 A6 f" \: o/ 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)
# T1 S9 K$ U+ x. n - {
/ u) `2 o4 O4 | - string selectedText; z9 X2 f: z8 ]% w6 r/ z) b% |
- IEnumerator enumerator;
% W, {# m$ e) x2 B - string str = "";( {0 I7 U' v6 u" O# |3 b
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];
* d! c- X2 T; M9 f - try
8 p5 Z4 {1 r' |) Q% h - {
8 a) y5 L; ?; s' t7 R - enumerator = list.GetEnumerator();4 e: Q: O; j+ E7 [
- while (enumerator.MoveNext())
( j9 Z. E( @: ?7 B% i - {9 G8 o5 w: j E3 b; `. u- }
- string str4 = Conversions.ToString(enumerator.Current);
2 O8 r; |, `' J3 W {$ o/ e# R - str = str + str4.Trim().ToLower() + ",";" M2 y, L; l4 s7 Q, C% B- ^6 s
- }
1 k4 ~) ]- a2 [6 k6 r( \ - }
/ P5 ]; J i# c8 B, }: z - finally8 q0 c3 e* R. u
- {7 `. m( z+ p7 C. D
- if (enumerator is IDisposable)
4 Z. i( @0 f2 j - {
2 h8 u. x6 W: T! h J3 M - (enumerator as IDisposable).Dispose();
# h& E! [, g2 \3 S' o6 J$ O7 S7 V - }4 `. [* D5 Y9 D" t1 s9 k
- }
" l+ U8 t. D: V6 b" q ^ - if (str.Length > 0)6 i$ B- y" Y- ^% O1 J4 z6 M
- {: [9 _- F8 f: m
- str = str.Substring(0, str.Length - 1);5 o! @9 g1 Z5 T/ ]) Y
- }; Z6 h& S" a0 k5 v
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)5 C7 u' N' Q& B2 @. P$ g# }
- {
7 X, o- O [" x& i$ v+ D! S; I) ] - selectedText = osd.spinTab.spinDoc.artf.SelectedText;
+ Y) a* m ^' K4 h - }$ q( [, C( f, `, s+ H% P: w; J
- else
9 h$ p% G* ^4 E; I- s o, C! \. h; E - {. t' } A$ g- B
- selectedText = osd.spinTab.spinDoc.artf.Text;% K; J- h7 f- G: {
- }* N5 L9 \. c9 r9 y' \; N8 X( f6 q
- 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, ""));
& f$ u G2 C5 j+ ?+ R - if (txt.IndexOf("<success>true</success>") > -1)
' R) F, C3 H% `: w q$ H - {! I4 Q# O' n9 J! u
- txt = txt.Substring(txt.IndexOf("<output>") + 8);
- M k6 d2 X) m. ~! ?+ @ - txt = txt.Substring(0, txt.IndexOf("</output>"));+ f6 L. v2 a3 E9 @( L
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
) {4 V* X# h) j9 G - {
7 h! a. B, m) @# G! v0 y" r! W. L - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
3 x* x2 o Q1 P7 D( N - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
* V* m* w) q U& j - }
! T1 C$ q6 X# s6 ?/ L; F5 A. x - else& M0 U0 |5 J2 T0 j5 x I- T
- {
* @5 s7 J( W- ^+ q - osd.spinTab.spinDoc.artf.Text = "";
w/ i) h+ S3 P7 j" ` - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);* a: k0 b. W) U% r" g5 V; D
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
3 U, y8 |. E( A. g+ O# a- { - }
$ h6 }( F; t: y - }
+ ]% I! F& d- l4 \5 f0 ^. L - else if (txt.IndexOf("<error>") > -1)
9 \- \% o$ e" G - {5 F% }0 f+ n9 l% p8 J; ^
- txt = txt.Substring(txt.IndexOf("<error>") + 7);
5 \ q1 w; M4 w - txt = txt.Substring(0, txt.IndexOf("</error>"));
5 E5 A5 g) t, K% Z7 o# s, ?; s - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- F# J2 M& I+ p/ y - }
, Z5 [/ r: }+ w$ W( w - else
; s& g( q5 G) ^, [ - {0 j, D) i6 S& B
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);) Y) T0 P" T: k, h8 G& Y6 y
- 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, ""));, i! x5 J8 |7 j/ Q) }6 u/ r
- }; r( S" G$ C0 T
- }% Q" I' V5 v% n% X( q# w
- 5 ]7 @0 t% S& N
- 6 j+ @9 j9 S6 h7 w* G: e. Q4 K6 J
. g4 p$ ^, o" k2 E-
* }7 v0 D7 d+ B3 Z2 W - 5 R j) ^" E) M. [
- ) j9 ?3 e9 y9 I1 d9 N. S
复制代码 |
|