di .NET e di altre amenità

Usare gli Adapter di Live Writer

Da qualche giorno su XeDotNet ho realizzato una interessante funzionalità che consente di postare i propri articoli tecnici direttamente da Windows Live Writer. In realtà quello che ho fatto è di implementare le MovableType API ritagliandone una versione ad-hoc per il sito web. Assodato che mi sono divertito parecchio (con questo tipo di lavoretti mi sento proprio a mio agio) ho avuto l'occasione di mettere il naso negli assembly di Live Writer. Sono così riuscito a scoprire come fare per istanziare uno degli Adapter (vi ricordate IMHO?). Ecco l'esempio.

using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.BlogClient.Clients;
using WindowsLive.Writer.BlogClient;
using WindowsLive.Writer.CoreServices.Settings;
using Microsoft.Win32;
using WindowsLive.Writer.Extensibility.BlogClient;
using WindowsLive.Writer.CoreServices;

namespace TestWriter
{
    
class Program
    {
        
static void Main(string[] args)
        {
            ApplicationEnvironment.Initialize();
            WebProxySettings.ProxyEnabled = 
false;

            ISettingsPersister persister = 
               new RegistrySettingsPersister(Registry.CurrentUser, @"Software\Windows Live Writer");
            IBlogCredentials credentials = 
              
new BlogCredentials(new SettingsPersisterHelper(persister));
            IBlogCredentialsAccessor credentialsAccessor = 
              
new BlogCredentialsAccessor("dummy-value", credentials);

            credentials.Username = "username";
            credentials.Password = "password";

            MovableTypeClient client = 
new MovableTypeClient(
                
new Uri("http://localhost/services/movabletype.aspx"),
                credentialsAccessor,
                PostFormatOptions.Unknown);

            
try
            
{
                BlogPost[] posts = client.GetRecentPosts("0", 5);
                Console.WriteLine(posts.Length);
            }
            
catch (BlogClientInvalidServerResponseException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.ErrorMessage);
            }
        }
    }
}

A cosa serve? Ad esempio come nel mio caso a testare le API implementate, ma sono convinto che qualche altro utilizzo si possa trovare facilmente.

powered by IMHO 1.3

Commenti

2006-09-22T01.04.00+01.00 #

Di .NET e di altre amenita'

2006-11-21T21.23.50+01.00 #

Carino, in pratica ri-usando gli assembly di Live Writer disponiamo di un livello di astrazione per gestire i blog tramite le varie API native (tu hai usato MovableType, ma ce ne sono parecchie in effetti) senza doversele imparare....
Thanks!

Daniele Muscetta

2006-11-24T23.18.03+01.00 #

Ciao, ti ho citato e ho usato questo codice come base su questo post del mio blog:
http://www.muscetta.com/2006/11/24/out-blog/

Daniele Muscetta

2009-12-25T21.00.52+01.00 #

hi,
  i have seen this blog but when i copy and paste above code in my editer then i m getting error in the following 2 statements.

1)IBlogCredentials credentials = new BlogCredentials(new SettingsPersisterHelper(persister));

2)MovableTypeClient client = new MovableTypeClient(new Uri("http://localhost/services/movabletype.aspx"), credentialsAccessor, PostFormatOptions.Unknown);IN WHICH ASSEMBY THIS IS AVAILABLE PostFormatOptions.Unknown   ??

Actually I want to get remote login url of current user or all the account information of currently logged in user...

Please send me asnwer on my email id if possible(contacttoshailesh@gmail.com)

Thanks
Shailesh

shailesh

Aggiungi commento




  Country flag

biuquote
  • Commento
  • Anteprima
Loading