|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 : y' k1 E& X# ]9 }9 P; K
zhangandma 发表于 2013-1-25 10:16 0 d. D# V! R4 o5 `& X
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
) S5 u+ f! M( Y% i因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。 I0 A' Q; p$ K2 y Q" l
/ n, F% d! \ o# \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)
: @& q8 B1 `+ D# n - {" A4 m8 _# W" J; a
- string selectedText;6 u8 k1 A/ Y3 m) t4 u- L/ B
- IEnumerator enumerator;, F/ h: X t' S& _" f! o ]
- string str = "";
9 C9 d/ g1 \' B% S r" r' I - ArrayList list = (ArrayList) g_protected[g_projectedCategory];
8 n$ y! x7 m) p+ m; l$ a3 C - try% ]1 S4 d4 o7 U+ }3 X: n. N
- {1 D% j0 R; A3 ^2 h+ A* c8 B9 R
- enumerator = list.GetEnumerator();3 _0 O ^5 M0 ~( n j# I# J4 L, R
- while (enumerator.MoveNext())
$ ]6 u+ S) Z6 o3 B; |) n U2 L - {2 t# |' N% o* t, T. K7 n
- string str4 = Conversions.ToString(enumerator.Current); k1 s& ^0 d6 _4 j' O0 @
- str = str + str4.Trim().ToLower() + ",";( a6 L: a5 c* B2 w* d1 a
- }! m! k# D9 @, r1 Z: d0 F
- }& n8 P5 n& n9 Z. _
- finally
B, ?4 E& b) k% X8 ?2 c - {8 T( i0 O5 u$ q+ O; E9 c$ R
- if (enumerator is IDisposable). W) ]$ P0 Z3 U+ Z6 _3 M s+ J
- {
- L9 z2 {# R( o$ x* Z - (enumerator as IDisposable).Dispose();! h# \8 z3 v6 T4 e
- }2 e7 r# }; \/ p8 d
- }
~. Y1 D7 ?. g - if (str.Length > 0)
. o7 Y6 `" U; ]! {/ j" I - {* o' T2 O2 W w# y3 W Q
- str = str.Substring(0, str.Length - 1);
* k$ V: d! k2 R; y/ c ]1 p - }2 K, c0 N8 K# }+ l+ J
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0): }% q/ V( K& G5 ?
- {
% L/ K4 B) d4 A( E' V2 q - selectedText = osd.spinTab.spinDoc.artf.SelectedText;, s2 x# p9 Q1 M7 C- I9 o) L7 y
- }0 J8 R' v3 T$ ?9 F) B) c2 h5 D- m
- else% f! x0 F3 Y* D; D `! o: Z
- {
& u! y. {/ j0 k/ w - selectedText = osd.spinTab.spinDoc.artf.Text;
/ e( u; C0 Q! c8 q9 p) p. g s - }
( r. o5 y3 \0 X 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, ""));
9 L- c9 f2 [) x- w& h - if (txt.IndexOf("<success>true</success>") > -1)% `5 ~1 O9 W! S1 h
- {& D9 E; W, F2 s
- txt = txt.Substring(txt.IndexOf("<output>") + 8);
/ J+ B1 p P+ h5 \8 `+ d. H5 {& J - txt = txt.Substring(0, txt.IndexOf("</output>"));4 W9 e( I! _0 k/ \4 C6 ^4 S
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
# o/ Q* @' f+ r' a- A! P/ e - {8 O j- J. Q1 h% p$ r
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
7 J7 J3 {/ T* M) l( U - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
$ m5 [+ k& B: F g - }2 T. V5 M# \8 m, e
- else8 \- j, R5 C) n
- {
/ E% Z5 Q! y( J8 r$ @ - osd.spinTab.spinDoc.artf.Text = "";
( @- e# [9 g# L' Q: A - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
+ O2 {6 V/ z2 U$ [0 G - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
2 @2 S5 ^: V9 o/ V. V% J, p - }
! u% {) M6 |( E - }
- @8 f, ^% l: o$ y+ G9 m - else if (txt.IndexOf("<error>") > -1)
, l, h! o. y3 r8 Q - {
) ^; W4 T' a% m' Y5 x9 }- z - txt = txt.Substring(txt.IndexOf("<error>") + 7);
; [# a! Z3 F: `+ Z4 _' d - txt = txt.Substring(0, txt.IndexOf("</error>"));
- n( C, {- I1 U; g1 h - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);, n2 T% T) ?9 Q. f% U
- }% X+ f8 e3 w' i$ Y' Z$ V8 F6 g
- else; ~# K2 ]- `/ ?4 Q; h- s6 D, Y
- {
* B8 A% K* y+ s$ L8 n5 t - 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 N m& i1 L5 t2 F2 K, u - 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, ""));2 h$ j, Q2 g4 h: m1 s' j
- }
" @6 Q. X" t% T0 Q5 i. X2 e6 v9 b - }
# }. d" O/ r6 j6 Q
# g3 k# g( P6 i. P% B-
% W: U, n4 }( R) w - 3 A! H/ z( q/ k
-
3 ? F4 r; A& ^ - ; U" v: n* h" x' U/ |: q0 H
5 o& k e+ Q) L# s
复制代码 |
|