示例#1
0
        private static string GetPath(IAnkhServiceProvider context, SvnRevision revision, SvnItem item, string tempDir)
        {
            if (revision == SvnRevision.Working)
            {
                return(item.FullPath);
            }

            string strRevision;

            if (revision.RevisionType == SvnRevisionType.Time)
            {
                strRevision = revision.Time.ToLocalTime().ToString("yyyyMMdd_hhmmss");
            }
            else
            {
                strRevision = revision.ToString();
            }
            string tempFile = Path.GetFileNameWithoutExtension(item.Name) + "." + strRevision + Path.GetExtension(item.Name);

            tempFile = Path.Combine(tempDir, tempFile);
            // we need to get it from the repos
            context.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingFileForComparison, delegate(object o, ProgressWorkerArgs ee)
            {
                SvnTarget target;

                switch (revision.RevisionType)
                {
                case SvnRevisionType.Head:
                case SvnRevisionType.Number:
                case SvnRevisionType.Time:
                    target = item.Uri;
                    break;

                default:
                    target = item.FullPath;
                    break;
                }
                SvnWriteArgs args = new SvnWriteArgs();
                args.Revision     = revision;
                args.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES);

                using (FileStream stream = File.Create(tempFile))
                {
                    ee.Client.Write(target, stream, args);
                }
            });

            return(tempFile);
        }
示例#2
0
        public string GetTempFile(SharpSvn.SvnTarget target, SharpSvn.SvnRevision revision, bool withProgress)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            else if (revision == null)
            {
                throw new ArgumentNullException("revision");
            }

            string file      = GetTempPath(target.FileName, revision);
            bool   unrelated = false;

            ProgressRunnerResult r = GetService <IProgressRunner>().RunModal(ServiceStrings.RetrievingFileForComparison,
                                                                             delegate(object sender, ProgressWorkerArgs aa)
            {
                SvnWriteArgs wa = new SvnWriteArgs();
                wa.Revision     = revision;
                wa.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES);

                using (Stream s = File.Create(file))
                    if (!aa.Client.Write(target, s, wa))
                    {
                        if (wa.LastException.SvnErrorCode == SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES)
                        {
                            unrelated = true;
                        }
                    }
            });

            if (!r.Succeeded || unrelated)
            {
                return(null); // User canceled
            }
            if (File.Exists(file))
            {
                File.SetAttributes(file, FileAttributes.ReadOnly); // A readonly file does not allow editting from many diff tools
            }
            return(file);
        }
示例#3
0
        private static string GetPath(IAnkhServiceProvider context, SvnRevision revision, SvnItem item, string tempDir)
        {
            if (revision == SvnRevision.Working)
            {
                return item.FullPath;
            }

            string strRevision;
            if (revision.RevisionType == SvnRevisionType.Time)
                strRevision = revision.Time.ToLocalTime().ToString("yyyyMMdd_hhmmss");
            else
                strRevision = revision.ToString();
            string tempFile = Path.GetFileNameWithoutExtension(item.Name) + "." + strRevision + Path.GetExtension(item.Name);
            tempFile = Path.Combine(tempDir, tempFile);
            // we need to get it from the repos
            context.GetService<IProgressRunner>().RunModal("Retrieving file for diffing", delegate(object o, ProgressWorkerArgs ee)
            {
                SvnTarget target;

                switch(revision.RevisionType)
                {
                    case SvnRevisionType.Head:
                    case SvnRevisionType.Number:
                    case SvnRevisionType.Time:
                        target = new SvnUriTarget(item.Uri);
                        break;
                    default:
                        target = new SvnPathTarget(item.FullPath);
                        break;
                }
                SvnWriteArgs args = new SvnWriteArgs();
                args.Revision = revision;
                args.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES);

                using (FileStream stream = File.Create(tempFile))
                {
                    ee.Client.Write(target, stream, args);
                }
            });

            return tempFile;
        }
示例#4
0
        public string GetTempFile(SharpSvn.SvnTarget target, SharpSvn.SvnRevision revision, bool withProgress)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            else if (revision == null)
                throw new ArgumentNullException("revision");

            string file = GetTempPath(target.FileName, revision);
            bool unrelated = false;

            ProgressRunnerResult r = GetService<IProgressRunner>().RunModal("Getting file",
                delegate(object sender, ProgressWorkerArgs aa)
                {
                    SvnWriteArgs wa = new SvnWriteArgs();
                    wa.Revision = revision;
                    wa.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES);

                    using (Stream s = File.Create(file))
                        if (!aa.Client.Write(target, s, wa))
                        {
                            if (wa.LastException.SvnErrorCode == SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES)
                                unrelated = true;
                        }
                });

            if (!r.Succeeded || unrelated)
                return null; // User canceled

            if (File.Exists(file))
                File.SetAttributes(file, FileAttributes.ReadOnly); // A readonly file does not allow editting from many diff tools

            return file;
        }