Atlanta Code Camp slides and sample code

As mentioned here, I presented at Atlanta Code Camp over the weekend.  It was a really well-run event and I had a lot of fun up there.  I met some great people and it seems like my session attendees got pretty excited about the tools that I presented.  You can get my slides here:

Microsoft Test Manager

Continuous Integration with TFS

Succeeding with Scrum

During the “Continuous Integration” talk, i showed how some samples of custom build activities.  You can download that code here.

Here is the sample code for my Twitter update Activity

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  using System.Activities;
   6:  using Microsoft.TeamFoundation.Build.Client;
   7:  using System.IO;
   8:  using System.Drawing;
   9:  using System.Drawing.Imaging;
  10:  using System.Drawing.Drawing2D;
  11:  using Microsoft.TeamFoundation.VersionControl.Client;
  12:  using Microsoft.TeamFoundation.Build.Workflow.Activities;
  13:  using TweetSharp;
  14:   
  15:  namespace Demo.Tfs.BuildTasks.Activities
  16:  {
  17:      [BuildActivity(HostEnvironmentOption.All)]
  18:      public class SendTwitterUpdate : CodeActivity
  19:      {
  20:          /// 
  21:          /// Message to update.
  22:          /// 
  23:          public InArgument<string> UpdateMessage { get; set; }
  24:   
  25:          protected override void Execute(CodeActivityContext context)
  26:          {
  27:              var updateMessage = context.GetValue(this.UpdateMessage);
  28:   
  29:              SendMessage(updateMessage);
  30:          }
  31:   
  32:          public void SendMessage(string message)
  33:          {
  34:              TwitterService svc = new TwitterService("fdafwTdI6eE8Xg", "3X5467TicVasrfdasfdasC4M", "xxxxxxxx-XVGL93uBK91KIpZEXDssez25CYs4ZH6bzonLEB7Z", "asfasreaklejfasd");
  35:              svc.SendTweet(message);
  36:          }        
  37:      }
  38:  }

And for my “Add Date to Image” activity:

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  using System.Activities;
   6:  using Microsoft.TeamFoundation.Build.Client;
   7:  using System.IO;
   8:  using System.Drawing;
   9:  using System.Drawing.Imaging;
  10:  using System.Drawing.Drawing2D;
  11:  using Microsoft.TeamFoundation.VersionControl.Client;
  12:  using Microsoft.TeamFoundation.Build.Workflow.Activities;
  13:   
  14:  namespace Demo.Tfs.BuildTasks.Activities
  15:  {
  16:      [BuildActivity(HostEnvironmentOption.All)]
  17:      public sealed class AddDateToImage : CodeActivity
  18:      {
  19:          /// 
  20:          /// The workspace that is used by the build
  21:          /// 
  22:          [RequiredArgument]
  23:          public InArgument Workspace { get; set; }
  24:   
  25:          /// 
  26:          /// Server file path to the image.
  27:          /// 
  28:          [RequiredArgument]
  29:          public InArgument<string> ImageFilePath { get; set; }
  30:   
  31:          /// 
  32:          /// Server file path to the source image.
  33:          /// 
  34:          [RequiredArgument]
  35:          public InArgument<string> SourceImageFilePath { get; set; }
  36:   
  37:          
  38:          protected override void Execute(CodeActivityContext context)
  39:          {
  40:              var workspace = context.GetValue(this.Workspace);
  41:              var imageFilePath = context.GetValue(this.ImageFilePath);
  42:              var sourceImageFilePath = context.GetValue(this.SourceImageFilePath);
  43:   
  44:              //Get the file that matches the server item
  45:              var sourceFilePath = workspace.GetLocalItemForServerItem(sourceImageFilePath);
  46:              var filePath = workspace.GetLocalItemForServerItem(imageFilePath);
  47:              if (!string.IsNullOrWhiteSpace(filePath) && !string.IsNullOrWhiteSpace(sourceFilePath))
  48:              {
  49:                  workspace.PendEdit(filePath);
  50:                  context.TrackBuildMessage("Updating Image File");
  51:   
  52:                  Color color = Color.Black;
  53:   
  54:                  using (Image img = Image.FromFile(sourceFilePath))
  55:                  using (Graphics gr = Graphics.FromImage(img))
  56:                  using (Font font = new Font("Calibri", 14f, FontStyle.Bold))
  57:                  using (StringFormat stringFormat = new StringFormat())
  58:                  {
  59:                      stringFormat.Alignment = StringAlignment.Far;
  60:                      stringFormat.LineAlignment = StringAlignment.Center;
  61:                      gr.SmoothingMode = SmoothingMode.AntiAlias;
  62:   
  63:                      
  64:                      gr.DrawString(DateTime.Now.ToLongDateString(), font, new SolidBrush(color), 10f, 10f, stringFormat);
  65:                      img.Save(filePath, ImageFormat.Png);
  66:                  }
  67:   
  68:                  workspace.CheckIn(workspace.GetPendingChanges(), null, "***NO_CI***", null, null, new PolicyOverrideInfo("Auto checkin", null), CheckinOptions.SuppressEvent);
  69:              }
  70:          }
  71:      }
  72:  }

About esteban

Esteban is the Founder and Chief Technologist at Nebbia Technology, an ALM consulting and Azure-powered technology company. He is a software developer with a passion for ALM, TFS, Azure, and software development best practices. Esteban is a Microsoft Visual Studio ALM MVP and ALM Ranger, Pluralsight author, and the president of ONETUG (Orlando .NET User Group).


Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? *