spsaturday sydney 2013 - analysing sharepoint code with spcaf

32
Major Sponsors Minor Sponsors Analyzing SharePoint Code with SPCAF Anton Vishnyakov SharePoint Consultant/Developer

Upload: anton-vishnyakov

Post on 21-Dec-2014

705 views

Category:

Technology


0 download

DESCRIPTION

Slides from the SharePoint Saturday Sydney 2013 session about Analysing SharePoint code with SPCAF. The SharePoint Code Analysis Framework (SPCAF) is a set of tools created by Torsten Mandelkow and Matthias Einig. You can use the tools to examine .WSP files and .APP files to compare against a set of 400 rules, analyze dependencies, calculate metrics and more. In this session, I am going to take you through a tour of the SPCAF features, discuss the pros and cons of using it, show you how to integrate it with Team Foundation Server (TFS) and how you can add your own custom rules. If you spend time developing or managing SharePoint code, this is the session you have been waiting for. Most of the slides are based on original SPCAF presentation by Matthias Einig, and were used with Matthias Einig permission. More information could be found here: http://spsevents.org/worldwide/Sydney/Pages/Sessions.aspx http://www.spcaf.com http://spdevlab.com/

TRANSCRIPT

Page 1: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Major Sponsors Minor Sponsors

Analyzing SharePoint Code with SPCAFAnton Vishnyakov SharePoint Consultant/Developer

Page 2: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Anton VishnyakovSoftware Engineer, Ensysthttp://ensyst.com.auContacts

@[email protected]://spdevlab.com

SharePoint Consultant/Developer

MCTS/MCPD/MCITP

Main Focus:

• Solution Architecture• Solution Development

Page 3: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

What is the code analysis?

Why is it important for SharePoint?

SPCAF! SPCAF! SPCAF!

Agenda

Page 4: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Static vs. Dynamic

Source Code vs. Object Code

Manual vs. Automated

Coding Errors

Best Recommended Practices

Metrics

What is Code Analysis

Page 5: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Solutions / apps are black boxes

Code quality differs a lot

Solutions change (ALM)

Complexity complicatesmaintainability

Farm stability / security

Policies / best practices are hard to enforce

Why is it so important for SharePoint?

Page 6: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

.NET code using SP API

XML Files: Manifest, Features, Content Types, Web Templates

HTML/ASPX/ASCX/CSS/JS/XSLT

Resources: images, resx, document templates…

Deployment locations!

… And 100500 more «very small details»

So, what the heck is SharePoint Code?

Page 7: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Who needs it and why?

Page 8: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Who needs it and why?

Developer

Page 9: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Who needs it and why?

Is my code correct

and follows

best practices?

Developer

Page 10: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Who needs it and why?

Is my code correct

and follows

best practices?

DeveloperAdministrator

Page 11: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Who needs it and why?

Is my code correct

and follows

best practices?

Developer

Will the code harm my

farm?

Administrator

Page 12: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Architect

Who needs it and why?

Is my code correct

and follows

best practices?

Developer

Will the code harm my

farm?

Administrator

Page 13: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Who needs it and why?

Is my code correct

and follows

best practices?

Developer

Will the code harm my

farm?

Administrator

Is the code well

designed and maintainable

?

Architect

Page 14: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Quality Manager

Who needs it and why?

Is my code correct

and follows

best practices?

Developer

Will the code harm my

farm?

Administrator

Is the code well

designed and maintainable

?

Architect

Page 15: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Who needs it and why?

Is my code correct

and follows

best practices?

Developer

Will the code harm my

farm?

Administrator

Is the code well

designed and maintainable

?

Architect

Does the code comply with

company policies and standards?

Quality Manager

Page 16: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Object codeFxCop/VS CAFxCop MetricsCAT.net

Checks against general coding errors (not SharePoint-specific)

Calculates code metrics (only .NET code, not SharePoint specific)

Analyses code security (not SharePoint-specific)

Source codeStyleCop Checks coding style guidelines

(only .NET code, not SharePoint specific)

SharePoint codeSPDisposeCheck

MSOCAF

Checks memory leaks (SharePoint-specific)

Combination of FxCop and SPDisposeCheck for SharePoint Online

Page 17: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

What is missing?

No tool to check all SharePoint specific Code

Analyze solution dependencies

Calculate SharePoint metrics

Show what’s inside the solution / app!

Page 18: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

The Solution!

Page 19: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

What is in it?

Identifies coding violations against ~400 rules

Visualizes dependencies between SharePoint elements

Calculates metrics on SharePoint Code

Creates content reports of packages

Page 20: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

SPCAF VS Integrationdemonstration

Page 21: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Continuous Integration and TFS

Run SPCAF in TeamBuild as Quality Gate

Custom Build Activity

Supports TFS 2010/2012 and TFS Online (Cloud)

Build in TFS on-premisesBuild in Team Foundation Services

Page 22: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Client Applications

SPCAF runs on Azure (WCF Service)

Available Clients:

Windows 8 AppDesktop Client (WPF)

Web Client (Silverlight)

SPCAF on Azure

Page 23: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

SPCAF Desktop Clientdemonstration

Page 24: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

SPCAF Extensibilitydemonstration

Page 25: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Ruling the world! – step 1/3using SPCAF.Sdk;using SPCAF.Sdk.Rules;using SPCAF.Sdk.Model;using SPCAF.Sdk.Model.Extensions;

namespace SPSaturday.Rules{ public class FeatureStartsWithSPSaturday : Rule<FeatureDefinition> { public override void Visit(FeatureDefinition target, NotificationCollection notifications) {} }}

Page 26: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Ruling the world! – step 2/3namespace SPSaturday.Rules{ [RuleMetadata(typeof(Naming), CheckId = "SPC99001", DisplayName = "Feature name should start with SPSaturday", Description = "A feature name should start with 'SPSaturday'.", DefaultSeverity = Severity.Warning, SharePointVersion = new string[] { "12", "14", "15" }, Message = "Feature '{0}' should start with 'SPSaturday'.", Resolution = "Change feature name to start with 'SPSaturday'”)] public class FeatureStartsWithSPSaturday : Rule<FeatureDefinition> { ...

Page 27: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Ruling the world! – step 3/3public class FeatureStartsWithSPSaturday : Rule<FeatureDefinition>{

public override void Visit(FeatureDefinition target, NotificationCollection notifications)

{ if (!target.FeatureName.StartsWith("SPSaturday"))

{ var message = string.Format(MessageTemplate(), target.FeatureName); Notify(target, message, notifications); }

}}

Page 28: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

SharePoint Code Analysis

is important for EVERYBODYimproves solution quality improves farm stability

SPCAFfills the tooling gap runs locally and in the cloudintegrates in the ALM processis extensible

Page 29: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Action plan! Follow SPCAF team!

Matthias [email protected]

Torsten Mandelkow@tmandelkow

SPCAF@spcaf www.spcaf.com

Download SPCAF at www.spcaf.com

Improve your solutions

Feedback the enhancements

Write your own rules/metrics

Share your story with SPCAF

Page 30: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Question and Answer

Page 31: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Questions?Comments?More info

Contact details:[email protected]

@avishnyakov

http://spdevlab.com

Related links:

SharePoint Code Analysis Framework (SPCAF)

SharePoint Code Analysis Framework (SPCAF) – Documentation

First impression of SPCAF – SharePoint Code Analysis Framework: code analysis, metrics, rules and dependencies

Writing your second rule for SPCAF – big brother watches your code!

Writing your first metric for SPCAF – put the best practices in place!

Writing your first rule for SPCAF – put the best practices in place!

Codeplex: SPCAF Contrib – http://spcafcontrib.codeplex.com

Twitter: @SPCAF #SPCAF

Support: [email protected]

Feedback: [email protected]

Page 32: SPSaturday Sydney 2013 -  Analysing SharePoint code with SPCAF

Major Sponsors Minor Sponsors

Thanks for listeningRemember to submit your feedback so you go in the draw to win prizes at the end of the day