Ejemplo n.º 1
0
        public bool CheckOutFile(string pageUrl, string checkoutToLocal, string lastmodified)
        {
            //<pageUrl>http://snbppc070/Root/Sites/Default_Site/workspaces/Document/losangelesdocumentworkspace/Document_Library/Duis%20et%20lorem.doc</pageUrl>
            //<checkoutToLocal>true</checkoutToLocal>
            //<lastmodified>3/25/2011 3:25:14 PM</lastmodified></CheckOutFile>

            if (DwsHelper.CheckVisitor())
            {
                return(false);
            }

            var path = DwsHelper.GetPathFromUrl(pageUrl);
            var node = Node.LoadNode(path);

            if (node != null)
            {
                if (!node.Lock.Locked)
                {
                    try
                    {
                        var gc = node as GenericContent;
                        gc.CheckOut();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteException(ex);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public bool UndoCheckOut(string pageUrl)
        {
            if (DwsHelper.CheckVisitor())
            {
                return(false);
            }

            var path = DwsHelper.GetPathFromUrl(pageUrl);
            var node = Node.LoadNode(path);

            if (node != null)
            {
                if (node.Lock.Locked && node.LockedById == ContentRepository.User.Current.Id)
                {
                    try
                    {
                        var gc = node as GenericContent;
                        gc.UndoCheckOut();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteException(ex);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        public bool CheckInFile(string pageUrl, string comment, string CheckinType)
        {
            //<pageUrl>http://snbppc070/Root/Sites/Default_Site/workspaces/Document/romedocumentworkspace/Document_Library/Aenean%20semper.doc</pageUrl>
            //<comment>fff</comment>
            //<CheckinType>0</CheckinType>

            if (DwsHelper.CheckVisitor())
            {
                return(false);
            }

            var path = DwsHelper.GetPathFromUrl(pageUrl);
            var node = Node.LoadNode(path);

            if (node != null)
            {
                if (node.Lock.Locked && node.LockedById == ContentRepository.User.Current.Id)
                {
                    try
                    {
                        var gc = node as GenericContent;
                        gc["CheckInComments"] = comment;
                        if (CheckinType == "0")
                        {
                            gc.CheckIn();       // from 1.5 -> 1.6
                        }
                        if (CheckinType == "1")
                        {
                            gc.Publish();       // from 1.5 -> 2.0
                        }
                        if (CheckinType == "2")
                        {
                            return(false);       // from 1.5 -> 1.5, not implemented
                        }
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteException(ex);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        public object RestoreVersion(string fileName, string fileVersion)
        {
            string[] vrsSpl = fileVersion.Split('.');
            int      major  = Convert.ToInt32(vrsSpl[0]);
            int      minor  = Convert.ToInt32(vrsSpl[1]);

            var path        = RepositoryPath.Combine(this.RequestPath, fileName);
            var docNodeHead = NodeHead.Get(path);

            if (docNodeHead == null)
            {
                // maybe it is a full path or url (Office 2013) instead of a name
                path        = DwsHelper.GetPathFromUrl(fileName);
                docNodeHead = NodeHead.Get(path);
            }

            if (docNodeHead != null)
            {
                var content = Content.Load(docNodeHead.Id, new VersionNumber(major, minor));

                if (content != null)
                {
                    try
                    {
                        content.Save();
                        if (content.Approvable)
                        {
                            content.Approve();
                        }
                        return(GetVersions(fileName));
                    }
                    catch (SecurityException)
                    {
                        MakeError(VersionErrorCodes.SERVER_ERROR, "You do not have enough permissions to restore previous versions of the current document.");
                    }
                    catch (InvalidContentActionException icaex)
                    {
                        MakeError(VersionErrorCodes.SERVER_ERROR, icaex.Message);
                    }
                }
            }

            MakeError(VersionErrorCodes.SERVER_ERROR, "The system cannot find the file specified. (Exception from HRESULT: 0x80070002)");
            return(null);
        }
Ejemplo n.º 5
0
        public VersionOperationResult GetVersions(string fileName)
        {
            if (DwsHelper.CheckVisitor() || string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            var url  = this.RequestUrl + "/" + fileName;
            var path = RepositoryPath.Combine(this.RequestPath, fileName);
            var file = Node.Load <GenericContent>(path);

            if (file == null)
            {
                // maybe it is a full path or url (Office 2013) instead of a name
                path = DwsHelper.GetPathFromUrl(fileName);
                file = Node.Load <GenericContent>(path);

                // re-set the url
                if (file != null)
                {
                    var bUrl   = file.BrowseUrl;
                    var domain = new Uri(this.RequestUrl).GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped);

                    // remove query string parameters
                    url = new Uri(domain + bUrl).GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.SafeUnescaped);
                }
            }

            if (file == null)
            {
                return(null);
            }

            var list = file.ContentListId;

            var vr = new VersionOperationResult();

            vr.results                    = new VersionResults();
            vr.results.list               = new VersionResultsList();
            vr.results.list.id            = list == 0 ? string.Empty : list.ToString();
            vr.results.settings           = new VersionResultsSettings();
            vr.results.settings.url       = url;
            vr.results.versioning         = new VersionResultsVersioning();
            vr.results.versioning.enabled = file.VersioningMode > VersioningType.None ? (byte)1 : (byte)0;

            var versionData = new List <VersionData>();

            foreach (var version in file.Versions)
            {
                var createdBy   = version.VersionCreatedBy as User;
                var fileVersion = version as File;

                var vd = new VersionData();
                vd.version       = String.Format("{0}{1}.{2}", file.Version == version.Version ? "@" : String.Empty, version.Version.Major, version.Version.Minor);
                vd.url           = url + "?version=" + version.Version;
                vd.created       = version.VersionCreationDate.ToString();
                vd.createdRaw    = version.VersionCreationDate.ToString("yyyy-MM-ddThh:mm:ssZ");
                vd.createdBy     = createdBy == null ? string.Empty : createdBy.Username;
                vd.createdByName = createdBy == null ? string.Empty : createdBy.DisplayName;
                vd.size          = fileVersion == null ? (ulong)0 : (ulong)fileVersion.Size;
                vd.comments      = version.GetProperty <string>("CheckInComments") ?? string.Empty;

                versionData.Add(vd);
            }

            vr.results.result = versionData.ToArray();

            return(vr);
        }
Ejemplo n.º 6
0
        private void HandleAuthorGetDocsMetaInfo(HttpContext context)
        {
            //method=getDocsMetaInfo:14.0.0.6009&url_list=[http://snbppc070/Root/Sites/Default_Site/workspaces/Document/losangelesdocumentworkspace/Document_Library/Doc4.docx;http://snbppc070/Root/Sites/Default_Site/workspaces/Document/losangelesdocumentworkspace/Document_Library]&listHiddenDocs=false&listLinkInfo=false

            var urllist = context.Request.Form["url_list"];
            //System.Diagnostics.Trace.Write("   URLLIST: " + urllist);

            IEnumerable <Node> docList = null;
            IEnumerable <Node> dirList = null;

            if (urllist.Contains(';'))
            {
                var pathList = urllist.Substring(1, urllist.Length - 2).Split(';').ToList();
                var nodeList = pathList.Select(path => Node.LoadNode(DwsHelper.GetPathFromUrl(path)));

                docList = nodeList.Where(node => !(node is IFolder));
                dirList = nodeList.Where(node => node is IFolder);
            }
            else
            {
                var path = urllist.Substring(1, urllist.Length - 2);
                var node = Node.LoadNode(DwsHelper.GetPathFromUrl(path));

                //docList = Enumerable.Empty<Node>();
                //dirList = new[] { node };

                if (node is IFolder)
                {
                    docList = Enumerable.Empty <Node>();
                    dirList = new[] { node };
                }
                else
                {
                    docList = new[] { node };

                    var doclib = Node.GetAncestorOfNodeType(node, "DocumentLibrary") ?? node.Parent;

                    dirList = new[] { doclib };
                }
            }

            var docinfo = string.Empty;

            // create docinfo
            foreach (var doc in docList)
            {
                if (doc == null)
                {
                    continue;
                }

                var dinfo = GetDocInfo(doc);
                docinfo = string.Concat(docinfo, dinfo);
            }

            var dirinfo = String.Empty;

            // create dirinfo
            foreach (var dir in dirList)
            {
                if (dir == null)
                {
                    continue;
                }

                var name             = dir.Name;                              //documentLibrary
                var timecreated      = dir.CreationDate.ToString(DATEFORMAT); //23 Mar 2011 11:31:58 +0000
                var timelastmodified = dir.ModificationDate.ToString(DATEFORMAT);
                var timelastwritten  = timelastmodified;
                var hassubdirs       = (dir as IFolder).ChildCount > 0 ? "true" : "false"; // true / false
                var gc = dir as GenericContent;
                var enableversioning    = gc.InheritableVersioningMode != ContentRepository.Versioning.InheritableVersioningType.None ? "true" : "false";
                var enableminorversions = gc.InheritableVersioningMode == ContentRepository.Versioning.InheritableVersioningType.MajorAndMinor ? "true" : "false";
                var enablemoderation    = "false"; // word does not seem to handle this - var enablemoderation = gc.HasApproving ? "true" : "false";

                var dinfo = string.Format(GETDOCSMETAINFOURLDIRSSTR, name, timecreated, timelastmodified, timelastwritten, hassubdirs, enableversioning, enableminorversions, enablemoderation);
                dirinfo = string.Concat(dirinfo, dinfo);
            }

            var responseStr = GetFormattedString(string.Format(GETDOCSMETAINFOSTR, docinfo, dirinfo));

            context.Response.Charset     = "";
            context.Response.ContentType = "application/x-vermeer-rpc";
            context.Response.AddHeader("Content-Length", responseStr.Length.ToString());
            context.Response.Write(responseStr);
            context.Response.Flush();
            context.Response.End();
        }