public string GetDisplayName()
        {
            using (TfsTeamProjectCollection service = Service)
            {
                TeamFoundationIdentity identity = null;
                service.GetAuthenticatedIdentity(out identity);

                return(identity.DisplayName);
            }
        }
예제 #2
0
        protected override string Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            string text           = context.GetValue(this.OutputFile);
            string filename       = context.GetValue(this.FileName);
            string configFilePath = context.GetValue(this.ServerName);
            //http://team:8080/tfs/WebSites

            /*
             * string BaseTFSDir = bldConfig.Rules["BaseTFSDir"].Value;
             * string BaseDeploymentDir = bldConfig.Rules["BaseDeploymentDir"].Value;
             * string BuildDeploymentDir = bldConfig.Rules["BuildDeploymentDir"].Value;
             */

            IBuildDetail bldD = context.GetValue(BuildDetail);

            TfsTeamProjectCollection tfs = bldD.BuildServer.TeamProjectCollection;
            ///new  TfsTeamProjectCollection(new Uri(context.GetValue(ServerName) as string));//
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            bldD.RefreshAllDetails();
            //commensurate the zip deployment with the current build
            TeamFoundationIdentity id;

            tfs.GetAuthenticatedIdentity(out id);
            //ZipDeployer.UID = (id == null)?"UnknownUser" : id.UniqueName;

            //var changesets = InformationNodeConverters.GetAssociatedChangesets(bldD);//.OrderBy(a=> a.ChangesetId);
            var changesets = context.GetValue(this.AssocSets);


            TFSDeployerController deploy = new TFSDeployerController(tfs.Uri.AbsoluteUri, configFilePath, bldD.BuildNumber);

            return(deploy.deploy(tfs, changesets));
            /**/
            //if (string.IsNullOrEmpty(text))
            //  throw new ArgumentException("Please specify a path");
            //String.Format("{0}@$/{1}", LabelName, BuildDetail.BuildDefinition.TeamProject)
        }
예제 #3
0
        internal static void CheckBypassRulePermission(TfsTeamProjectCollection tfs)
        {
            IIdentityManagementService identityService        = (IIdentityManagementService)tfs.GetService(typeof(IIdentityManagementService));
            TeamFoundationIdentity     serviceAccountIdentity = identityService.ReadIdentity(GroupWellKnownDescriptors.ServiceUsersGroup, MembershipQuery.None, ReadIdentityOptions.None);

            TeamFoundationIdentity authenticatedUser;

            tfs.GetAuthenticatedIdentity(out authenticatedUser);
            if (null == authenticatedUser)
            {
                return;
            }

            if (!identityService.IsMember(serviceAccountIdentity.Descriptor, authenticatedUser.Descriptor))
            {
                return;

                throw new PermissionException(
                          string.Format(TfsWITAdapterResources.UserNotInServiceAccountGroup, authenticatedUser.DisplayName, tfs.Uri.ToString()),
                          authenticatedUser.DisplayName, string.Empty, serviceAccountIdentity.DisplayName);
            }
            TraceManager.TraceInformation("BypassRulePermission verified for user '{0}'", authenticatedUser.DisplayName);
        }
예제 #4
0
        internal static void CheckBypassRulePermission(TfsTeamProjectCollection tfs)
        {
            // Verify whether the user is in the service account group. Throw an exception if it is not.
            IGroupSecurityService gss       = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));
            Identity serviceAccountIdentity = gss.ReadIdentity(SearchFactor.ServiceApplicationGroup, null, QueryMembership.None);

            TeamFoundationIdentity authenticatedUser;

            tfs.GetAuthenticatedIdentity(out authenticatedUser);
            if (null == authenticatedUser)
            {
                return;
            }

            Identity authenticatedUserId = gss.Convert(authenticatedUser);

            if (!gss.IsMember(serviceAccountIdentity.Sid, authenticatedUserId.Sid))
            {
                throw new PermissionException(
                          string.Format(TfsWITAdapterResources.UserNotInServiceAccountGroup, authenticatedUser.DisplayName, tfs.Uri.ToString()),
                          authenticatedUserId.AccountName, authenticatedUserId.Domain, serviceAccountIdentity.DisplayName);
            }
            TraceManager.TraceInformation("BypassRulePermission verified for user '{0}'", authenticatedUser.DisplayName);
        }
        public string deploy(TfsTeamProjectCollection tfs, IList <Changeset> changesets, string deployerBuildDirectory)
        {
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
            string logString         = "Deploying " + base.buildNumber.ToString();

            //commensurate the zip deployment with the current build
            TeamFoundationIdentity id;

            tfs.GetAuthenticatedIdentity(out id);

            foreach (var changesetSummary in changesets.OrderBy(a => a.ChangesetId))
            {
                Changeset changeSet = vcs.GetChangeset(changesetSummary.ChangesetId);
                var       b         = changeSet.Changes.Where(c =>
                                                              c.Item.ItemType == ItemType.File
                                                              )
                                      .Where(d => !d.Item.ServerItem.EndsWith(".sql"))
                                      .Select(a => a.Item.ServerItem)
                                      .ToList();

                string committer = changeSet.Committer;
                string comment   = changeSet.Comment;

                if (b.Count > 0)
                {
                    string depDir = zipDeploymentDir + "\\" + Regex.Replace(changesetSummary.Committer, @"\W", "_") + "\\";

                    logString += DeployZip(b, depDir, committer, comment);
                }
                if (!string.IsNullOrEmpty(_bldConfig.ConnectionString))
                {
                    var e = changeSet.Changes.Where(c =>
                                                    c.Item.ItemType == ItemType.File
                                                    )
                            .Where(d => d.Item.ServerItem.EndsWith(".sql"))
                            .OrderBy(f => f.Item.ServerItem)
                            .Select(a => a.Item.ServerItem)
                            .ToList()
                    ;
                    if (e.Count > 0)
                    {
                        //try
                        //{
                        string      depDir      = (_bldConfig.Rules["SqlDeploymentDir"] != null && !string.IsNullOrEmpty(_bldConfig.Rules["SqlDeploymentDir"].Value)) ? _bldConfig.Rules["SqlDeploymentDir"].Value + "\\" + Regex.Replace(changesetSummary.Committer, @"\W", "_") + "\\" : buildDir;
                        SqlDeployer sqldeployer = new SqlDeployer(_bldConfig.ConnectionString);
                        sqldeployer.SourceDir = new List <string> {
                            baseDir
                        };
                        sqldeployer.DeploymentDir = depDir;
                        sqldeployer.BuildNumber   = buildNumber;
                        sqldeployer.SetComment(comment);
                        sqldeployer.LoadFiles(e);
                        logString += sqldeployer.Deploy();
                        //SqlDeploymentDir

                        //logString += DeployZip(e, depDir, committer, comment);
                        //}
                        //catch (Exception ex)
                        //{

                        //}
                    }
                }
            }

            return(logString);
        }