Ejemplo n.º 1
0
        /// <summary>
        /// Get an iFolder Entry
        /// </summary>
        /// <param name="c">The Collection Object</param>
        /// <param name="n">The Node Object</param>
        /// <returns>An iFolderEntry Object</returns>
        private static iFolderEntry GetEntry(Collection c, Node n)
        {
            iFolderEntry entry = new iFolderEntry();

            entry.ID        = n.ID;
            entry.Name      = n.Name;
            entry.iFolderID = c.ID;

            try
            {
                entry.ParentID = (n.Properties.GetSingleProperty(PropertyTags.Parent).Value as Relationship).NodeID;
            }
            catch
            {
                // ignore
            }

            // file node
            if (n.IsBaseType(NodeTypes.FileNodeType))
            {
                FileNode fileNode = (FileNode)FileNode.NodeFactory(c, n);

                entry.Path         = fileNode.GetRelativePath();
                entry.LastModified = fileNode.LastWriteTime;
                entry.Size         = fileNode.Length;
            }

            // dir node
            else if (n.IsBaseType(NodeTypes.DirNodeType))
            {
                DirNode dirNode = (DirNode)DirNode.NodeFactory(c, n);

                entry.Path         = dirNode.GetRelativePath();
                entry.LastModified = dirNode.CreationTime;
                entry.IsDirectory  = true;
                entry.IsRoot       = dirNode.IsRoot;
                entry.HasChildren  = dirNode.HasChildren(c);

                entry.Size = (long)dirNode.GetSize(c);
            }

            // bad node
            else
            {
                throw new EntryDoesNotExistException(n.ID);
            }

            return(entry);
        }
Ejemplo n.º 2
0
        //---------------------------------------------------------------------------
        /// <summary>
        /// resolve file name conflict and commit
        /// </summary>
        public void Resolve(string newNodeName)
        {
            if (!SyncFile.IsNameValid(newNodeName))
            {
                throw new MalformedException(newNodeName);
            }
            FileNode fn = node as FileNode;

            if (fn != null)
            {
                DirNode parent = fn.GetParent(collection);
                if (newNodeName == node.Name)
                {
                    Log.log.Debug("Resolving the name conflict >>>>> name: {0}  newName: {1}", node.Name, newNodeName);
                    // We are resolving to the same name.
                    if (Path.GetDirectoryName(FileNameConflictPath) != Path.GetDirectoryName(NonconflictedPath))
                    {
                        // This file is in the conflict bin and has been sync-ed from the server.  We do not need
                        // To push it back up.  Set internal.
                        node.Properties.State = PropertyList.PropertyListState.Internal;
                        try
                        {
                            File.Move(FileNameConflictPath, NonconflictedPath);
                        }
                        catch (IOException)
                        {
                            // The file exists it must have been modified locally create a node conflict.
                            File.Move(FileNameConflictPath, GetUpdateConflictPath(collection, fn));
                            fn = (FileNode)RemoveNameConflict(collection, fn);
                            collection.Commit(fn);
                            Node serverNode = collection.GetNodeByID(fn.ID);
                            // Now commit the node to update the file (size and dates);
                            fn.UpdateFileInfo(collection);
                            collection.Commit(fn);
                            // Create the node conflict.
                            fn = (FileNode)collection.CreateCollision(serverNode, false);
                            collection.Commit(fn);
                            return;
                        }
                    }
                }
                else
                {
                    Log.log.Debug("Resolving the name conflict >>>>> name: {0}  newName: {1}", node.Name, newNodeName);

                    if (SyncFile.DoesNodeExist(collection, parent, newNodeName))
                    {
                        throw new ExistsException(newNodeName);
                    }
                    //TODO: what if move succeeds but node rename or commit fails?
                    File.Move(FileNameConflictPath, Path.Combine(Path.GetDirectoryName(NonconflictedPath), newNodeName));
                    string relativePath = fn.GetRelativePath();
                    relativePath = relativePath.Remove(relativePath.Length - node.Name.Length, node.Name.Length) + newNodeName;
                    node.Properties.ModifyNodeProperty(new Property(PropertyTags.FileSystemPath, Syntax.String, relativePath));
                    node.Name = newNodeName;
                }
                node = RemoveNameConflict(collection, node);
                collection.Commit(node);
            }
            else
            {
                DirNode dn = node as DirNode;
                if (dn != null)
                {
                    DirNode parent = dn.GetParent(collection);
                    string  oldname, newname;
                    oldname = FileNameConflictPath;
                    newname = Path.Combine(Path.GetDirectoryName(dn.GetFullPath(collection)), newNodeName);
                    if (newNodeName != node.Name)
                    {
                        if (SyncFile.DoesNodeExist(collection, parent, newNodeName))
                        {
                            throw new ExistsException(newNodeName);
                        }
                        if (Directory.Exists(oldname))
                        {
                            Directory.Move(oldname, newname);
                        }
                        else
                        {
                            Directory.CreateDirectory(newname);
                        }
                        string oldRelativePath = dn.GetRelativePath();
                        string relativePath    = oldRelativePath.Remove(oldRelativePath.Length - node.Name.Length, node.Name.Length) + newNodeName;
                        node.Properties.ModifyNodeProperty(new Property(PropertyTags.FileSystemPath, Syntax.String, relativePath));
                        node.Name = newNodeName;
                        node      = RemoveNameConflict(collection, node);
                        collection.Commit(node);
                        FileWatcher.RenameDirsChildren(collection, dn, oldRelativePath);
                    }
                    else
                    {
                        // The name did not change.
                        if (Directory.Exists(oldname))
                        {
                            Directory.Move(oldname, newname);
                        }
                        else
                        {
                            Directory.CreateDirectory(newname);
                        }
                        node = RemoveNameConflict(collection, node);
                        collection.Commit(node);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// process and send the reply for request
        /// </summary>
        /// <param name="Context">httpcontext object</param>
        public void Send(HttpContext Context)
        {
            ctx = Context;
            ctx.Response.Write("<item>");
            FileNode fileNode = null;

            ctx.Response.Write("<title>");
            if (node.IsType("Member") == true)
            {
                Member collectionMember = new Member(node);
                ctx.Response.Write(" - " + collectionMember.FN);
            }
            else
            if (node.IsType("FileNode") == true)
            {
                fileNode = new FileNode(node);
                ctx.Response.Write(fileNode.GetFileName());
            }
            else
            {
                ctx.Response.Write(node.Name);
            }
            ctx.Response.Write("</title>");

            ctx.Response.Write("<guid isPermaLink=\"false\">" + node.ID + "</guid>");
            Simias.RssFeed.Util.SendPublishDate(ctx, published);

            if (node.IsType("Member") == true)
            {
                Member collectionMember = new Member(node);
                ctx.Response.Write("<description>");
                ctx.Response.Write(" - " + collectionMember.FN);
                ctx.Response.Write("</description>");

                ctx.Response.Write("<type>Member</type>");
            }
            else
            if (node.IsType("FileNode") == true)
            {
                fileNode = new FileNode(node);
                ctx.Response.Write("<description>");
                ctx.Response.Write(fileNode.GetRelativePath());
                ctx.Response.Write("</description>");

                /*
                 * ctx.Response.Write(
                 *      String.Format(
                 *              "<link>{0}{1}:{2}{3}/sfile.ashx?fid={4}{5}</link>",
                 *              ctx.Request.IsSecureConnection ? "https://" : "http://",
                 *              ctx.Request.Url.Host,
                 *              ctx.Request.Url.Port.ToString(),
                 *              ctx.Request.ApplicationPath,
                 *              fileNode.ID,
                 *              HttpUtility.UrlEncode( "&name=" + fileNode.Name ) ) );
                 */

                ctx.Response.Write(
                    String.Format(
                        "<link>{0}{1}:{2}{3}{4}?fid={5}</link>",
                        ctx.Request.IsSecureConnection ? "https://" : "http://",
                        ctx.Request.Url.Host,
                        ctx.Request.Url.Port.ToString(),
                        ctx.Request.ApplicationPath,
                        (publicAccess == true) ? "/pubsfile.ashx" : "/sfile.ashx",
                        fileNode.ID));

                if (enclosures == true)
                {
                    ctx.Response.Write(
                        String.Format(
                            "<enclosure url=\"{0}{1}:{2}{3}{4}?fid={5}\" length=\"{6}\" type=\"{7}\"/>",
                            ctx.Request.IsSecureConnection ? "https://" : "http://",
                            ctx.Request.Url.Host,
                            ctx.Request.Url.Port.ToString(),
                            ctx.Request.ApplicationPath,
                            (publicAccess == true) ? "/pubsfile.ashx" : "/sfile.ashx",
                            node.ID,
                            fileNode.Length,
                            Simias.HttpFile.Response.GetMimeType(fileNode.GetFileName())));
                }
            }
            else
            if (node.IsType("DirNode") == true)
            {
                DirNode dirNode = new DirNode(node);
                ctx.Response.Write("<description>");
                ctx.Response.Write(dirNode.GetRelativePath());
                ctx.Response.Write("</description>");
            }

            Domain domain = store.GetDomain(store.DefaultDomain);
            Member member = domain.GetMemberByID(node.Creator);

            if (member != null)
            {
                ctx.Response.Write("<author>");
                if (member.FN != null && member.FN != "")
                {
                    ctx.Response.Write(member.FN);
                }
                else
                {
                    ctx.Response.Write(member.Name);
                }
                ctx.Response.Write("</author>");
            }

            if (strict == false)
            {
                ctx.Response.Write("<authorID>" + member.UserID + "</authorID>");
                ctx.Response.Write("<type>" + node.Type.ToString() + "</type>");
                ctx.Response.Write("<id>" + node.ID + "</id>");
            }

            // Category  - use tags and types


            /*
             * if (slog.Generator != "")
             * {
             *      ctx.Response.Write("<generator>");
             *      ctx.Response.Write(slog.Generator);
             *      ctx.Response.Write("</generator>");
             * }
             *
             * if (slog.Cloud != "")
             * {
             *      ctx.Response.Write("<cloud>");
             *      ctx.Response.Write(slog.Cloud);
             *      ctx.Response.Write("</cloud>");
             * }
             */

            ctx.Response.Write("</item>");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get iFolder Entries by Name
        /// </summary>
        /// <param name="ifolderID">The ID of the iFolder.</param>
        /// <param name="parentID">The ID of the Parent Entry.</param>
        /// <param name="operation">The Search Operation</param>
        /// <param name="pattern">The Search Pattern</param>
        /// <param name="index">The Search Start Index</param>
        /// <param name="max">The Search Max Count of Results</param>
        /// <param name="accessID">The Access User ID.</param>
        /// <returns>A Set of iFolderEntry Objects</returns>
        public static iFolderEntrySet GetEntriesByName(string ifolderID, string parentID, SearchOperation operation, string pattern, int index, int max, string accessID)
        {
            Store store = Store.GetStore();

            Collection c = store.GetCollectionByID(ifolderID);

            if (c == null)
            {
                throw new iFolderDoesNotExistException(ifolderID);
            }

            // impersonate
            iFolder.Impersonate(c, accessID);

            // path
            string path;

            if ((parentID == null) || ifolderID.Equals(parentID))
            {
                path = c.Name + "/";
            }
            else
            {
                Node    n       = c.GetNodeByID(parentID);
                DirNode dirNode = (DirNode)DirNode.NodeFactory(c, n);

                path = dirNode.GetRelativePath() + "/";
            }

            // match the pattern
            Regex regex = null;

            if ((pattern != null) && (pattern.Length > 0))
            {
                switch (operation)
                {
                case SearchOperation.BeginsWith:
                    pattern = "^" + pattern;
                    break;

                case SearchOperation.EndsWith:
                    pattern = pattern + "$";
                    break;

                case SearchOperation.Equals:
                    pattern = "^" + pattern + "$";
                    break;

                case SearchOperation.Contains:
                default:
                    break;
                }

                regex = new Regex(pattern, RegexOptions.IgnoreCase);
            }

            // find children deep
            ICSList children = c.Search(PropertyTags.FileSystemPath, path, SearchOp.Begins);

            // sort the list
            ArrayList sortList = new ArrayList();

            foreach (ShallowNode sn in children)
            {
                if ((regex == null) || regex.Match(sn.Name).Success)
                {
                    sortList.Add(sn);
                }
            }

            sortList.Sort(new EntryComparer());

            // build the result list
            ArrayList list = new ArrayList();
            int       i    = 0;

            foreach (ShallowNode sn in sortList)
            {
                if (sn.IsBaseType(NodeTypes.FileNodeType) || sn.IsBaseType(NodeTypes.DirNodeType))
                {
                    if ((i >= index) && (((max <= 0) || i < (max + index))))
                    {
                        Node n = c.GetNodeByID(sn.ID);

                        list.Add(iFolderEntry.GetEntry(c, n));
                    }

                    ++i;
                }
            }

            return(new iFolderEntrySet((iFolderEntry[])list.ToArray(typeof(iFolderEntry)), i));
        }