|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
. D/ d$ I+ j3 `/ e, m# Tzhangandma 发表于 2013-1-25 10:16 
; l' V% e0 E. s' x$ m% L$ \5 @发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
; ]* W$ S) \# d& e4 `( R因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
. ^! h: H }5 y7 [7 X9 S* s% c; v( Z
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)
! k: @0 Q, m/ d1 l/ x - {; {" \( I0 J# S6 Z& {3 H
- string selectedText;- R5 P f6 M( g0 l
- IEnumerator enumerator;
( d( `9 k$ V! `& e4 B - string str = "";' N& D2 f8 I* W, Q; b' b; z
- ArrayList list = (ArrayList) g_protected[g_projectedCategory];
6 J5 x, ^' }# k+ U - try8 T9 i, W2 v; Z) W4 V; M
- {& b% L: m* Z2 _/ Z; H7 I
- enumerator = list.GetEnumerator();' y" o5 M+ C% P. N
- while (enumerator.MoveNext())
* N* V# W) S4 ~ |; N - {
* S8 C: L+ E2 M1 r# ? - string str4 = Conversions.ToString(enumerator.Current);+ x$ V9 {0 ]* Y( f
- str = str + str4.Trim().ToLower() + ",";9 i/ r: Q/ i- r$ N9 z' @
- }
7 U7 p+ j3 i/ Q) T8 r - }
2 w1 x$ N4 c1 A) j/ a: G H - finally2 X7 u# u" l, e! s/ e2 ?
- {
7 ~1 k' S- w' Z6 p - if (enumerator is IDisposable); i6 n; K# }8 E6 u# Y: M R
- {
5 Q& e' @2 C7 V$ q9 M - (enumerator as IDisposable).Dispose();1 F1 i5 i$ `' \( O. I* X
- }
e: w' O3 T0 m& V8 O1 s' E: r - }
- t3 Y6 B; @! N' a; q% l9 T' n - if (str.Length > 0)$ w! N7 X. Y! [1 f
- {
2 p- m0 ?& `" w - str = str.Substring(0, str.Length - 1);
3 F6 K/ Y) [7 B% J | m9 w - } Q% C) d2 J$ \; K) W$ p: [5 P
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)# x, z- e9 P! A, {
- {: D i' G/ X$ F g$ R
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;6 a" [; d; e$ h
- }
+ e. T$ M, P4 v - else+ J( ?- [) v V4 n# x0 I! t8 K
- {
! ~0 J. g8 f3 E5 E- d! ]7 b6 l - selectedText = osd.spinTab.spinDoc.artf.Text;# b1 J3 K) @% B R. S) n
- } P- ~4 H9 E: u; L ?" B
- 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, ""));/ u! f- ?0 W( z" u9 c" m
- if (txt.IndexOf("<success>true</success>") > -1)) W& v7 S% h- @2 P" w
- {
% a- ^( ?- ^4 ~1 {3 r h( o - txt = txt.Substring(txt.IndexOf("<output>") + 8);- L3 [1 ]# ~' n1 |" V
- txt = txt.Substring(0, txt.IndexOf("</output>"));' T$ q3 n/ \, i
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)0 N5 s6 x" ?7 c0 Y9 P, l
- {
0 p. a3 q# D: ~( L - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
- R( A- L7 C$ C' k - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
, U2 l8 \4 k/ Z! x - }
2 e% A3 ]- k# B! q, E* w% S# K - else
. g" Q0 ?! X: d3 a9 o/ [ - {
3 R! ]/ u( n4 j2 n& l$ w9 n9 m - osd.spinTab.spinDoc.artf.Text = "";- ?$ j( E( G, l- o y2 A4 s- v$ z
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);. _/ W% |! n& y* _) S
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
7 f# ^1 q3 i0 s( o4 G' I; X3 `$ A - }
" q" L. I+ z# ~0 }4 r* L" A& ]% @ - }' d, e$ C- o5 D$ X) @
- else if (txt.IndexOf("<error>") > -1)+ e$ C v/ W$ N* l% b- d
- {; _' M3 R, r$ h% k2 H. \) Y& s
- txt = txt.Substring(txt.IndexOf("<error>") + 7);
, k- D$ N& @& A% N - txt = txt.Substring(0, txt.IndexOf("</error>"));5 g" }# M# t8 f& H
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
: Z! ~! b" A. S- j8 ` - }
) \5 @9 K1 M5 b+ G/ M: _ - else8 t- A W/ I4 R/ v% p% ]3 {
- {2 r2 M1 z/ p7 h3 c3 y
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);) k0 {: ^ I* E2 h+ l9 Q% d1 n
- 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, "")); f( l, c2 l7 n2 j/ m, W+ b2 d% w
- }1 ?6 e! H& A! X0 C8 @# l
- }
1 M4 {7 p. ?/ t/ [5 J) ^: b8 e1 `
' l% F" U" ]8 Y0 z& H) {' u-
3 p! \3 v8 y- [& }* ]- i' B - : @# f" \# r( }" S1 K% X8 {2 J f0 c
- ( ]6 `6 m0 n8 H) a6 l8 O. |
- ; f& x6 a3 S6 s$ v) [& H# A/ X
$ C3 e& \ f: i( _ l) u
复制代码 |
|