Exemplo n.º 1
0
 public CalDavRequestData BuildRequestData(HttpRequest httpRequest, IPrincipalItem currentPrincipal)
 {
     return(new CalDavRequestData
     {
         Depth = SolveDepth(httpRequest),
         XmlBody = GetRequestXml(httpRequest),
         CurrentPrincipal = currentPrincipal,
         CurrentCalendar = GetRequestCalendar(httpRequest)
     });
 }
 public PrincipalFolder(IPrincipalItem currentPrincipal, UserFolderAccess userAccess, FolderInfo folderInfo, CalDavServer server) : base(userAccess, folderInfo, server)
 {
     Principal = currentPrincipal;
 }
Exemplo n.º 3
0
        public AbstractFolder GetFileSystemInfo(string path, int depth, IPrincipalItem principalItem)
        {
            // the request is for a file
            string file          = null;
            string fileextension = ".ics";

            //00000000-0000-0000-0000-000000000000
            Guid fileGuid = new Guid();

            if (path.EndsWith(fileextension))
            {
                var temp = path.Split("/");

                file = temp.Last();
                path = path.Remove(path.Length - file.Length, file.Length);

                if (!Guid.TryParse(file.Remove(file.Length - fileextension.Length, fileextension.Length), out fileGuid))
                {
                    return(null);
                }
            }

            if (!path.Contains("well-known") && path.Last() != '/')
            {
                path += "/";
            }

            var userFolderAccess = principalItem.TestAccess(path, Server);

            // check that a folder was found and that the user has read access
            if (userFolderAccess == null || userFolderAccess.Folder == null || !userFolderAccess.Read)
            {
                return(null);
            }

            var fileinfo = userFolderAccess.Folder;

            // if the url has a file but is not a path to a calendar then the url is not valid
            if (fileinfo.FolderType != (int)FileSystem.FolderType.CalendarFolder && file != null)
            {
                return(null);
            }


            // we are now at a safe place to physically ensure the folder exists
            var dir = System.IO.Path.Combine(Directory.GetCurrentDirectory(), $"{CalDavSettings.SERVERFILEPATH}\\{CleanPath(path)}");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (fileinfo.FolderType == (int)FileSystem.FolderType.WellKnown)
            {
                return(new WellKnownFolder(userFolderAccess, fileinfo, Server));
            }

            AbstractFolder result = null;

            switch (fileinfo.FolderType)
            {
            case (int)FileSystem.FolderType.CalendarFolder:
                result = new CalendarRepository(mDb, userFolderAccess, fileinfo, Server, fileGuid);
                break;

            case (int)FileSystem.FolderType.CalendarHomeset:
                result = new CalendarHomeSet(userFolderAccess, fileinfo, Server);
                break;

            case (int)FileSystem.FolderType.ContextPath:
                result = new ContextPath(principalItem, userFolderAccess, fileinfo, Server);
                break;

            case (int)FileSystem.FolderType.AclFolder:
                result = new PrincipalFolder(principalItem, userFolderAccess, fileinfo, Server);
                break;

            default:
                return(null);
            }

            // Add Children
            if (depth > 0)
            {
                depth--;
                var childPaths = mDb.FolderInfo.Where(a => a.ParentFolderId.Equals(fileinfo.FolderId)).Select(a => a.Path).ToList();
                result.ChildFolders = new List <AbstractFolder>();
                foreach (var childpath in childPaths)
                {
                    var childFileInfo = GetFileSystemInfo(childpath, depth, principalItem);
                    if (childFileInfo != null)
                    {
                        result.ChildFolders.Add(childFileInfo);
                    }
                }
            }

            return(result);
        }