|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 + t" u" v2 ~9 Q4 u
zhangandma 发表于 2013-1-25 10:16 * X0 o& S: M" C/ B+ R$ o
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的 . z0 a+ K, k- q0 T
因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。 O0 e$ @3 ?5 `/ C% _' l) t3 a
* V# D6 k' r v' x
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)) k0 V! C: s: J9 V) M& R
- {1 j9 v0 o0 ?+ _! S
- string selectedText;: i% f4 `: ~6 n7 D
- IEnumerator enumerator;
- C' R% C* `$ @' M) F* F - string str = "";* X: L, R1 _! {2 u! t8 Y: M/ q+ F+ q
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];0 i& ?% ^2 Q5 `' u
- try
3 \4 u. ~ K& B @# O. @5 M - {
/ ~6 ?& L3 A( }: K: s - enumerator = list.GetEnumerator();0 J0 T* P- I" f" v
- while (enumerator.MoveNext())% I+ v7 k' o$ l" @6 O: P
- {
$ m6 D G' D1 d - string str4 = Conversions.ToString(enumerator.Current);: j$ ]& N; C8 [- o8 [( J; z
- str = str + str4.Trim().ToLower() + ",";
. m$ H3 }0 u- D; N+ O5 } - }! x0 [. G8 r2 g' p. n4 H
- }
* {% S4 l" Y9 [, G, s. x/ ?+ x) \ - finally
5 [9 q" {1 w" ~* z - {* y& N6 \( p& V4 t
- if (enumerator is IDisposable)
1 r# [* h- ?) ^% Q6 Y# g3 }# a. K/ u - {
& n" f- w; U3 ^ - (enumerator as IDisposable).Dispose();
& r s: K+ ~6 s - }) a6 z6 n; w8 M
- }' x+ Q+ d' ?0 }& e6 W+ z
- if (str.Length > 0)
1 U5 E- m$ R7 G) G) X- U- V5 h - {
: P7 u" R& x, S - str = str.Substring(0, str.Length - 1);
3 U- {9 r4 I2 V0 r! t- u; w. P - }# {3 E3 _* ?6 ?0 w1 D4 M1 s
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)* P4 V0 ^% Y! p& m
- {1 w, f! j; u6 _2 |0 @
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;
; X: w# }, A4 ^% @2 M9 D - }
, R7 n! f' Q& } - else: y( b+ I1 A. a- w" f
- {% P. D+ A7 ~6 {, |6 V' l% a, \
- selectedText = osd.spinTab.spinDoc.artf.Text;5 i9 v9 ?, J) A
- }2 {! G. D7 |$ N! E% p+ l+ 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, ""));
8 N* _3 _. P/ x3 ~* | - if (txt.IndexOf("<success>true</success>") > -1)+ y% x3 E2 x& g" S4 C
- {
, F" h: m$ ^" X5 n: V - txt = txt.Substring(txt.IndexOf("<output>") + 8);
. f P7 A! `& d2 J4 b: t - txt = txt.Substring(0, txt.IndexOf("</output>"));2 q4 M9 m* g d6 `* _2 Q6 M
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)4 |; t1 F# u9 g- [# P2 n i! f Y
- {
3 u' D3 J) a% m6 X3 t - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
0 V9 A( ^- P8 H; k% {0 I' B2 o; R - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
/ d% l3 K; r( W/ q - }
: ~1 {& H" ]1 y9 k& C - else4 f+ {8 p" a2 ]+ c' {
- {. J) c$ u( _- @% e( ?$ Y" J
- osd.spinTab.spinDoc.artf.Text = "";% y& n9 ~" f' C( {. Z
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);' @ G7 _' }/ W7 B- \0 J
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";# J1 C" a- Z# o, E) d
- }( y6 O; F. n5 _
- }
% p+ P4 g* M: H8 e6 j) U- X - else if (txt.IndexOf("<error>") > -1)
d; O: W/ I; Q: N - {& h+ [+ ?; z9 v1 F2 ]# o5 K
- txt = txt.Substring(txt.IndexOf("<error>") + 7);
$ h' N- d' N- U4 j: u3 y - txt = txt.Substring(0, txt.IndexOf("</error>"));
* P5 M/ n& I+ n% `6 M/ Q - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);$ V, C% e. m: N
- }
$ `% A0 b5 x1 q0 [4 f! C m - else
) H2 f g, q/ N; } - {3 p6 G- R# p- P/ s/ v
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
* M2 q$ V) ^5 Q G# s - 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, ""));3 R" S; h: X6 n. @3 k
- }
. J. N3 ?& i3 r4 e) g2 B - }# w- x R5 ]$ P: Y& L
- 0 S2 O+ v, K1 I" R- A- @4 y1 E
-
; o7 w2 z9 M* f( J
% \, P) Q/ q1 {: d5 b* G* a-
: Z- Q$ z- u( m3 [5 w& K- Y
3 q H2 ]; V% E" c- 6 f2 R$ Q% L6 G
复制代码 |
|