예제 #1
0
        /// <summary>
        ///     Writes all text.
        /// </summary>
        public void WriteAllText_old(string path, string content)
        {
            if (IntegrateWithTFS == false && IntegrateWithTFSAndCheckInAutomatically == false)
            {
                FileHelper.WriteAllText(path, content);
                return;
            }

            FileAccessWriteResult fileAccessWriteResult = null;

            if (IntegrateWithTFSAndCheckInAutomatically)
            {
                var fileAccessWithAutoCheckIn = new FileAccessWithAutoCheckIn {
                    CheckInComment = CheckinComment
                };

                fileAccessWriteResult = fileAccessWithAutoCheckIn.WriteAllText(path, content);
            }
            else
            {
                var fileAccess = new FileAccess();

                fileAccessWriteResult = fileAccess.WriteAllText(path, content);
            }

            if (fileAccessWriteResult.Exception != null)
            {
                throw fileAccessWriteResult.Exception;
            }
        }
예제 #2
0
        public void WriteAllText(string path, string content)
        {
            const int tryCount  = 5;
            const int sleepTime = 2000;

            if (IntegrateWithTFS == false && IntegrateWithTFSAndCheckInAutomatically == false)
            {
                FileHelper.WriteAllText(path, content);
                return;
            }

            var i = 0;

            while (true)
            {
                FileAccessWriteResult fileAccessWriteResult = null;

                if (IntegrateWithTFSAndCheckInAutomatically)
                {
                    var fileAccessWithAutoCheckIn = new FileAccessWithAutoCheckIn {
                        CheckInComment = CheckinComment
                    };

                    try
                    {
                        fileAccessWriteResult = fileAccessWithAutoCheckIn.WriteAllText(path, content);
                    }
                    catch (Exception e)
                    {
                        if (i <= tryCount)
                        {
                            Task.Delay(sleepTime);
                            i++;
                            continue;
                        }

                        OnErrorOccured(new IOException(Path.GetFileName(path), e));
                        return;
                    }
                }
                else
                {
                    var fileAccess = new FileAccess();

                    try
                    {
                        fileAccessWriteResult = fileAccess.WriteAllText(path, content);
                    }
                    catch (Exception e)
                    {
                        if (i <= tryCount)
                        {
                            Task.Delay(sleepTime);
                            i++;
                            continue;
                        }

                        OnErrorOccured(new IOException(Path.GetFileName(path), e));
                        return;
                    }
                }

                if (fileAccessWriteResult.Exception == null)
                {
                    return;
                }

                if (i <= tryCount)
                {
                    Task.Delay(sleepTime);
                    i++;
                    continue;
                }

                OnErrorOccured(new IOException(Path.GetFileName(path), fileAccessWriteResult.Exception));
                return;
            }
        }