DavPropFind.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » Rfc » WebDAV » 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 » Content Management Systems CMS » Kooboo 
Kooboo » Everest » CmsServices » Rfc » WebDAV » DavPropFind.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using Everest.CmsServices.Models;
using Everest.CmsServices.Services;
using Everest.Library.ExtensionMethod;

using Sphorium.WebDAV.Server.Framework.BaseClasses;
using Sphorium.WebDAV.Server.Framework.Resources;
using Everest.Library;
using System.Collections.Specialized;
using Everest.CmsServices.MvcHelper;
namespace Everest.CmsServices.Rfc.WebDAV{
    public class DavPropFind : DavPropFindBase
    {
        public DavPropFind()
        {
            this.ProcessDavRequest += new DavProcessEventHandler(DavPropFind_ProcessDavRequest);
        }

        void DavPropFind_ProcessDavRequest(object sender, EventArgs e)
        {
            WebDavUrlData urlData = new WebDavUrlData(WebDavHelper.GetRawHostUrl(HttpApplication.Request), RelativeRequestPath);

            if (HttpApplication.Request.Headers["Depth"] == "0")
            {
                switch (urlData.UrlType)
                {
                    case WebDavUrlType.Root:
                        OutputRoot(urlData);
                        break;
                    case WebDavUrlType.Application:
                        OutputApplication(urlData);
                        break;
                    case WebDavUrlType.Folder:
                        OutputFolder(urlData);
                        break;
                    case WebDavUrlType.Content:
                        ContentRequest(urlData);
                        break;
                    default:

                        break;
                }

                //HttpApplication.Response.Write(@"<?xml version=""1.0"" encoding=""utf-8""?><D:multistatus xmlns:D=""DAV:""><D:response><D:href>http://www.smallbusiness.com:10665/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype>application/octet-stream</D:getcontenttype><D:getlastmodified>2010-03-18T17:47:55Z</D:getlastmodified><D:lockdiscovery/><D:ishidden>0</D:ishidden><D:getetag/><D:displayname>/</D:displayname><D:getcontentlanguage/><D:getcontentlength>0</D:getcontentlength><D:iscollection>1</D:iscollection><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response></D:multistatus>");
            }
            else
            {
                switch (urlData.UrlType)
                {
                    case WebDavUrlType.Root:
                        OutputRoot(urlData);
                        RootRequest(urlData);
                        break;
                    case WebDavUrlType.Application:
                        OutputApplication(urlData);
                        ApplicationRequest(urlData);
                        break;
                    case WebDavUrlType.Folder:
                        OutputFolder(urlData);
                        FolderReqeust(urlData);
                        break;
                    case WebDavUrlType.Content:
                        ContentRequest(urlData);
                        break;
                    default:
                        break;
                }

            }
            //var _dirInfo = new DirectoryInfo(@"E:\Opensources\WebDav\Sphorium.WebDAV.Server.Framework_111609_001247_ver3.1-src\Sphorium.WebDAV.Server.Framework\Framework");
            //foreach (DirectoryInfo _subDir in _dirInfo.GetDirectories())
            //{
            //    //TODO: Only populate the requested properties
            //    DavFolder _davFolder = new DavFolder(_subDir.Name, _subDir.Name);
            //    _davFolder.CreationDate = _subDir.CreationTime;
            //    _davFolder.LastModified = _subDir.LastWriteTime.ToUniversalTime();
            //    _davFolder.ContentLength = _subDir.GetDirectories().Length + _subDir.GetFiles().Length;

            //    base.CollectionResources.Add(_davFolder);
            //}
        }
        private void OutputRoot(WebDavUrlData urlData)
        {
            var url = WebDavHelper.GetCurrentUrl(HttpApplication.Request);
            DavFolder davFolder = new DavFolder("/", url);
            
            davFolder.LastModified = DateTime.Now;
            davFolder.CreationDate = DateTime.Now;
            base.CollectionResources.Add(davFolder);
        }
        private void OutputApplication(WebDavUrlData urlData)
        {
            var url = WebDavHelper.GetCurrentUrl(HttpApplication.Request);
            var app = CachedData.GetApplication(urlData.Application);
            if (app != null)
            {
                DavFolder davFolder = new DavFolder(app.ApplicationName, url);
                davFolder.LastModified = DateTime.Now;
                davFolder.CreationDate = DateTime.Now;
                base.CollectionResources.Add(davFolder);
            }
        }
        private void OutputFolder(WebDavUrlData urlData)
        {
            var url = WebDavHelper.GetCurrentUrl(HttpApplication.Request);
            var folder = CachedData.GetFolder(urlData.Application, urlData.FolderName);
            if (folder != null)
            {
                DavFolder davFolder = new DavFolder(folder.FolderName, url);
                davFolder.LastModified = DateTime.Now;
                davFolder.CreationDate = DateTime.Now;
                base.CollectionResources.Add(davFolder);
            }
        }
        #region RootRequest
        private void RootRequest(WebDavUrlData urlData)
        {
            string host = HttpApplication.Request.GetRawHostWithoutPort();
            var app = CachedData.GetApplicationByHostName(host);
            if (app != null)
            {
                OutputApplications(urlData, new aspnet_Applications[] { app });
            }
            else
            {
                IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
                OutputApplications(urlData, dataContext.aspnet_Applications);
            }
        }
        private void OutputApplications(WebDavUrlData urlData, IEnumerable<aspnet_Applications> applications)
        {
            PermissionService permissionService = UnityManager.Resolve<PermissionService>();

            foreach (var app in applications)
            {
                if (permissionService.CanAccessApplication(WebDavHelper.GetUserName(HttpApplication), app.ApplicationName))
                {
                    DavFolder appFolder = new DavFolder(app.ApplicationName, urlData.BuildNextUrl(app.ApplicationName));
                    if (app.CreateDate != null)
                    {
                        appFolder.CreationDate = app.CreateDate.Value;
                    }
                    else
                    {
                        appFolder.CreationDate = DateTime.Now;
                    }
                    appFolder.LastModified = DateTime.Now;
                    appFolder.ContentLength = 0;
                    base.CollectionResources.Add(appFolder);
                }
            }
        }
        #endregion

        #region ApplicationRequest
        private void ApplicationRequest(WebDavUrlData urlData)
        {
            IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();

            var folders = dataContext.QueryFolders(urlData.Application, FolderType.BinaryContent);

            OutputFolders(urlData, folders);

        }
        private void OutputFolders(WebDavUrlData urlData, IEnumerable<Cms_Folder> folders)
        {
            PermissionService permissionService = UnityManager.Resolve<PermissionService>();
            foreach (var folder in folders)
            {
                if (permissionService.IsAllowedEditContent(WebDavHelper.GetUserName(HttpApplication), folder.UUID, urlData.Application, ActionType.View))
                {
                    DavFolder davFolder = new DavFolder(folder.FolderName, urlData.BuildNextUrl(folder.FolderName.ToString()));
                    davFolder.CreationDate = DateTime.Now;
                    davFolder.LastModified = DateTime.Now;
                    davFolder.ContentLength = 0;
                    base.CollectionResources.Add(davFolder);
                }
            }
        }
        #endregion

        #region Folder Request
        private void FolderReqeust(WebDavUrlData urlData)
        {
            BinaryContentService binaryContentService = UnityManager.Resolve<BinaryContentService>();
            var folder = CachedData.GetFolder(urlData.Application, urlData.FolderName);
            int count;
            var contents = binaryContentService.QueryBinaryContents(folder.UUID, WebDavHelper.GetUserName(HttpApplication), "", null, null, "", out count, 1, int.MaxValue);
            OutputContents(urlData, contents);
        }
        private void OutputContents(WebDavUrlData urlData, IEnumerable<IDictionary<string, object>> contents)
        {
            foreach (var content in contents)
            {
                OutputContent(urlData, content);
            }
        }

        private void OutputContent(WebDavUrlData urlData, IDictionary<string, object> content)
        {
            var filePath = content["FilePath"].ToString();
            var extension = Path.GetExtension(filePath);
            DavFile file = new DavFile(content["Title"].ToString() + extension, urlData.BuildNextUrl(content["UserKey"].ToString() + extension));
            file.CreationDate = (DateTime)content["PostDate"];
            file.LastModified = (DateTime)content["ModifiedDate"];
            file.ContentLength = (int)content["FileSize"];
            base.FileResources.Add(file);
        }

        #endregion

        #region Content Request
        private void ContentRequest(WebDavUrlData urlData)
        {
            ContentService contentService = new ContentService(urlData.Application);

            var content = contentService.SetQueryType(Everest.CmsServices.Providers.QueryType.All).GetBinaryContentByUserKey(urlData.ContentKey, null);
            if (content == null)
            {
                this.AbortRequest(ServerResponseCode.NotFound);
            }
            else
            {
                OutputContent(urlData, content);
            }
        }
        #endregion

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.