|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 . v9 ~- c/ @& ~ T" B
zhangandma 发表于 2013-1-25 10:16 
* ~, \! j6 p5 u/ b发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
, s$ |7 q# B7 t" G8 y& y/ i因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。2 N* U: u. E9 O$ u _9 K
; e$ s( f) M3 b* J9 }* 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, ""));- internal static void AutoRewrite(ref OpenSpinDocument osd)3 x% C6 X4 s, T5 F
- {
" B7 `* Q1 b# f% x: K d) F - string selectedText;
/ E+ V. I3 T: W# y- j% i' e - IEnumerator enumerator;
2 r; f: d3 g" A- E, \! r( A+ y2 a - string str = "";5 Q) }( X3 Y/ K9 W& L
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];& R5 N& Y4 }" A" u
- try
% N4 z. L6 @1 p - {$ n2 k5 k5 S; c- w2 |! t
- enumerator = list.GetEnumerator();
0 P( k" {" t9 V& G! @/ g+ E( x - while (enumerator.MoveNext())& i! B# d0 y& K0 e T
- {
% A3 x2 f {$ y- x - string str4 = Conversions.ToString(enumerator.Current);5 y- b3 }' w9 a3 x% ^* f, g- [
- str = str + str4.Trim().ToLower() + ",";7 I" p6 @& s% n; J
- }
" D3 _% ?2 C( }# O6 [& l - }) y% ~0 g4 U3 `4 }" k% ~8 _$ |
- finally h% ]: {7 u4 r
- {( t- r1 o% g, Z: K, _
- if (enumerator is IDisposable)- F- g7 V/ q; m( G0 T0 t1 ?- `; s
- {
' z! T* u' I1 Q$ ~ - (enumerator as IDisposable).Dispose();1 \6 e; o; S# f
- }* S4 H/ M/ ^/ B3 ]1 p
- }
, I3 k# L, W3 g! G- R7 P6 L - if (str.Length > 0)
% K; O; v* i1 {$ b" K' t: \ - {
6 _) _0 o5 l% `: Q7 _" A - str = str.Substring(0, str.Length - 1);
4 D3 W, U: g- W- @ - }" s: d6 m: C; m! O8 i( J8 O
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0) L% W2 R( H; a5 R5 M
- {
( X G6 ]7 w( S" W$ f0 G( i - selectedText = osd.spinTab.spinDoc.artf.SelectedText;* F8 }) s: O' t( s; K! _
- }% b! G6 E$ O% t; T
- else
6 n. w0 z$ Z# l( m/ i3 @ - {( l" B/ ^$ A4 K+ s8 k
- selectedText = osd.spinTab.spinDoc.artf.Text;
$ F3 w' y+ T% ?( }! b - }
0 t" x. T# \' u0 m+ e0 U1 J4 V( ` - 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, ""));
/ S$ p# t4 ?& n) y" L; \ - if (txt.IndexOf("<success>true</success>") > -1)# o3 r4 B9 W, h
- {
2 n$ T/ ], F" _! k6 Z8 _ - txt = txt.Substring(txt.IndexOf("<output>") + 8);+ i: X! y; N) B( V/ N; K
- txt = txt.Substring(0, txt.IndexOf("</output>"));
8 Q5 |( D# m# B* U1 v! n- k5 r. s - if (osd.spinTab.spinDoc.artf.SelectionLength > 0): @" X$ q' q# [& W6 |' x
- {
/ U* I1 o9 i3 J% N - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
' T/ v; t2 v4 ]+ ^) ?$ i - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
! ?" Q9 G4 Y/ T9 P$ M: R - }3 F& i9 h& Z. u l$ y1 l0 C9 G
- else
* Y7 X; n R# R" c6 H - {( R3 s6 a0 g) u6 o S# Y
- osd.spinTab.spinDoc.artf.Text = "";8 d" F4 R) i, E L3 u3 t2 s, Z
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
+ Z, x. x* p/ [% C( o) {/ U - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";' @- ~2 l' k3 f8 D V6 y& N
- }
$ S6 q6 [4 l5 D - }
0 ` S4 r' P+ Z1 O - else if (txt.IndexOf("<error>") > -1)
" l$ _: V/ ~& G, `7 p8 J8 K, p - {5 N6 u; B6 L: W! T9 ~: K# A
- txt = txt.Substring(txt.IndexOf("<error>") + 7);
# r8 k% u% i3 B5 K( U" D - txt = txt.Substring(0, txt.IndexOf("</error>"));! d% h$ |2 U& p
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
7 G5 j2 }/ B# @; Q* q) F. R) f" r - }
' S. K" A6 y( p - else+ T3 V# B6 E& c
- {
1 m; o2 [; v, Z# ] - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
. \5 N! \/ Z4 }" Q L N" p - 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, ""));
- E+ N6 x% X+ v: G8 ?1 W - }
, E( R9 A7 Y: m* r3 | - }
6 v% q4 o5 {* c* e$ G; W; ^ - . y3 A, K1 B8 h8 ~7 q
-
7 O" t& d* i U% ~ - 5 d; P0 [% M( _& } n9 B
-
( { P, @% O. J0 R
/ Q3 A% B% g* j6 ~: O- # b2 k* p/ |2 O
复制代码 |
|