|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
0 `: d; J8 h: _/ Q* Izhangandma 发表于 2013-1-25 10:16 
/ b8 j* [! J L! R- ~, Z" O7 W. q4 @发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
: p q: W7 E* B' W0 m) \. M/ ?因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。: ?4 y' f; h# G9 L$ J8 t& g' `2 b
: R; ?0 d0 o0 J/ t0 @# _# t/ gstring 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)
( a- X8 n7 o& t' W* `7 _ - {
8 S( u' e5 z% a" U1 T - string selectedText;/ N2 l2 F% l: v
- IEnumerator enumerator;$ z! k7 l7 k# H
- string str = "";
9 O! ?# L* d' T! n9 Q" h/ R$ P, _ - ArrayList list = (ArrayList) g_protected[g_projectedCategory];6 e# u! P# s' E+ e {
- try2 d4 Z. [- v% }5 r8 [# }
- {+ e. y- Q+ Y5 W ~
- enumerator = list.GetEnumerator();# Q- ]9 G0 ?) s, E9 ]$ w
- while (enumerator.MoveNext())
) [! j& Z) z2 P: r2 Q j; x# v% J - {
* k l" P0 ~) S' A0 M' k" \, P - string str4 = Conversions.ToString(enumerator.Current);
6 ?0 o% o4 J' k5 l! { - str = str + str4.Trim().ToLower() + ",";
# Y/ @$ l) Y9 |' Q7 L. a \ - }0 W3 a+ H+ x# J( e1 ~1 J8 ]
- }4 N& j2 P; B+ }$ [- V
- finally$ ~! Z) v% u/ r" V- p
- {0 }% ?6 m; i- i2 z
- if (enumerator is IDisposable)
5 U& Y! ? F3 l5 Q4 o5 Y. R3 ]$ i - {( ^6 O7 I5 R0 a( A0 W2 C3 j
- (enumerator as IDisposable).Dispose();' T- {2 K7 J( ^1 L
- }
% G) e0 I( D- S5 V( W5 ? - }6 E$ u4 \7 {% k! C9 \
- if (str.Length > 0)* q' O. z# `! x+ l
- {
, \1 {/ I9 c0 _2 T+ } - str = str.Substring(0, str.Length - 1);
- d- @1 Z) r3 \' P B - }
4 y' e( o# ]' E/ Y - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)" ]; G# u1 z0 h* r/ p& b5 k" } H
- {) S8 S# G( p4 I; D6 }- F
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;5 V2 z% b9 m& |2 u+ E
- }
% G" g" d; Z# t" Y; I6 b( ^! d - else0 i( I, _$ x% f3 X* B
- {
$ t1 d$ _' v6 q - selectedText = osd.spinTab.spinDoc.artf.Text;- d& z2 |7 G E
- }
# J& N2 ?6 W* m8 _5 S - 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 P/ q- S9 ^0 t1 H
- if (txt.IndexOf("<success>true</success>") > -1)
5 M, e' j) s4 u* V" j* p - { c, J$ G: K5 R: u0 B
- txt = txt.Substring(txt.IndexOf("<output>") + 8);& S6 C+ c! F) o+ y6 W V- l* C; r( ?- _4 X
- txt = txt.Substring(0, txt.IndexOf("</output>"));, j& |5 y/ o3 I& O! [, f0 h
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)2 J' [. T o4 _. L, C
- {0 h9 [. B s, d% z+ ^. V3 e
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);1 ^: r7 b) z; ]3 \4 g
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";2 R/ A; S. ~4 u' r7 i* d
- }. h. V8 l! \, G" o. V
- else2 j1 l1 E- f4 V0 f" w& ^' B
- {+ G- v! B7 n6 b3 i" E- c
- osd.spinTab.spinDoc.artf.Text = "";
, r4 U6 h0 H: O4 K - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
7 l4 D% w' Q: z& B# @0 ?( [ - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";( N$ ^/ a( F/ |% v
- }
- U8 m4 M# f j( R/ \ - }3 x) o6 M8 ]2 A& e% j
- else if (txt.IndexOf("<error>") > -1)/ U7 u& ]: Y$ g3 m3 P' S, g h
- {
$ `( S9 q. O# L& Q! Y/ R' J - txt = txt.Substring(txt.IndexOf("<error>") + 7);
3 S' t; }8 Q7 a+ f2 ~" f - txt = txt.Substring(0, txt.IndexOf("</error>"));
, P3 T0 }2 c$ S9 j V$ ]+ T1 E1 h9 V - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
# r/ t# W: M1 b9 c; ?' b - }
+ U+ J! u: Z M3 c - else. y& M; y: c. q* B/ B
- { _' _' B9 k, E/ {6 O2 \
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
3 B& ]* G- T& X$ W - 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, ""));
. L1 [0 M# I9 C" k" S) P# b. g G - }" Z" V& @6 d$ v2 @5 L8 _% [, Y
- }& H- Z# W$ w' J6 \$ }7 h
' `9 ^# G- w7 I/ w8 m- 6 n3 |3 [! \& Q y* R5 I
9 u% _( s# \ G+ F' W' b2 v$ }$ ]-
) [' Q+ N. U: J# g" q k - ) Z! S4 X. {: G) H! C; s
' n! K8 v. H4 e% Q7 m- y. \0 v
复制代码 |
|