best practices with sharepoint 2010 sandboxed solutions
DESCRIPTION
SharePoint 2010 sandboxed solutions changed the way how we can develop applications on top of SharePoint platform. This session will talk about sandboxed solutions architecture, do's and don'ts, types of solutions that should be built as sandboxed solutions. We are going to discuss tools that can help us develop solutions in a sandbox and tricks that can assist us to streamline code development and application life cycle. The session will be accompanied with series of demoes that are going to show some of best and worst practices with SharePoint solutions.TRANSCRIPT
![Page 1: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/1.jpg)
Best practices with SharePoint 2010 Sandboxed Solutions
Toni FrankolaSharePoint Services MVP, Croatia
http://[email protected]@ToniFrankola
![Page 2: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/2.jpg)
About speaker…
![Page 3: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/3.jpg)
Agenda
• Intro to SharePoint SandBoxed solutions• SandBoxed solutions for DEVs• SandBoxed solutions for IT PROs• Demo
![Page 4: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/4.jpg)
The problem in v2007 (1)
• Case study:– A Customer wants to use WSS 3.0 for group
collaboration in hosting environment…– …with Custom permissions, views, web-parts
• Your only option for hosted WSS 3.0:– SP Designer 2007 + Javascript (JQuery)
![Page 5: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/5.jpg)
The problem in v2007 (2)
• In non-hosted environments:– Using GAC or Full-trust for everything– One webpart could jeopardize entire farm• „Performance Issues” with entire farm
![Page 6: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/6.jpg)
The solution
![Page 7: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/7.jpg)
SandBoxed Solutions
• Isolated SP process (User Code Service)
• Exposes a subset of Microsoft.SharePoint namespace
• Managed via Site Coll. Solutions gallery
![Page 8: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/8.jpg)
HELLO WORLD FROM SANDBOXED SOLUTION
DEMO
![Page 9: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/9.jpg)
SANDBOXED SOLUTIONS - DEV PERSPECTIVE
![Page 10: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/10.jpg)
How stuff works
Worker Service(SPUCWorkerProcess.exe)
Full Object Model
Host Services (SPUCHostService.exe)
Execution Manager(Inside Application Pool)
Subset Object Model
Untrusted Code
IIS(WPW3.EXE)
FRONT END BACK END
Subset-Model RequestFull-Model
Request
![Page 11: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/11.jpg)
Supported in Sandboxed Solutions
• Web Parts (no Visual WPs)• Lists• List Templates• Custom Actions• Workflows• Event Receivers• Content Types• Site Columns• …Source: http://msdn.microsoft.com/en-us/library/ff872402.aspx
![Page 12: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/12.jpg)
Supported API• All of the Microsoft.SharePoint namespace, except:
– SPSite constructor– SPSecurity object– SPWorkItem and SPWorkItemCollection objects– SPAlertCollection.Add method– SPAlertTemplateCollection.Add method– SPUserSolution and SPUserSolutionCollection objects– SPTransformUtilities object– Microsoft.SharePoint.Navigation namespace
• All of the Microsoft.SharePoint.Utilities namespace, except– SPUtility.SendEmail method– SPUtility.GetNTFullNameandEmailFromLogin method– Microsoft.SharePoint.Workflow namespace
• All of the Microsoft.SharePoint.WebPartPages namespace, except– SPWebPartManager object– SPWebPartConnection object– WebPartZone object– WebPartPage object– ToolPane object– ToolPart object
Source: http://msdn.microsoft.com/en-us/library/ff872402.aspx
![Page 13: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/13.jpg)
BP1 – Proper Tools
• Visual Studio 2010 SharePoint Power Tools– adds Visual Web Part– SandBoxed solution validation (must have!)
• CKSDEV add-on– Trusted proxy– Deployment options
• Other must have stuff:– Visual Studio 2010 Productivity Pack– SP Dispose Checker (how to integrate with VS)
![Page 14: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/14.jpg)
BP2 – VS2010 deployment configurations
• Generate SandBoxed/Farm solutions from same code base (blog post):
![Page 15: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/15.jpg)
BP 3 – How to detect if SandBoxed?
• No OOTB, but:AppDomain.CurrentDomain.FriendlyName.Contains("Sandbox")
![Page 16: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/16.jpg)
BP4 – „Sandboxed is default”
• When developing:– Use Sandboxed whenever possible• Faster deployment (no Recycling required)
– Separate farm/sandboxed solutions
![Page 17: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/17.jpg)
BP5 – Use it for „Small fixes”
• Auto apply theme• Auto apply language settings• JQuery loader• UI adjustments (e.g. hide or add something)
![Page 18: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/18.jpg)
Sandboxed vs. JQuery copy/paste
• Version control (e.g. via VSTS)• SharePoint Feature Versions• Easy to deploy to different environments• Can be deployed to site coll. level
![Page 19: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/19.jpg)
Not supported
• Off-box connections, http, web services, etc• ADO.net• Enterprise features (Search, BCS, etc.)• Threading• P-Invoke• IO• Other sites (site collections)
![Page 20: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/20.jpg)
SANDBOXED SOLUTIONS - ITPRO PERSPECTIVE
![Page 21: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/21.jpg)
Very bad WebPart
• Infinite loop example:
• Farm solution = problem• Sandboxed solution:
![Page 22: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/22.jpg)
Monitoring 101
• Site Collection Admin
• Farm admin
![Page 23: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/23.jpg)
Monitored ResourcesMetric Name Description Units Resources
Per PointHard Limit
AbnormalProcessTerminationCount Process gets abnormally terminated Count 1 1
CPUExecutionTime CPU exception time Seconds 3,600 60CriticalExceptionCount Critical exception fired Number 10 3
InvocationCount Number of times solution has been invoked Count N/A N/A
PercentProcessorTime Note: # of cores not factored in Percentage Units of Overall Processor Consumed 85 100
ProcessCPUCycles CPU Cycles 1E+11 1E+11ProcessHandleCount Windows Handles 10,000 1,000
ProcessIOBytes (Hard Limit Only) Bytes written to IO Bytes 0 1E+08
ProcessThreadCount Number of Threads in Overall Process Threads 10,000 200
ProcessVirtualBytes (Hard Limit Only) Memory consumed Bytes 0 1E+09
SharePointDatabaseQueryCount SharePoint DB Queries Invoked Number 20 100
SharePointDatabaseQueryTime Amount of time spent waiting for a query to be performed Seconds 120 60
UnhandledExceptionCount Unhanded Exceptions 50 3
UnresponsiveprocessCount We have to kill the process because it has become unresponsive Number 2 1
![Page 24: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/24.jpg)
BP6 – Resource usage
• Resource: SharePointDatabaseQueryCount– Number of SharePoint DB Queries Invoked– 20 = 1 point
• Default day limit 300 points
• Best practice: Adjust the limits to the env.
![Page 25: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/25.jpg)
Benefits for ITPROs
• Stability of SharePoint farm cannot be jeopardized
• You can control which web parts will allowed• Less administration required– Empowering Site Coll. owners
![Page 26: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/26.jpg)
BP7 – for IT PROs
• Do not enable if not necessary• Configure permissions• In hosting env. (from business perspective):– Gain competitive advantage:
![Page 27: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/27.jpg)
BEYOND SANDBOX
![Page 28: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/28.jpg)
Sandboxed solution limitations
• 3rd party .NET components do not work well with Sandboxed Solutions– Solutions: Revert back to JQuery– JQuery charts (licensing!):
![Page 29: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/29.jpg)
BP8.1 – Extending Sandbox
• Trusted proxies:
Worker Service(SPUCWorkerProcess.exe)
SPUtility
SPProxyOperationArgs
GAC
SPProxyOperation
SPProxyOperationArgs
Untrusted Code
SecuredResource
![Page 30: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/30.jpg)
BP8.1 – Extending Sandbox (2)
• Code sample:public class FileProxy : SPProxyOperation { public override object Execute(SPProxyOperationArgs args) { if (args != null) { FileArgs fileArgs = args as FileArgs; FileStream fStream = new FileStream(@"C:\Path\SampleFile.txt", FileMode.CreateNew); fStream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(fileArgs.FileContents), 0, fileArgs.FileContents.Length); fStream.Flush(); fStream.Close(); return fileArgs.FileContents; } else return null; } }
Source: http://blah.winsmarts.com/2009-12-SharePoint_2010_Sandboxed_Solutions__Full_Trust__Proxies.aspx
![Page 31: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/31.jpg)
BP8.2 – Extending Sandbox
• Using SharePoint Client API:
Worker Service(SPUCWorkerProcess.exe)
Silverlight Web Part Host
Uncustomized Page
Silverlight App
JavaScript
Web Service (or Client OM)
SecuredResource
Or SPServices open-source
http://spservices.codeplex.com
![Page 32: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/32.jpg)
Samples
Source: www.sharepointaccelerators.com
Source: www.21scrum.com
![Page 33: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/33.jpg)
Active Resolved Closed
SandBoxed solution case study
Email Inbox Issues
Contacts
Confirmation Email
![Page 34: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/34.jpg)
SANDBOXED SOLUTION EXAMPLE
DEMO
![Page 35: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/35.jpg)
Conclusion
• Use whenever possible…• …But know the limits!• Happy programming!
![Page 36: Best practices with SharePoint 2010 sandboxed solutions](https://reader031.vdocuments.us/reader031/viewer/2022012918/54809652b4af9ff2518b4573/html5/thumbnails/36.jpg)
QUESTIONS?