|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 `0 S. G* J! p2 r4 T0 V1 h2 h
zhangandma 发表于 2013-1-25 10:16 6 V4 l7 d, Y7 @( o! ^4 H- R/ |4 c
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
& T% g9 Y" q3 g1 l. p- W# S8 U因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
0 W3 \( l+ ]3 `$ F* \+ |$ X7 w# K6 k
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)
* [6 V2 \* W% y6 u6 ^ - {
) {1 ^8 v2 @* D5 s- J% Y - string selectedText;* @. C: j! o5 F) K& ^9 V
- IEnumerator enumerator; t7 h6 F1 {- y `. i$ H
- string str = "";$ E% `/ M8 \6 [" P: r; z$ I4 Y) O3 y
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];% y, D5 M; {; \& a; b
- try
6 A" c, ~* Q E! `/ I+ C - {
% x% b- O5 [& Y5 n/ x - enumerator = list.GetEnumerator();
, w/ k* a8 W% k4 A( T/ L - while (enumerator.MoveNext())7 e: L/ W. }9 v6 y/ W
- {
- H% K* X! i' L5 h& A1 m s3 l& ] - string str4 = Conversions.ToString(enumerator.Current);
" F3 R) T' q! p B - str = str + str4.Trim().ToLower() + ",";9 [" e/ b/ i G9 f/ ~
- }
3 X( D4 e* g: Q- @( H - } w5 ]& m$ e( g8 Q& @$ L* b, P
- finally
( R7 A' z$ p7 k2 q* F) y: k1 C* [; O6 K - {
/ d! M" n# n1 J - if (enumerator is IDisposable)
, A1 G" d- @3 n3 L+ H4 b - {
9 c# P2 O4 _$ M - (enumerator as IDisposable).Dispose();* s' _. {& V- P! L4 ?
- }& w% _% u: R+ s) n
- }) k3 g0 G9 n, }
- if (str.Length > 0)
* |* D3 ?! {7 \ - {
x' Z$ e) `1 F6 c - str = str.Substring(0, str.Length - 1);
8 i4 u. i5 R- |, A4 o - }- U# p0 v1 _6 W. @3 f1 c
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
- P$ \/ j% N8 c8 Z - {
* {. f- q( x: [; I* V$ P - selectedText = osd.spinTab.spinDoc.artf.SelectedText;
* J5 }/ V. |# q0 y. c( v - }* E u- t6 `1 c# \( ^* \/ d
- else
0 p, _ \* [' C/ O6 E+ ^9 k( c - {! m+ [9 d U4 G& z
- selectedText = osd.spinTab.spinDoc.artf.Text;
0 J! L9 c% a6 W8 r8 T4 ~ - }
1 S& k ~1 L1 F: h; 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, ""));
# _! C5 ~5 f" V5 C% O, S - if (txt.IndexOf("<success>true</success>") > -1) `/ p; x) U, |0 ?5 h# d: P0 @9 C+ P4 y+ |
- {
% e; S- @. C( B8 g$ j4 H. U1 t - txt = txt.Substring(txt.IndexOf("<output>") + 8);
4 P" L3 C3 v4 d3 T- T - txt = txt.Substring(0, txt.IndexOf("</output>"));
+ Q% ?! }4 C8 P7 P" n2 r - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
9 M: V& s5 t1 G; X+ U# a# {( A8 Z) b - {
( z' i8 z- |" V* @/ D - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);0 }- I0 m& z0 _) ~8 e
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
0 S B6 Q. e8 g" r% G - }
' {8 m9 \/ {1 H - else
m7 ?* F1 n7 a$ t2 X* U$ P - {4 t% f, P+ g* Y3 w2 p {& t! M
- osd.spinTab.spinDoc.artf.Text = "";
8 o0 j- z# \4 ]7 C9 K - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
9 l& \4 S+ `- E7 m - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";. u6 V3 S* }+ ^6 y+ H t
- }
+ }% M5 E, [8 O' h8 H8 l - }( L- i2 a& l( F# V) a: N
- else if (txt.IndexOf("<error>") > -1)& J& N- {' }5 ~. l3 j
- {/ G& g. n' k6 Z* f
- txt = txt.Substring(txt.IndexOf("<error>") + 7);) K" Q% e% w, U# Z) \1 h" S
- txt = txt.Substring(0, txt.IndexOf("</error>"));
; |" r5 |- ~. C. ]+ P+ }, s4 t - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);1 s$ b: \+ s4 S2 s/ X& S
- }/ z6 ~' ?/ ^5 |" n( B
- else" y$ i) T. v }2 B. D
- {& F$ O. C8 |/ [/ l; T2 r5 ^, j3 }4 X) w
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
7 v& b: c! G; B0 x+ \" ^$ x% V" Y* a - 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, ""));
8 p! y$ i5 g* m9 j# X - }
5 D8 J: ?* x8 W; A S4 K6 O - }
+ J6 x5 m" P7 |: p7 b/ D
$ l7 U* B; s1 V. P' m- W. @1 Q- # s7 c% o8 s9 v8 o' F/ s' B
6 s7 ?% }3 B- e' N' Q- 9 E. _& x/ q1 g+ c) e3 a
A8 n+ {: B2 o8 I+ }/ `- 1 j" P9 P- @ U7 O
复制代码 |
|