示例#1
0
        private FolderMetaData GetMetadataForUpdate(IHttpRequest request, UpdateReportData updatereport, TFSSourceControlProvider sourceControlProvider, out int targetRevision)
        {
            string         basePath = PathParser.GetLocalPath(request, updatereport.SrcPath);
            FolderMetaData metadata;

            if (updatereport.TargetRevision != null)
            {
                targetRevision = int.Parse(updatereport.TargetRevision);
            }
            else
            {
                targetRevision = sourceControlProvider.GetLatestVersion();
            }
            if (updatereport.IsCheckOut)
            {
                metadata = (FolderMetaData)sourceControlProvider.GetItemsWithoutProperties(targetRevision, basePath, Recursion.Full);
            }
            else
            {
                metadata = sourceControlProvider.GetChangedItems(basePath,
                                                                 int.Parse(updatereport.Entries[0].Rev),
                                                                 targetRevision,
                                                                 updatereport);
            }
            if (metadata != null)
            {
                loader = new AsyncItemLoader(metadata, sourceControlProvider);
                ThreadPool.QueueUserWorkItem(state => loader.Start());
            }
            return(metadata);
        }
示例#2
0
        private void ReplayReport(IHttpRequest request, IHttpResponse response, TFSSourceControlProvider sourceControlProvider, ReplayReportData replayReport)
        {
            if (replayReport.Revision == 0)
            {
                response.StatusCode = (int)HttpStatusCode.OK;
                using (var output = new StreamWriter(response.OutputStream))
                {
                    output.Write(
                        @"<?xml version=""1.0"" encoding=""utf-8""?>
<S:editor-report xmlns:S=""svn:"">
<S:target-revision rev=""0""/>
</S:editor-report>");
                    return;
                }
            }

            var data = new UpdateReportData();

            data.SrcPath = request.Url.AbsoluteUri;
            data.Entries = new List <EntryData>();
            var     item      = new EntryData();
            string  localPath = PathParser.GetLocalPath(request);
            LogItem log       = sourceControlProvider.GetLog(localPath, 0,
                                                             sourceControlProvider.GetLatestVersion(),
                                                             Recursion.None, 1);

            if (log.History.Length == 0)
            {
                WriteFileNotFoundResponse(request, response);
            }

            item.Rev            = (replayReport.Revision - 1).ToString();
            data.TargetRevision = (replayReport.Revision).ToString();
            data.Entries.Add(item);
            SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 200);
            response.SendChunked = true;
            using (var output = new StreamWriter(response.OutputStream))
            {
                try
                {
                    output.Write(@"<?xml version=""1.0"" encoding=""utf-8""?>
<S:editor-report xmlns:S=""svn:"">");

                    int            targetRevision;
                    FolderMetaData metadata = GetMetadataForUpdate(request, data, sourceControlProvider,
                                                                   out targetRevision);
                    output.WriteLine("<S:target-revision rev=\"{0}\"/>", targetRevision);

                    OutputEditorReport(sourceControlProvider, metadata, replayReport.Revision,
                                       localPath == "/",
                                       output);

                    output.Write("</S:editor-report>");
                }
                catch (FileNotFoundException)
                {
                    WriteFileNotFoundResponse(request, response);
                }
            }
        }
 public string GetLocalPathFromUrl(string path)
 {
     return(PathParser.GetLocalPath(httpContext.Request, path));
 }
示例#4
0
        protected override void Handle(IHttpContext context, TFSSourceControlProvider sourceControlProvider)
        {
            IHttpRequest  request  = context.Request;
            IHttpResponse response = context.Response;
            string        path     = GetPath(request);

            using (XmlReader reader = XmlReader.Create(request.InputStream, Helper.InitializeNewXmlReaderSettings()))
            {
                reader.MoveToContent();
                object data = null;
                try
                {
                    if (reader.NamespaceURI == WebDav.Namespaces.SVN && reader.LocalName == "get-locks-report")
                    {
                        SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 200);
                        response.SendChunked = true;
                        using (var writer = new StreamWriter(response.OutputStream))
                        {
                            GetLocksReport(writer);
                        }
                    }
                    else if (reader.NamespaceURI == WebDav.Namespaces.SVN && reader.LocalName == "update-report")
                    {
                        data = Helper.DeserializeXml <UpdateReportData>(reader);

                        UpdateReportData dt = (UpdateReportData)data;
                        int targetRevision;
                        if (dt != null && dt.TargetRevision != null)
                        {
                            targetRevision = int.Parse(dt.TargetRevision);
                        }
                        else
                        {
                            targetRevision = -1;
                        }

                        /*
                         * const string latestVersion = "Repository.Latest.Version";
                         * if (RequestCache.Items[latestVersion] == null)
                         * {
                         *  RequestCache.Items[latestVersion] = targetRevision = GetSDKObject().GetLastestVersionNum(path);
                         * }
                         * else
                         * {
                         *  targetRevision = (int)RequestCache.Items[latestVersion];
                         * }
                         */
                        //    FolderMetaData update = GetMetadataForUpdate(request, (UpdateReportData)data, sourceControlProvider, out targetRevision);
                        string       rep;
                        string       str = PathParser.GetLocalPath(request, dt.SrcPath);
                        ItemMetaData up  = QueryItems(ParsePath(str, out rep), targetRevision, Recursion.Full);
                        if (up != null)
                        {
                            FolderMetaData update;
                            if (up is FolderMetaData)
                            {
                                update = up as FolderMetaData;
                            }
                            else
                            {
                                update = new FolderMetaData();
                                update.Items.Add(up);
                            }
                            SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 200);
                            response.SendChunked = true;
                            using (var output = new StreamWriter(response.OutputStream))
                            {
                                UpdateReport(sourceControlProvider, (UpdateReportData)data, output, update, targetRevision);
                            }
                        }
                        else
                        {
                            SendTargetDoesNotExistResponse(response);
                        }
                    }
                    else if (reader.NamespaceURI == WebDav.Namespaces.SVN && reader.LocalName == "replay-report")
                    {
                        var relayReport = Helper.DeserializeXml <ReplayReportData>(reader);
                        ReplayReport(request, response, sourceControlProvider, relayReport);
                    }
                    else if (reader.NamespaceURI == WebDav.Namespaces.SVN && reader.LocalName == "log-report")
                    {
                        data = Helper.DeserializeXml <LogReportData>(reader);
                        SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 200);
                        response.SendChunked  = true;
                        response.BufferOutput = false;
                        using (var output = new StreamWriter(response.OutputStream))
                        {
                            LogReport(sourceControlProvider, (LogReportData)data, path, output);
                        }
                    }
                    else if (reader.NamespaceURI == WebDav.Namespaces.SVN && reader.LocalName == "get-locations")
                    {
                        data = Helper.DeserializeXml <GetLocationsReportData>(reader);
                        SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 200);
                        response.SendChunked = true;
                        using (var output = new StreamWriter(response.OutputStream))
                        {
                            GetLocationsReport(sourceControlProvider, (GetLocationsReportData)data, path, output);
                        }
                    }
                    else if (reader.NamespaceURI == WebDav.Namespaces.SVN && reader.LocalName == "dated-rev-report")
                    {
                        data = Helper.DeserializeXml <DatedRevReportData>(reader);
                        SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 200);
                        response.SendChunked = true;
                        using (var output = new StreamWriter(response.OutputStream))
                        {
                            GetDatedRevReport(sourceControlProvider, (DatedRevReportData)data, output, path);
                        }
                    }
                    else if (reader.NamespaceURI == WebDav.Namespaces.SVN && reader.LocalName == "file-revs-report")
                    {
                        data = Helper.DeserializeXml <FileRevsReportData>(reader);
                        string serverPath = "/";
                        if (path.IndexOf('/', 9) > -1)
                        {
                            serverPath = path.Substring(path.IndexOf('/', 9));
                        }
                        SendBlameResponse(request, response, sourceControlProvider, serverPath, (FileRevsReportData)data);
                        return;
                    }
                    else
                    {
                        SendUnknownReportResponse(response);
                    }
                    //if (data != null)
                    //{
                    //    RequestCache.Items["RequestBody"] = data;
                    //    DefaultLogger logger = Container.Resolve<DefaultLogger>();
                    //    logger.ErrorFullDetails(new Exception("Logging"), context);
                    //}
                }
                catch
                {
                    RequestCache.Items["RequestBody"] = data;
                    throw;
                }
            }
        }