|
|
发表于 2013-1-25 10:20:15
|
显示全部楼层
本帖最后由 潜水大帝 于 2013-1-25 10:21 编辑
- c7 b& G& N5 f' Ozhangandma 发表于 2013-1-25 10:16 : A7 d$ x# O0 L
发过啊...我找的时候论坛里有下这个了..也是不支持Auto-Rewrite的
( {' i# V$ K" k1 J9 {) M$ k3 |因为Auto-Rewrite是要调用官方API接口的,这个提供的验证服务器上没有官方的API所以用不了。
5 K% m! e8 R1 ~4 D7 H$ }" t* K) P/ u( {6 m5 a
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)4 l7 w' P8 J9 H, Z/ r1 E% Y8 W8 K, R
- {
% b3 B1 x2 Q3 q. w! N, S+ l - string selectedText;
% r, x2 W& f4 t1 n# J - IEnumerator enumerator;, d1 F8 D# |( W U3 u" O- P% F
- string str = "";; s5 a& Y! J, j
- ArrayList list = (ArrayList) g_protected[g_projectedCategory]; L, v2 f0 ~7 u9 H- [
- try# ^0 J+ ]( N; H$ O2 \! y
- {$ k- L2 i* Z u$ Z# A8 i
- enumerator = list.GetEnumerator();
V0 a0 f& b, ]& p - while (enumerator.MoveNext())
% l- `. P' D# J# Z2 V6 N - {! s" N7 ~' a+ b2 I/ z; U6 M5 r
- string str4 = Conversions.ToString(enumerator.Current);! B" y% l7 P" S3 D
- str = str + str4.Trim().ToLower() + ",";3 H! }: E4 z0 `& T4 n
- }$ z5 N5 a' i1 Q% @
- }9 V; r+ h0 C# o. S- @
- finally7 Y4 C; B' [) A8 G# {
- {9 O: ~' Z& s1 u, Z
- if (enumerator is IDisposable)8 H1 I3 L; L9 [ z8 C$ X& m& }. D3 Z
- {% j. Z$ D* p2 V0 P/ D2 W
- (enumerator as IDisposable).Dispose();' C& k2 O/ k: J# @/ d
- }
% x2 J3 E$ D) T# u& V - }
# G8 U: j" ]3 c: z Q - if (str.Length > 0)% a) I/ O2 w3 F: } Q- s& c; d f3 K4 `
- { n) e4 `( d3 ?& V1 J
- str = str.Substring(0, str.Length - 1);
5 h+ J7 R* \* D& e - }4 Z2 R" y2 L1 }
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
9 A& Y% J/ W0 V: z. Q& ~' g) s y - {- o0 g: e: Z2 ]" ]% r$ j5 _
- selectedText = osd.spinTab.spinDoc.artf.SelectedText;" y. ], E9 _0 n; x2 Z7 i7 U \
- }
6 D( S6 v; [7 }, e. S - else. _( J, u6 a, P4 ?7 h+ r
- {/ F! w, I. y7 b8 H: n. G
- selectedText = osd.spinTab.spinDoc.artf.Text;/ r. [1 P8 [! B) D
- }
: Z2 N9 A# b+ x" X5 ^ - 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% ~, D% @. p& n - if (txt.IndexOf("<success>true</success>") > -1)! ~' N3 V3 \- @& t; G, e9 y( ^
- {
" r6 F3 w7 R/ i, G2 @: k* Y - txt = txt.Substring(txt.IndexOf("<output>") + 8);
/ g0 U4 x2 {6 |( C! m; m - txt = txt.Substring(0, txt.IndexOf("</output>")); t8 {0 h7 X9 X; T# o4 F7 w5 x
- if (osd.spinTab.spinDoc.artf.SelectionLength > 0)
2 e: Q% X' Y' I, S - {3 {3 [1 [: A, X" u% ^; I! J
- osd.spinTab.spinDoc.AddCodedTextFast(txt, true, false, true);8 J* F: _% _: U# k6 d" x0 u
- MyProject.Forms.MainForm.status.Text = "Text was successfully rewritten.";% x0 w7 U7 q3 d ^
- }( }+ p5 a4 |1 L8 p
- else; k, d1 Z; u+ d7 E! \1 w! x& J
- {7 m* \' v: A. N: f% d; [
- osd.spinTab.spinDoc.artf.Text = "";" ^# \; R* C }1 E5 ~
- osd.spinTab.spinDoc.AddCodedTextFast(txt, false, false, true);
( N$ b, o: o3 d- D - MyProject.Forms.MainForm.status.Text = "Article was successfully rewritten.";
4 i% n4 _% r% { ` - }
; p+ d5 {2 p# z- D/ |7 O" A - }
/ |8 J; K2 C8 O - else if (txt.IndexOf("<error>") > -1), P# l) y& E/ [
- {
# e' ?; B: G+ y+ q) i - txt = txt.Substring(txt.IndexOf("<error>") + 7);
+ y9 Q L; f4 A - txt = txt.Substring(0, txt.IndexOf("</error>"));
{% _, m( b& m0 J7 d. L - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\n" + txt, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);+ c! @1 [0 i( K5 H# C3 r/ w
- }" P" S; T( ~& t4 }5 K+ Y
- else- a) ^! Z9 g P3 g% j
- {
! d; Y3 O& M( `( A: o - MessageBox.Show("An error occurred while attempting to rewrite this article:\r\n\r\nUnknown error. Empty result returned.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
4 I* { X9 Z! v7 P+ x - 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, ""));
' p w! F- y1 s' b) X* J - }
+ L2 n7 i& Y% f6 M( e! H - }
5 S- T# K" X9 M. H; J& Y e
$ w0 ?' x& E) S: V-
0 _ q% a$ x: K. S! ?% Z$ \ - . g2 ?2 u" Y0 Q3 G# M6 Q
- 8 u" z4 K, Y) V+ A* _+ B
1 z7 l0 B1 \ Y, \- : ]. v& L. V2 u4 v5 G# B& v
复制代码 |
|