예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        private void HandleUrlToWebUrl(HttpContext context)
        {
            var path = context.Request.Form["url"];

            var weburl  = path;
            var fileurl = string.Empty;

            // ie.: /Sites or /Sites/Default_Site/workspace/Document/myws/Document_Library/mydoc.docx
            if (path != "/")
            {
                path   = DwsHelper.GetFullPath(path);
                weburl = path;

                var node = Node.LoadNode(path);
                if (node == null)
                {
                    node = Node.LoadNode(RepositoryPath.GetParentPath(path));
                }

                // searching starts from parentpath
                if (node != null)
                {
                    using (new SystemAccount())
                    {
                        var doclib = DwsHelper.GetDocumentLibraryForNode(node);
                        if (doclib != null)
                        {
                            // weburl should be doclibs parent (most of the time currentworkspace)
                            // fileurl should be doclib name and doclib relative path
                            // this will work for /Sites/MySite/Doclib/document.docx, for /Sites/Mysite/myworkspace/Doclib/document.docx and for /Root/Doclib/document.docx
                            weburl  = doclib.ParentPath;
                            fileurl = (path.Length > doclib.ParentPath.Length) ? path.Substring(doclib.ParentPath.Length + 1) : string.Empty;
                        }
                        else
                        {
                            // weburl should be parent's parentpath
                            // fileurl should be parentname + name  -> parent will act as a mocked document library
                            // this will work for /Root/YourDocuments/document.docx
                            if (node.Parent != null)
                            {
                                weburl  = node.Parent.ParentPath;
                                fileurl = RepositoryPath.Combine(node.Parent.Name, node.Name);
                            }
                        }
                    }
                }
            }

            var responseStr = GetFormattedString(string.Format(URLTOWEBURLSTR, weburl, fileurl));

            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();
        }
예제 #4
0
        public string WebUrlFromPageUrl(string pageUrl)
        {
            // ie: pageurl:  http://localhost/Root/Sites/Default_Site/workspaces/Document/mydocumentws/Document_Library/my.doc
            // result: http://localhost/Root/Sites/Default_Site/workspaces/Document/mydocumentws

            // get root-relative url
            var hostIdx      = pageUrl.IndexOf(HttpContext.Current.Request.Url.Host);
            var prefixLength = hostIdx + HttpContext.Current.Request.Url.Host.Length;
            var path         = HttpUtility.UrlDecode(pageUrl.Substring(prefixLength));

            var rootIdx = pageUrl.ToLower().IndexOf("/root");

            if (rootIdx == -1)
            {
                // host selected in open dialog of office and navigated to doclibrary folder -> /Root is missing
                // ie: path:  /Sites/Default_Site/workspaces/Document/mydocumentws/Document_Library/my.doc
                if (path.ToLower().StartsWith("/sites"))
                {
                    path = RepositoryPath.Combine("/Root", path);
                }
                else
                {
                    path = RepositoryPath.Combine(PortalContext.Current.Site.Path, path);
                }
            }

            // searching starts from parentpath
            path = RepositoryPath.GetParentPath(path);
            var node = Node.LoadNode(path);
            var url  = string.Empty;

            if (node != null)
            {
                var ws = Workspace.GetWorkspaceForNode(node);
                if (ws != null)
                {
                    url = string.Concat(pageUrl.Substring(0, prefixLength), ws.Path);
                }
                else
                {
                    // workspace not found, it should be parent doclibrary's parent
                    var doclib = DwsHelper.GetDocumentLibraryForNode(node);
                    if (doclib != null)
                    {
                        url = string.Concat(pageUrl.Substring(0, prefixLength), doclib.ParentPath);
                    }
                    else
                    {
                        // standalone document, return parentpath
                        url = string.Concat(pageUrl.Substring(0, prefixLength), node.ParentPath);
                    }
                }
            }

            return(String.Concat(url));
        }
예제 #5
0
        public VersionOperationResult GetVersions(string fileName)
        {
            if (DwsHelper.CheckVisitor())
            {
                return(null);
            }

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

            if (file == null)
            {
                return(null);
            }
            var list = file.ContentListId;

            VersionOperationResult 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;

            List <VersionData> versionData = new List <VersionData>();

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

                VersionData 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.CreationDate.ToString();
                vd.createdRaw    = version.CreationDate.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);
        }
예제 #6
0
        private static string GetDocInfo(Node doc)
        {
            var doclib = DwsHelper.GetDocumentLibraryForNode(doc);
            var name   = doc.Name;

            // name should be documentLibrary/x.docx
            if (doclib != null)
            {
                name = doc.Path.Substring(doclib.ParentPath.Length + 1);
            }

            var metainfo = GetDocMetaInfo(doc);
            var dinfo    = string.Format(GETDOCSMETAINFODOCUMENTSTR, name, metainfo);

            return(dinfo);
        }
예제 #7
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);
        }
예제 #8
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 (SenseNetSecurityException)
                    {
                        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);
        }
예제 #9
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"];

            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));

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

                    using (new SystemAccount())
                    {
                        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();
        }
예제 #10
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.TrySkipIisCustomErrors = true;
            context.Response.Headers.Add("MicrosoftSharePointTeamServices", "14.0.0.5128");
            if (DwsHelper.CheckVisitor())
            {
                return;
            }

            var requestPath = PortalContext.Current.RequestedUri.AbsolutePath.ToLower();

            // mock workflow.asmx -> we don't implement, simply return HTTP 200
            if (requestPath.EndsWith("_vti_bin/workflow.asmx"))
            {
                HandleWorkflow(context);
                return;
            }

            // initial request to _vti_inf.html
            if (requestPath.EndsWith("_vti_inf.html"))
            {
                HandleVtiInf(context);
                return;
            }

            var method = context.Request.Form["method"];

            if (method == null)
            {
                // check inputstream's first line
                using (var reader = new System.IO.StreamReader(context.Request.InputStream))
                {
                    var firstLine = reader.ReadLine();
                    if (!string.IsNullOrEmpty(firstLine))
                    {
                        var decodedFirstLine = HttpUtility.UrlDecode(firstLine);

                        if (decodedFirstLine.StartsWith("method=put document"))
                        {
                            // seek to end of first line (also skip end-of-line char)
                            using (var resultStream = new OffsetStream(reader.BaseStream, firstLine.Length + 1))
                            {
                                resultStream.Position = 0;
                                HandleAuthorPutDocument(context, decodedFirstLine, resultStream);
                            }
                            return;
                        }
                    }
                }
                HandleError(context);
                return;
            }


            if (requestPath.EndsWith("_vti_rpc"))
            {
                if (method.StartsWith("server version"))
                {
                    HandleServerVersion(context);
                    return;
                }
                if (method.StartsWith("url to web url"))
                {
                    HandleUrlToWebUrl(context);
                    return;
                }
            }

            if (requestPath.EndsWith("_vti_aut/author.dll"))
            {
                // method=open+service%3a12%2e0%2e0%2e6415&service%5fname=%2f
                if (method.StartsWith("open service"))
                {
                    HandleAuthorOpenService(context);
                    return;
                }
                if (method.StartsWith("getDocsMetaInfo"))
                {
                    HandleAuthorGetDocsMetaInfo(context);
                    return;
                }
                if (method.StartsWith("get document"))
                {
                    HandleError(context);
                    return;
                }
                if (method.StartsWith("put document"))
                {
                    // this is handled with inputstream's first line above
                    HandleError(context);
                    return;
                }
                if (method.StartsWith("checkout document"))
                {
                    HandleAuthorCheckoutDocument(context);
                    return;
                }
            }

            context.Response.Flush();
            context.Response.End();
        }
예제 #11
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.VersionModifiedBy 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);
        }
예제 #12
0
        public void ProcessRequest(HttpContext context)
        {
            #region Trace
            //string traceMessage = string.Concat("===== FPP ===== Path: '", context.Request.Path, "'", Environment.NewLine);
            //traceMessage = string.Concat(traceMessage, "   Authenticated: ", HttpContext.Current.User.Identity.IsAuthenticated.ToString(), ", ", "UserName: "******"   HEADERS: ", Environment.NewLine);

            //foreach (var x in context.Request.Headers.AllKeys)
            //{
            //    traceMessage = string.Concat(traceMessage, string.Format("      {0}={1}", x, context.Request.Headers[x]));
            //    traceMessage = string.Concat(traceMessage, Environment.NewLine);
            //}

            //System.Diagnostics.Trace.Write(traceMessage);
            #endregion

            context.Response.TrySkipIisCustomErrors = true;
            context.Response.Headers.Add("MicrosoftSharePointTeamServices", "14.0.0.5128");
            if (DwsHelper.CheckVisitor())
            {
                return;
            }

            var requestPath = PortalContext.Current.RequestedUri.AbsolutePath.ToLower();
            //System.Diagnostics.Trace.Write("   REQUESTPATH: " + requestPath);

            // mock workflow.asmx -> we don't implement, simply return HTTP 200
            if (requestPath.EndsWith("_vti_bin/workflow.asmx"))
            {
                HandleWorkflow(context);
                return;
            }

            // initial request to _vti_inf.html
            if (requestPath.EndsWith("_vti_inf.html"))
            {
                HandleVtiInf(context);
                return;
            }

            var method = context.Request.Form["method"];

            //System.Diagnostics.Trace.Write("   FPP METHOD: " + method);

            if (method == null)
            {
                // check inputstream's first line
                using (var reader = new System.IO.StreamReader(context.Request.InputStream))
                {
                    var firstLine = reader.ReadLine();
                    if (!string.IsNullOrEmpty(firstLine))
                    {
                        var decodedFirstLine = HttpUtility.UrlDecode(firstLine);
                        //System.Diagnostics.Trace.Write("   FPP CONTENT 1st line: " + decodedFirstLine);

                        if (decodedFirstLine.StartsWith("method=put document"))
                        {
                            // seek to end of first line (also skip end-of-line char)
                            reader.BaseStream.Position = firstLine.Length + 1;

                            var resultStream = new System.IO.MemoryStream();
                            reader.BaseStream.CopyTo(resultStream);
                            resultStream.Position = 0;

                            HandleAuthorPutDocument(context, decodedFirstLine, resultStream);
                            return;
                        }
                    }
                }
                HandleError(context);
                return;
            }


            if (requestPath.EndsWith("_vti_rpc"))
            {
                if (method.StartsWith("server version"))
                {
                    HandleServerVersion(context);
                    return;
                }
                if (method.StartsWith("url to web url"))
                {
                    HandleUrlToWebUrl(context);
                    return;
                }
            }

            if (requestPath.EndsWith("_vti_aut/author.dll"))
            {
                //method=open+service%3a12%2e0%2e0%2e6415&service%5fname=%2f
                if (method.StartsWith("open service"))
                {
                    HandleAuthorOpenService(context);
                    return;
                }
                if (method.StartsWith("getDocsMetaInfo"))
                {
                    HandleAuthorGetDocsMetaInfo(context);
                    return;
                }
                if (method.StartsWith("get document"))
                {
                    HandleError(context);
                    return;
                }
                if (method.StartsWith("put document"))
                {
                    // this is handled with inputstream's first line above
                    HandleError(context);
                    return;
                }
                if (method.StartsWith("checkout document"))
                {
                    HandleAuthorCheckoutDocument(context);
                    return;
                }
            }

            context.Response.Flush();
            context.Response.End();
        }