Exemplo n.º 1
0
        /// <summary>
        /// 签入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkInbtn_Click(object sender, EventArgs e)
        {
            if (tfsHelper != null)
            {
                List <FileInfo> fileInfos = TriStateTreeNodeHelper.GetTreeNodeChecked(this.updateTriSatateTreeView.Nodes);

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

                if (string.IsNullOrEmpty(this.remarktbx.Text))
                {
                    MessageBox.Show("请输入签入说明!");
                    return;
                }

                try
                {
                    foreach (var item in fileInfos)
                    {
                        JoeyLog.Logging.WriteLog("签入文件:" + item.FullName);
                    }
                    if (tfsHelper.CheckIn(fileInfos, this.remarktbx.Text) == false)
                    {
                        MessageBox.Show("有文件没有签入,请打开VS查看详情!");
                        return;
                    }
                    else
                    {
                        JoeyLog.Logging.WriteLog("签入成功!说明:" + this.remarktbx.Text);
                        MessageBox.Show("签入成功!");
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    JoeyLog.Logging.WriteErrorLog(ex);
                    MessageBox.Show("可能有冲突,请先撤销签出编辑,再复制编辑签入!");
                }
            }
        }
Exemplo n.º 2
0
        void CheckInScripts()
        {
            List <CheckInModel> errorlist   = new List <CheckInModel>();
            List <CheckInModel> successlist = new List <CheckInModel>();

            OpResult = new List <LogText>();
            bool vsucess = true;

            successlist = StoredProcedures;

            var bVersion = cbVersion.Checked;
            var bSingle  = cbSP.Checked;

            try
            {
                if (_username.Length > 0 && _password.Length > 0)
                {
                    TFSAuthModel auth = new TFSAuthModel()
                    {
                        Username = _username, Password = _password
                    };

                    if (successlist.Count > 0)
                    {
                        if (bVersion || bSingle)
                        {
                            // get latest project files
                            if (bVersion)
                            {
                                var res = TFSHelper.GetLatest(_path_version_tfs, auth);
                                AddConsoleText(res);
                                if (res.IsError)
                                {
                                    OpResult.Add(new LogText()
                                    {
                                        IsError = true,
                                        Output  = "Operation failed - Error occured while updating version scripts."
                                    });
                                    vsucess = false;
                                    MessageBox.Show("Error occured while updating version scripts", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                            }

                            if (bSingle)
                            {
                                var res = TFSHelper.GetLatest(_path_sp_tfs, auth);
                                AddConsoleText(res);
                                if (res.IsError)
                                {
                                    OpResult.Add(new LogText()
                                    {
                                        IsError = true,
                                        Output  = "Operation failed - Error occured while updating Stored Procedures."
                                    });
                                    MessageBox.Show("Error occured while updating Stored Procedures", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                            }



                            AddManualConsoleTest("Getting latest scripts successful....");

                            // end getting latest

                            //create files if not exists - version
                            bool vcreated = false;
                            if (bVersion)
                            {
                                string path = _path_version_local + "\\" + FileHelper.GenerateDateFile(ScriptDate);
                                if (!File.Exists(path))
                                {
                                    FileHelper.CreateFile(path);
                                    vcreated = true;
                                }
                            }

                            //create files if not exists - single
                            if (bSingle)
                            {
                                foreach (var sp in successlist)
                                {
                                    string path = _path_sp_local + "\\" + sp.Name + ".sql";
                                    if (!File.Exists(path))
                                    {
                                        FileHelper.CreateFile(path);
                                        sp.fCreated = true;
                                    }
                                }
                            }

                            //checkout files for edit
                            if (bVersion)
                            {
                                if (!vcreated)
                                {
                                    string path = _path_version_tfs + "\\" + FileHelper.GenerateDateFile(ScriptDate);
                                    var    res  = TFSHelper.Checkout(path, auth);
                                    AddConsoleText(res);
                                    if (res != null && res.IsError)
                                    {
                                        OpResult.Add(new LogText()
                                        {
                                            IsError = true,
                                            Output  = "Version Script(" + FileHelper.GenerateDateFile(ScriptDate) + ") - Failed."
                                        });
                                        vsucess = false;
                                    }
                                }
                            }

                            if (bSingle)
                            {
                                foreach (var sp in successlist)
                                {
                                    string path = _path_sp_tfs + "\\" + sp.Name + ".sql";
                                    if (!sp.fCreated)
                                    {
                                        var res = TFSHelper.Checkout(path, auth);
                                        AddConsoleText(res);
                                        if (res.IsError)
                                        {
                                            sp.IsError = true;
                                            errorlist.Add(sp);
                                        }
                                    }
                                }

                                foreach (var ersp in errorlist)
                                {
                                    var sp = successlist.Where(x => x.ID == ersp.ID).SingleOrDefault();
                                    if (sp != null)
                                    {
                                        successlist.Remove(sp);
                                    }
                                }
                            }


                            //add new files to tfs
                            //version script
                            if (bVersion)
                            {
                                if (vcreated)
                                {
                                    var res = TFSHelper.AddFile(_path_version_local, FileHelper.GenerateDateFile(ScriptDate), auth);
                                    AddConsoleText(res);
                                }
                            }

                            if (bSingle)
                            {
                                foreach (var sp in successlist)
                                {
                                    string name = sp.Name + ".sql";
                                    if (sp.fCreated)
                                    {
                                        var res = TFSHelper.AddFile(_path_sp_local, name, auth);
                                        AddConsoleText(res);
                                    }
                                }
                            }


                            //update scripts text
                            if (bVersion)
                            {
                                if (vcreated)
                                {
                                    string path = _path_version_local + "\\" + FileHelper.GenerateDateFile(ScriptDate);
                                    FileHelper.UpdateFileText(path, new ScriptHelper().GenerateVersionScript(successlist.Select(x => x.Name).ToList()));
                                }
                                else
                                {
                                    string path    = _path_version_local + "\\" + FileHelper.GenerateDateFile(ScriptDate);
                                    string vscript = FileHelper.ReadFile(path);
                                    StoredProcedureBusiness spData = new StoredProcedureBusiness();
                                    foreach (var s in successlist)
                                    {
                                        string script = new ScriptHelper().GenerateIndividualScript(s.Name, spData.GetScript(null, s.Name).Trim(), true);
                                        vscript = ReplaceScript(vscript, script, s.Name);
                                    }
                                    FileHelper.UpdateFileText(path, vscript);
                                }
                            }

                            //update single scripts
                            if (bSingle)
                            {
                                StoredProcedureBusiness spData = new StoredProcedureBusiness();
                                foreach (var sp in successlist)
                                {
                                    string script = new ScriptHelper().GenerateIndividualScript(sp.Name, spData.GetScript(null, sp.Name).Trim(), false);
                                    string path   = _path_sp_local + "\\" + sp.Name + ".sql";
                                    FileHelper.UpdateFileText(path, script);
                                }
                            }


                            //checkin pending changes
                            string comment = "";
                            if (txtComment.Text.Trim().Length > 0)
                            {
                                comment = txtComment.Text.Trim();
                            }
                            else
                            {
                                comment = "Script Changes";
                            }
                            var checkinres = TFSHelper.CheckIn(comment, auth);
                            AddConsoleText(checkinres);
                            AddManualConsoleTest("Operation completed successfuly");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                GenerateLog(successlist, errorlist, vsucess, bVersion);
            }
        }