|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑 0 ?1 Q% t1 R7 Q
zhangandma 发表于 2013-1-25 10:16 
5 Z- E8 ~- e G2 s) v y! T发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的 % T/ Y5 \* p4 I; n; D
因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
% L# D& D/ q$ _+ m. \9 N
& b/ d0 x% z3 f% e3 Q* xstring 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)
$ D3 L# D. x) H/ _ - {
- K7 C# y" y" \0 J - string selectedText;
( }5 O% v" S3 W% d% g - IEnumerator enumerator;
3 F& Q s1 _4 `: j. e' ?: V% G9 O - string str = "";
- m6 _+ @, E! f9 F2 @: @* y9 T - ArrayList list = (ArrayList) g_protected[g_projectedCategory];
1 Y5 g0 T' _/ a7 ? - try: }% a! V; H1 _
- {! ~) {- ` o. U
- enumerator = list.GetEnumerator();
6 T5 N. J2 ]. a" [' v m0 v7 v - while (enumerator.MoveNext())/ [* [% p; n/ p" r4 X( k' A
- {
' P3 [0 K9 l0 [$ q5 t7 U$ w% }4 D6 E - string str4 = Conversions.ToString(enumerator.Current);
( X& O! J' o K' h# G1 D - str = str + str4.Trim().ToLower() + ",";4 I7 {1 U! s }8 a
- }
! O5 r* |- U8 x+ `% c+ S% x) E9 O - }
) Z; w+ h: h: p2 @. P3 M& I7 f - finally
/ L3 c( x; b4 d% H' s - {! Q Z# g* O! s8 w
- if (enumerator is IDisposable)
- [. |/ \' @ W0 H5 q - {
" ~6 |% B7 O$ K8 r4 @+ P' y - (enumerator as IDisposable).Dispose();: f+ @4 K* P$ l( E! ~
- }" o* U. Q! B1 S# C
- }
) y$ d$ I m2 s* Z3 c+ l - if (str.Length > 0)/ B. [/ u7 `5 z9 k, t; h5 w# w- c
- {
& {& M B4 E$ c5 W9 c: Z' l - str = str.Substring(0, str.Length - 1);6 a: d0 D5 u8 n+ L/ m; o( F2 w6 x
- }
. _# U' Z1 L# Q0 |5 { - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
) ~% C6 b' W' D. `: b# l, ^) i1 R - {
4 V) E' \8 |# s - selectedText = osd.spinTab.spinDoc.artf.SelectedText;
- M: ^ l0 K) @ | - }
2 N9 ]) x% o. w7 [. h4 ^ - else- |1 c1 d5 ?+ ^* Q" s7 d; ?
- {0 g( s' n6 `! U& ~4 R$ D- P
- selectedText = osd.spinTab.spinDoc.artf.Text;, x+ `1 d1 M; \' w; Z+ z& P
- }* Q$ p: r5 P8 l! b* n
- 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, ""));
& W2 a7 o( d6 b( ^# b( J3 V" n6 T - if (txt.IndexOf("<success>true</success>") > -1)7 l4 E! ?& G3 \# q! H7 Y
- {
. B0 o. ~% M4 Z - txt = txt.Substring(txt.IndexOf("<output>") + 8);
" w' p6 h I3 k% L7 z( v! Z2 ? - txt = txt.Substring(0, txt.IndexOf("</output>"));
. J5 s; w- ?6 c - if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
/ j% R9 C8 X6 Q0 w. ] - {* y/ Y# `% @2 l/ L
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);
1 L5 ~3 q+ c" G5 R% M0 u- P. y" o - MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";
6 v( }7 p7 T( c8 A5 W- H - }: o+ _1 S* r& a& `) n
- else6 ^. O+ N' J# ?, J
- {& O2 a w) d( w* B; J1 B. t8 h
- osd.spinTab.spinDoc.artf.Text = "";
U0 C: V0 `* z: k0 x - osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);1 j% c6 o1 ]5 \7 A7 d; b
- MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
, ^. h& s- C: J! x6 l, m! U* y - }
4 G$ |8 M6 r' g6 z& O; f7 D - }
2 f$ x' f. h* z3 r3 _! r9 N( R - else if (txt.IndexOf("<error>") > -1)
" i+ `, Y% N$ H( A - {% L& M& T \# p9 O' ]
- txt = txt.Substring(txt.IndexOf("<error>") + 7);: {7 C" C# `1 O3 K' g9 O5 x. ~6 p$ t/ B
- txt = txt.Substring(0, txt.IndexOf("</error>"));5 n( A C1 C1 ~
- MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
# |# K! y+ K3 a8 |9 a - }- y( o' w2 U5 |4 b
- else
) ~3 T: x7 J' j' n - {/ g- l2 c5 D8 Y5 m+ C M! b( g
- 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: E5 E' a2 E - 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, ""));) c2 R( `7 j: ]9 n% J
- }2 @9 Z- f+ [! ~' C# \
- }
9 w. u1 b) M2 Y% M7 Q1 W9 T
, g8 ^6 C6 Q, `+ M* U-
$ o# c- x' J/ B( v
# K. x. {6 m$ ~! {9 B% Q9 H-
$ E! O7 V4 u4 k% d
- a! @* j! z- B
% W% w, C- i5 A2 h2 j) Q, j
复制代码 |
|