Exemple #1
0
    public string CrossPost(string WebBlogID, string BlogService, string Username, string Password, string WPAddress)
    {
        string ErrorMessage = string.Empty;

        BlogDescriptor bDescr = new BlogDescriptor();

        bDescr.Username = Username;
        bDescr.Password = Password;

        BlogEntry blog = BlogEntry.GetBlogEntryByWebBlogEntryID(WebBlogID);

        if (blog == null)
        {
            throw new Exception("invalid blog entry");
        }

        try
        {
            switch (BlogService)
            {
            case "blogger":
                bDescr.BlogType = BlogType.Blogger;
                bDescr.Address  = "http://www.blogger.com";

                Service service = new Service("blogger", "");
                service.Credentials = new GDataCredentials(Username, Password);
                Uri       blogPostUri  = SelectUserBlog(service);
                AtomEntry createdEntry = PostNewEntry(service, blogPostUri, blog.Title, blog.Body);
                break;

            case "wordpress":
                bDescr.BlogType = BlogType.WordPress;
                bDescr.Address  = WPAddress;

                WordPressEngine wpe = new WordPressEngine();
                wpe.PublishNewEntry(bDescr, blog.Title, blog.Body);
                break;

            case "livejournal":
                bDescr.BlogType = BlogType.LiveJournal;
                bDescr.Address  = "http://www.livejournal.com";

                LiveJournalEngine lje = new LiveJournalEngine();
                lje.PublishNewEntry(bDescr, blog.Title, blog.Body);
                break;

            default:
                break;
            }
        }
        catch (Exception ex)
        {
            //ErrorMessage = ex.Message;
            ErrorMessage = "Could not login, please check your credentials";
        }

        return(ErrorMessage);
    }
Exemple #2
0
    public int CrossPost(string BlogService, string Username, string Password, string WPAddress, bool AutoSubmit)
    {
        member = (Member)Session["Member"];
        int Result = 0;

        BlogDescriptor bDescr = new BlogDescriptor();

        bDescr.Username = Username;
        bDescr.Password = Password;

        string Title = "Next2Friends test post";
        string Body  = "If you are reading this post then your username and password have been entered correctly";

        bool LoginOK = false;

        try
        {
            switch (BlogService)
            {
            case "blogger":
                bDescr.BlogType = BlogType.Blogger;
                bDescr.Address  = "http://www.blogger.com";
                Service service = new Service("blogger", "");
                service.Credentials = new GDataCredentials(Username, Password);
                Uri       blogPostUri  = SelectUserBlog(service);
                AtomEntry createdEntry = PostNewEntry(service, blogPostUri, Title, Body);
                LoginOK = true;
                break;

            case "wordpress":
                bDescr.BlogType = BlogType.WordPress;
                bDescr.Address  = WPAddress;

                WordPressEngine wpe = new WordPressEngine();
                wpe.PublishNewEntry(bDescr, Title, Body);
                LoginOK = true;
                break;

            case "livejournal":
                bDescr.BlogType = BlogType.LiveJournal;
                bDescr.Address  = "http://www.livejournal.com";

                LiveJournalEngine lje = new LiveJournalEngine();
                lje.PublishNewEntry(bDescr, Title, Body);
                LoginOK = true;
                break;

            default:
                break;
            }

            Result = 0;
        }
        catch (Exception ex)
        {
            Result = 1;
        }

        //if (LoginOK)
        if (true) // always save
        {
            MemberBlogSettings memberBlogSettings = MemberBlogSettings.GetMemberBlogSettingsByMemberID(member.MemberID);

            switch (BlogService)
            {
            case "blogger":
                memberBlogSettings.BloggerUserName   = Username;
                memberBlogSettings.BloggerPassword   = Password;
                memberBlogSettings.BloggerAutoSubmit = AutoSubmit;
                break;

            case "wordpress":
                memberBlogSettings.WordPressUserName   = Username;
                memberBlogSettings.WordPressPassword   = Password;
                memberBlogSettings.WordPressURL        = WPAddress;
                memberBlogSettings.WordPressAutoSubmit = AutoSubmit;
                break;

            case "livejournal":
                memberBlogSettings.LiveJournalUserName   = Username;
                memberBlogSettings.LiveJournalPassword   = Password;
                memberBlogSettings.LiveJournalAutoSubmit = AutoSubmit;
                break;

            default:
                break;
            }

            memberBlogSettings.Save();
        }

        return(Result);
    }