private void CalculateChildLines(IHierarchyItem item)
        {
            var ySelectedItemEnd = (item.Parents.Count * (int)HierarchyValues.ItemHeight) + (int)HierarchyValues.SelectedItemHeight + HierarchyValues.SelectedItemVerticalMargin;
            var xBase            = HierarchyValues.BaseMarginSize + (HierarchyValues.ChildIndentLevel - 1) * HierarchyValues.IndentSize;
            var xStartChild      = xBase + HierarchyValues.HorizontalLineXPos;
            var xEndChild        = xStartChild + HierarchyValues.HorizontalLineSize;
            var lastYValue       = 0;

            for (var i = 0; i < item.Children.Count; i++)
            {
                var yBase  = HierarchyValues.SelectedItemVerticalMargin + i * (int)HierarchyValues.ItemHeight;
                var yValue = ySelectedItemEnd + yBase + (int)HierarchyValues.ItemHeight / 2;
                var line   = new HierarchyLine
                {
                    X1 = xStartChild,
                    X2 = xEndChild,
                    Y1 = yValue,
                    Y2 = yValue,
                };
                _collection.Add(line);
                lastYValue = yValue;
            }

            if (item.Children.Any())
            {
                var verticalLine = new HierarchyLine
                {
                    X1 = xStartChild,
                    X2 = xStartChild,
                    Y1 = ySelectedItemEnd,
                    Y2 = lastYValue
                };
                _collection.Add(verticalLine);
            }
        }
예제 #2
0
        public override void ExecuteResult(ControllerContext context)
        {
            string path = context.RequestContext.HttpContext.Request.Path;
            IEnumerable <IHierarchyItem> items = _engine.GetResources(new List <string>()
            {
                path
            }, null, Headers.Depth.Zero);

            if (items.Count() > 1)
            {
                throw new Exception("too many results - should be 0 or 1");
            }

            IHierarchyItem   item     = items.First();
            HttpResponseBase response = context.RequestContext.HttpContext.Response;

            if (item != null && item is IFile)
            {
                IFile file = item as IFile;

                if (file.Properties.ContainsKey(PropertyName.CONTENTTYPE))
                {
                    response.ContentType = file.Properties[PropertyName.CONTENTTYPE].Value.ToString();
                }
                response.AddHeader("Content-Disposition", file.Name);
                response.BufferOutput = false;

                _engine.WriteFileToStream(file, response.OutputStream);
            }
            // else {}  // we should provide a handler to output the contents - or offer up a default one

            response.End();
        }
예제 #3
0
        /// <summary>
        /// Reads version history from database.
        /// </summary>
        /// <param name="path">Version history path.</param>
        /// <returns>Instance of <see cref="VersionHistory"/>.</returns>
        private VersionHistory readVersionHistory(string path)
        {
            int ind = path.IndexOf('&', path.IndexOf('?'));

            if (ind > 0)
            {
                path = path.Remove(ind);
            }
            string         itemPath = path.Remove(path.IndexOf('?'));
            IHierarchyItem item     = GetHierarchyItem(itemPath);

            if (item != null)
            {
                Guid newItemId = (item as DavFile).ItemId;

                string command =
                    @"SELECT ItemId, VersionId, VersionNumber, Name, CreatedOn, SerialNumber
                      FROM DMS_DocumentVersions
                      WHERE ItemId = @ItemId";

                IList <IVersion> versions = ExecuteVersion(
                    itemPath,
                    command,
                    "@ItemId", newItemId);

                if (versions.Count > 0)
                {
                    return(new VersionHistory(this, newItemId, path));
                }
            }

            return(null);
        }
예제 #4
0
        public static bool Move(IHierarchyItem item, IFolder target, string newName,
                                bool overwrite, LockCollection locks)
        {
            string sourcePath                 = item.Href.AbsolutePath;
            bool   isSourceFolder             = item is IFolder;
            List <LockUriTokenPair> lockPairs = GetLockPairs(item, locks);

            try
            {
                item.MoveTo(target, newName, overwrite,
                            (lockPairs != null) ? lockPairs.ToArray() : null);
                ChangeLocks(sourcePath, isSourceFolder, target, newName, locks);
                return(true);
            }
            catch (WebDavException ex)
            {
                WebDavHttpException exept = ex as WebDavHttpException;
                if (exept == null || exept.Multistatus.Responses.Length == 0)
                {
                    Informator.ShowError(item.DisplayName + ": " + ex.Message);
                }
                else
                {
                    return(false);
                }
                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #5
0
 /// <summary>
 /// For internal use only.
 /// </summary>
 /// <param name="comment"></param>
 public void SetHierarchyItem(IHierarchyItem item)
 {
     this.SetComment(item.Comment);
     this.SetCreationDate(item.CreationDate);
     this.SetCreatorDisplayName(item.CreatorDisplayName);
     this.SetHref(item.Href);
     this.SetLastModified(item.LastModified);
     this.SetProperties(item.Properties);
 }
예제 #6
0
        public void AddChild(IHierarchyItem hierarchyItem)
        {
            if (RootObjects == null)
            {
                RootObjects = new List <IHierarchyItem>();
            }

            RootObjects.Add(hierarchyItem);
        }
예제 #7
0
            public WebDavResource(ICredentials credentials, IHierarchyItem item)
            {
                SendChunked = false;
                AllowWriteStreamBuffering = false;

                IsRootItem = item.IsRootItem;
                SetCredentials(credentials);
                SetHierarchyItem(item);
            }
예제 #8
0
            public WebDavResource(ICredentials credentials, IHierarchyItem item)
            {
                SendChunked = false;
                AllowWriteStreamBuffering = false;

                IsRootItem = item.IsRootItem;
                SetCredentials(credentials);
                SetHierarchyItem(item);
            }
예제 #9
0
파일: IFolder.cs 프로젝트: rajeshwarn/Creek
        /// <summary>
        /// Gets the specified resource from server.
        /// </summary>
        /// <param name="name">Name of the resource.</param>
        /// <returns>Resource corresponding to requested name.</returns>
        public IResource GetResource(string name)
        {
            IHierarchyItem item =
                this._children.Where(i => i.ItemType == ItemType.Resource && i.DisplayName == name).Single();
            WebDavResource resource = new WebDavResource();

            resource.SetCredentials(this._credentials);
            resource.SetHierarchyItem(item);
            return(resource);
        }
예제 #10
0
            /// <summary>
            ///     Gets the specified resource from server.
            /// </summary>
            /// <param name="name">Name of the resource.</param>
            /// <returns>Resource corresponding to requested name.</returns>
            public IResource GetResource(string name)
            {
                IHierarchyItem item =
                    _children.Single(i => i.DisplayName.ToLowerInvariant().Trim('/') == name.ToLowerInvariant().Trim('/'));
                var resource = new WebDavResource();

                resource.SetCredentials(_credentials);
                resource.SetHierarchyItem(item);
                return(resource);
            }
예제 #11
0
 public static object Lock(IHierarchyItem item, LockScope scope, string owner)
 {
     try
     {
         return(item.Lock(scope, false, owner, TimeSpan.MaxValue));
     }
     catch (Exception e)
     {
         return(e.InnerException ?? e);
     }
 }
예제 #12
0
 public static void UpdateProperties(IHierarchyItem item, Property[] toAddOrUpdate, PropertyName[] toDelete, string lockToken)
 {
     try
     {
         item.UpdateProperties(toAddOrUpdate, toDelete, lockToken);
     }
     catch (Exception e)
     {
         Informator.ShowError(e.ToString());
     }
 }
예제 #13
0
 public static object Delete(IHierarchyItem item, LockUriTokenPair[] lockUriTokenPairs)
 {
     try
     {
         item.Delete(lockUriTokenPairs);
         return(null);
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }
예제 #14
0
 public static object Unlock(IHierarchyItem item, string lockToken)
 {
     try
     {
         item.Unlock(lockToken);
         return(null);
     }
     catch (Exception e)
     {
         return(e.InnerException ?? e);
     }
 }
예제 #15
0
 public static object Delete(IHierarchyItem item, string lockToken)
 {
     try
     {
         item.Delete(lockToken);
         return(null);
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }
예제 #16
0
        /// <summary>
        /// Copies this folder to another folder with option to rename it.
        /// </summary>
        /// <param name="destFolder">Folder to copy this folder to.</param>
        /// <param name="destName">New name of this folder.</param>
        /// <param name="deep">Whether children shall be copied.</param>
        /// <param name="multistatus">Container for errors. We put here errors which occur with
        /// individual items being copied.</param>
        public override void CopyTo(IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus)
        {
            DavFolder destDavFolder = destFolder as DavFolder;

            if (destFolder == null)
            {
                throw new DavException("Destination folder doesn't exist", DavStatus.CONFLICT);
            }
            if (!destDavFolder.ClientHasToken())
            {
                throw new LockedException("Doesn't have token for destination folder.");
            }

            if (isRecursive(destDavFolder))
            {
                throw new DavException("Cannot copy folder to its subtree", DavStatus.FORBIDDEN);
            }

            IHierarchyItem destItem = destDavFolder.FindChild(destName);

            if (destItem != null)
            {
                try
                {
                    destItem.Delete(multistatus);
                }
                catch (DavException ex)
                {
                    multistatus.AddInnerException(destItem.Path, ex);
                    return;
                }
            }

            DavFolder newDestFolder = CopyThisItem(destDavFolder, null, destName);

            // copy children
            if (deep)
            {
                foreach (IHierarchyItem child in GetChildren(new PropertyName[0]))
                {
                    var dbchild = child as DavHierarchyItem;
                    try
                    {
                        dbchild.CopyTo(newDestFolder, child.Name, deep, multistatus);
                    }
                    catch (DavException ex)
                    {
                        multistatus.AddInnerException(dbchild.Path, ex);
                    }
                }
            }
        }
예제 #17
0
        ///<inheritdoc/>
        public List <T> FindParents(IHierarchyItem <T, int, int?> element)
        {
            List <T> Parents = new List <T>();
            IHierarchyItem <T, int, int?> CurrentNode = element;

            while (CurrentNode.Parent != null)
            {
                Parents.Add(CurrentNode.Parent);
                CurrentNode = CurrentNode.Parent;
            }
            Parents.Reverse(); //So that the parent items in the list go in order - the first is the top level, the second is nested in it, and so on
            return(Parents);
        }
예제 #18
0
 public static bool Copy(IHierarchyItem item, IFolder target, bool overwrite)
 {
     try
     {
         item.CopyTo(target, item.DisplayName, true, overwrite);
         return(true);
     }
     catch (Exception ex)
     {
         Informator.ShowError(item.DisplayName + ": " + ex.Message);
         return(false);
     }
 }
        public ObservableCollection <HierarchyLine> CalculatePositions(IHierarchyItem item)
        {
            _collection = new ObservableCollection <HierarchyLine>();

            if (item == null)
            {
                return(_collection);
            }

            CalculateParentLines(item);
            CalculateChildLines(item);

            return(_collection);
        }
예제 #20
0
        ///<inheritdoc/>
        public List <T> FindChilds(IHierarchyItem <T, int, int?> host)
        {
            List <T> result = new List <T>();

            if (host.Childs != null)
            {
                foreach (T item in host.Childs) //Iterate over all descendants of the current element (for which Id == hostId)
                {
                    result.AddRange(FindChilds(item));
                    result.Add(item);
                }
            }

            return(result);
        }
예제 #21
0
        /// <summary>
        /// Handles GET and HEAD request.
        /// </summary>
        /// <param name="context">Instace of <see cref="DavContextBaseAsync"/>.</param>
        /// <param name="item">Instance of <see cref="IHierarchyItemAsync"/> which was returned by
        /// <see cref="DavContextBaseAsync.GetHierarchyItemAsync"/> for this request.</param>
        public void ProcessRequest(DavContextBase context, IHierarchyItem item)
        {
            if (item is IItemCollection)
            {
                // In case of GET requests to WebDAV folders we serve a web page to display
                // any information about this server and how to use it.

                // Remember to call EnsureBeforeResponseWasCalled here if your context implementation
                // makes some useful things in BeforeResponseAsync.
                context.EnsureBeforeResponseWasCalled();
                IHttpAsyncHandler page = (IHttpAsyncHandler)System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(
                    "~/MyCustomHandlerPage.aspx", typeof(MyCustomHandlerPage));
                page.ProcessRequest(HttpContext.Current);
            }
            else
            {
                OriginalHandler.ProcessRequest(context, item);
            }
        }
        private void CalculateParentLines(IHierarchyItem item)
        {
            var xStart = HierarchyValues.BaseMarginSize + HierarchyValues.HorizontalLineXPos;
            var xEnd   = HierarchyValues.BaseMarginSize + HierarchyValues.HorizontalLineXPos + HierarchyValues.HorizontalLineSize;

            for (var i = 0; i < item.Parents.Count; i++)
            {
                var yBase  = i * (int)HierarchyValues.ItemHeight;
                var yValue = yBase + (int)HierarchyValues.ItemHeight / 2;
                var line   = new HierarchyLine
                {
                    X1 = xStart,
                    X2 = xEnd,
                    Y1 = yValue,
                    Y2 = yValue,
                };
                _collection.Add(line);
            }

            if (item.Parents.Any())
            {
                var yParentEnd   = item.Parents.Count * (int)HierarchyValues.ItemHeight;
                var yValue       = yParentEnd + HierarchyValues.SelectedItemVerticalMargin + (int)HierarchyValues.SelectedItemHeight / 2;
                var verticalLine = new HierarchyLine
                {
                    X1 = xEnd,
                    X2 = xEnd,
                    Y1 = (int)HierarchyValues.ItemHeight / 2,
                    Y2 = yValue
                };

                var horizontalLine = new HierarchyLine
                {
                    X1 = xEnd,
                    X2 = HierarchyValues.BaseMarginSize + HierarchyValues.SelectedIndentLevel * HierarchyValues.IndentSize,
                    Y1 = yValue,
                    Y2 = yValue
                };

                _collection.Add(verticalLine);
                _collection.Add(horizontalLine);
            }
        }
예제 #23
0
        protected static void FindLocksDown(IHierarchyItem root, bool skipShared)
        {
            IFolder folder = root as IFolder;

            if (folder != null)
            {
                foreach (IHierarchyItem child in folder.GetChildren(new PropertyName[0]))
                {
                    DavHierarchyItem dbchild = child as DavHierarchyItem;
                    if (dbchild.ItemHasLock(skipShared))
                    {
                        MultistatusException mex = new MultistatusException();
                        mex.AddInnerException(dbchild.Path, new LockedException());
                        throw mex;
                    }

                    FindLocksDown(child, skipShared);
                }
            }
        }
예제 #24
0
        public void DataBindItem(DotvvmControl parent, IHierarchyItem item, IDotvvmRequestContext context)
        {
            // render item template
            var templatePlaceholder = new PlaceHolder();

            templatePlaceholder.DataContext = item;
            parent.Children.Add(templatePlaceholder);

            ItemTemplate.BuildContent(context, templatePlaceholder);
            if (item.Children.Any())
            {
                // wrap children in div
                var childContainer = new HtmlGenericControl("div");
                childContainer.Attributes["class"] = "child-container";
                foreach (var child in item.Children)
                {
                    DataBindItem(childContainer, child, context);
                }
            }
        }
예제 #25
0
        public bool GetIsTargetBlank(IHierarchyItem item)
        {
            var opener = this[Path.GetExtension(item.DisplayName)];
            var result = false;

            switch (opener)
            {
                case FileOpenerType.OfficeOnline:
                {
                    result = true;
                    break;
                }
                    case FileOpenerType.Open:
                {
                    result = true;
                    break;
                }
            }

            return result;
        }
예제 #26
0
        public string GetUrl(IHierarchyItem item, UrlHelper urlHelper)
        {
            var opener = this[Path.GetExtension(item.DisplayName)];
            string href = "/";

            switch (opener)
            {
                case FileOpenerType.OfficeOnline:
                {
                    var pathPart = item.Href.AbsolutePath.Replace("/" + WspContext.User.OrganizationId, "").TrimStart('/');
                    href = string.Concat(urlHelper.RouteUrl(FileSystemRouteNames.EditOfficeOnline, new { org = WspContext.User.OrganizationId, pathPart = "" }), pathPart);
                    break;
                }
                default:
                {
                    href = item.Href.LocalPath;
                    break;
                }
            }

            return href;
        }
예제 #27
0
        private void DrawEntry(IHierarchyItem entry)
        {
            GUILayout.Label("", GUILayout.Width(itemWidth), GUILayout.Height(itemHeight));
            if (Event.current.type == EventType.Repaint)
            {
                entry.RenderRect = GUILayoutUtility.GetLastRect();
                entry.RenderRect = new Rect(offset, entry.RenderRect.y, itemWidth - offset, entry.RenderRect.height);
                containingWindow.Repaint();
            }

            var shouldRenderChildren = false;

            using (new GUIBeginArea(entry.RenderRect))
                shouldRenderChildren = entry.Render();

            var clickableRect = entry.RenderRect;

            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && clickableRect.Contains(Event.current.mousePosition))
            {
                if (entry.OnClick != null)
                {
                    entry.OnClick(entry);
                }

                Event.current.Use();
            }

            if (entry.Children != null && shouldRenderChildren)
            {
                offset += offsetStep;

                foreach (var child in entry.Children)
                {
                    DrawEntry(child);
                }

                offset -= offsetStep;
            }
        }
예제 #28
0
        public bool GetIsTargetBlank(IHierarchyItem item)
        {
            var opener = this[Path.GetExtension(item.DisplayName)];
            var result = false;

            switch (opener)
            {
            case FileOpenerType.OfficeOnline:
            {
                result = true;
                break;
            }

            case FileOpenerType.Open:
            {
                result = true;
                break;
            }
            }

            return(result);
        }
예제 #29
0
        public string GetUrl(IHierarchyItem item, UrlHelper urlHelper)
        {
            var    opener = this[Path.GetExtension(item.DisplayName)];
            string href   = "/";

            switch (opener)
            {
            case FileOpenerType.OfficeOnline:
            {
                var pathPart = item.Href.AbsolutePath.Replace("/" + ScpContext.User.OrganizationId, "").TrimStart('/');
                href = string.Concat(urlHelper.RouteUrl(FileSystemRouteNames.EditOfficeOnline, new { org = ScpContext.User.OrganizationId, pathPart = "" }), pathPart);
                break;
            }

            default:
            {
                href = item.Href.LocalPath;
                break;
            }
            }

            return(href);
        }
예제 #30
0
        private static List <LockUriTokenPair> GetLockPairs(IHierarchyItem item, LockCollection locks)
        {
            List <LockUriTokenPair> lockPairs = new List <LockUriTokenPair>();

            if (locks != null)
            {
                lockPairs = new List <LockUriTokenPair>();
                foreach (KeyValuePair <string, string> pair in locks)
                {
                    if (!string.IsNullOrEmpty(pair.Value))
                    {
                        if (pair.Key.StartsWith(item.Href.AbsolutePath))
                        {
                            lockPairs.Add(
                                new LockUriTokenPair(
                                    new Uri(item.Href.OriginalString +
                                            pair.Key.Remove(0, item.Href.AbsolutePath.Length)),
                                    pair.Value));
                        }
                    }
                }
            }
            return(lockPairs);
        }
예제 #31
0
 public void Add(IHierarchyItem item, string lockToken)
 {
     Add(item.Href.AbsolutePath, lockToken);
 }
예제 #32
0
 public string this[IHierarchyItem item]
 {
     get { return(this[item.Href.AbsolutePath]); }
 }
예제 #33
0
 public void Remove(IHierarchyItem item)
 {
     Remove(item.Href.AbsolutePath);
 }
예제 #34
0
            // IConnectionSettings

            /// <summary>
            ///     For internal use only.
            /// </summary>
            /// <param name="comment"></param>
            public void SetHierarchyItem(IHierarchyItem item)
            {
                SetComment(item.Comment);
                SetCreationDate(item.CreationDate);
                SetCreatorDisplayName(item.CreatorDisplayName);
                SetHref(item.Href);
                SetLastModified(item.LastModified);
                SetProperties(item.Properties);
                SetItemType(item.ItemType);
            }