using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Samples.ServiceHosting.StorageClient;
namespace newtelligence.DasBlog.Runtime.Azure{
public class BlogDataServiceAzure : IBlogDataService
{
private string location;
private ILoggingDataService loggingDataService;
private StorageAccountInfo accountInfo;
public BlogDataServiceAzure(string location, ILoggingDataService loggingService)
{
this.location = location;
this.loggingDataService = loggingService;
this.accountInfo = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();
}
public Entry GetEntry(string entryId)
{
var ctx = new BlogEntryServiceContext(accountInfo);
var ent = (from e in ctx.Entries where e.RowKey == entryId select e).FirstOrDefault();
return ent == null ? null : ent.GetValue();
}
public Entry GetEntryForEdit(string entryId)
{
// the get entry method copies the
// entry
return GetEntry(entryId);
}
public EntryCollection GetEntries(bool fullContent)
{
// fullContent is ignored in this implementation
var ctx = new BlogEntryServiceContext(accountInfo);
var entries = (from e in ctx.Entries select e).ToList();
return new EntryCollection(entries.ConvertAll(x => x.GetValue()));
}
public EntryCollection GetEntriesForDay(DateTime start, TimeZone tz, string acceptLanguages, int maxDays, int maxEntries, string categoryName)
{
//todo: implement filter
return GetEntries(false);
}
public EntryCollection GetEntriesForMonth(DateTime month, TimeZone tz, string acceptLanguages)
{
return new EntryCollection();
}
public EntryCollection GetEntriesForCategory(string categoryName, string acceptLanguages)
{
return new EntryCollection();
}
public EntryCollection GetEntriesForUser(string user)
{
return new EntryCollection();
}
public DateTime[] GetDaysWithEntries(TimeZone tz)
{
return new DateTime[0];
}
public DayEntry GetDayEntry(DateTime dateUtc)
{
DayEntry entry = new DayEntry();
entry.DateUtc = dateUtc;
var startDate = dateUtc.Date;
var endDate = dateUtc.Date.AddDays(1).AddSeconds(-1);
var ctx = new BlogEntryServiceContext(accountInfo);
var entries = (from e in ctx.Entries where startDate < e.Created && e.Created < endDate select e).ToList();
if (entries == null)
{
entry.Entries = new EntryCollection();
return entry;
}
entry.Entries = new EntryCollection(entries.ConvertAll(e => e.GetValue()));
return entry;
}
public DayExtra GetDayExtra(DateTime date)
{
return null;
}
public void DeleteEntry(string entryId, CrosspostSiteCollection crosspostSites)
{
if (string.IsNullOrEmpty(entryId)) { throw new ArgumentNullException("entryId"); }
var ctx = new BlogEntryServiceContext(accountInfo);
var ent = (from e in ctx.Entries where e.RowKey == entryId select e).FirstOrDefault();
if (ent != null)
{
ctx.DeleteEntry(ent);
}
// delete crosspost collection
}
public EntrySaveState SaveEntry(Entry entry, params object[] trackingInfos)
{
try
{
var ctx = new BlogEntryServiceContext(accountInfo);
BlogEntryEntity ent = (from e in ctx.Entries where e.RowKey == entry.EntryId select e).FirstOrDefault();
if (ent == null)
{
ent = new BlogEntryEntity(entry);
ctx.AddEntry(ent);
return EntrySaveState.Added;
}
ent.Update(entry);
ctx.UpdateEntry(ent);
return EntrySaveState.Updated;
}
catch (Exception exc)
{
loggingDataService.AddEvent(new EventDataItem(EventCodes.Error, exc.Message, entry.Link));
return EntrySaveState.Failed;
}
return EntrySaveState.Added;
}
public CategoryCacheEntryCollection GetCategories()
{
return new CategoryCacheEntryCollection();
}
public void RunActions(object[] actions)
{
//
}
public void AddTracking(Tracking tracking, params object[] actions)
{
//
}
public void DeleteTracking(string entryId, string trackingPermalink, TrackingType trackingType)
{
//
}
public TrackingCollection GetTrackingsFor(string entryId)
{
return new TrackingCollection();
}
public void AddComment(Comment comment, params object[] actions)
{
//
}
public Comment GetCommentById(string entryId, string commentId)
{
return null;
}
public void ApproveComment(string entryId, string commentId)
{
//
}
public void DeleteComment(string entryId, string commentId)
{
//
}
public CommentCollection GetCommentsFor(string entryId)
{
return new CommentCollection();
}
public CommentCollection GetPublicCommentsFor(string entryId)
{
return new CommentCollection();
}
public CommentCollection GetCommentsFor(string entryId, bool allComments)
{
return new CommentCollection();
}
public CommentCollection GetAllComments()
{
return new CommentCollection();
}
public DateTime GetLastEntryUpdate()
{
return DateTime.Now;
}
public DateTime GetLastCommentUpdate()
{
return DateTime.Now;
}
}
}
|