Пример #1
0
    /// <summary>
    /// 获取本地Working Copy中某个文件的状态
    /// </summary>
    public static SvnStatusEventArgs GetLocalFileState(string localPath, out SvnException svnException)
    {
        Collection <SvnStatusEventArgs> status = new Collection <SvnStatusEventArgs>();
        SvnStatusArgs statusArgs = new SvnStatusArgs();

        statusArgs.RetrieveAllEntries = true;

        try
        {
            _svnClient.GetStatus(localPath, statusArgs, out status);
            if (status.Count > 0)
            {
                svnException = null;
                return(status[0]);
            }
            else
            {
                svnException = new SvnException("未知原因导致无法读取本地文件信息");
                return(null);
            }
        }
        catch (SvnException exception)
        {
            svnException = exception;
            return(null);
        }
    }
		private static void HandleConnectionError(SvnException e, PluginProfileErrorCollection errors)
		{
			if (e is SvnAuthorizationException)
			{
				errors.Add(ErrorFor(ConnectionSettings.LoginField, "Authorization failed"));
				errors.Add(ErrorFor(ConnectionSettings.PasswordField));
			}
			else if (e is SvnAuthenticationException || e.RootCause is SvnAuthenticationException)
			{
				errors.Add(ErrorFor(ConnectionSettings.LoginField, "Authentication failed"));
				errors.Add(ErrorFor(ConnectionSettings.PasswordField));
			}
			else if (e.Message.Contains("200 OK"))
			{
				errors.Add(ErrorFor(ConnectionSettings.UriField, "Invalid path to repository"));
			}
			else if (e is SvnRepositoryIOException)
			{
				errors.Add(ErrorFor(ConnectionSettings.UriField, "Could not connect to server"));
			}
			else if (e is SvnFileSystemException || e is SvnClientUnrelatedResourcesException)
			{
				errors.Add(ErrorFor(SubversionPluginProfile.StartRevisionField));
			}
			else
			{
				errors.Add(ErrorFor(ConnectionSettings.UriField, e.Message.Fmt("Connection failed. {0}")));
			}
		}
Пример #3
0
        static IntPtr _libsvnsharp_cancel_func(IntPtr cancelBaton)
        {
            var client = AprBaton <SvnClientContext> .Get(cancelBaton);

            SvnCancelEventArgs ea = new SvnCancelEventArgs();

            try
            {
                client.HandleClientCancel(ea);

                if (ea.Cancel)
                {
                    return(svn_error.svn_error_create(
                               (int)SvnErrorCode.SVN_ERR_CANCELLED,
                               null,
                               "Operation canceled from OnCancel").__Instance);
                }

                return(IntPtr.Zero);
            }
            catch (Exception e)
            {
                return(SvnException.CreateExceptionSvnError("Cancel function", e).__Instance);
            }
            finally
            {
                ea.Detach(false);
            }
        }
Пример #4
0
        /// <summary>
        /// Adds all files which are marked as to be added to subversion
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        private bool PreCommit_AddNewFiles(PendingCommitState state)
        {
            Queue <string> toAdd = new Queue <string>();

            foreach (PendingChange pc in state.Changes)
            {
                if (pc.Change != null &&
                    (pc.Change.State == PendingChangeKind.New ||
                     pc.Change.State == PendingChangeKind.DeletedNew))
                {
                    SvnItem item = pc.SvnItem;

                    // HACK: figure out why PendingChangeKind.New is still true
                    if (item.IsVersioned && !item.IsDeleteScheduled)
                    {
                        continue; // No need to add
                    }
                    toAdd.Enqueue(item.FullPath);
                }
            }
            while (toAdd.Count > 0)
            {
                SvnException error = null;

                state.GetService <IProgressRunner>().RunModal(PccStrings.AddingTitle,
                                                              delegate(object sender, ProgressWorkerArgs e)
                {
                    SvnAddArgs aa   = new SvnAddArgs();
                    aa.AddParents   = true;
                    aa.Depth        = SvnDepth.Empty;
                    aa.ThrowOnError = false;

                    while (toAdd.Count > 0)
                    {
                        if (!e.Client.Add(toAdd.Dequeue(), aa))
                        {
                            error = aa.LastException;
                            break;
                        }
                    }
                });

                if (error != null)
                {
                    if (error.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_UNSUPPORTED_FORMAT)
                    {
                        state.MessageBox.Show(error.Message + Environment.NewLine + Environment.NewLine
                                              + PccStrings.YouCanDownloadAnkh, "", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return(false);
                    }
                    else if (state.MessageBox.Show(error.Message, "", MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Error) != DialogResult.OK)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #5
0
        static unsafe IntPtr _svn_wc_conflict_resolver_func(
            void **resultPtr, IntPtr descriptionPtr, IntPtr baton, IntPtr resultPoolPtr, IntPtr scratchPoolPtr)
        {
            var client = AprBaton <SvnClient> .Get(baton);

            var conflictResult = svn_wc.svn_wc_create_conflict_result(
                svn_wc_conflict_choice_t.svn_wc_conflict_choose_postpone,
                null,
                apr_pool_t.__CreateInstance(resultPoolPtr));

            *resultPtr = conflictResult.__Instance.ToPointer();

            var resultPool  = new AprPool(resultPoolPtr, false);  // Connect to parent pool
            var scratchPool = new AprPool(scratchPoolPtr, false); // Connect to parent pool

            var description = svn_wc_conflict_description2_t.__CreateInstance(descriptionPtr);

            var ea = new SvnConflictEventArgs(description, scratchPool);

            try
            {
                client.HandleClientConflict(ea);

                if (ea.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Operation canceled from OnConflict").__Instance);
                }

                conflictResult.choice = (svn_wc_conflict_choice_t)ea.Choice;

                if (ea.Choice == SvnAccept.Merged)
                {
                    if (ea.MergedValue != null)
                    {
                        conflictResult.merged_value = resultPool.AllocSvnString(ea.MergedValue);
                    }
                    if (ea.MergedFile != null)
                    {
                        conflictResult.merged_file = resultPool.AllocAbsoluteDirent(ea.MergedFile);
                    }
                }

                return(IntPtr.Zero);
            }
            catch (Exception e)
            {
                return(SvnException.CreateExceptionSvnError("Conflict resolver", e).__Instance);
            }
            finally
            {
                ea.Detach(false);

                scratchPool.Dispose();
                resultPool.Dispose();
            }
        }
Пример #6
0
        static unsafe /*svn_error_t*/ IntPtr _svn_auth_ssl_server_trust_prompt_func(
            /*out svn_auth_cred_ssl_server_trust_t*/ void **ppCred, IntPtr baton, sbyte *realm, uint failures, /*svn_auth_ssl_server_cert_info_t*/ IntPtr certInfo, int maySave, /*apr_pool_t*/ IntPtr pool)
        {
            var wrapper = AprBaton <SvnAuthWrapper <SvnSslServerTrustEventArgs> > .Get(baton);

            var certInfoT = svn_auth_ssl_server_cert_info_t.__CreateInstance(certInfo);

            var args = new SvnSslServerTrustEventArgs(
                (SvnCertificateTrustFailures)failures,
                SvnBase.Utf8_PtrToString(certInfoT.hostname),
                SvnBase.Utf8_PtrToString(certInfoT.fingerprint),
                SvnBase.Utf8_PtrToString(certInfoT.valid_from),
                SvnBase.Utf8_PtrToString(certInfoT.valid_until),
                SvnBase.Utf8_PtrToString(certInfoT.issuer_dname),
                SvnBase.Utf8_PtrToString(certInfoT.ascii_cert),
                SvnBase.Utf8_PtrToString(realm), maySave != 0);

            var cred = (svn_auth_cred_ssl_server_trust_t.__Internal * *)ppCred;

            using (var tmpPool = new AprPool(pool, false))
            {
                *cred = null;
                try
                {
                    wrapper.Raise(args);
                }
                catch (Exception e)
                {
                    return(SvnException.CreateExceptionSvnError("Authorization handler", e).__Instance);
                }

                if (args.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Authorization canceled operation").__Instance);
                }
                if (args.Break)
                {
                    return(IntPtr.Zero);
                }

                if (args.AcceptedFailures != SvnCertificateTrustFailures.None)
                {
                    *cred = (svn_auth_cred_ssl_server_trust_t.__Internal *)tmpPool.AllocCleared(
                        sizeof(svn_auth_cred_ssl_server_trust_t.__Internal));

                    (*cred)->accepted_failures = (uint)args.AcceptedFailures;
                    (*cred)->may_save          = args.Save ? 1 : 0;
                }
            }

            return(IntPtr.Zero);
        }
Пример #7
0
        public unsafe ArgsStore(SvnClientContext client, SvnClientArgs args, AprPool pool)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            if (client._currentArgs != null)
            {
                throw new InvalidOperationException(SharpSvnStrings.SvnClientOperationInProgress);
            }

            args.Prepare();
            client._currentArgs = args;
            _client             = client;

            var ctx = _client.CtxHandle;

            _wcCtx = ctx.wc_ctx;

            {
                svn_client__private_ctx_t pctx = libsvnsharp_client.svn_client__get_private_ctx(ctx);
                pctx.total_progress = 0;
            }

            _lastContext = SvnClientContext._activeContext;
            SvnClientContext._activeContext = _client;

            try
            {
                if (!client.KeepSession && pool != null)
                {
                    svn_wc_context_t.__Internal *p_wc_ctx = null;

                    var error = svn_wc.svn_wc_context_create((void **)&p_wc_ctx, null, pool.Handle, pool.Handle);
                    if (error != null)
                    {
                        throw SvnException.Create(error);
                    }

                    ctx.wc_ctx = svn_wc_context_t.__CreateInstance(new IntPtr(p_wc_ctx));
                }

                client.HandleProcessing(new SvnProcessingEventArgs(args.CommandType));
            }
            catch (Exception)
            {
                client._currentArgs             = null;
                SvnClientContext._activeContext = _lastContext;
                throw;
            }
        }
Пример #8
0
 /// <summary>
 /// 执行SVN的Update操作
 /// </summary>
 public static bool Update(string localPath, out SvnException svnException)
 {
     try
     {
         bool result = _svnClient.Update(localPath);
         svnException = null;
         return(result);
     }
     catch (SvnException exception)
     {
         svnException = exception;
         return(false);
     }
 }
Пример #9
0
        private void backgroundWorkerCheckOut_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                ListBox myListBox = listBoxProjectList as ListBox;

                if (e.Error != null)
                {
                    ModernDialog.ShowMessage(e.Error.Message, "Error Checking out Components", MessageBoxButton.OK);
                    if (e.Error is SvnException)
                    {
                        SvnException svnEx = e.Error as SvnException;
                        logger.Error(svnEx, string.Format("Error Checking out Components SvnErrorCode = {0} ", svnEx.SvnErrorCode));
                    }
                    else
                    {
                        logger.Error(e.Error, "Error Checking out Components");
                    }
                }
                else
                {
                    if (e.Result != null)
                    {
                        if (e.Result is List <SvnListEventArgs> )
                        {
                            this.LoadProjectList(e.Result as List <SvnListEventArgs>);
                            this.Log("Every thing is loaded now.", checkBoxShowMoreInfor.IsChecked.Value);
                        }
                        else
                        {
                            this._checkoutStopwatch.Stop();

                            this.Log("Finished. [" + DateTime.Now.ToString() + "] Time it took: [" + this._checkoutStopwatch.Elapsed + "]", false);
                            this.ValidateWorkSpacePath();
                        }
                    }
                }
                this.ButtonState = ButtonState.CheckOut;
            }
            catch (Exception ex)
            {
                ModernDialog.ShowMessage(ex.Message, "Error backgroundWorker issue", MessageBoxButton.OK);
            }
            finally
            {
                progressBarMain.Visibility = System.Windows.Visibility.Hidden;
                this._cancelCheckout       = false;
                Mouse.OverrideCursor       = null;
            }
        }
Пример #10
0
        static unsafe IntPtr _libsvnsharp_commit_log_func(
            sbyte **logMsg, sbyte **tmpFile, IntPtr commitItemsPtr, IntPtr baton, IntPtr pool)
        {
            var client = AprBaton <SvnClientContext> .Get(baton);

            var tmpPool = new AprPool(pool, false);

            var commit_items = apr_array_header_t.__CreateInstance(commitItemsPtr);

            var ea = new SvnCommittingEventArgs(commit_items, client.CurrentCommandArgs.CommandType, tmpPool);

            *logMsg  = null;
            *tmpFile = null;

            try
            {
                client.HandleClientCommitting(ea);

                if (ea.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Operation canceled from OnCommitting").__Instance);
                }
                else if (ea.LogMessage != null)
                {
                    *logMsg = tmpPool.AllocUnixString(ea.LogMessage);
                }
                else if (!client._noLogMessageRequired)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Commit canceled: A logmessage is required").__Instance);
                }
                else
                {
                    *logMsg = tmpPool.AllocString("");
                }

                return(IntPtr.Zero);
            }
            catch (Exception e)
            {
                return(SvnException.CreateExceptionSvnError("Commit log", e).__Instance);
            }
            finally
            {
                ea.Detach(false);

                tmpPool.Dispose();
            }
        }
Пример #11
0
 /// <summary>
 /// 执行SVN的Commit操作
 /// </summary>
 public static bool Commit(string localFilePath, string logMessage, out SvnException svnException)
 {
     try
     {
         SvnCommitArgs commitArgs = new SvnCommitArgs();
         commitArgs.LogMessage = logMessage;
         bool result = _svnClient.Commit(localFilePath, commitArgs);
         svnException = null;
         return(result);
     }
     catch (SvnException exception)
     {
         svnException = exception;
         return(false);
     }
 }
Пример #12
0
    /// <summary>
    /// 获取SVN中某个文件的信息
    /// </summary>
    public static SvnInfoEventArgs GetSvnFileInfo(string svnPath, out SvnException svnException)
    {
        SvnInfoEventArgs svnFileInfo;
        SvnUriTarget     svnUriTarger = new SvnUriTarget(svnPath);

        try
        {
            _svnClient.GetInfo(svnPath, out svnFileInfo);
            svnException = null;
            return(svnFileInfo);
        }
        catch (SvnException exception)
        {
            svnException = exception;
            return(null);
        }
    }
Пример #13
0
    /// <summary>
    /// 获取本地Working Copy中某个文件的信息
    /// </summary>
    public static SvnInfoEventArgs GetLocalFileInfo(string localPath, out SvnException svnException)
    {
        SvnInfoEventArgs localFileInfo;
        SvnPathTarget    localPathTarget = new SvnPathTarget(localPath);

        try
        {
            _svnClient.GetInfo(localPathTarget, out localFileInfo);
            svnException = null;
            return(localFileInfo);
        }
        catch (SvnException exception)
        {
            svnException = exception;
            return(null);
        }
    }
Пример #14
0
 public static void HandleSourceSVNException(Source source, SvnException svnex)
 {
     if (source != null)
     {
         string message = string.Format("{0}: {1}", source.Name, svnex.Message);
         Logger.Log.Error(message);
         if (source.IsAlive)
         {
             long errorID = Append(message, source, svnex);
             source.SetError(message, errorID);
         }
     }
     else
     {
         Logger.Log.Error(svnex.ToString());
     }
 }
Пример #15
0
        static unsafe IntPtr svnStreamSeek(IntPtr baton, IntPtr mark)
        {
            SvnStreamWrapper sw = AprBaton <SvnStreamWrapper> .Get(baton);

            long newPos = 0;

            if (mark != IntPtr.Zero)
            {
                newPos = *(long *)mark.ToPointer();
            }

            try
            {
                sw.Stream.Position = newPos;
            }
            catch (Exception ex)
            {
                return(SvnException.CreateExceptionSvnError("Seek stream", ex).__Instance);
            }

            return(IntPtr.Zero);
        }
Пример #16
0
        static string ErrorToString(SvnException ex)
        {
            if (Enum.IsDefined(typeof(SvnErrorCode), ex.SvnErrorCode))
            {
                return(ex.SvnErrorCode.ToString());
            }
            else if (Enum.IsDefined(typeof(SvnAprErrorCode), ex.AprErrorCode))
            {
                return(ex.AprErrorCode.ToString());
            }
            else if (ex.SvnErrorCategory == SvnErrorCategory.OperatingSystem)
            {
                if (Enum.IsDefined(typeof(SvnWindowsErrorCode), ex.WindowsErrorCode))
                {
                    return(ex.WindowsErrorCode.ToString());
                }
                //
                int num = (int)ex.WindowsErrorCode;

                if ((num & 0x80000000) == 0)
                {
                    num = unchecked ((int)(((uint)num & 0xFFFF) | 0x80070000));
                }

                Exception sysEx = Marshal.GetExceptionForHR(num);

                if (sysEx != null)
                {
                    return(string.Format("OS:{0}/{1}", sysEx.GetType().Name, ex.WindowsErrorCode));
                }
            }
            else if (ex.SvnErrorCategory > SvnErrorCategory.None &&
                     Enum.IsDefined(typeof(SvnErrorCategory), ex.SvnErrorCategory))
            {
                return(string.Format("{0}:{1}", ex.SvnErrorCategory, ex.SvnErrorCode));
            }

            return(((int)ex.SvnErrorCode).ToString());
        }
Пример #17
0
        static unsafe /*svn_error_t*/ IntPtr _svn_auth_simple_prompt_func(
            /*out svn_auth_cred_simple_t*/ void **credPtr, IntPtr baton, sbyte *realm, sbyte *username, int maySave, /*apr_pool_t*/ IntPtr pool)
        {
            var wrapper = AprBaton <SvnAuthWrapper <SvnUserNamePasswordEventArgs> > .Get(baton);

            var args = new SvnUserNamePasswordEventArgs(SvnBase.Utf8_PtrToString(username), SvnBase.Utf8_PtrToString(realm), maySave != 0);

            var cred = (svn_auth_cred_simple_t.__Internal * *)credPtr;

            using (var tmpPool = new AprPool(pool, false))
            {
                *cred = null;
                try
                {
                    wrapper.Raise(args);
                }
                catch (Exception e)
                {
                    return(SvnException.CreateExceptionSvnError("Authorization handler", e).__Instance);
                }

                if (args.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Authorization canceled operation").__Instance);
                }
                if (args.Break)
                {
                    return(IntPtr.Zero);
                }

                *cred = (svn_auth_cred_simple_t.__Internal *)tmpPool.AllocCleared(sizeof(svn_auth_cred_simple_t.__Internal));

                (*cred)->username = new IntPtr(tmpPool.AllocString(args.UserName));
                (*cred)->password = new IntPtr(tmpPool.AllocString(args.Password));
                (*cred)->may_save = args.Save ? 1 : 0;
            }

            return(IntPtr.Zero);
        }
Пример #18
0
        static IntPtr the_commit_callback2(IntPtr commit_info_ptr, IntPtr baton, IntPtr pool)
        {
            var tmpPool  = new AprPool(pool, false);
            var receiver = AprBaton <CommitResultReceiver> .Get(baton);

            try
            {
                var commit_info = svn_commit_info_t.__CreateInstance(commit_info_ptr);

                receiver.ProvideCommitResult(commit_info, tmpPool);

                return(IntPtr.Zero);
            }
            catch (Exception e)
            {
                return(SvnException.CreateExceptionSvnError("CommitResult function", e).__Instance);
            }
            finally
            {
                tmpPool.Dispose();
            }
        }
Пример #19
0
        public unsafe NoArgsStore(SvnClientContext client, AprPool pool)
        {
            if (client._currentArgs != null)
            {
                throw new InvalidOperationException(SharpSvnStrings.SvnClientOperationInProgress);
            }

            _client = client;

            var ctx = _client.CtxHandle;

            _wcCtx = ctx.wc_ctx;

            _lastContext = SvnClientContext._activeContext;
            SvnClientContext._activeContext = _client;

            try
            {
                if (!client.KeepSession && pool != null)
                {
                    svn_wc_context_t.__Internal *p_wc_ctx = null;

                    var error = svn_wc.svn_wc_context_create((void **)&p_wc_ctx, null, pool.Handle, pool.Handle);
                    if (error != null)
                    {
                        throw SvnException.Create(error);
                    }

                    ctx.wc_ctx = svn_wc_context_t.__CreateInstance(new IntPtr(p_wc_ctx));
                }
            }
            catch (Exception)
            {
                SvnClientContext._activeContext = _lastContext;
                throw;
            }
        }
 private static void HandleConnectionError(SvnException e, PluginProfileErrorCollection errors)
 {
     if (e is SvnAuthorizationException)
     {
         errors.Add(ErrorFor(ConnectionSettings.LoginField, "Authorization failed"));
         errors.Add(ErrorFor(ConnectionSettings.PasswordField));
     }
     else if (e.Message.Contains("200 OK"))
     {
         errors.Add(ErrorFor(ConnectionSettings.UriField, "Invalid path to repository"));
     }
     else if (e is SvnRepositoryIOException)
     {
         errors.Add(ErrorFor(ConnectionSettings.UriField, "Could not connect to server"));
     }
     else if (e is SvnFileSystemException || e is SvnClientUnrelatedResourcesException)
     {
         errors.Add(ErrorFor(SubversionPluginProfile.StartRevisionField));
     }
     else
     {
         errors.Add(ErrorFor(ConnectionSettings.UriField, e.Message.Fmt("Connection failed. {0}")));
     }
 }
Пример #21
0
		internal SvnClientException(SvnException ex) : base(ex.Message, ex)
		{
			this.errorCode = ex.SvnErrorCode;
			LoggingService.Debug(ex);
		}
Пример #22
0
        static string ErrorToString(SvnException ex)
        {
            if (Enum.IsDefined(typeof(SvnErrorCode), ex.SvnErrorCode))
                return ex.SvnErrorCode.ToString();
            else if (Enum.IsDefined(typeof(SvnAprErrorCode), ex.AprErrorCode))
                return ex.AprErrorCode.ToString();
            else if (ex.SvnErrorCategory == SvnErrorCategory.OperatingSystem)
            {
                if (Enum.IsDefined(typeof(SvnWindowsErrorCode), ex.WindowsErrorCode))
                    return ex.WindowsErrorCode.ToString();
                //
                int num = (int)ex.WindowsErrorCode;

                if ((num & 0x80000000) == 0)
                {
                    num = unchecked((int)(((uint)num & 0xFFFF) | 0x80070000));
                }

                Exception sysEx = Marshal.GetExceptionForHR(num);

                if (sysEx != null)
                    return string.Format("OS:{0}/{1}", sysEx.GetType().Name, ex.WindowsErrorCode);
            }
            else if (ex.SvnErrorCategory > SvnErrorCategory.None
                     && Enum.IsDefined(typeof(SvnErrorCategory), ex.SvnErrorCategory))
                return string.Format("{0}:{1}", ex.SvnErrorCategory, ex.SvnErrorCode);

            return ((int)ex.SvnErrorCode).ToString();
        }
Пример #23
0
 internal SvnClientException(SvnException ex) : base(ex.Message, ex)
 {
     this.errorCode = ex.SvnErrorCode;
     LoggingService.Debug(ex);
 }
        // 点击“提交”按钮
        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;
            }
        }
Пример #25
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;
            }
        }
Пример #26
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;
                }
            }
        }
Пример #27
0
        private void ShowErrorDialog(Exception ex, bool showStackTrace, bool internalError, ExceptionInfo info)
        {
            string stackTrace = ex.ToString();
            string message    = GetNestedMessages(ex);

            System.Collections.Specialized.StringDictionary additionalInfo =
                new System.Collections.Specialized.StringDictionary();

            IAnkhSolutionSettings ss = GetService <IAnkhSolutionSettings>();

            if (ss != null)
            {
                additionalInfo.Add("VS-Version", VSVersion.FullVersion.ToString());
            }

            if (info != null && info.CommandArgs != null)
            {
                additionalInfo.Add("Command", info.CommandArgs.Command.ToString());
            }

            IAnkhPackage pkg = GetService <IAnkhPackage>();

            if (pkg != null)
            {
                additionalInfo.Add("Ankh-Version", pkg.UIVersion.ToString());
            }

            additionalInfo.Add("SharpSvn-Version", SharpSvn.SvnClient.SharpSvnVersion.ToString());
            additionalInfo.Add("Svn-Version", SharpSvn.SvnClient.Version.ToString());
            additionalInfo.Add("OS-Version", Environment.OSVersion.Version.ToString());

            using (ErrorDialog dlg = new ErrorDialog())
            {
                dlg.ErrorMessage   = message;
                dlg.ShowStackTrace = showStackTrace;
                dlg.StackTrace     = stackTrace;
                dlg.InternalError  = internalError;

                if (dlg.ShowDialog(Context) == DialogResult.Retry)
                {
                    string subject = _errorReportSubject;

                    if (info != null && info.CommandArgs != null)
                    {
                        subject = string.Format("Error handling {0}", info.CommandArgs.Command);
                    }

                    SvnException sx = ex as SvnException;
                    SvnException ix;

                    while (sx != null &&
                           sx.SvnErrorCode == SvnErrorCode.SVN_ERR_BASE &&
                           (null != (ix = sx.InnerException as SvnException)))
                    {
                        sx = ix;
                    }

                    if (sx != null)
                    {
                        SvnException rc = sx.RootCause as SvnException;
                        if (rc == null || rc.SvnErrorCode == sx.SvnErrorCode)
                        {
                            subject += " (" + ErrorToString(sx) + ")";
                        }
                        else
                        {
                            subject += " (" + ErrorToString(sx) + "-" + ErrorToString(rc) + ")";
                        }
                    }

                    AnkhErrorMessage.SendByMail(_errorReportMailAddress,
                                                subject, ex, typeof(AnkhErrorHandler).Assembly, additionalInfo);
                }
            }
        }
Пример #28
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;
            }
        }
Пример #29
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;
            }
        }
Пример #30
0
 public static void ShowSvnException(string path, SvnException svnException)
 {
     UseRedColor();
     Console.WriteLine($"Error: {svnException.SvnErrorCode}, SharpSvn error on: {path}, {svnException.RootCause.Message}. {svnException}.");
     RestoreColor();
 }
Пример #31
0
        internal static void EnsureLoaded()
        {
            if (Interlocked.CompareExchange(ref _ensurer, 1, 0) < 2)
            {
                lock (_ensurerLock)
                {
                    if (!_aprInitialized)
                    {
                        _aprInitialized = true;

                        if (apr_general.apr_initialize() != 0) // First
                        {
                            throw new InvalidOperationException();
                        }

                        var error = svn_dso.svn_dso_initialize2(); // Before first pool
                        if (error != null)
                        {
                            throw SvnException.Create(error);
                        }

                        var pool = svn_pools.svn_pool_create(null);

                        var allocator = apr_pools.apr_pool_allocator_get(pool);

                        if (allocator != null)
                        {
                            apr_allocator.apr_allocator_max_free_set(allocator, 1); // Keep a maximum of 1 free block
                        }
                        svn_utf.svn_utf_initialize2(true, pool);
                        {
                            var settings = svn_cache_config.svn_cache_config_get();
                            settings.cache_size        = 0;
                            settings.file_handle_count = 0;
                            settings.single_threaded   = false;
                            svn_cache_config.svn_cache_config_set(settings);
                        }

                        if (Environment.GetEnvironmentVariable("SVN_ASP_DOT_NET_HACK") != null)
                        {
                            svn_wc.svn_wc_set_adm_dir("_svn", pool);
                        }

                        error = svn_ra.svn_ra_initialize(pool);
                        if (error != null)
                        {
                            throw SvnException.Create(error);
                        }

                        _admDir = svn_wc.svn_wc_get_adm_dir(pool);

                        InstallAbortHandler();
                        //InstallSslDialogHandler();

                        //int r = libssh2_init(0);
                        //if (r != 0)
                        //    throw new InvalidOperationException("Can't initialize libssh2");

                        var v = Interlocked.Exchange(ref _ensurer, 2);

                        System.Diagnostics.Debug.Assert(v == 1);
                    }
                }
            }
        }