Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Blog/Impl/PostWriterWebServiceAdapter.cs @ 109:6bd9be78caa0
Merge
author | Nelo@Kenia.neluz.int |
---|---|
date | Tue, 07 Jun 2011 23:21:07 -0300 |
parents | 1d820f17fc75 |
children |
comparison
equal
deleted
inserted
replaced
108:786a90e26c9b | 109:6bd9be78caa0 |
---|---|
1 using System; | |
2 using System.Globalization; | |
3 using System.Security.Cryptography; | |
4 using System.ServiceModel; | |
5 using Agendas.Blog.Exceptions; | |
6 using Agendas.Blog.PortalSitefinity; | |
7 | |
8 namespace Agendas.Blog.Impl | |
9 { | |
10 public class PostWriterWebServiceAdapter : IPostWriterWebService | |
11 { | |
12 private readonly BlogPublicadorConfig _config; | |
13 private readonly PostWriterWebServiceSoapClient _service; | |
14 | |
15 public PostWriterWebServiceAdapter(BlogPublicadorConfig config) | |
16 { | |
17 _config = config; | |
18 _service = new PortalSitefinity.PostWriterWebServiceSoapClient(new BasicHttpBinding(), | |
19 new EndpointAddress(config.PostWriterServiceUrl)); | |
20 } | |
21 | |
22 private static string buildToken(string key, DateTime time) | |
23 { | |
24 var aux = key + time.ToString(CultureInfo.InvariantCulture); | |
25 | |
26 var enc = System.Text.Encoding.ASCII.GetEncoder(); | |
27 | |
28 var data = new byte[aux.Length]; | |
29 enc.GetBytes(aux.ToCharArray(), 0, aux.Length, data, 0, true); | |
30 | |
31 var md5 = new MD5CryptoServiceProvider(); | |
32 var result = md5.ComputeHash(data); | |
33 | |
34 return BitConverter.ToString(result).Replace("-", "").ToLower(); | |
35 } | |
36 | |
37 public void WriteBlogPost(string postTitle, string postHtmlContent, string postAuthor, bool setPublicationDate) | |
38 { | |
39 var securityToken = getSecurityToken(); | |
40 _service.WriteBlogPost(securityToken, _config.BlogName, postTitle, postHtmlContent, postAuthor, setPublicationDate); | |
41 } | |
42 | |
43 private string getSecurityToken() | |
44 { | |
45 var now = DateTime.UtcNow; | |
46 now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0, 0); | |
47 | |
48 return buildToken(_config.BlogWriterMasterKey, now); | |
49 } | |
50 } | |
51 } |