public virtual void ReadFileAsync(ItemMetaData item, Guid repositoryUuid)
 {
     byte[] data = GetFile(item, repositoryUuid);
     item.Base64DiffData = SvnDiffParser.GetBase64SvnDiffData(data);
     item.Md5Hash        = Helper.GetMd5Checksum(data);
     item.DataLoaded     = true;
 }
示例#2
0
        private bool Put(TFSSourceControlProvider sourceControlProvider, string path, Stream inputStream, string baseHash, string resultHash)
        {
            if (!path.StartsWith("//"))
            {
                path = "/" + path;
            }

            string activityId = path.Substring(11, path.IndexOf('/', 11) - 11);
            string serverPath = Helper.Decode(path.Substring(11 + activityId.Length));

            byte[] sourceData = new byte[0];
            if (baseHash != null)
            {
                ItemMetaData item = sourceControlProvider.GetItemInActivity(activityId, serverPath);
                sourceData = sourceControlProvider.ReadFile(item);
                if (ChecksumMismatch(baseHash, sourceData))
                {
                    throw new Exception("Checksum mismatch with base file");
                }
            }
            byte[] fileData = SvnDiffParser.ApplySvnDiffsFromStream(inputStream, sourceData);
            if (fileData.Length > 0)
            {
                if (ChecksumMismatch(resultHash, fileData))
                {
                    throw new Exception("Checksum mismatch with new file");
                }
            }
            return(sourceControlProvider.WriteFile(activityId, serverPath, fileData));
        }
示例#3
0
        private bool Put(TFSSourceControlProvider sourceControlProvider, string path, Stream inputStream, string baseHash, string resultHash)
        {
            if (!path.StartsWith("//"))
            {
                path = "/" + path;
            }

            string activityId = path.Substring(11, path.IndexOf('/', 11) - 11);
            string serverPath = Helper.Decode(path.Substring(11 + activityId.Length));

            byte[] sourceData = ReadFile(serverPath, GetSDKObject().GetLastestVersionNum(serverPath));

            /*
             * if (baseHash != null)
             * {
             *  // TODONEXT:
             *  // ItemMetaData item = sourceControlProvider.GetItemInActivity(activityId, serverPath);
             *  ItemMetaData item = new ItemMetaData();
             *  item.Name = serverPath;
             *  GetData(item);
             *  sourceData = null;
             * //   sourceData = sourceControlProvider.ReadFile(item);
             *  if (ChecksumMismatch(baseHash, sourceData))
             *  {
             *      throw new Exception("Checksum mismatch with base file");
             *  }
             * }*/

            if (baseHash != null && sourceData != null && ChecksumMismatch(baseHash, sourceData))
            {
                throw new ConflictException();
                //    throw new Exception("Checksum mismatch with base file, please save your work, recheckout the project, apply changes, and try to commit again.");
            }

            byte[] fileData = SvnDiffParser.ApplySvnDiffsFromStream(inputStream, sourceData);
            string data     = string.Format("{0}", fileData);

            if (fileData.Length > 0)
            {
                if (resultHash != null && fileData != null && ChecksumMismatch(resultHash, fileData))
                {
                    throw new ConflictException();
                    //    throw new Exception("Checksum mismatch with new file, , please save your work, recheckout the project, apply changes, and try to commit again.");
                }
            }


            bool bRet = true;

            ActivityRepository.Use(activityId, delegate(Activity activity)
            {
                activity.MergeList.Add(new ActivityItem(serverPath, CodePlex.TfsLibrary.RepositoryWebSvc.ItemType.File, ActivityItemAction.Updated));

                bRet = WriteData(serverPath, fileData, activity.Comment);
            });

            return(bRet);
        }
示例#4
0
        private void SendBlameResponse(IHttpRequest request, IHttpResponse response, TFSSourceControlProvider sourceControlProvider, string serverPath, FileRevsReportData data)
        {
            LogItem log = sourceControlProvider.GetLog(
                serverPath,
                data.StartRevision,
                data.EndRevision,
                Recursion.Full,
                data.EndRevision - data.StartRevision);

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

            foreach (SourceItemHistory history in log.History)
            {
                foreach (SourceItemChange change in history.Changes)
                {
                    if (change.Item.ItemType == ItemType.Folder)
                    {
                        SendErrorResponseCannotRunBlameOnFolder(response, serverPath);
                        return;
                    }
                }
            }
            using (var output = new StreamWriter(response.OutputStream))
            {
                response.StatusCode = (int)HttpStatusCode.OK;
                output.Write(
                    @"<?xml version=""1.0"" encoding=""utf-8""?>
<S:file-revs-report xmlns:S=""svn:"" xmlns:D=""DAV:"">");

                foreach (SourceItemHistory history in Helper.SortHistories(true, log.History))
                {
                    foreach (SourceItemChange change in history.Changes)
                    {
                        ItemMetaData items    = sourceControlProvider.GetItems(change.Item.RemoteChangesetId, change.Item.RemoteName, Recursion.None);
                        byte[]       itemData = sourceControlProvider.ReadFile(items);
                        string       txdelta  = SvnDiffParser.GetBase64SvnDiffData(itemData);

                        output.Write(@"<S:file-rev path=""" + change.Item.RemoteName + @""" rev=""" +
                                     change.Item.RemoteChangesetId + @""">
                            <S:rev-prop name=""svn:log"">" + history.Comment + @"</S:rev-prop>
                            <S:rev-prop name=""svn:author"">" + history.Username + @"</S:rev-prop>
                            <S:rev-prop name=""svn:date"">" + Helper.FormatDate(change.Item.RemoteDate) + @"</S:rev-prop>
                            <S:txdelta>" + txdelta + @"</S:txdelta></S:file-rev>");
                    }
                }
                output.Write("</S:file-revs-report>");
            }
        }
 protected bool GetData(ItemMetaData metadata)
 {
     if (metadata is FolderMetaData)
     {
         bool bRet = true;
         foreach (var x in ((FolderMetaData)metadata).Items)
         {
             bRet = bRet && GetData(x);
         }
         return(bRet);
     }
     else
     {
         byte[] buffer = ReadFile(metadata.Name, metadata.ItemRevision);
         if (buffer == null)
         {
             return(false);
         }
         metadata.Base64DiffData = SvnDiffParser.GetBase64SvnDiffData(buffer);
         metadata.Md5Hash        = Helper.GetMd5Checksum(buffer);
         metadata.DataLoaded     = true;
         return(true);
     }
 }