예제 #1
0
        public ActionResult GetCode()
        {
            ViewBag.Title = "Utry持续集成平台";
            //VSSDatabase vssDatabase = new VSSDatabase();
            //try { vssDatabase.Open(txtDbPath.Text, txtAccount.Text, txtPasswd.Text); }
            //catch { MessageBox.Show("Can't login to the VSS database"); return; }
            //try { VSSItem vssitem = vssDatabase.get_VSSItem(txtItemPath.Text, false);
            //    VSSItem vssitemVersion = vssitem.get_Version(int.Parse(txtVersion.Text));
            //    string localPath = txtLocalpath.Text; vssitemVersion.Get(ref localPath, 0);
            //    if (File.Exists(txtLocalpath.Text)) { MessageBox.Show("Succeed!"); } }
            //catch { MessageBox.Show("Download failed"); }

            VSSDatabase vssDatabase = new VSSDatabaseClass();
            //var VSSini = GetValue("VSSini");
            var VSSini     = ConfigHelper.GetValue("VSSini");
            var VSSuser    = ConfigHelper.GetValue("VSSuser");
            var VSSpwd     = ConfigHelper.GetValue("VSSpwd");
            var CCMS_PRJ   = ConfigHelper.GetValue("CCMS_PRJ");
            var CCMS_Local = ConfigHelper.GetValue("CCMS_Local");

            //WorkGroupNetwork iss = new WorkGroupNetwork("ccms", "ip", "ccms");

            vssDatabase.Open(@VSSini, VSSuser, VSSpwd);
            VSSItem vssitem = vssDatabase.get_VSSItem(CCMS_PRJ, false);


            var code = Request["txtCode"];

            code = code.Replace("(", "").Replace(")", "").Replace("(", "").Replace(")", "").Replace("新增", "").Replace("修改", "");

            string[] files = code.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;

                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);//获取到本地文件夹
            }

            //iss.Dispose();
            //VSSItem vssitemVersion = vssitem.get_Version(1);
            //string s = "c:\\JobMate.sln";
            //vssitemVersion.Get(ref s, 0);
            ViewBag.Tip = "获取代码成功";
            return(Redirect("?act=success"));
        }
예제 #2
0
 public void Pull(string vssPath, DirectoryInfo localPath)
 {
     try
     {
         VSSItem dir = VSSDB.get_VSSItem(vssPath, false);
         sender($"Папка {vssPath} найдена");
         if (!localPath.Exists)
         {
             localPath.Create();
             sender($"Папка {vssPath} найдена");
         }
         dir.Get(localPath.FullName, (int)(VSSFlags.VSSFLAG_RECURSYES | VSSFlags.VSSFLAG_REPREPLACE));
         //DeleteLocalIfNotExistsInVSS(dir, localPath);
         sender("Папка загружена!");
     }
     catch (System.Runtime.InteropServices.COMException exc)
     {
         throw new ArgumentException(VSSErrors.GetMessageByCode(exc.ErrorCode));
     }
 }
예제 #3
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));
        }
예제 #4
0
        private static void GetFileVersion(IVSSItem vssFile, IVSSVersion vssVersion, SvnClient svnClient)
        {
            numFilesHandled++;
            string dir = string.Format("{0}{1}", repoDIR, vssFile.Spec.Substring(1)).Replace("/", "\\");

            dir = Path.GetDirectoryName(dir);
            string  filePath    = Path.Combine(dir, vssFile.Name);
            VSSItem versionItem = vssVersion.VSSItem;

            try
            {
                migrateLog.DebugFormat("Fetching VSSItem: {0}, Version: {1}", versionItem.Spec, versionItem.VersionNumber);

                if (versionItem.Type != (int)VSSItemType.VSSITEM_PROJECT)
                {
                    versionItem.Get(ref filePath,
                                    (int)
                                    (VSSFlags.VSSFLAG_USERRONO | VSSFlags.VSSFLAG_CMPFAIL | VSSFlags.VSSFLAG_GETYES |
                                     VSSFlags.VSSFLAG_REPREPLACE | VSSFlags.VSSFLAG_TIMEMOD));

                    //kill them *.scc files worth for nothing
                    string[] files = Directory.GetFiles(dir, "*.scc", SearchOption.TopDirectoryOnly);
                    foreach (string file in files)
                    {
                        File.SetAttributes(file, FileAttributes.Normal);
                        File.Delete(file);
                    }
                }

                else
                {
                    Directory.CreateDirectory(filePath);
                }


                //This seems to fail rather often on binary files and directories, so dont let us use it on them

                if (versionItem.Type != (int)VSSItemType.VSSITEM_PROJECT)
                {
                    if (!versionItem.Binary)
                    {
                        migrateLog.DebugFormat("Diffing ...");
                        if (versionItem.get_IsDifferent(filePath))
                        {
                            migrateLog.WarnFormat(
                                "Files should not be different for version {0}; possible corruption in file {1}:{0}",
                                versionItem.VersionNumber, versionItem.Spec);
                        }
                    }
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode == -2147166575)
                {
                    // VSS file's checkbox "keep only latest version" is checked therefore no file could be fetched
                    // so that calling versionItem.Get(...) results in an exception
                    migrateLog.WarnFormat(
                        "Version {0} of file {1} not stored in VSS. File has option 'Keep only latest version' (see file's properties) enabled in VSS",
                        versionItem.VersionNumber, versionItem.Spec);
                }
                else
                {
                    throw;
                }
            }

            VssBindingRemover.RemoveBindings(filePath);

            Collection <SvnStatusEventArgs> svnStatus;

            svnClient.GetStatus(filePath, out svnStatus);

            if (svnStatus.Count == 1)
            {
                SvnStatus fileStatus = svnStatus[0].LocalContentStatus;
                if (fileStatus == SvnStatus.Normal)
                {
                    migrateLog.WarnFormat("No modification detected for {0}:{1}", vssVersion.VSSItem.Spec,
                                          vssVersion.VersionNumber);
                    return;
                }
                if (fileStatus == SvnStatus.NotVersioned || fileStatus == SvnStatus.Incomplete ||
                    fileStatus == SvnStatus.Missing)
                {
                    try
                    {
                        svnClient.Add(filePath);
                    }
                    catch (SvnException e)
                    {
                        if (!e.ToString().Contains("already under version"))
                        {
                            throw;
                        }
                    }
                }
            }
            else
            {
                //Should never get here because we're always looking for the results of an individual file; only display a message
                migrateLog.WarnFormat("Invalid svn status detected for {0}:{1}", vssVersion.VSSItem.Spec,
                                      vssVersion.VersionNumber);
                migrateLog.WarnFormat("Status count was: {0}", svnStatus.Count);
                return;
            }
            //simply continue as expected
        }