BlogDataServiceAzure.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » Runtime » Azure » 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 » Runtime » Azure » BlogDataServiceAzure.cs
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;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.