Exemple #1
0
        public ActionResult GetCheckListCode()
        {
            var         version     = PressRequest.GetQueryInt("v");
            VSSDatabase vssDatabase = new VSSDatabaseClass();
            var         VSSini      = GetValue("VSSini");
            var         VSSuser     = GetValue("VSSuser");
            var         VSSpwd      = GetValue("VSSpwd");
            var         CCMS_PRJ    = GetValue("CCMS_PRJ");
            var         CCMS_Local  = GetValue("CCMS_Local");
            var         ccmsversion = "";
            var         ids         = PressRequest.GetFormString("ItemId");
            bool        success     = true;

            try
            {
                vssDatabase.Open(@VSSini, VSSuser, VSSpwd);
                VSSItem vssitem = vssDatabase.get_VSSItem(CCMS_PRJ, false);
            }
            catch (COMException ex)
            {
                ErrorNotification("VSS连接失败");
                success = false;
            }

            if (ids != "")
            {
                var idarr = ids.TrimEnd(',').Split(',');

                foreach (var id in idarr)
                {
                    var checkitem = _checkItemService.GetCheckItem(id);
                    var codelist  = TypeConverter.ObjectToString(checkitem.CodeList);

                    if (version == 7)
                    {
                        codelist    = codelist.Replace("CCMS_V6", "CCMS_V7");
                        ccmsversion = "CCMS_V7";
                    }
                    if (version == 6)
                    {
                        codelist    = codelist.Replace("CCMS_V7", "CCMS_V6");
                        ccmsversion = "CCMS_V6";
                    }

                    var      codefile = codelist.Replace("(", "").Replace(")", "").Replace("(", "").Replace(")", "").Replace("新增", "").Replace("修改", "");
                    string[] files    = codefile.Split('\n');
                    foreach (string file in files)
                    {
                        var    vfile     = file.Replace("\r", "").Replace(" ", "").Trim();
                        var    localfile = vfile.Replace("/", "\\");
                        string vssfile   = CCMS_PRJ + vfile;
                        string localFile = CCMS_Local + localfile;

                        try
                        {
                            VSSItem vssFolder = vssDatabase.get_VSSItem(vssfile, false);
                            //更新之前先删除文件
                            if (System.IO.File.Exists(localFile))
                            {
                                System.IO.FileInfo f = new System.IO.FileInfo(localFile);
                                f.Attributes = FileAttributes.Normal;//解除只读权限
                                f.Delete();
                            }
                            vssFolder.Get(localFile, 0);//获取到本地文件夹

                            #region 自动添加到工程文件
                            var vbproj      = "";
                            var projectName = "";

                            if (localfile.EndsWith(".aspx"))
                            {
                                vbproj      = "SCH.vbproj";
                                projectName = CCMS_Local + ccmsversion + @"\web\" + vbproj;
                            }
                            if (localfile.EndsWith(".vb") && localfile.IndexOf(".aspx") < 0)
                            {
                                var t1       = localfile.Substring(ccmsversion.Length, localfile.Length - ccmsversion.Length);
                                var foldname = t1.Substring(1, t1.LastIndexOf(@"\") - 1);
                                vbproj      = foldname + ".vbproj";
                                projectName = CCMS_Local + ccmsversion + @"\" + foldname + @"\" + vbproj;
                            }

                            if (!string.IsNullOrEmpty(projectName))
                            {
                                Project project = new Project();
                                project.Load(projectName);

                                var foldname = localfile.Substring(0, localfile.LastIndexOf(@"\"));
                                var include  = localfile.Substring(foldname.LastIndexOf(@"\") + 1, localfile.Length - foldname.LastIndexOf(@"\") - 1);

                                var isnew = true;
                                foreach (BuildItemGroup itemGroup in project.ItemGroups)
                                {
                                    foreach (BuildItem item in itemGroup)
                                    {
                                        if ((item.Include.ToLower() == include.ToLower()) || (include.ToLower().LastIndexOf(item.Include.ToLower()) > 0))
                                        {
                                            isnew = false;
                                            break;
                                        }
                                    }
                                }
                                if (isnew && localfile.EndsWith(".aspx"))
                                {
                                    var includedesigner = include + ".designer.vb";
                                    var includevb       = include + ".vb";

                                    var itemGroup = project.AddNewItemGroup();
                                    var buildItem = itemGroup.AddNewItem("Content", include);

                                    var buildItemdesigner = itemGroup.AddNewItem("Compile", includedesigner);
                                    var filename          = include.Substring(include.LastIndexOf(@"\") + 1, include.Length - include.IndexOf(@"\") - 1);
                                    buildItemdesigner.SetMetadata("DependentUpon", filename);

                                    var buildItemvb = itemGroup.AddNewItem("Compile", includevb);
                                    buildItemvb.SetMetadata("DependentUpon", filename);
                                    buildItemvb.SetMetadata("SubType", "ASPXCodebehind");
                                    project.Save(projectName);
                                }
                                else if (isnew && localfile.EndsWith(".vb") && vbproj != "SCH.vbproj") //非web工程
                                {
                                    var itemGroup = project.AddNewItemGroup();
                                    var buildItem = itemGroup.AddNewItem("Compile", include.Substring(include.IndexOf(@"\") + 1));
                                    project.Save(projectName);
                                }
                            }

                            #endregion
                        }
                        catch (COMException ex)
                        {
                            ErrorNotification("代码不存在:" + file);
                            success = false;
                        }
                    }

                    checkitem.GetVssCnt += 1;//增加获取次数
                    _checkItemService.UpdateCheckItem(checkitem, null);
                }
                if (success)
                {
                    SuccessNotification("获取代码成功");
                }
            }
            else
            {
                ErrorNotification("获取代码失败");
            }
            // return Redirect(Url.Action("deploylist", "checkitem"));
            var url = PressRequest.GetUrlReferrer();
            return(Redirect(url));
        }
Exemple #2
0
        public ActionResult ItemEdit(CICheckItem Item)
        {
            var model = new CheckItemModel();

            model.CheckItem = Item;

            bool success = true;

            //验证代码清单
            #region 格式验证
            Item.CodeList = Item.CodeList.Trim().Replace("(", "(").Replace(")", ")");
            //if (Item.CodeList == "")
            //{
            //    ErrorNotification("代码不能为空");
            //    success = false;
            //}
            if (Item.DemandCode == "")
            {
                ErrorNotification("需求编号不能为空");
                success = false;
            }
            var attachment = Request.Files["AttachmentFile"];
            if ((attachment == null || attachment.FileName == "") && string.IsNullOrEmpty(Item.Attachment))
            {
                success = false;
                ErrorNotification("提交物不能为空");
            }
            else
            {
                if (attachment != null && attachment.FileName != "")
                {
                    var folder = "/" + ConfigHelper.GetValue("uploadpath") + "/" + CurrentUser.UserName;

                    if (!System.IO.Directory.Exists(Server.MapPath(folder)))
                    {
                        System.IO.Directory.CreateDirectory(Server.MapPath(folder));
                    }
                    var savepath = Server.MapPath(folder + "/" + attachment.FileName);
                    if (System.IO.File.Exists(savepath))
                    {
                        System.IO.File.Delete(savepath);
                    }
                    attachment.SaveAs(savepath);
                    Item.Attachment = Request.Url.Authority + folder + "/" + attachment.FileName;
                    if (Item.Attachment.IndexOf("http://") < 0)
                    {
                        Item.Attachment = "http://" + Item.Attachment;
                    }
                }
            }
            if (Item.DeployNote == "")
            {
                success = false;
                ErrorNotification("部署注意事项不能为空");
            }

            var codelist = Item.CodeList;

            if (!string.IsNullOrEmpty(codelist))
            {
                codelist = codelist.Replace("/", @"\");//统一替换成反斜杠
                string[] stringSeparators = new string[] { "\r\n" };
                string[] files            = codelist.Split(stringSeparators, StringSplitOptions.None);
                foreach (var file in files)
                {
                    //正则验证:^ccms_7|ccms_6(\/[\w-]*)(新增)|(修改)$
                    //必须是ccms_7或者ccms_v6开头
                    var v6 = file.ToLower().IndexOf(@"ccms_v6\");
                    var v7 = file.ToLower().IndexOf(@"ccms_v7\");
                    if (v6 != 0 && v7 != 0)
                    {
                        ErrorNotification(@"代码必须是ccms_v7\或者ccms_v6\开头:" + file);
                        success = false;
                    }
                    //(新增)或者(修改)结尾
                    var posfixadd  = file.LastIndexOf("(新增)");
                    var postfixmod = file.LastIndexOf("(修改)");
                    if (posfixadd == -1 && postfixmod == -1)
                    {
                        success = false;
                        ErrorNotification("代码必须是(新增)或者(修改)结尾:" + file);
                    }
                    // 中间必须包含这个斜杠 /
                    if (file.IndexOf(@"\") <= 0)
                    {
                        success = false;
                        ErrorNotification(@"代码中间必须包含这个斜杠 \:" + file);
                    }
                    // 不能包含这个斜杠 \
                    //if (file.IndexOf("\\") >= 0)
                    //{
                    //    success = false;
                    //    ErrorNotification("代码不能包含这个斜杠 \\:" + file);
                    //}
                }
            }

            #endregion

            if (string.IsNullOrEmpty(Item.ID))
            {
                Item.AddTime    = DateTime.Now;
                Item.UpdateTime = DateTime.Now;
                Item.Developer  = CurrentUser.FullName;
                Item.UserName   = CurrentUser.UserName;
                //验证需求编号
                if (!_checkItemService.ExistsDemandCode(Item.DemandCode))
                {
                    success = false;
                    ErrorNotification("需求或者bug编号不存在");
                    return(View(model));
                }
                int num = 0;
                if (success)
                {
                    Item.ID = Guid.NewGuid().ToString();
                    num     = _checkItemService.InsertCheckItem(Item);
                }
                if (num > 0)
                {
                    SuccessNotification("添加成功");
                }
                else
                {
                    ErrorNotification("添加失败");
                    return(View(model));
                }
            }
            else
            {
                var oldmodel = _checkItemService.GetCheckItem(Item.ID);
                Item.AddTime    = oldmodel.AddTime;
                Item.GetVssCnt  = oldmodel.GetVssCnt;
                Item.Developer  = oldmodel.Developer;
                Item.UpdateTime = DateTime.Now;
                Item.PlanId     = oldmodel.PlanId;
                Item.UserName   = oldmodel.UserName;
                model.plan      = new VersionPlanService().GetPlan(Item.PlanId);
                int num = 0;
                if (success)
                {
                    num = _checkItemService.UpdateCheckItem(Item);
                }
                if (num > 0)
                {
                    SuccessNotification("修改成功");
                }
                else
                {
                    ErrorNotification("修改失败");
                    return(View(model));
                }
            }
            if (success)
            {
                var url = PressRequest.GetUrlReferrer();
                return(Redirect(url));
            }
            else
            {
                return(View(model));
            }
        }