|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
1 ?: c+ c" u, ^+ w# Fzhangandma 发表于 2013-1-25 10:16 5 R' T* y; c r$ H6 E
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
1 ]* j b) B* H' p0 `% Z/ T因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
8 W. F, T. X2 ?& i1 g: T
9 c' k& y8 A3 p: M0 S) 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)% _. V% x) v2 f& O& q
- {2 a; n- \, u. S# T/ r# L
- string selectedText;! w3 N1 N$ f! R- j) G
- IEnumerator enumerator;
( t8 J( q; z- ~/ S5 h, x6 n - string str = "";9 p. u3 ]+ d! f! P( g2 i# N
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];
" L# ?5 M8 U; L6 y3 J - try6 a9 k; z `3 m
- {
- Z# Y% N: b @3 o8 ^* o+ _ - enumerator = list.GetEnumerator();6 ?) |2 h7 o0 D `. @! ?% g1 g7 ?
- while (enumerator.MoveNext())& e& H) L4 E+ z' b% Y. }- }
- {
) P" e* H8 b" d0 [: z - string str4 = Conversions.ToString(enumerator.Current);
. r; K; f- i% K9 g5 \ - str = str + str4.Trim().ToLower() + ",";
! b9 ]: l' A9 \& w. w, T& d) R - }
' b' I6 Q) S- r2 Q, ]2 c - }+ C; }* T/ n0 d8 \
- finally
?' m8 q# u3 _3 N3 f3 h* j3 m - {
& s8 ~8 l( c0 n6 p) c - if (enumerator is IDisposable)0 A$ P8 Q7 X3 @8 u$ V! n7 J2 N
- {
+ C6 U: P6 |3 a4 H( P - (enumerator as IDisposable).Dispose();2 p2 \* a! X0 Q
- }
3 j4 G5 b' r! h2 ~: ] - }8 @' U! \. b5 _7 ?4 u$ ]' B- D
- if (str.Length > 0)
' j) E1 U7 P3 q - {7 r. R! B+ Y9 H: a0 a; B g+ b I
- str = str.Substring(0, str.Length - 1);7 n) r' [) H4 y( M; r
- }
$ W1 P+ j7 j) W7 f+ O - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
& S4 {/ h- N. P. E1 g7 b) w# p - {
% Q# N7 X- C# s2 ^3 a2 m( K - selectedText = osd.spinTab.spinDoc.artf.SelectedText;
1 }8 l1 Z5 ?2 I' }7 _1 C - }- ~2 R( ]) n* L6 J
- else* X# {0 z# q2 O. j K( ]: N. u4 T$ M
- {
% H" M+ q9 I/ m7 m- `$ h; q8 } - selectedText = osd.spinTab.spinDoc.artf.Text;# {' L; V# |1 o* M3 ~( O X& o
- }
& T$ h4 c) K( }' M - 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, ""));
- h, x' M9 }! u4 x% [ - if (txt.IndexOf("<success>true</success>") > -1)
, }$ K' C/ C% s( H' d! g8 w" i% y - {7 ^. P; i. q8 ]8 x$ [$ n
- txt = txt.Substring(txt.IndexOf("<output>") + 8);
3 p( c, G F5 K/ {: Y5 F+ t# o$ E - txt = txt.Substring(0, txt.IndexOf("</output>"));7 o- Z8 v/ s/ X# V% I
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
' p: n1 d" W; ^! W1 u$ f2 g/ g3 o - {4 H4 F7 ~0 d8 v' J* M
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);) i9 u" T5 b7 Q: Q2 H2 E
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";5 p- x, N: }8 H6 p$ p
- }
/ @9 [& p* q$ M" F# [6 O - else
, R, K# ]: h* c% F - {
R: n/ H. G: { - osd.spinTab.spinDoc.artf.Text = "";1 U; J* \0 B" V0 `9 Z
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
; R3 B6 u0 @$ s2 F( O* ? - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
- [! _$ o$ W6 ?2 s! ^ - }
" O1 K( t6 L7 B' r: h - }3 m: D' z! z+ H, f* ]# ~3 i6 n
- else if (txt.IndexOf("<error>") > -1)
7 |$ x/ r3 I4 g, ^- [# G; d - {
2 E0 E! {8 W7 n6 l+ B - txt = txt.Substring(txt.IndexOf("<error>") + 7);
, {3 p. r; G1 u' e0 z, x; c4 O. w - txt = txt.Substring(0, txt.IndexOf("</error>"));
J* ?3 [2 F# z3 c3 q - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);! K7 t$ U" ?3 w2 ?0 ]* Z
- }
3 s0 ]$ s* ~, I7 D. {5 T/ _8 s - else. }, R6 J8 p: {" ^! U# j0 ]
- {) W& ? W/ ^ h) j& t: F9 | 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);' d% [5 R9 r& R( G% {5 F
- 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, ""));
. n% x! w( a: R' [ - }" l2 {5 \5 X9 }9 j0 g, I
- }
/ F9 s! S% V/ r" ` - , m0 B0 @1 J1 R6 S
-
Y! n2 t3 D. R - : G1 I8 E7 @( d& g' k! \( N
- ! D' M; y c! ^1 ]
5 p3 a( z+ q9 ^# v; N
% u8 C8 G5 N" W/ e" w6 x; l
复制代码 |
|