|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 ' m `( K- A! ~6 c+ _. t; l
zhangandma 发表于 2013-1-25 10:16 + S) P* {( {! g) R
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的 + _3 v5 V% e5 f2 B- Y5 x: W
因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
7 ^$ n9 a5 V( n) E
! q+ ^1 T" \8 U. _9 @' C6 G+ {" {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)8 ~+ S1 M( }% P0 X5 S
- {8 O$ W+ Y u* J, e3 ]* ~5 D
- string selectedText;
2 G9 v ?& w& p# T- Z' |2 e - IEnumerator enumerator;% B7 Z% V# ]; y- L3 P0 n) {
- string str = "";0 I [ y( a6 [, w
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];! q4 q6 }% J4 ?. H" h7 b
- try
2 X+ e8 K, S4 P& c# g9 Q. k) ?- q - {3 p, K& c: m: c% Z0 h6 _/ E; e
- enumerator = list.GetEnumerator();& ?4 A" M& u1 f+ x8 ]
- while (enumerator.MoveNext())
0 x7 e2 ?( P4 V/ {8 S! k) Y1 { - {# Q8 ^" m5 [$ b8 |# f, b8 v
- string str4 = Conversions.ToString(enumerator.Current);: H9 \2 X, m! Q2 [. {
- str = str + str4.Trim().ToLower() + ",";
, L f. V/ U2 J( p3 v - }) r9 F- l/ k; V7 r% _; X
- }7 J& {& M' _7 |3 l
- finally
) {( a9 f! r' h - {
3 p: i" C# I% X J - if (enumerator is IDisposable)
6 R6 U; y' b' s - {
- I) G# A$ _/ P1 Q8 H - (enumerator as IDisposable).Dispose();! S5 q h1 y2 v% u# f
- }
! I1 V( o- S3 Q9 K0 V' k - }
; B: }1 _) j; h& X) F( B - if (str.Length > 0)
$ Z1 p4 _! H, s: R - {
( Q" t* ~3 ` d& J/ D. j% ]# T - str = str.Substring(0, str.Length - 1);5 W7 o( c. ^4 L, G4 i) [5 z) g
- }
$ L/ Y- k+ a' l& G7 w# g - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
/ K, `6 Y( N! q! } - {
7 E3 ~% p# a7 a& [% L* `/ S - selectedText = osd.spinTab.spinDoc.artf.SelectedText;
7 v) @# y8 s1 {% Y - }
" n0 A1 e* K& s5 |& d2 A - else
. Y ^. X5 t. S C: J - {
9 a2 E" u# h/ O+ @' b" r! @5 x- P - selectedText = osd.spinTab.spinDoc.artf.Text;
. j" g. I+ o3 l: S( q E: a: U - }! a$ v8 }: d$ q8 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, ""));( K( }0 F/ R, D2 @
- if (txt.IndexOf("<success>true</success>") > -1)6 \6 M8 F1 z) F+ S$ U( E
- {' c! P6 X. Y5 T* v
- txt = txt.Substring(txt.IndexOf("<output>") + 8);
! `7 ?2 `1 n! J$ n0 O - txt = txt.Substring(0, txt.IndexOf("</output>"));" r# k* R9 E& _ a
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)3 U' c) ~( N' o8 }8 |
- {5 _% l, Q, J5 A
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);( S! @0 _8 C1 W8 d1 `) K/ @, N9 E
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";( O2 l. j+ b4 k1 W3 D J! `
- }2 u( L: K' J+ w! a& n
- else' k, V+ C6 g |2 i1 W& Y
- {
, F$ X( d. l& j2 X6 C - osd.spinTab.spinDoc.artf.Text = "";
7 @# a; A7 E9 F, H/ n0 | - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);" G& w- x' N0 L" t
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
8 u- Y) j! C$ X& F4 H6 @ - }) ^, s/ A$ \, ]' O
- }
7 `0 A# J" m- | - else if (txt.IndexOf("<error>") > -1)
+ _0 h3 c5 h% Y+ z1 e1 f5 o( [ - {
" j z# G8 A2 R) R; }: b) D4 S8 u - txt = txt.Substring(txt.IndexOf("<error>") + 7);! J, m( P- `& U1 t
- txt = txt.Substring(0, txt.IndexOf("</error>"));5 |: q2 B! Y, h, s, w5 `
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
) u n0 Y% W: |8 k5 e - }
1 P6 Y4 w4 J& ]- U4 N( u - else/ M2 H5 ]- q+ F$ J+ A
- {
$ d' l" H5 D, {9 {9 |3 H - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
1 ~8 B; F% j0 g7 J2 R. q - 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, ""));
/ G/ a' _+ M" h& o% n) Q: ]2 q - }
! [( Z9 w& `* M5 G& ~ - }% a, }1 w8 U5 f, b( B
+ X" q8 Q. t" ]: {, B S-
0 ]5 F5 L/ a- y" w: n/ P" d/ q - 7 ?" v! j* [6 @2 j
-
$ d3 j0 I, \' {3 V! s4 ]$ J* y - 0 _" }, @- w. `" C
- 9 D- k% _& Y# a. F& s7 }
复制代码 |
|