|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 0 Y9 K, `+ |9 K" y
zhangandma 发表于 2013-1-25 10:16 
. m1 e6 C7 W+ C# t# H发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
3 U, M j6 l/ g) \% V3 ~ L! Q5 u因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。: i: a- ^/ X: g! U1 H
% \2 A1 d4 y' c/ l1 y0 R$ [ H& y
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)
; e% N' B0 e: N- y! f$ f$ n0 K0 X - {. l6 R+ J" E1 I z
- string selectedText;# Q/ F A) ^2 k3 ?
- IEnumerator enumerator;
! Z- \, a% [( T& H$ t! d$ K - string str = "";
9 i3 J: \3 L3 H4 M/ d - ArrayList list = (ArrayList) g_protected[g_projectedCategory];
) s! |- i. R* D' V' _ - try
" ?& ]; P' _8 w- y/ J - { C( g7 C* C" t& q
- enumerator = list.GetEnumerator();0 r5 U' c/ F7 y7 D w. N
- while (enumerator.MoveNext())$ x1 K% _, } ]. e: U) D, R
- {
& @. A/ M) Z6 p9 ~ - string str4 = Conversions.ToString(enumerator.Current);2 ~) d/ B, K. z/ x& r$ d% E
- str = str + str4.Trim().ToLower() + ",";9 f5 r# G" t7 L! R8 O: o( O0 Q$ L
- }1 h6 P! c) V% O4 k7 Y) M7 w, O
- }' o! J4 f% U; p& e- I
- finally
X( C9 h, e0 e0 { - {
+ U5 N: c; S% V4 b- u - if (enumerator is IDisposable)* q+ O2 g" v2 W1 g0 {% u
- {
1 y( J; M, Q3 s" X: u. i! G, i& O1 t - (enumerator as IDisposable).Dispose();
3 T8 A5 c$ Q% W+ @; G* a - }
$ F8 r8 x2 t: W3 c# @/ n: V - } a5 a( o& v7 k
- if (str.Length > 0)
% m$ {8 }1 L+ F5 Y4 C: r' C - {- f2 L3 A W( Y6 j
- str = str.Substring(0, str.Length - 1);
: S* Z4 U0 M1 Z( z! T" E - }
/ l2 U0 p2 J! ]8 m - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)- e6 ?! ]3 b/ q/ }1 c
- {
3 N2 s! k0 }4 Q. [) ] - selectedText = osd.spinTab.spinDoc.artf.SelectedText;- h) ~3 o2 W9 X% b6 M
- }
/ P, {4 L' J- B( y7 Z }# M! k6 D1 t - else
% o3 k! t0 Y7 r, f e7 R8 ~ - {$ X( B/ ^- ^: L1 s* T6 T- ?3 D6 i
- selectedText = osd.spinTab.spinDoc.artf.Text;
: L5 |: |' @ x/ o5 d: e - }
" W; L1 A7 J3 X9 {" _! l$ W - 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, "")); f1 O8 {' N/ b. L: d4 i
- if (txt.IndexOf("<success>true</success>") > -1)5 f) `5 k' ^9 J5 s+ C/ _
- {
/ q- U$ w; ?; \# c' v& r - txt = txt.Substring(txt.IndexOf("<output>") + 8);8 G: W, q) B) u. h9 R( b: r
- txt = txt.Substring(0, txt.IndexOf("</output>"));2 |: F8 F: z/ Q) [
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0); \; G: t9 l6 ]( q/ ^" }2 i6 M# ~
- {
- I# l3 N' p0 W2 |' g2 m - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);( [) {* Y# z" j( F5 A) x. L: u+ l( ]
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten."; T) ^6 o, d! o, ?
- }% S% b! Z, X, O! J2 s; g5 g: Q
- else7 Z/ m3 _3 t+ c a
- {: n# p0 U4 r8 p0 D3 F& p9 L
- osd.spinTab.spinDoc.artf.Text = "";
- y: r; s& k9 V$ ~+ Y - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);5 I& A0 u/ {: X
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";# ?# r- D. J& n; ?
- }3 N# S! O, z _2 L* d
- }
, [7 l3 Y) Y6 ?/ ?) O$ A0 I - else if (txt.IndexOf("<error>") > -1)
2 m2 W5 E* g, ]" ]- w/ W - {
" Y9 F. K% z I) z* J) r! ~3 F - txt = txt.Substring(txt.IndexOf("<error>") + 7);) }5 q# }# G: m. K4 q3 ~! }- ?
- txt = txt.Substring(0, txt.IndexOf("</error>"));
; f9 u3 [, \* P" g. K1 j; Q2 w - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
' I8 v4 `# w( O( I; _ - }7 m) x7 k0 a0 w
- else
% N/ @9 M# L! N8 M5 {$ v - {" Q# _+ w' l$ m( q2 D5 u7 q
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); Q! O9 J' g: ?$ i# t, p X4 {) O
- 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, ""));
& Q, l# w# b3 |: x - }
5 D& B7 N1 N: d2 W8 A; x4 R - }
$ l4 B8 e' F$ W2 H: Y - , O, ` Z2 S8 Q# b6 C V; r! J v
- + s/ a' `0 c' E; [8 C
- . ] B; n9 |+ F. k3 g
- 2 `0 ]/ N Z" k
- % B* [- r0 _4 _
- ! o2 [, C$ [ W( Q' i( T2 i
复制代码 |
|