Esempio n. 1
0
        /// <summary>
        /// 复制更新文件并签出编辑
        /// </summary>
        private bool CopyUpdateFile(TFSHelper tfsHelper)
        {
            //复制文件
            List <FileInfo> removeFiles      = new List <FileInfo>();
            List <FileInfo> undoFiles        = new List <FileInfo>();
            decimal         progressAddValue = 10M / this._updateFiles.Count;

            foreach (var updateFile in this._updateFiles)
            {
                progressValue += progressAddValue;
                this.worker.ReportProgress((int)progressValue, "开始复制文件" + updateFile.Name + ",请稍后.....");
                var directoryName = updateFile.DirectoryName.Replace(rootProductPath + "\\", "");
                if (directoryName.Contains(rootProductPath))
                {
                    directoryName = updateFile.DirectoryName.Replace(rootProductPath, "");
                }
                var fileName = Path.Combine(customizePath, directoryName, updateFile.Name);

                if (File.Exists(fileName))
                {
                    FileInfo fi = new FileInfo(fileName);
                    //修改文件只读
                    if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        fi.Attributes = FileAttributes.Normal;
                    }
                    //如果相同文件没有修改过
                    if (MD5Helper.CompareFile(updateFile.FullName, fileName) && _addFiles.FirstOrDefault(n => n == updateFile) == null)
                    {
                        removeFiles.Add(updateFile);
                        //撤销签出编辑
                        undoFiles.Add(new FileInfo(fileName));
                        JoeyLog.Logging.WriteLog("撤销签出编辑文件:" + fileName);
                        continue;
                    }
                }
                try
                {
                    File.Copy(updateFile.FullName, fileName, true);
                    JoeyLog.Logging.WriteLog("复制编辑签出文件:" + fileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    return(false);
                }
            }
            if (undoFiles.Count > 0)
            {
                tfsHelper.Undo(undoFiles);
                foreach (var item in removeFiles)
                {
                    this._updateFiles.Remove(item);
                }
            }
            this.worker.ReportProgress(100, "完成");
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 撤销挂起的更改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void undobtn_Click(object sender, EventArgs e)
        {
            if (tfsHelper != null)
            {
                List <FileInfo> fileInfos = TriStateTreeNodeHelper.GetTreeNodeChecked(this.updateTriSatateTreeView.Nodes);

                if (fileInfos.Count == 0)
                {
                    MessageBox.Show("没有要撤销的文件!");
                    return;
                }

                try
                {
                    foreach (var item in fileInfos)
                    {
                        JoeyLog.Logging.WriteLog("撤销文件:" + item.FullName);
                    }
                    List <string> addPendingChangesFilePaths = tfsHelper.GetAddPendingChanges();

                    if (tfsHelper.Undo(fileInfos) == false)
                    {
                        MessageBox.Show("有文件没有撤销,请打开VS查看详情!");
                        return;
                    }
                    else
                    {
                        foreach (var filePath in addPendingChangesFilePaths)
                        {
                            if (File.Exists(filePath))
                            {
                                File.Delete(filePath);
                                JoeyLog.Logging.WriteLog("删除新增才文件:" + filePath);
                            }
                        }
                        JoeyLog.Logging.WriteLog("撤销成功!");
                        MessageBox.Show("撤销成功!");
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    JoeyLog.Logging.WriteErrorLog(ex);
                    MessageBox.Show("可能有冲突,请打开VS解决冲突!");
                }
            }
        }