示例#1
0
        private void StoreConflicts(object sender, SvnInfoEventArgs e)
        {
            if (e.Conflicts != null && e.Conflicts.Count > 0)
            {
                _conflicts = e.Conflicts;

                foreach (var d in _conflicts)
                {
                    d.Detach();
                }
            }
        }
示例#2
0
        private static void SeparateSourceRootAndPath(SvnInfoEventArgs info, out Uri sourceRoot, out string sourcePath)
        {
            sourceRoot = info.RepositoryRoot;
            string s      = info.Uri.ToString().Substring(sourceRoot.ToString().Length);
            var    length = s.Length;
            var    sb     = new StringBuilder(length + 1);

            if (length == 0 || s[0] != '/')
            {
                sb.Append('/');
            }
            sb.Append(s);
            if (length != 0 && s[length - 1] == '/')
            {
                sb.Length -= 1;
            }
            sourcePath = sb.ToString();
        }
示例#3
0
        public void InfoTest2()
        {
            SvnSandBox sbox     = new SvnSandBox(this);
            Uri        ReposUrl = sbox.CreateRepository(SandBoxRepository.Default);

            using (SvnClient client = NewSvnClient(false, false))
            {
                Collection <SvnInfoEventArgs> items;
                client.GetInfo(ReposUrl, new SvnInfoArgs(), out items);

                Assert.That(items, Is.Not.Null, "Items retrieved");
                Assert.That(items.Count, Is.EqualTo(1), "1 info item");

                string fileName = SvnTools.GetFileName(ReposUrl);

                SvnInfoEventArgs info = items[0];
                Assert.That(info.Uri.AbsoluteUri, Is.EqualTo(ReposUrl.AbsoluteUri), "Repository uri matches");
                Assert.That(info.HasLocalInfo, Is.False, "No WC info");
                Assert.That(info.Path, Is.EqualTo(Path.GetFileName(ReposUrl.LocalPath.TrimEnd('\\'))), "Path is end of folder name");
            }
        }
示例#4
0
        private static long CommitNGetRevisionNumber(string source, string comment, SvnClient client)
        {
            SvnCommitArgs ca = new SvnCommitArgs();

            ca.LogMessage = comment;
            SvnCommitResult commitResults;
            long            revision;

            bool success = client.Commit(source, ca, out commitResults);

            if (ReferenceEquals(commitResults, null))
            {
                SvnInfoEventArgs svnInfo = GetLatestRevisionInfo(client, client.GetRepositoryRoot(source).AbsoluteUri);
                revision = svnInfo.LastChangeRevision;
            }
            else
            {
                revision = commitResults.Revision;
            }

            return(revision);
        }
示例#5
0
        private SvnInfoEventArgs GetRepositoryInfo()
        {
            SvnInfoEventArgs info      = null;
            Exception        exception = null;
            var repositoryUri          = new Uri(_settings.Uri).AbsoluteUri;

            var thread = new Thread(() =>
            {
                try
                {
                    info = GetRepositoryInfo(repositoryUri);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }
            });

            thread.Start();
            var timeoutAcquired = !thread.Join(TimeSpan.FromSeconds(Timeout));

            if (timeoutAcquired)
            {
                thread.Abort();
            }

            if (!timeoutAcquired && exception != null)
            {
                throw exception;
            }

            if (timeoutAcquired)
            {
                throw new SvnException(string.Format("Timeout while connecting to svn repository {0}", _settings.Uri));
            }

            return(info);
        }
        // 点击“提交”按钮
        private void btnCommit_Click(object sender, EventArgs e)
        {
            // 判断是否填写了提交所需的LogMessage信息
            string logMessage = txtCommitLogMessage.Text.Trim();

            if (string.IsNullOrEmpty(logMessage))
            {
                MessageBox.Show("执行SVN提交操作时必须填写说明信息", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // 记录用户是否选择了至少一处需要合并到SVN中的差异内容
            bool isChooseCommitChange = false;
            // 记录未对主语言译文不同的差异条目进行处理方式选择的编号
            List <int> unresolvedDiffInfoNum = new List <int>();
            // 记录未对本地表新增Key条目进行处理方式选择的编号
            List <int> unresolvedLocalAddKeyNum = new List <int>();
            // 记录未对SVN表新增Key条目进行处理方式选择的编号
            List <int> unresolvedSvnAddKeyNum = new List <int>();
            // 记录要进行提交的差异项
            CommitCompareResult commitCompareResult = new CommitCompareResult();

            // 检查用户是否对每一条差异都选择了处理方式
            // 主语言译文不同
            const string PART_DIFF_INFO_RESOLVE_CONFLICT_WAY_COLUMN_NAME = _PART_NAME_DIFF_INFO + _RESOLVE_CONFLICT_WAY_COLUMN_NAME;
            int          diffInfoCount = _compareResult.DiffInfo.Count;

            for (int i = 0; i < diffInfoCount; ++i)
            {
                CommitDifferentDefaultLanguageInfo oneDiffInfo = _compareResult.DiffInfo[i];
                string selectedValue = _partControls[_PART_NAME_DIFF_INFO].DataGridView.Rows[i].Cells[PART_DIFF_INFO_RESOLVE_CONFLICT_WAY_COLUMN_NAME].Value as string;
                if (AppValues.RESOLVE_COMMIT_DIFF_WAYS[0].Equals(selectedValue))
                {
                    oneDiffInfo.ResolveConflictWay = ResolveConflictWays.UseLocal;
                    commitCompareResult.DiffInfo.Add(oneDiffInfo);
                    isChooseCommitChange = true;
                }
                else if (AppValues.RESOLVE_COMMIT_DIFF_WAYS[1].Equals(selectedValue))
                {
                    oneDiffInfo.ResolveConflictWay = ResolveConflictWays.UseSvn;
                }
                else
                {
                    oneDiffInfo.ResolveConflictWay = ResolveConflictWays.NotChoose;
                    int num = i + 1;
                    unresolvedDiffInfoNum.Add(num);
                }
            }
            // 本地表新增Key
            const string PART_LOCAL_ADD_KEY_RESOLVE_CONFLICT_WAY_COLUMN_NAME = _PART_NAME_LOCAL_ADD_KEY + _RESOLVE_CONFLICT_WAY_COLUMN_NAME;
            int          localAddKeyCount = _compareResult.LocalAddKeyInfo.Count;

            for (int i = 0; i < localAddKeyCount; ++i)
            {
                CommitDifferentKeyInfo oneLocalAddKey = _compareResult.LocalAddKeyInfo[i];
                string selectedValue = _partControls[_PART_NAME_LOCAL_ADD_KEY].DataGridView.Rows[i].Cells[PART_LOCAL_ADD_KEY_RESOLVE_CONFLICT_WAY_COLUMN_NAME].Value as string;
                if (AppValues.RESOLVE_COMMIT_DIFF_WAYS[0].Equals(selectedValue))
                {
                    oneLocalAddKey.ResolveConflictWay = ResolveConflictWays.UseLocal;
                    commitCompareResult.LocalAddKeyInfo.Add(oneLocalAddKey);
                    isChooseCommitChange = true;
                }
                else if (AppValues.RESOLVE_COMMIT_DIFF_WAYS[1].Equals(selectedValue))
                {
                    oneLocalAddKey.ResolveConflictWay = ResolveConflictWays.UseSvn;
                }
                else
                {
                    oneLocalAddKey.ResolveConflictWay = ResolveConflictWays.NotChoose;
                    int num = i + 1;
                    unresolvedLocalAddKeyNum.Add(num);
                }
            }
            // SVN表新增Key
            const string PART_SVN_ADD_KEY_RESOLVE_CONFLICT_WAY_COLUMN_NAME = _PART_NAME_SVN_ADD_KEY + _RESOLVE_CONFLICT_WAY_COLUMN_NAME;
            int          svnAddKeyCount = _compareResult.SvnAddKeyInfo.Count;

            for (int i = 0; i < svnAddKeyCount; ++i)
            {
                CommitDifferentKeyInfo oneSvnAddKey = _compareResult.SvnAddKeyInfo[i];
                string selectedValue = _partControls[_PART_NAME_SVN_ADD_KEY].DataGridView.Rows[i].Cells[PART_SVN_ADD_KEY_RESOLVE_CONFLICT_WAY_COLUMN_NAME].Value as string;
                if (AppValues.RESOLVE_COMMIT_DIFF_WAYS[0].Equals(selectedValue))
                {
                    oneSvnAddKey.ResolveConflictWay = ResolveConflictWays.UseLocal;
                    commitCompareResult.SvnAddKeyInfo.Add(oneSvnAddKey);
                    isChooseCommitChange = true;
                }
                else if (AppValues.RESOLVE_COMMIT_DIFF_WAYS[1].Equals(selectedValue))
                {
                    oneSvnAddKey.ResolveConflictWay = ResolveConflictWays.UseSvn;
                }
                else
                {
                    oneSvnAddKey.ResolveConflictWay = ResolveConflictWays.NotChoose;
                    int num = i + 1;
                    unresolvedSvnAddKeyNum.Add(num);
                }
            }

            StringBuilder unresolvedConflictStringBuilder = new StringBuilder();

            if (unresolvedDiffInfoNum.Count > 0)
            {
                unresolvedConflictStringBuilder.Append("主语言译文不同的差异条目中,以下编号的行未选择处理方式:");
                unresolvedConflictStringBuilder.AppendLine(Utils.CombineString <int>(unresolvedDiffInfoNum, ","));
            }
            if (unresolvedLocalAddKeyNum.Count > 0)
            {
                unresolvedConflictStringBuilder.Append("本地表新增Key的差异条目中,以下编号的行未选择处理方式:");
                unresolvedConflictStringBuilder.AppendLine(Utils.CombineString <int>(unresolvedLocalAddKeyNum, ","));
            }
            if (unresolvedSvnAddKeyNum.Count > 0)
            {
                unresolvedConflictStringBuilder.Append("SVN表新增Key的差异条目中,以下编号的行未选择处理方式:");
                unresolvedConflictStringBuilder.AppendLine(Utils.CombineString <int>(unresolvedSvnAddKeyNum, ","));
            }
            string unresolvedConflictString = unresolvedConflictStringBuilder.ToString();

            if (!string.IsNullOrEmpty(unresolvedConflictString))
            {
                MessageBox.Show(string.Concat("存在以下未选择处理方式的差异条目,请全部选择处理方式后重试\n\n", unresolvedConflictString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // 判断用户是否选择了至少一处需要合并到SVN中的差异内容
            if (isChooseCommitChange == false)
            {
                MessageBox.Show("未选择将任一差异提交到SVN表,无需进行提交操作", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // 即将提交时判断此时SVN中最新版本号是否还是进入此界面时与本地表对比的版本号,如果不是需要重新对比
            SvnException     svnException = null;
            SvnInfoEventArgs svnFileInfo  = OperateSvnHelper.GetSvnFileInfo(AppValues.SvnExcelFilePath, out svnException);

            if (svnException == null)
            {
                // 若此时SVN最新版本仍旧为之前与之对比的版本,则根据用户选择将结果合并到最新SVN母表副本中然后上传
                if (svnFileInfo.LastChangeRevision == _compareResult.SvnFileRevision)
                {
                    string errorString         = null;
                    string mergedExcelFilePath = CommitExcelFileHelper.GenerateCommitExcelFile(_compareResult, _localExcelInfo, _newestSvnExcelInfo, out errorString);
                    if (errorString != null)
                    {
                        MessageBox.Show(string.Format("生成合并之后的Excel母表文件失败,错误原因为:{0}\n\n提交操作被迫中止", errorString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    // 进行SVN提交操作(将本地Working Copy文件备份至本工具所在路径,然后用合并后的Excel母表替换Working Copy文件后执行SVN提交操作)
                    string backupFilePath = Utils.CombinePath(AppValues.PROGRAM_FOLDER_PATH, string.Format("备份自己修改的本地表 {0:yyyy年MM月dd日 HH时mm分ss秒} 对应SVN版本号{1}.xlsx", DateTime.Now, _localExcelInfo.Revision));
                    try
                    {
                        File.Copy(AppValues.LocalExcelFilePath, backupFilePath, true);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(string.Format("自动备份本地表至本工具所在路径失败,错误原因为:{0}\n\n为了防止因不备份导致自己编辑的原始本地表丢失,提交SVN操作被迫中止", exception.ToString()), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    // 因为SVN提交文件需要在同一版本号下进行且SVN无法在Update时对Excel进行Merge操作,则如果本地表的版本号低于SVN最新版本,必须将本地表执行Revert和Update操作后才可以提交
                    if (_compareResult.LocalFileRevision != _compareResult.SvnFileRevision)
                    {
                        // Revert操作
                        bool revertResult = OperateSvnHelper.Revert(AppValues.LocalExcelFilePath, out svnException);
                        if (svnException == null)
                        {
                            if (revertResult == false)
                            {
                                MessageBox.Show("因本地表版本不是SVN中最新的,必须执行Revert以及Update操作后才可以提交\n但因为Revert失败,提交SVN操作被迫中止", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show(string.Format("因本地表版本不是SVN中最新的,必须执行Revert以及Update操作后才可以提交\n但因为Revert失败,错误原因为:{0}\n提交SVN操作被迫中止", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        // Update操作
                        bool updateResult = OperateSvnHelper.Update(AppValues.LocalExcelFilePath, out svnException);
                        if (svnException == null)
                        {
                            if (updateResult == false)
                            {
                                MessageBox.Show("因本地表版本不是SVN中最新的,必须执行Revert以及Update操作后才可以提交\n但因为Update失败,提交SVN操作被迫中止", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else
                        {
                            if (svnException is SvnAuthorizationException || svnException is SvnOperationCanceledException)
                            {
                                MessageBox.Show("因本地表版本不是SVN中最新的,必须执行Revert以及Update操作后才可以提交\n但因为没有权限进行Update操作,提交SVN操作被迫中止,请输入合法的SVN账户信息后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            else
                            {
                                MessageBox.Show(string.Format("因本地表版本不是SVN中最新的,必须执行Revert以及Update操作后才可以提交\n但因为Update失败,错误原因为:{0}\n提交SVN操作被迫中止", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }
                    // 用合并后的Excel文件覆盖掉原有的本地表
                    try
                    {
                        File.Copy(mergedExcelFilePath, AppValues.LocalExcelFilePath, true);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(string.Format("将合并后的Excel母表覆盖到本地表所在路径失败,错误原因为:{0}\n\n提交SVN操作被迫中止", exception), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    // 执行提交操作
                    bool commitResult = OperateSvnHelper.Commit(AppValues.LocalExcelFilePath, logMessage, out svnException);
                    if (svnException == null)
                    {
                        if (commitResult == false)
                        {
                            MessageBox.Show("执行提交操作失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            MessageBox.Show(string.Concat("执行提交操作成功\n\n自己修改的原始本地表备份至:", backupFilePath), "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Format("执行提交操作失败,错误原因为:{0}\n\n请修正错误后重试", svnException.RootCause.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("很遗憾,在提交时发现了更新的SVN表的版本({0}),需要重新对比与新表的差异(本次新发现的差异项会将“编号”列的单元格背景调为橙色突出显示)然后选择处理方式后再提交\n\n但之前已选择的差异项的处理方式将被保留,直接在下拉列表中默认选中刚才你选择的处理方式\n\n注意:在展示主语言不同(第1个表格)以及SVN表新增Key(第2个表格)的表格中,若两次SVN表主语言译文发生变动,会将“SVN表主语言译文”列的单元格背景调为橙色突出显示", svnFileInfo.LastChangeRevision), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    // 需要下载SVN最新版本表与本地表进行对比
                    string    svnNewRevisionCopySavePath = Utils.CombinePath(AppValues.PROGRAM_FOLDER_PATH, string.Format("SVN最新母表副本 {0:yyyy年MM月dd日 HH时mm分ss秒} 对应SVN版本号{1}.xlsx", DateTime.Now, svnFileInfo.LastChangeRevision));
                    Exception exportException;
                    bool      result = OperateSvnHelper.ExportSvnFileToLocal(AppValues.SvnExcelFilePath, svnNewRevisionCopySavePath, svnFileInfo.LastChangeRevision, out exportException);
                    if (exportException != null)
                    {
                        MessageBox.Show(string.Format("下载SVN中最新版本号({0})的母表文件存到本地失败,错误原因为:{1}", svnFileInfo.LastChangeRevision, exportException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;
                    }
                    else if (result == false)
                    {
                        MessageBox.Show(string.Format("下载SVN中最新版本号({0})的母表文件存到本地失败", svnFileInfo.LastChangeRevision), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;
                    }
                    // 解析SVN中最新的母表文件
                    string          errorString;
                    CommitExcelInfo newRevisionExcelInfo = CommitExcelFileHelper.AnalyzeCommitExcelFile(svnNewRevisionCopySavePath, AppValues.CommentLineStartChar, svnFileInfo.LastChangeRevision, out errorString);
                    if (errorString != null)
                    {
                        MessageBox.Show(string.Format("下载的SVN中最新版本号({0})的母表文件存在以下错误,请修正后重试\n\n{1}", svnFileInfo.LastChangeRevision, errorString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;
                    }
                    _newestSvnExcelInfo = newRevisionExcelInfo;
                    // 对比本地表与SVN中最新母表文件
                    CommitCompareResult newCompareResult = CommitExcelFileHelper.CompareCommitExcelFile(_localExcelInfo, newRevisionExcelInfo);
                    // 如果最新的SVN中母表与本地表反而没有任何差异,则无需提交
                    if (newCompareResult.IsHasDiff() == false)
                    {
                        _compareResult = newCompareResult;
                        // 清空DataGridView中的内容
                        _CleanDataGridView();
                        // 更新SVN版本号显示
                        txtSvnFileRevision.Text      = svnFileInfo.LastChangeRevision.ToString();
                        txtSvnFileRevision.BackColor = Color.Orange;

                        MessageBox.Show("经对比发现本地母表与SVN中最新版本内容完全相同,无需进行提交操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    _RefreshDataGridView(newCompareResult);
                }
            }
            else
            {
                MessageBox.Show(string.Format("无法获取SVN中最新母表信息,错误原因为:{0}\n\n提交操作被迫中止", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
示例#7
0
 private void OnInfo(object sender, SvnInfoEventArgs info)
 {
     _info = info;
     info.Detach();
 }
示例#8
0
        public override void OnExecute(CommandEventArgs e)
        {
            // TODO: Choose which conflict to edit if we have more than one!
            SvnItem conflict = null;

            if (e.Command == AnkhCommand.DocumentConflictEdit)
            {
                conflict = e.Selection.ActiveDocumentSvnItem;

                if (conflict == null || !conflict.IsConflicted)
                {
                    return;
                }
            }
            else
            {
                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
                {
                    if (item.IsConflicted)
                    {
                        conflict = item;
                        break;
                    }
                }
            }

            if (conflict == null)
            {
                return;
            }

            conflict.MarkDirty();
            if (conflict.Status.LocalTextStatus != SvnStatus.Conflicted)
            {
                AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                mb.Show(string.Format(CommandStrings.TheConflictInXIsAlreadyResolved, conflict.FullPath), CommandStrings.EditConflictTitle,
                        System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                return;
            }

            SvnInfoEventArgs conflictInfo = null;

            bool ok = false;
            ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingConflictDetails,
                                                                               delegate(object sender, ProgressWorkerArgs a)
            {
                ok = a.Client.GetInfo(conflict.FullPath, out conflictInfo);
            });

            if (!ok || !r.Succeeded || conflictInfo == null)
            {
                return;
            }

            AnkhMergeArgs da  = new AnkhMergeArgs();
            string        dir = conflict.Directory;

            da.BaseFile   = Path.Combine(dir, conflictInfo.ConflictOld ?? conflictInfo.ConflictNew);
            da.TheirsFile = Path.Combine(dir, conflictInfo.ConflictNew ?? conflictInfo.ConflictOld);

            if (!string.IsNullOrEmpty(conflictInfo.ConflictWork))
            {
                da.MineFile = Path.Combine(dir, conflictInfo.ConflictWork);
            }
            else
            {
                da.MineFile = conflict.FullPath;
            }

            da.MergedFile = conflict.FullPath;

            da.BaseTitle   = "Base";
            da.TheirsTitle = "Theirs";
            da.MineTitle   = "Mine";
            da.MergedTitle = conflict.Name;


            e.GetService <IAnkhDiffHandler>().RunMerge(da);
        }
示例#9
0
        private void MaybeRevert(string newName, SvnEntry toBefore)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (toBefore == null)
            {
                return;
            }

            SvnInfoArgs      ia   = new SvnInfoArgs();
            SvnInfoEventArgs info = null;

            ia.ThrowOnError = false;
            ia.Depth        = SvnDepth.Empty;
            ia.Info        += delegate(object sender, SvnInfoEventArgs e) { e.Detach(); info = e; };

            if (!Client.Info(newName, ia, null) || info == null)
            {
                return;
            }

            // Use SvnEntry to peek below the current delete
            if (toBefore.RepositoryId != info.RepositoryId ||
                toBefore.Uri != info.CopyFromUri ||
                toBefore.Revision != info.CopyFromRevision)
            {
                return;
            }

            using (MarkIgnoreRecursive(newName))
                using (MoveAway(newName))
                {
                    SvnRevertArgs ra = new SvnRevertArgs();
                    ra.Depth        = SvnDepth.Empty;
                    ra.ThrowOnError = false;

                    // Do a quick check if we can safely revert with depth infinity
                    using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0))
                    {
                        SvnStatusArgs sa = new SvnStatusArgs();
                        sa.IgnoreExternals = true;
                        sa.ThrowOnError    = false;
                        bool modifications = false;
                        if (Client.Status(newName, sa,
                                          delegate(object sender, SvnStatusEventArgs e)
                        {
                            if (e.Conflicted ||
                                (e.LocalPropertyStatus != SvnStatus.Normal &&
                                 e.LocalPropertyStatus != SvnStatus.None))
                            {
                                e.Cancel = modifications = true;
                            }
                            else if (e.FullPath == newName)
                            {
                                return;
                            }

                            switch (e.LocalNodeStatus)
                            {
                            case SvnStatus.None:
                            case SvnStatus.Normal:
                            case SvnStatus.Modified:               // Text only change is ok
                            case SvnStatus.Ignored:
                            case SvnStatus.External:
                            case SvnStatus.NotVersioned:
                                break;

                            default:
                                e.Cancel = modifications = true;
                                break;
                            }
                        }) &&
                            !modifications)
                        {
                            ra.Depth = SvnDepth.Infinity;
                        }
                    }

                    Client.Revert(newName, ra);
                }
        }
 private void InfoReceiver(object sender, SvnInfoEventArgs e) 
 {
     svnInfo = new SvnInformation(e.Uri.ToString(), e.RepositoryRoot.ToString(), e.Path);
 }
 private void InfoReceiver(object sender, SvnInfoEventArgs e)
 {
     svnInfo = new SvnInformation(e.Uri.ToString(), e.RepositoryRoot.ToString(), e.Path);
 }
示例#12
0
        // 点击“提交到SVN”按钮
        private void btnCommit_Click(object sender, EventArgs e)
        {
            FileState fileState = Utils.GetFileState(AppValues.LocalExcelFilePath);

            if (fileState == FileState.Inexist)
            {
                MessageBox.Show("本地表已不存在,请勿在使用本工具时对母表进行操作", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (fileState == FileState.IsOpen)
            {
                MessageBox.Show("本地表正被其他软件使用,请关闭后再重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // 判断本地表是否相较SVN最新版本发生变动,如果本地就是SVN中最新版本且未进行改动则无需提交
            SvnException       svnException   = null;
            SvnStatusEventArgs localFileState = OperateSvnHelper.GetLocalFileState(AppValues.LocalExcelFilePath, out svnException);

            if (svnException == null)
            {
                SvnInfoEventArgs svnFileInfo = OperateSvnHelper.GetSvnFileInfo(AppValues.SvnExcelFilePath, out svnException);
                if (svnException == null)
                {
                    // 本地表的版本号
                    long localFileRevision = localFileState.LastChangeRevision;
                    // SVN中的母表的版本号
                    long svnFileRevision = svnFileInfo.LastChangeRevision;
                    if (localFileState.LocalContentStatus == SvnStatus.Normal)
                    {
                        if (localFileRevision == svnFileRevision)
                        {
                            MessageBox.Show("本地母表与SVN最新版本完全一致,无需进行提交操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        else if (MessageBox.Show("本地母表不是SVN最新版本,但与同版本SVN表完全一致\n\n确定要在此情况下进行提交操作吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            return;
                        }
                    }
                    // 本地表与SVN最新版本不同,则要下载一份SVN中最新版本与本地表进行对比,在用户手工选择需要提交哪些改动后将合并后的新表进行提交操作
                    string    svnCopySavePath = Utils.CombinePath(AppValues.PROGRAM_FOLDER_PATH, string.Format("SVN最新母表副本 {0:yyyy年MM月dd日 HH时mm分ss秒} 对应SVN版本号{1}.xlsx", DateTime.Now, svnFileInfo.LastChangeRevision));
                    Exception exportException;
                    bool      result = OperateSvnHelper.ExportSvnFileToLocal(AppValues.SvnExcelFilePath, svnCopySavePath, svnFileInfo.LastChangeRevision, out exportException);
                    if (exportException != null)
                    {
                        MessageBox.Show(string.Concat("下载SVN中最新母表存到本地失败,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (result == false)
                    {
                        MessageBox.Show("下载SVN中最新母表存到本地失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // 解析本地母表
                    string          errorString    = null;
                    CommitExcelInfo localExcelInfo = CommitExcelFileHelper.AnalyzeCommitExcelFile(AppValues.LocalExcelFilePath, AppValues.CommentLineStartChar, localFileRevision, out errorString);
                    if (errorString != null)
                    {
                        MessageBox.Show(string.Concat("本地母表存在以下错误,请修正后重试\n\n", errorString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    // 解析下载到本地的SVN最新母表的副本
                    CommitExcelInfo svnExcelInfo = CommitExcelFileHelper.AnalyzeCommitExcelFile(svnCopySavePath, AppValues.CommentLineStartChar, svnFileRevision, out errorString);
                    if (errorString != null)
                    {
                        MessageBox.Show(string.Concat("SVN母表存在以下错误,请修正后重试\n\n", errorString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // 对比本地母表与SVN中的母表
                    CommitCompareResult compareResult = CommitExcelFileHelper.CompareCommitExcelFile(localExcelInfo, svnExcelInfo);
                    if (compareResult.IsHasDiff() == false)
                    {
                        MessageBox.Show("经对比发现本地母表与SVN中内容完全相同,无需进行提交操作\n请注意本功能仅会对比本地母表与SVN中母表的Key及主语言译文变动,不对各语种进行比较", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else
                    {
                        // 弹出对比结果界面,让用户选择需要合并到SVN中母表的变动
                        ResolveConflictWhenCommitForm resolveForm = new ResolveConflictWhenCommitForm(compareResult, localExcelInfo, svnExcelInfo);
                        resolveForm.ShowDialog(this);
                    }
                }
                else
                {
                    MessageBox.Show(string.Concat("无法获取SVN中母表信息,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show(string.Concat("无法获取本地表状态,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
示例#13
0
        // 点击“Revert并Update本地表”按钮
        private void btnRevertAndUpdateLocalExcelFile_Click(object sender, EventArgs e)
        {
            FileState fileState = Utils.GetFileState(AppValues.LocalExcelFilePath);

            if (fileState == FileState.Inexist)
            {
                MessageBox.Show("本地表已不存在,请勿在使用本工具时对母表进行操作", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (fileState == FileState.IsOpen)
            {
                MessageBox.Show("本地表正被其他软件使用,请关闭后再重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 判断本地文件是否相较SVN中发生变动,若有变动提示进行备份后执行Revert
            SvnException       svnException   = null;
            SvnStatusEventArgs localFileState = OperateSvnHelper.GetLocalFileState(AppValues.LocalExcelFilePath, out svnException);

            if (svnException == null)
            {
                if (localFileState.LocalContentStatus == SvnStatus.Modified)
                {
                    DialogResult dialogResult = MessageBox.Show("检测到本地文件相较于线上已发生变动,是否要进行备份?\n\n点击“是”选择存放本地表备份路径后进行备份\n点击“否”不进行备份,直接Revert后Update", "选择是否对本地表进行备份", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        SaveFileDialog dialog = new SaveFileDialog();
                        dialog.ValidateNames = true;
                        dialog.Title         = "请选择本地表备份路径";
                        dialog.Filter        = "Excel files (*.xlsx)|*.xlsx";
                        dialog.FileName      = string.Format("Revert前本地母表备份 {0:yyyy年MM月dd日 HH时mm分ss秒} 对应SVN版本号{1}.xlsx", DateTime.Now, localFileState.LastChangeRevision);
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            string backupPath = dialog.FileName;
                            // 检查要覆盖备份的Excel文件是否已存在且正被其他程序使用
                            if (Utils.GetFileState(backupPath) == FileState.IsOpen)
                            {
                                MessageBox.Show("要覆盖的Excel文件正被其他程序打开,请关闭后重试\n\nRevert并Update功能被迫中止", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }

                            try
                            {
                                File.Copy(AppValues.LocalExcelFilePath, backupPath, true);
                                MessageBox.Show("备份本地母表成功,点击“确定”后开始执行Revert并Update操作", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            catch (Exception exception)
                            {
                                string errorString = string.Format("备份本地母表({0})至指定路径({1})失败:{2}\n\nRevert并Update功能被迫中止", AppValues.LocalExcelFilePath, backupPath, exception.Message);
                                MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("未选择备份路径,无法进行本地母表备份\n\nRevert并Update功能被迫中止", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    bool result = OperateSvnHelper.Revert(AppValues.LocalExcelFilePath, out svnException);
                    if (svnException == null)
                    {
                        if (result == false)
                        {
                            MessageBox.Show("Revert失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Concat("Revert失败,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (localFileState.LocalContentStatus != SvnStatus.Normal)
                {
                    MessageBox.Show(string.Format("本地表状态为{0},本工具仅支持Normal或Modified状态", localFileState.LocalContentStatus), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // 判断是否需要进行Update
                SvnInfoEventArgs svnFileInfo = OperateSvnHelper.GetSvnFileInfo(AppValues.SvnExcelFilePath, out svnException);
                if (svnException == null)
                {
                    // 本地表的版本号
                    long localFileRevision = localFileState.LastChangeRevision;
                    // SVN中的母表的版本号
                    long svnFileRevision = svnFileInfo.LastChangeRevision;
                    if (localFileRevision == svnFileRevision)
                    {
                        if (localFileState.LocalContentStatus == SvnStatus.Modified)
                        {
                            MessageBox.Show("成功进行Revert操作,本地表已是SVN最新版本无需Update\n\nRevert并Update功能完成", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("本地表已是SVN最新版本且与SVN中内容一致,无需进行此操作", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    else
                    {
                        bool result = OperateSvnHelper.Update(AppValues.LocalExcelFilePath, out svnException);
                        if (svnException == null)
                        {
                            if (result == false)
                            {
                                MessageBox.Show("Update失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            else
                            {
                                MessageBox.Show("执行Revert并Update功能成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                        }
                        else
                        {
                            if (svnException is SvnAuthorizationException || svnException is SvnOperationCanceledException)
                            {
                                MessageBox.Show("没有权限进行Update操作,请输入合法的SVN账户信息后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            else
                            {
                                MessageBox.Show(string.Concat("Update失败,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show(string.Concat("无法获取SVN中母表信息,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show(string.Concat("无法获取本地表状态,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
示例#14
0
        // 点击“获取本地表状态”按钮
        private void btnGetLocalExcelFileState_Click(object sender, EventArgs e)
        {
            FileState fileState = Utils.GetFileState(AppValues.LocalExcelFilePath);

            if (fileState == FileState.Inexist)
            {
                MessageBox.Show("本地表已不存在,请勿在使用本工具时对母表进行操作", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            SvnException       svnException   = null;
            SvnStatusEventArgs localFileState = OperateSvnHelper.GetLocalFileState(AppValues.LocalExcelFilePath, out svnException);

            if (svnException == null)
            {
                SvnInfoEventArgs svnFileInfo = OperateSvnHelper.GetSvnFileInfo(AppValues.SvnExcelFilePath, out svnException);
                if (svnException == null)
                {
                    // 本地表的版本号
                    long localFileRevision = localFileState.LastChangeRevision;
                    // 本地表文件相较SVN中的状态
                    SvnStatus svnStatus = localFileState.LocalContentStatus;

                    // SVN中的母表的版本号
                    long svnFileRevision = svnFileInfo.LastChangeRevision;
                    // 最后修改时间
                    DateTime svnFileChangeTime = svnFileInfo.LastChangeTime;
                    // 最后修改者
                    string svnFileChangeAuthor = svnFileInfo.LastChangeAuthor;

                    StringBuilder infoStringBuilder = new StringBuilder();
                    infoStringBuilder.Append("本地路径:").AppendLine(AppValues.LocalExcelFilePath);
                    infoStringBuilder.Append("SVN路径:").AppendLine(AppValues.SvnExcelFilePath);
                    infoStringBuilder.Append("本地版本号:").AppendLine(localFileRevision.ToString());
                    infoStringBuilder.Append("SVN版本号:").AppendLine(svnFileRevision.ToString());
                    infoStringBuilder.Append("SVN版本最后修改时间:").AppendLine(svnFileChangeTime.ToLocalTime().ToString());
                    infoStringBuilder.Append("SVN版本最后修改者:").AppendLine(svnFileChangeAuthor);
                    infoStringBuilder.Append("本地文件是否被打开:").AppendLine(fileState == FileState.IsOpen ? "是" : "否");
                    if (svnFileInfo.Lock != null)
                    {
                        infoStringBuilder.AppendLine("SVN中此文件是否被锁定:是");
                        infoStringBuilder.Append("锁定者:").AppendLine(svnFileInfo.Lock.Owner);
                        infoStringBuilder.Append("锁定时间:").AppendLine(svnFileInfo.Lock.CreationTime.ToLocalTime().ToString());
                        infoStringBuilder.Append("锁定原因:").AppendLine(svnFileInfo.Lock.Comment);
                    }
                    infoStringBuilder.Append("本地文件相较SVN中的状态:").Append(svnStatus.ToString()).Append("(").Append(OperateSvnHelper.GetSvnStatusDescription(svnStatus)).AppendLine(")");
                    infoStringBuilder.Append("本地文件是否是SVN中最新版本且本地内容未作修改:").AppendLine(localFileRevision == svnFileRevision && svnStatus == SvnStatus.Normal ? "是" : "否");

                    MessageBox.Show(infoStringBuilder.ToString(), "本地表状态信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(string.Concat("无法获取SVN中母表信息,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show(string.Concat("无法获取本地表状态,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
示例#15
0
        // 点击“检查本地表”按钮
        private void btnCheckLocalExcelFilePath_Click(object sender, EventArgs e)
        {
            string localExcelFilePath = txtLocalExcelFilePath.Text.Trim();

            if (string.IsNullOrEmpty(localExcelFilePath))
            {
                MessageBox.Show("请先输入或选择本机Working Copy中Excel母表所在路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            FileState fileState = Utils.GetFileState(localExcelFilePath);

            if (fileState == FileState.Inexist)
            {
                MessageBox.Show("输入的本机Working Copy中Excel母表所在路径不存在,建议点击\"选择\"按钮进行文件选择", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!AppValues.EXCEL_FILE_EXTENSION.Equals(Path.GetExtension(localExcelFilePath), StringComparison.CurrentCultureIgnoreCase))
            {
                MessageBox.Show(string.Format("本工具仅支持读取扩展名为{0}的Excel文件", AppValues.EXCEL_FILE_EXTENSION), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // 检查指定的本地表是否处于SVN管理下
            SvnException     svnException  = null;
            string           fileFullPath  = Path.GetFullPath(localExcelFilePath);
            SvnInfoEventArgs localFileInfo = OperateSvnHelper.GetLocalFileInfo(fileFullPath, out svnException);

            if (svnException == null)
            {
                // 判断该文件相较SVN中的状态
                SvnStatusEventArgs localFileState = OperateSvnHelper.GetLocalFileState(fileFullPath, out svnException);
                if (svnException == null)
                {
                    if (localFileState.LocalContentStatus == SvnStatus.Normal || localFileState.LocalContentStatus == SvnStatus.Modified)
                    {
                        _ChangeStateWhenSetLocalExcelPath(true);
                        txtCommentLineStartChar.Enabled = false;
                        // 读取设置的注释行开头字符
                        _SetCommentLineStartChar();
                        AppValues.LocalExcelFilePath = fileFullPath;
                        AppValues.SvnExcelFilePath   = localFileInfo.Uri.ToString();
                    }
                    else
                    {
                        MessageBox.Show(string.Format("本地表状态为{0},本工具仅支持Normal或Modified状态", localFileState.LocalContentStatus), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(string.Concat("无法获取本地表状态,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                if (svnException is SvnInvalidNodeKindException)
                {
                    MessageBox.Show("输入的本机Working Copy中Excel母表所在路径不在SVN管理下", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    MessageBox.Show(string.Concat("输入的本机Working Copy中Excel母表所在路径无效,错误原因为:", svnException.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
        }
示例#16
0
文件: SvnInfo.cs 项目: ainiaa/svn2svn
 private void OnInfo(object sender, SvnInfoEventArgs info)
 {
     _info = info;
     info.Detach();
 }