|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 8 [' j, x7 A5 q
zhangandma 发表于 2013-1-25 10:16 5 ^. W3 }9 k: z1 X5 o0 O- c
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
9 j2 J! R8 M0 a因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。( i L: E0 S4 R# b- g$ s& ^* N
; J% W# F1 `) q y
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)
! H8 k( k' {4 u+ c* s* n - {
. k% L9 e+ b4 G4 d8 w. n3 u - string selectedText;
, r2 j% y: S6 C4 V - IEnumerator enumerator;
0 ^; E* k n; C4 @ - string str = "";. p2 E9 y* { p1 a) O" k
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];8 G5 z1 Z4 k% W C' G
- try
' g9 k% f3 h' o - {
1 ~0 d5 e- I4 X4 ? q% p - enumerator = list.GetEnumerator();7 f: U5 p8 _6 J6 r
- while (enumerator.MoveNext())
* g* d( t! x/ W9 B' z6 U# }) a0 D - {0 R- Q, |& ?9 b# o% B( k: ?
- string str4 = Conversions.ToString(enumerator.Current);( [; J" q ]# a1 ^( j; J, E& T$ R! `
- str = str + str4.Trim().ToLower() + ",";- d$ F0 J5 b* L. V. F' N1 x
- }1 E. w0 ~+ W: j S0 g. ]3 E+ I4 j
- } E! {7 e* |" M& _" s4 @
- finally
7 ~1 m& n) R' A - {! F/ A8 ^7 j/ K* S$ Z
- if (enumerator is IDisposable)
7 Y* V; n3 b% {& g( t: r: o - {
: Y' R$ Q: b& D# E5 O( L' i8 t - (enumerator as IDisposable).Dispose();5 |8 a$ i7 W+ n; J! L2 r7 U
- }0 A F! r/ C6 E& m Q O7 J
- }
$ z6 V+ D9 e. ~5 @" @' ?0 A: V - if (str.Length > 0)( l* a: j8 s' _/ D4 w1 {7 L3 i3 H* z
- {
) K) z4 V Q7 m2 f - str = str.Substring(0, str.Length - 1);
$ o+ a0 y4 b. W' ] - }9 O7 U) k) p5 ^
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
1 J% j9 K8 B/ r. a - { y1 H8 M0 Z0 J% e- C+ \8 L8 t. H: a
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;9 Q( n i I' @) D1 a% }
- }* g; N9 A9 ~2 `
- else
2 v' j% \5 q' u3 a - {
+ }1 b* p2 V) Z3 f( N5 d - selectedText = osd.spinTab.spinDoc.artf.Text;. I8 `* \. ] i) R) O) G* V
- }
0 q, z# \4 f: \: P1 W! I - 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, ""));& L8 K6 Q2 y$ F. _& |
- if (txt.IndexOf("<success>true</success>") > -1); w, j5 ]/ ?8 [ ?% q
- {
0 a; i# Q& W! m' c% s+ s& M& n - txt = txt.Substring(txt.IndexOf("<output>") + 8);
7 C. W M6 o- ~; ^ - txt = txt.Substring(0, txt.IndexOf("</output>"));
4 S! g' }8 V3 {+ h- [' E+ d, R8 j: w2 b& j% A - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)1 ?- S7 H3 T2 G
- {
9 s2 d+ v. n! j& ?9 p& [6 z8 f/ I - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);5 P$ ]0 \1 G7 K1 e9 b! i. g8 d( q
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";! M! `; u3 g; u; e
- }
- M6 Y/ d8 {" g7 h, { - else
, v* F' h6 a7 t* p3 a - {
0 L: N; U3 Q8 A7 [ - osd.spinTab.spinDoc.artf.Text = "";3 o' m& o. Y7 \0 r* B2 L
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);; x8 U2 e* ]: B3 L/ X# F& W
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";; a0 y) x' A8 r1 N
- }" ?; U3 l( w Z% R. k d+ V4 n$ Q; l+ ^
- }( {* D, r9 Z! {% h# C( q \9 g6 U
- else if (txt.IndexOf("<error>") > -1)
8 \9 w0 z8 `2 O6 V& ] [3 h9 h3 g - {& [9 ~8 `9 }* Q& f: h
- txt = txt.Substring(txt.IndexOf("<error>") + 7);5 {& w/ y0 _, S: F" g7 t
- txt = txt.Substring(0, txt.IndexOf("</error>"));
* g: G% r6 A7 b& b9 C - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);: B% {7 m) `) B; ?4 K3 W% S# W
- }5 z+ X' ? G1 m3 [
- else; ?% A/ n* B8 ^4 S" w5 e
- {
$ [9 u( ~3 `, Z7 G4 {+ V: h8 L; U - 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 d5 o4 H' \! `, O
- 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, ""));
, a* }( ]& `! |; H - }
, P; s8 D: P6 D' u" t6 o& c5 m - }
" }1 L4 Z6 C# R' x9 o3 o7 d! { c - # O! W! D- Y: ^& E
-
; \( @$ N; V/ M" y
* d' E" I, x" z- % V* T0 w4 g# Q8 d$ c8 H. t
$ Q. \- B- O) x+ T" X. O- 6 H9 W0 ]1 C9 x% o( ^5 d7 J4 h
复制代码 |
|