|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 " O- k* m6 j' w+ H' V- \1 {
zhangandma 发表于 2013-1-25 10:16 
5 C B4 w% e9 J* @: D% X. Q发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的 , J) C/ T" x8 C# ~
因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。- C$ o: |8 S+ ]: \# m
9 s0 I. e( a t, @/ x! 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)( G" `8 U- O* R9 W
- {- J% ^. E: z N# L8 R
- string selectedText;0 f' u& M" Q# r; M4 r9 p6 B
- IEnumerator enumerator;
2 ?1 J$ J# @. Z1 F; @' o - string str = "";
, \) E7 q5 _, M( M8 b - ArrayList list = (ArrayList) g_protected[g_projectedCategory];# @2 h: o7 U5 |* ^5 F1 i
- try \! L* i4 Y% W' \0 Z5 r
- {6 t+ Z( I7 j9 N
- enumerator = list.GetEnumerator();' s/ S+ i4 W* a; _
- while (enumerator.MoveNext())
7 l) `% U2 k% v" k! D: y - {9 S6 ~$ i; P/ ]
- string str4 = Conversions.ToString(enumerator.Current);
: g! [# P T& i f; K - str = str + str4.Trim().ToLower() + ",";
) p* n0 {/ {' }& @5 I; k$ Z - }
2 Z. _( p% B% F3 D4 t0 d4 { - }1 }) t8 g- H X% F
- finally
2 Y( Q3 P* u* j7 `" n - {
. \6 _- z+ u5 j' ?, k. c. k5 R' o - if (enumerator is IDisposable)
3 X( Z* j4 T5 Q1 q# p+ e - {9 n5 C6 q. q, w, J
- (enumerator as IDisposable).Dispose();# J3 c* T2 b7 z* Y/ C' m
- }
" u. B! O$ [4 T) O! w0 F+ e, N) } - }
* K2 E- i2 c, ^, h6 E6 O! O% s - if (str.Length > 0)
8 z2 \0 X1 }3 c - {# a6 c' f2 h! M3 S/ Z. T; L
- str = str.Substring(0, str.Length - 1);
* \) O! @( y6 {% u" _" K* M4 T- B2 { - }3 z7 a( G; o; O! ~# R! \1 p! m$ k
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
" {: U7 H4 l# `' C; |) q- e! u - {# b8 W8 b! I _5 G6 f- @ t
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;
5 p1 J+ U* x( t5 k; k: v r - }0 U" F6 Y# q/ f
- else" V; S; q1 M; q- }
- {: g7 j i6 Q0 U# D+ ^ S
- selectedText = osd.spinTab.spinDoc.artf.Text;
- l5 f/ D6 p5 T" a/ m) Q - }- l) J: r; O( L; j- V% F
- 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, ""));7 j, Z: x4 x7 L5 \" G% E% M9 X) U9 j* h4 J
- if (txt.IndexOf("<success>true</success>") > -1)
: K# O0 h7 y# Y- G - {
2 s, W9 h% ^2 P, l0 ~* ` - txt = txt.Substring(txt.IndexOf("<output>") + 8);
. a" X$ _0 |5 f - txt = txt.Substring(0, txt.IndexOf("</output>"));# }. p; Y4 ?0 ]% E( R
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)# G9 ~- T- d4 i9 b4 ~- `
- {
) }. G ~! C" K7 M! u+ U - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);8 }1 h2 I* r& b/ e" U
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
2 O$ d& k, W5 W6 {8 u* @ - }
% X/ ~* v5 S3 u4 z8 V4 ~+ B s - else4 S( `3 a4 H' V( [, J) L9 H7 |9 c
- {
+ t6 W& c1 u) H! v - osd.spinTab.spinDoc.artf.Text = "";, i1 m+ [- K" P L
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true); J" b+ m* O% h Q7 k7 k6 G
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
! E3 ?* W: E% [5 I3 w" n* K: ] - }# i# u7 y& B- x5 Y
- }
' i5 ]' N$ q5 R" [- T6 ^: R" k - else if (txt.IndexOf("<error>") > -1)* n5 M, Y b1 P
- {
* r* j4 V+ j- T7 g2 m; ~ - txt = txt.Substring(txt.IndexOf("<error>") + 7);' A) T& R C0 L' `+ P; y! N2 t
- txt = txt.Substring(0, txt.IndexOf("</error>"));. j/ _* R* I" s5 f/ ]" x( \
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
6 D9 W4 {! e% j: O! l4 O - }3 }# u0 F0 {+ t
- else
# h% S+ R/ s5 F+ b6 s& L2 M - {. v( W! c# N7 I/ {4 Q
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
& U$ w$ O9 u8 S! d4 W8 | - 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, ""));. u" S2 K5 d. T% ^- i1 c
- }. D* ]* u+ Q" N; H5 b6 S% t% r
- }
! H& f& E; c7 k v7 A; E; o
9 V6 Q/ l# z2 N8 C0 F- + F$ W6 E0 @% ]! S) S) w4 r
- 7 E" q, z! K% ^( o
- # _" b1 r; j$ N$ V, |
- % z. d2 G, S2 Y4 q" b; v
- + {) L; k" _1 d: K# Y2 B
复制代码 |
|