BloggerAPI.cs :  » Bloggers » dasBlog » Microsoft » ServiceModel » Samples » XmlRpc » Contracts » Blogger » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » dasBlog 
dasBlog » Microsoft » ServiceModel » Samples » XmlRpc » Contracts » Blogger » BloggerAPI.cs

//  Copyright (c) Microsoft Corporation.  All Rights Reserved.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.ServiceModel;
using Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger;
using Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog;
using Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType;

namespace Microsoft.ServiceModel.Samples.XmlRpc{
    [ServiceContract]
    public interface IBloggerAPI : IMovableType { };

    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class BloggerAPI : IBloggerAPI
  {
        static List<Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post> mwPosts = new List<Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post>();

      public BloggerAPI()
    {
         }

         bool IBlogger.blogger_deletePost(string appKey, string postid, string username, string password, bool publish)
    {
            int postNum;

            if (int.TryParse(postid, out postNum) &&
                 postNum > 0 && postNum <= mwPosts.Count-1)
            {
                mwPosts.RemoveAt(postNum-1);
            }
            return true;
    }

    bool IBlogger.blogger_editPost(string appKey, string postid, string username, string password, string content, bool publish)
    {
            int postNum;

            if (int.TryParse(postid, out postNum) &&
                 postNum > 0 && postNum <= mwPosts.Count )
            {
                mwPosts[postNum-1].description = content;
            }
            return true;
    }

    Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Category[]  IBlogger.blogger_getCategories(string blogid, string username, string password)
    {
            ArrayList arrayList = new ArrayList();
            Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Category bcat = new Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Category();
            bcat.categoryid = "Front Page";
            bcat.description = "Front Page";
            bcat.htmlUrl = "http://localhost";
            bcat.rssUrl = "http://localhost";
            bcat.title = bcat.description;
            arrayList.Add( bcat );
            return arrayList.ToArray(typeof(Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Category)) as Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Category[];
    }

    Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Post IBlogger.blogger_getPost(string appKey, string postid, string username, string password)
    {
           int postNum;

           if (int.TryParse(postid, out postNum) &&
                postNum > 0 && postNum <= mwPosts.Count )
           {
               Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Post post = new Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Post();
               post.content = mwPosts[postNum-1].description;
               post.dateCreated = mwPosts[postNum-1].dateCreated;
               post.postid = mwPosts[postNum-1].postid;
               return post;
           }
           return null;
    }

    Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Post[] IBlogger.blogger_getRecentPosts(string appKey, 
                               string blogid, 
                               string username, 
                               string password, 
                               int numberOfPosts)
    {
            List<Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Post> posts = new List<Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Post>();
            foreach (Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post mwPost in mwPosts)
            {
                Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Post post = new Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.Post();
                post.content = mwPost.description;
                post.dateCreated = mwPost.dateCreated;
                post.postid = mwPost.postid;
                posts.Add(post);
            }
            return posts.ToArray();
    }

    string  IBlogger.blogger_getTemplate(string appKey, string blogid, string username, string password, string templateType)
    {
            return "";
    }

    Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.UserInfo  IBlogger.blogger_getUserInfo(string appKey, string username, string password)
    {
            Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.UserInfo userInfo = new Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.UserInfo();
            userInfo.firstname = "";
            userInfo.lastname  = "";
            return userInfo;
    }

    Microsoft.ServiceModel.Samples.XmlRpc.Contracts.Blogger.BlogInfo[]  IBlogger.blogger_getUsersBlogs(string appKey, string username, string password)
    {
            BlogInfo[] blogs = new BlogInfo[1];
      BlogInfo blog = new BlogInfo();
      blog.blogid="0";
      blog.blogName="title";
      blog.url="http://localhost";
            blogs[0]=blog;
      return blogs;
    }

    string IBlogger.blogger_newPost(
      string appKey, 
      string blogid, 
      string username, 
      string password, 
      string content, 
      bool publish)
    {
            int newId = mwPosts.Count + 1;
            Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post post = new Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post();
            post.dateCreated = DateTime.Now;
            post.description = content;
            post.postid = newId.ToString();
            mwPosts.Add(post);
            return post.postid;
    }

    bool IBlogger.blogger_setTemplate(string appKey, string blogid, string username, string password, string template, string templateType)
    {
            return false;
    }

        
        // MoveableType
        Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.Category[] IMovableType.mt_getCategoryList(string blogid, string username, string password)
        {
            return null;
        }

        Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.Category[] IMovableType.mt_getPostCategories(string postid, string username, string password)
        {
            return null;
         }

        Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.PostTitle[] IMovableType.mt_getRecentPostTitles(string blogid, string username, string password, int numberOfPosts)
        {
            List<Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.PostTitle> postTitles = new List<Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.PostTitle>();
            foreach (Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post mwPost in mwPosts)
            {
                Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.PostTitle post = new Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.PostTitle();
                post.dateCreated = DateTime.Now;
                post.title = mwPost.title;
                post.dateCreated = mwPost.dateCreated;
                post.postid = mwPost.postid;
                postTitles.Add(post);
            }
            return postTitles.ToArray();
        }

        Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.TrackbackPing[] IMovableType.mt_getTrackbackPings(string postid)
        {
            ArrayList arrayList = new ArrayList();
            return arrayList.ToArray(typeof(Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.TrackbackPing)) as Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.TrackbackPing[];
        }

        bool IMovableType.mt_publishPost(string postid, string username, string password)
        {
            return true;
        }

        bool IMovableType.mt_setPostCategories(string postid, string username, string password, Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.Category[] categories)
        {
            return false;
        }

        string[] IMovableType.mt_supportedMethods()
        {
            ArrayList arrayList = new ArrayList();
            foreach( MethodInfo method in GetType().GetMethods() )
            {
                if ( method.IsDefined(typeof(OperationContractAttribute),true) )
                {
                    OperationContractAttribute attr = method.GetCustomAttributes(typeof(OperationContractAttribute), true)[0] as OperationContractAttribute;
                    arrayList.Add(attr.Action);
                }
            }
            return arrayList.ToArray(typeof(string)) as string[];
        }

        Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.TextFilter[] IMovableType.mt_supportedTextFilters()
        {
            TextFilter tf = new TextFilter();
            tf.key="default";
            tf.@value ="default";
            return new Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MovableType.TextFilter[]{tf};
        }

        // Metaweblog
        bool IMetaWeblog.metaweblog_editPost(string postid, string username, string password, Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post post, bool publish)
        {
            int postNum;

            if (int.TryParse(postid, out postNum) &&
                 postNum > 0 && postNum <= mwPosts.Count )
            {
                post.postid = postid;
                mwPosts[postNum-1] = post;
            }
            return true;
        }

        Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.CategoryInfo[] IMetaWeblog.metaweblog_getCategories(string blogid, string username, string password)
        {
            ArrayList arrayList = new ArrayList();
            
            Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.CategoryInfo bcat = new Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.CategoryInfo();
                bcat.categoryid = "Front Page";
                bcat.description = "Front Page";
                bcat.htmlUrl = "http://localhost";
                bcat.rssUrl = "http://localhost";
                bcat.title = bcat.description;
                arrayList.Add( bcat );
            return arrayList.ToArray(typeof(Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.CategoryInfo)) as Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.CategoryInfo[];
        }

        Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post IMetaWeblog.metaweblog_getPost(string postid, string username, string password)
        {
            int postNum;

            if (int.TryParse(postid, out postNum) &&
                 postNum > 0 && postNum <= mwPosts.Count )
            {
                return mwPosts[postNum-1];
            }
            return null;
        }

        Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post[] IMetaWeblog.metaweblog_getRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            return mwPosts.ToArray();
        }

        string IMetaWeblog.metaweblog_newPost(string blogid, string username, string password, Microsoft.ServiceModel.Samples.XmlRpc.Contracts.MetaWeblog.Post post, bool publish)
        {
            int newId = mwPosts.Count + 1;
            post.postid = newId.ToString();
            post.dateCreated = DateTime.Now;
            mwPosts.Add(post);
            return post.postid;
        }
        /// <summary>
    /// newMediaObject implementation : Xas
    /// </summary>
    /// <param name="blogid"></param>
    /// <param name="username"></param>
    /// <param name="password"></param>
    /// <param name="enc"></param>
    /// <returns></returns>
    UrlInfo IMetaWeblog.metaweblog_newMediaObject(object blogid, string username, string password, MediaType enc)
    {
      UrlInfo urlInfo = new UrlInfo();
      urlInfo.url = "";
      return urlInfo;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.