private static VivendiCollection GetRoot(HttpContext context, string userName, bool nested) => GetSessionVariable(context, "Vivendi-" + userName, c => { var connectionStrings = ((VivendiSource[])Enum.GetValues(typeof(VivendiSource))).ToDictionary(_ => _, v => ConfigurationManager.ConnectionStrings[v.ToString()].ConnectionString); VivendiCollection result; Vivendi vivendi; if (nested) { result = VivendiCollection.CreateStaticRoot(); vivendi = result.AddVivendi ( name: userName, userName: userName, connectionStrings: connectionStrings ); } else { result = vivendi = Vivendi.CreateRoot(userName, connectionStrings); } vivendi.AddBereiche(); vivendi.AddKlienten().AddKlienten("(Alle Klienten)").ShowAll = true; vivendi.AddMitarbeiter().AddMitarbeiter("(Alle Mitarbeiter)").ShowAll = true; return(result); });
private void WriteCollection(HttpContext context, VivendiCollection collection) { // build the response HTML var response = new StringBuilder(); response.AppendLine(@"<!DOCTYPE html>"); response.Append(@"<html><head><meta charset=""utf-8""/><title>/"); response.Append(HttpUtility.HtmlEncode(string.Join("/", collection.SelfAndAncestors.Select(c => c.DisplayName).Reverse().Skip(1)))); response.Append(@"</title></head><body>"); var parent = collection.Parent; if (parent != null) { response .Append(@"<a href=""") .Append(context.GetRelativeHref(parent)) .Append(@""">[..]</a><br/>"); } // write each readable resource ordered by name foreach (var res in collection.Children.Where(r => (r.Attributes & FileAttributes.Hidden) == 0).OrderBy(r => r.DisplayName, StringComparer.InvariantCultureIgnoreCase)) { response .Append(@"<a href=""") .Append(context.GetRelativeHref(res)) .Append(@""" title=""Creation Date: ") .Append(res.CreationDate) .Append(@" Last Modified: ") .Append(res.LastModified) .Append(@""">") .Append(HttpUtility.HtmlEncode(res.DisplayName)) .Append(@"</a><br/>"); } // final tags and write response.Append(@"</body></html>"); context.Response.Write(response); }
private static VivendiResource?TryGetResourceInternal(HttpContext context, Uri uri, out VivendiCollection parentCollection, out string name, out bool isCollection) { // ensure authentication if (!context.User.Identity.IsAuthenticated) { throw new UnauthorizedAccessException(); } var userName = context.User.Identity.Name; if (string.IsNullOrEmpty(userName)) { throw new UnauthorizedAccessException(); } // ensure the URI refers to the same store var localPath = uri.LocalPath; var prefix = context.Request.ApplicationPath; if (!localPath.StartsWith(prefix, Vivendi.PathComparison) || (localPath = localPath.Substring(prefix.Length)).Length > 0 && localPath[0] != '/') { throw WebDAVException.RequestDifferentStore(uri); } // check for empty segments before splitting if (localPath.Contains("//")) { throw WebDAVException.RequestInvalidPath(uri); } var segments = localPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); // super users specify the real user in the first segment if (ConfigurationManager.AppSettings.GetValues("SuperUser")?.Any(su => string.Equals(userName, su, StringComparison.OrdinalIgnoreCase)) ?? false) { if (segments.Length == 0) { // the Windows Redirector does not like it if there is no root parentCollection = VivendiCollection.CreateStaticRoot(); } else { parentCollection = GetRoot(context, segments[0], true); } } else { // strip away the domain part if there is one var domainSep = userName.IndexOf('\\'); parentCollection = GetRoot(context, domainSep > -1 ? userName.Substring(domainSep + 1) : userName, false); } // traverse all parts starting at the root name = string.Empty; isCollection = localPath.Length > 0 && localPath[localPath.Length - 1] == '/'; var result = parentCollection as VivendiResource; foreach (var segment in segments) { // ensure that the parent is a collection and get the next child parentCollection = result as VivendiCollection ?? throw WebDAVException.ResourceParentNotFound(uri); name = segment; result = parentCollection.GetChild(name); } // ensure that no document URI ends in a trailing slash if (isCollection && result != null && !(result is VivendiCollection)) { throw WebDAVException.ResourceParentNotFound(uri); } return(result); }
private static VivendiDocument?TryGetDocumentInternal(HttpContext context, Uri uri, out VivendiCollection parentCollection, out string name) { // try to get the resource var res = TryGetResourceInternal(context, uri, out parentCollection, out name, out var isCollection); if (res == null) { // if the URI ends with a slash also treat it as a collection if (isCollection) { throw WebDAVException.ResourceCollectionsImmutable(); } return(null); } // ensure the value is a document return(res as VivendiDocument ?? throw WebDAVException.ResourceCollectionsImmutable()); }
public static VivendiDocument?TryGetDocument(this HttpContext context, Uri uri, out VivendiCollection parentCollection, out string name) => TryGetDocumentInternal(context, context.VerifyUri(uri), out parentCollection, out name);
public static VivendiDocument?TryGetDocument(this HttpContext context, out VivendiCollection parentCollection, out string name) => TryGetDocumentInternal(context, context.Request.Url, out parentCollection, out name);
protected override void PerformOperation(VivendiDocument sourceDoc, Uri destUri, VivendiCollection destCollection, string destName) => sourceDoc.MoveTo(destCollection, destName);
protected override void PerformOperation(VivendiDocument sourceDoc, Uri destUri, VivendiCollection destCollection, string destName) => destCollection.NewDocument(destName, sourceDoc.CreationDate, sourceDoc.LastModified, sourceDoc.Data);
protected abstract void PerformOperation(VivendiDocument sourceDoc, Uri destUri, VivendiCollection destCollection, string destName);