|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
A p! X3 S7 qzhangandma 发表于 2013-1-25 10:16 / I# e' V O% P. @! \
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
. t$ R# D" @1 p' q$ m) [% b5 J因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。7 L/ u; R- Q9 W1 {
. A- g' S: h3 j7 y" g7 g
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)
V$ _5 j5 ^" c' h - {& `- O3 ^& W/ B! `$ B
- string selectedText;
3 a) t. s( V/ a. F& g4 h) V+ ] - IEnumerator enumerator;( A; y3 |7 J6 F4 S# b. D" E
- string str = "";
; g2 @, w8 U6 G, c8 X - ArrayList list = (ArrayList) g_protected[g_projectedCategory];) m# b; e, S" [( E. |) G$ Z
- try& c5 { ?# W& W1 \* A$ D* _
- {
7 q+ K% ~+ S7 R; k$ P# y- w - enumerator = list.GetEnumerator();& @# E! V: d- d8 l3 a {
- while (enumerator.MoveNext())
, N% T1 [ t, `$ C9 n, K' S - {0 n/ i" p7 i! T' z
- string str4 = Conversions.ToString(enumerator.Current);- ~- E9 I. h8 K0 ?) c8 W. Y
- str = str + str4.Trim().ToLower() + ",";
8 P* D; H" j* p3 T: z7 G7 ` - }
' Z8 D- ?* S- v- M; ` - }
2 G4 l- }" D s3 m j( ^7 e1 l8 O& i - finally: _. ]+ t% z2 _; r% @% z
- {$ J& {. H; v+ h; s/ q
- if (enumerator is IDisposable)9 v$ @; E" ?- r' M( r8 {
- {, ~7 q. n+ i! W6 H! R5 W
- (enumerator as IDisposable).Dispose();
) X; k% g B4 b6 J* r/ ?$ ] - }8 C7 p; |' j( y
- }( l( x/ Z9 o- f# A4 T/ G7 ^
- if (str.Length > 0)
+ _( m+ i* ^5 k6 i - {5 |% _ A$ |, e- p. ~/ `9 g' b
- str = str.Substring(0, str.Length - 1); x5 J" B( ^4 W) W" B3 ^
- }, ~: N" O( j2 B7 |6 C- w: z
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
' \2 c9 V$ v; }" w - {& f2 w! t6 t& X2 j$ q
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;$ r8 A* r3 c$ I/ E
- }
8 Z8 `$ N0 ~0 f1 B& b% n - else% G( F. q2 F! d2 |) ] r
- {
" [# i, L0 R% I - selectedText = osd.spinTab.spinDoc.artf.Text;/ v) z: w8 S5 U* p& H
- }
. ^0 V( x: J; B, e5 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, ""));
; {# h6 U( ]2 h- C v, b - if (txt.IndexOf("<success>true</success>") > -1)& g) r$ ]9 k4 Z- x1 V: G
- {
& d; }3 i X: H) {1 u, l6 k+ ? - txt = txt.Substring(txt.IndexOf("<output>") + 8);+ h) E- b# M$ T+ C5 ?
- txt = txt.Substring(0, txt.IndexOf("</output>"));' ^* b' V2 I @( f+ Q1 q
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)$ W8 J' r" k0 [7 x) S
- {
0 i1 L1 F' H9 ~3 u9 _ - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
( U' c$ |8 r3 n2 W. y - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
1 ]. e4 C9 N5 b8 E - }
6 I S6 K! s- r0 _0 m - else
9 y# [# {% |; A - {5 L, [+ D) V0 h2 @
- osd.spinTab.spinDoc.artf.Text = "";
0 t8 P S/ W" u - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);+ U) C1 j0 Q( E% y' u3 h S
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";4 @ F% F% q- E7 A! ]" J
- }
2 J/ v: s; k9 e) }' r9 E - }
/ l- I8 \ U5 [# I. U$ X5 o, y; }8 \ - else if (txt.IndexOf("<error>") > -1)
7 {. j4 b) p$ _1 P - {
- ?1 U4 B" T0 X+ V: E @" L1 t - txt = txt.Substring(txt.IndexOf("<error>") + 7);, a, h3 d( B/ T& ?
- txt = txt.Substring(0, txt.IndexOf("</error>"));4 _' j' v3 m5 G
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);* L! Z! h! V6 p7 ?# j1 r
- }
6 N. r2 h" H/ ?' v7 a0 m' e3 \ - else
$ u4 f# Z" q H9 E" l/ L' s - {" l! S' \/ m. B) b3 o' J
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);/ D5 Z& I" f" V& i9 h
- 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, ""));0 h' \$ u# H1 y+ A$ E6 z
- }
; n1 N4 Q2 f5 i$ ] - }
7 B) T& g3 b0 |" K2 z& G1 l - 5 g' q: |( h! |
-
* B0 C. Z3 X6 b) C - * {& J7 s; c9 [9 |
- 3 x& g1 b( Z, u! S) F. c
' h- E' g( ?$ x8 }$ C* t
8 d, L2 M9 D3 N
复制代码 |
|