|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
5 g7 q5 w" q' W: [7 Kzhangandma 发表于 2013-1-25 10:16 + \* T* c; A$ H
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
5 a4 b {/ z: x9 T/ u8 F因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
, s E0 Y$ L8 H& d' o3 J* {7 J7 {# L2 ~5 l5 @# 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, ""));- internal static void AutoRewrite(ref OpenSpinDocument osd)
9 P# ^4 p* J% g0 ]" \# O - {
* J& p/ E$ H p% Q* r6 k7 X - string selectedText;
- ~2 m& ~' Y2 y* f+ `* l - IEnumerator enumerator;8 ~, Z+ J( Y! H* n
- string str = "";+ ]* P% V8 w Q# K" R
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];8 q; l) i; w0 P4 J! Y2 j3 J$ J
- try
3 A- S& c4 q* h2 D, x _ - {
8 [3 q/ K- ~9 R; ? - enumerator = list.GetEnumerator();
% Y; J9 F3 D6 h9 H, i. E. q - while (enumerator.MoveNext())8 G* D# Y4 S3 ?, l+ y0 |
- {
# j- R. T3 |. A- _1 I - string str4 = Conversions.ToString(enumerator.Current);7 `% ?$ l2 r+ b- A$ L1 ]) a: V& F! v- a
- str = str + str4.Trim().ToLower() + ",";1 K' V1 E2 v/ r& @; w0 b( T
- }- \9 _4 D7 d' |: U+ j
- }' i A3 O+ L6 u, B- U
- finally
* ]0 u/ B' N! E6 X- D3 f8 ]! U - {, N4 q/ }2 I5 i0 l R3 g
- if (enumerator is IDisposable)3 T# ]8 p: C% h2 p& U) I
- {
( U: |3 |- @& M% J2 Z - (enumerator as IDisposable).Dispose();- Y- s+ p# `9 d _% u6 X( M
- }
. [* ~3 d. O' g - }
) h( G8 \. e+ M: L1 s5 F - if (str.Length > 0)7 S% a6 c4 B5 e* I8 }4 A% d$ K
- {1 z$ `5 k' m# i6 c
- str = str.Substring(0, str.Length - 1);+ O% B& r4 D5 j' B$ _: L# \1 f
- }: x' k2 r# z. Y1 a
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
9 a6 ^7 m: M# @& H - {3 A& X! e1 Y8 R
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;* P+ t) j0 r9 R* {
- }
( G8 F, ]' |3 w4 D1 X4 m - else) N. D' U, n V( l
- {
! h+ ]8 G" n I( a( S - selectedText = osd.spinTab.spinDoc.artf.Text;3 {6 [, d7 ^2 h6 S% w
- }) |( y' @" L2 W1 S) m6 d
- 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, ""));+ T. N' K! a% ~" r, h) Z
- if (txt.IndexOf("<success>true</success>") > -1)
9 h: s; z8 C _- a1 l/ u9 l - {) V2 z0 L' t" P
- txt = txt.Substring(txt.IndexOf("<output>") + 8);
+ q. g$ D9 u! {' X - txt = txt.Substring(0, txt.IndexOf("</output>"));6 K! \) X0 T7 D, t4 }
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
# j7 M7 f: | l( p! p R - {
: Q+ K) ~1 x, f' C1 R" A1 O - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
) h4 g, g s, u. }+ G, O, |: w - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
+ v) [8 t. l- }( n; n - }
4 F- K$ @' Y/ v. E - else
8 V; |7 J( m9 H: Q: B8 Q; T - {
; W" X# H- P& e+ |) C - osd.spinTab.spinDoc.artf.Text = "";% X; `3 ]/ c5 l6 C
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
9 k% `" ^" a& ]0 C U7 \1 @ - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
$ [9 `7 R4 {% H2 U/ U4 g - }
4 q2 @4 L: g( u$ j0 B - }/ J0 U+ w1 W' R0 T& p1 [& l [- M
- else if (txt.IndexOf("<error>") > -1)$ y- A, n" \& I* b. d. u3 A6 I. J
- {2 W+ D) S, k( ^! l. T& q
- txt = txt.Substring(txt.IndexOf("<error>") + 7);0 l9 g% t7 ^: y6 s; ~1 b3 m& A8 I/ ~3 l
- txt = txt.Substring(0, txt.IndexOf("</error>"));/ x6 X d0 K5 T8 M2 l
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);- i: [+ N: L; T6 X2 L% ^) R% p) w
- }
, `2 f* `1 y1 F' p/ b0 C$ | - else
) P7 Z* r+ V+ ~) H* ?, B - {
& i& i1 C! i: X - 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 @' |! O% J$ A7 B
- 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, ""));. A/ `) T% x$ x* G8 l$ ^
- }
% r: v/ o, m0 H' h' y/ ~ - }- P4 x# p6 a) p+ @; z
- ( l1 n8 z5 h: j3 L/ O5 K
-
( `. Y( A0 A* P1 B- m7 Z. @# l - % y: f% C/ L, f0 w0 s: E/ P
-
# x& [" o- O0 M5 l9 A6 c# y! X - 9 S; j! L) D: x O
% Y5 ?# X1 @' V- g( w
复制代码 |
|