|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
9 Y; s9 n; V, o' J+ Rzhangandma 发表于 2013-1-25 10:16 ! ]6 @& T; o y* t+ |
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
: P4 n$ ~0 M; u: W1 L2 ?4 P4 _: x因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。$ E9 I8 g; R- c6 q1 ?" l, n" e
1 n) ? h% l+ `- K" B
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)% p; C3 I; W0 f
- {
{1 e1 A- E2 z: g2 i' Y - string selectedText;2 r( d, {5 Y' f' s( W# P
- IEnumerator enumerator;
( E9 h' V5 I0 f- f5 u2 x* y - string str = "";
7 E0 Q& m5 e1 S - ArrayList list = (ArrayList) g_protected[g_projectedCategory];6 N9 e. r$ ], U( f0 Z& @: e8 s
- try" t& P8 Q! E" i. D! J* w
- {
7 n! _4 C2 z( `7 E - enumerator = list.GetEnumerator();/ K' Q0 e: S+ `! ~
- while (enumerator.MoveNext())# d6 y& S9 H( A+ F# j& B3 b( ]: ?, {
- {6 \; {% @4 q( Q" C: N
- string str4 = Conversions.ToString(enumerator.Current);
7 K( P3 }0 \" O g* l - str = str + str4.Trim().ToLower() + ",";
* s- `' c. e5 \) ]6 \) Y: x - }
: V2 m; z8 @/ Q n; | - } I: k0 s! B$ w9 X" @
- finally
" v! [3 y o1 [& S7 [ - {
) p5 H( E( ^9 J - if (enumerator is IDisposable)3 y7 j9 p# v s# ~, s W4 W1 v j
- {
: t `% i( U& k6 L3 K2 w6 W - (enumerator as IDisposable).Dispose();- C- s) w/ W, o( d/ {: f9 e
- }: U! j" d* @& m4 ]: V
- }
{$ t) e: _1 b# X1 A' r& [ - if (str.Length > 0)
) v0 ^, j% D1 N: ~ - {
2 l2 f: t( m8 \" P" l1 y - str = str.Substring(0, str.Length - 1);
$ j A! x$ v( R9 m9 W; i( R) {" O - }
+ Q, ^1 a4 J, e- u J - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)! N- E' |" X6 W. I
- {
" V2 G2 h1 F' v: m# v2 B - selectedText = osd.spinTab.spinDoc.artf.SelectedText;
, g' H* D* d5 L4 \6 R. l+ Q6 {1 I - }. ?, i) ^' B s- v6 g3 |! t1 z/ }; Y
- else( _, X+ w+ D/ W# h' L/ {5 a* b
- {- g: o* _. i: D& v. u
- selectedText = osd.spinTab.spinDoc.artf.Text;
6 ]! A1 J- y+ t3 z& j - }( d9 }: Y% Z/ n# j1 H! n. 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, ""));
1 Y8 U- Z- G) U( ~ - if (txt.IndexOf("<success>true</success>") > -1)0 g( W7 B1 f( d& w
- {' G! \! K* I# z
- txt = txt.Substring(txt.IndexOf("<output>") + 8);4 h" L& V7 c% H& b- K: z' q
- txt = txt.Substring(0, txt.IndexOf("</output>"));
, o" D4 I) G: ?6 C - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
g5 |( h# J( u4 ~ - {+ H5 R, ]' ~; N1 j7 K
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);8 f% d& w0 f( K) d0 N
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
1 L; f. M( B$ x( b - }
+ a2 x, T3 y% w1 {+ ?2 x I - else
7 t# X7 \4 _( \/ Y& K( [ - {( j; g2 I8 }/ W6 n7 U. s) J1 {
- osd.spinTab.spinDoc.artf.Text = "";; P( A% w* }5 c; g. _( W/ V* r
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
9 M: C, j) i _7 W5 e# f& G+ U: c - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
# I0 W1 ?( X; g e( d4 \ - }
5 p- ~/ m y, Z. @4 }! w, v - }
% x( h. q) n3 Y5 d5 b" N! `) ~' {# {5 I - else if (txt.IndexOf("<error>") > -1)9 ?. ^$ {- O/ ^7 D6 K$ ^; Z% C6 `4 f
- {
; C1 A7 c: a0 y9 J9 _" b* Y - txt = txt.Substring(txt.IndexOf("<error>") + 7);& n3 V$ P+ {1 e" V. ]
- txt = txt.Substring(0, txt.IndexOf("</error>"));
X! ~* ]6 Z& h9 r - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);. W9 `+ b$ K7 K% n' L ^- T9 E
- }
# ?( S. }; m, K$ B9 Q - else5 ?! {- L1 i" H- g: F
- {( u2 b0 M% l1 a3 T0 Z8 V
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
( o2 l* V6 T6 i, F7 M- F$ K+ @8 ?$ `& t - 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& s, J0 g2 F4 ?: }' ?' \+ [ - }" g) z) \. h, a
- }( r8 K$ j W- [
- : ]+ w8 D8 X5 j g& I* p
- 6 f4 B" N; T. Y$ c( b5 G
- / ]1 f# b: @/ Z) E ~# r+ J
- 5 E: Z4 x* p e! l6 f
- . s$ c3 W; t; z _8 j) P
; L) L) I' `% \0 y+ I! C C A
复制代码 |
|