Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3e4609d136
Fetching contributors…

Cannot retrieve contributors at this time

file 267 lines (226 sloc) 9.993 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
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.");
            }
        }
}
}
Something went wrong with that request. Please try again.