EditServiceImplementation.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » Web » Services » 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 » newtelligence » DasBlog » Web » Services » EditServiceImplementation.cs
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Web;
using System.Net.Mail;
using System.Web.Services;
using System.Collections;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using newtelligence.DasBlog.Runtime;
using newtelligence.DasBlog.Web.Core;
using newtelligence.DasBlog.Web.Services.Rsd;
using System.Security;

namespace newtelligence.DasBlog.Web.Services{
  /// <summary>
  /// Summary description for DasBlogEditting.
  /// </summary>
  public class EditServiceImplementation : WebService
  {
    public EditServiceImplementation()
    {
      InitializeComponent();
    }

    #region Component Designer generated code

    //Required by the Web Services Designer
    private IContainer components = null;

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose(bool disposing)
    {
      if (disposing && components != null)
      {
        components.Dispose();
      }
      base.Dispose(disposing);
    }

    #endregion

    [WebMethod]
    public bool CanEdit(string username, string password)
    {
      if (!SiteConfig.GetSiteConfig().EnableEditService)
      {
        throw new ServiceDisabledException();
      }

      try
      {
        if (Context.Request.IsAuthenticated)
        {
                    return SiteSecurity.IsValidContributor();
        }

                Authenticate(username, password);
                return true; // no exception we're good

      }
      catch (Exception e)
      {
        ErrorTrace.Trace(TraceLevel.Error, e);
        return false;
      }
    }

    [WebMethod]
    [SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Wrapped,Use=SoapBindingUse.Literal)]
    public RsdRoot GetRsd()
    {
            // TODO: NLS - Make the default API configurable through SiteConfig
      SiteConfig siteConfig = SiteConfig.GetSiteConfig();
      RsdApiCollection apiCollection = new RsdApiCollection();

      RsdRoot rsd = new RsdRoot();
      RsdService dasBlogService = new RsdService();
      dasBlogService.HomePageLink = SiteUtilities.GetBaseUrl(siteConfig);

      RsdApi metaWeblog    = new RsdApi();
      metaWeblog.Name      = "MetaWeblog";
      metaWeblog.Preferred = ( siteConfig.PreferredBloggingAPI == metaWeblog.Name );
      metaWeblog.ApiLink   = SiteUtilities.GetBloggerUrl(siteConfig);
      metaWeblog.BlogID    = dasBlogService.HomePageLink;
      apiCollection.Add(metaWeblog);

      RsdApi blogger    = new RsdApi();
      blogger.Name      = "Blogger";
      blogger.Preferred = ( siteConfig.PreferredBloggingAPI == blogger.Name );
      blogger.ApiLink   = SiteUtilities.GetBloggerUrl(siteConfig);
      blogger.BlogID    = dasBlogService.HomePageLink;
      apiCollection.Add(blogger);

            RsdApi moveableType    = new RsdApi();
            moveableType.Name      = "Moveable Type";
            moveableType.Preferred = ( siteConfig.PreferredBloggingAPI == moveableType.Name );
            moveableType.ApiLink   = SiteUtilities.GetBloggerUrl( siteConfig );
            moveableType.BlogID    = dasBlogService.HomePageLink;
            apiCollection.Add( moveableType );

      dasBlogService.RsdApiCollection = apiCollection;
      rsd.Services.Add(dasBlogService);

      return rsd;
    }

    [WebMethod]
    public void DeleteEntry(string entryId, string username, string password)
    {
      SiteConfig siteConfig = SiteConfig.GetSiteConfig();
      if (!siteConfig.EnableEditService)
      {
        throw new ServiceDisabledException();
      }

            Authenticate(username, password);

            ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
            IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);

      //dataService.DeleteEntry(entryId, siteConfig.CrosspostSites);
      SiteUtilities.DeleteEntry(entryId, siteConfig, logService, dataService);
    }

        [WebMethod]
    public string UpdateEntry(Entry entry, string username, string password)
    {
      SiteConfig siteConfig = SiteConfig.GetSiteConfig();
      if (!siteConfig.EnableEditService)
      {
        throw new ServiceDisabledException();
      }

            Authenticate(username, password);

            ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
            IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);

      EntrySaveState val = SiteUtilities.UpdateEntry(entry, null, null, siteConfig, logService, dataService);

            string rtn = string.Empty;
            if (val.Equals(EntrySaveState.Updated))
                rtn = entry.EntryId;
            else
                rtn = val.ToString();

            return rtn;
    }

    [WebMethod]
    public string CreateEntry(Entry entry, string username, string password)
    {
      SiteConfig siteConfig = SiteConfig.GetSiteConfig();
      if (!siteConfig.EnableEditService)
      {
        throw new ServiceDisabledException();
      }
            
            Authenticate(username, password);

      // ensure that the entryId was filled in
      //
      if (entry.EntryId == null || entry.EntryId.Length == 0)
      {
        entry.EntryId = Guid.NewGuid().ToString();
      }

      // ensure the dates were filled in, otherwise use NOW
      if (entry.CreatedUtc == DateTime.MinValue)
      {
        entry.CreatedUtc = DateTime.UtcNow;
      }
      if (entry.ModifiedUtc == DateTime.MinValue)
      {
        entry.ModifiedUtc = DateTime.UtcNow;
      }

            ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
            IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);

      SiteUtilities.SaveEntry(entry, string.Empty, null, siteConfig, logService, dataService);

      return entry.EntryId;
    }
        /// <summary>
        /// 12 Oct 2006 / MOT :
        /// Get entry by date and title.  If there is more than one match, the most recent entry will be returned.
        /// </summary>
        /// <param name="entryDate">Date the entry was posted.</param>
        /// <param name="entryTitle">Title of the post.</param>
        /// <returns>DasBlog.Runtime.Entry</returns>
        [WebMethod (MessageName="GetEntryByDateAndTitle",Description="Get entry by date and title.  If there is more than one match, the most recent entry will be returned.")]
        public Entry GetEntry(DateTime entryDate, string entryTitle)
        {
            SiteConfig siteConfig = SiteConfig.GetSiteConfig();
            ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
            IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);

            //Only pass in the date portion of the entry date, do not pass in the time portion.
            DayEntry dayEntry = dataService.GetDayEntry(entryDate.Date);

            //this replacement of characters in the title was lifted directly from
            //  DasBlog.Web.Core::TitleMapperModule.HandleBeginRequest()
            entryTitle = entryTitle.Replace(".aspx", "");
            entryTitle = entryTitle.Replace("+", "");
            entryTitle = entryTitle.Replace(" ", "");
            entryTitle = entryTitle.Replace("%2b", "");
            entryTitle = entryTitle.Replace("%20", "");

            //now that we have a properly formatted title, use it to get a specific
            //  entry from the DayEntry object.  If there is more than one match to the
            //  title, the most recent entry will be matched.
            Entry entry = dayEntry.GetEntryByTitle(entryTitle);

            return entry;
        }
        /// <summary>
        /// 12 Oct 2006 / MOT :
        /// Get entry by unique guid string.  This will return, at most, one entry.
        /// </summary>
        /// <param name="entryId">guid string</param>
        /// <returns>DasBlog.Runtime.Entry</returns>
        [WebMethod(MessageName = "GetEntryByEntryID", Description="Get entry by guid string.  There will only ever be at most one match.")]
        public Entry GetEntry(string entryId)
        {
            SiteConfig siteConfig = SiteConfig.GetSiteConfig();
            ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
            IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);

            Entry entry = dataService.GetEntry(entryId);
            return entry;
        }

        /// <summary>
        /// Tries to login the user with the supplied username and password, 
        /// throws when the user cannot be authenticated or is not a valid contributor.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <exception cref="System.Security.SecurityException">Thrown when the user can not be authenticated.</exception>
        private static void Authenticate(string username, string password)
        {
            // parameter validationis handled in the SiteSecurity.Login method.
            
            UserToken user = SiteSecurity.Login(username, password);
            if (user == null || !SiteSecurity.IsValidContributor())
            {
                throw new SecurityException("Invalid username or password.");
            }
        }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.