|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 7 ~1 v( u% e! l
zhangandma 发表于 2013-1-25 10:16
# r8 ?1 O' C4 o- g+ W发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的 5 T) x6 D# w9 X+ B* h
因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
. L/ S4 f9 ]. e' w2 c' W5 i1 }2 J7 {: Q! S6 J
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)
, W' L' U; h& x) |7 y( k. O - {! w9 q, r; _2 V M- W7 a
- string selectedText;' ^4 k# \; I1 k2 }
- IEnumerator enumerator;
- G4 J: a+ y8 Z6 I2 ~" B - string str = "";
/ f6 A n6 [2 l - ArrayList list = (ArrayList) g_protected[g_projectedCategory];
$ S2 a" P, a+ ?$ o - try: Y" V1 g) R; s+ K( O6 y2 C
- {
1 {( D* n' O8 [, g0 @, H - enumerator = list.GetEnumerator();5 Q5 l+ @* O) z& I, Q( W7 V0 K
- while (enumerator.MoveNext())+ p6 `2 G5 Q/ ~0 Q
- {
5 _9 I( g" E; C, z9 ]4 Y, K - string str4 = Conversions.ToString(enumerator.Current);2 `7 E0 r8 B1 G$ D7 y) W
- str = str + str4.Trim().ToLower() + ",";
2 ]: a% l" v& u U% ]' G - }7 ^. K* p! S \% r4 `4 Y* i+ E% n
- }$ J5 T& P: |1 J/ Z, n
- finally4 r. m$ A8 H0 K" q R! Z- S; C
- {2 G0 r/ b$ c* B) R K1 a
- if (enumerator is IDisposable)
- d/ Z% i0 F V, T! k - {/ W! S5 {+ x% O+ s- }$ {/ M
- (enumerator as IDisposable).Dispose();
# h4 ^$ r( W k) h) p/ F; C - }. |. j( F5 B/ q. a! G( [
- }" }+ f S' W* I' g3 Z5 y6 j% L
- if (str.Length > 0)
; g# s1 d2 E5 L! Z( Q6 t" n - {) ^1 ?; z* p( N: v+ _3 r% c
- str = str.Substring(0, str.Length - 1);, B5 l0 N' b" c
- }
- y) n% x" o1 }# Q) r - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
9 n+ ~" Y6 w$ `% F* v% T - {! f4 p8 F1 g+ s: t- Q5 H
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;
1 d. g% i9 N# C/ g( P% }0 V8 \4 U - }
. g0 Z" j3 \ K0 l* _0 C" O7 X, @ - else
2 A" X9 B7 l F( [0 O; i7 M - {2 O' B2 g: i2 q
- selectedText = osd.spinTab.spinDoc.artf.Text;
' L. B- T( ]; k0 Z W% S* I - }
& Z- T( l( j; i. 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, ""));
. N& A; V2 U3 p9 s- d% V+ Z - if (txt.IndexOf("<success>true</success>") > -1)
7 }! P) K' q& t1 [ W( H - {
' V0 l" Q: D" Y, j6 b - txt = txt.Substring(txt.IndexOf("<output>") + 8);/ Y7 t0 w6 D* Z0 O
- txt = txt.Substring(0, txt.IndexOf("</output>"));
/ z+ H# P( O& F) M - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
* t, U7 `2 J* ?2 u1 F. K - {
" M6 _$ v b; W k, Q - osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
' ~' }7 q* I. y- V+ [) P - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";: G% T3 E4 T- y' }& `8 ?
- }3 Z1 j/ j9 d( ^# I
- else1 S2 z) d8 O7 r0 D
- {
# K/ H( P; n# I2 P# x e - osd.spinTab.spinDoc.artf.Text = "";5 | j) O% y% e6 n) E; X
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
$ D' c2 F0 ?7 n V - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
U. U0 U$ p; T! l) v, _ - }
3 O( n. `# ^) @. Y - }
# Q2 Z% y2 u) V2 N) P - else if (txt.IndexOf("<error>") > -1) [ F6 S) T( ~+ P) ?
- {
' P, G& L5 r: s; J' h- ?( b7 O - txt = txt.Substring(txt.IndexOf("<error>") + 7);
% H% ]( R3 a# E - txt = txt.Substring(0, txt.IndexOf("</error>"));8 [9 H. r& c" r9 M# O) Q, O$ p9 b
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);5 A! o# K; L! j+ [" b
- }% _+ h! g! a( r: M) b
- else
3 l/ `9 a: g+ D& Z& s" I2 w/ S# c - {3 G9 q9 t4 H- H0 o& k! I' |, W# H
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);% k% c$ E% I4 y
- 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, ""));* R+ m6 J8 o5 W! q
- }! r2 P' X- L: W% K
- } e5 B, a* w8 O# q& {: {
: c1 J. n$ t' r) |8 P- 4 T8 f6 ?- ~" q, q$ B
- , C# t% j' g* L9 L2 }
- 5 q0 C6 R- |% K |, M7 Y& j
- * W& j/ ~+ \6 T1 Y
- / p8 i( Z W o) e# }: J; A
复制代码 |
|