Sunday, December 29, 2013

Best Coding Practices in Share Point Object Model

When developers code in SOM they always faces the  issues related to performance, extensibility, and scalability. Usually all these issue are trouble shoot and tried to resolve by doing some alternate options and developers skips the main reason causing for it.

I am listing some of the key points to use the best coding practice which could avoid the above issues in SOM. I have taken help of MS tech net and MSDN to prepare this article.


Caching Data and Objects

some  of the developers use the Microsoft .NET Framework caching objects to increase overall system performance. But many objects are not "thread safe" and caching those objects can cause applications to fail and unexpected or unrelated user errors

Caching SharePoint Objects That Are Not Thread Safe

Developers use  cache to hold the SPItemCollection for less memory utilization but this object contains the SPWeb opbject which is not thread safe and it leads to execute multiple times in the memory to cause bad performance of the application

Understanding the Potential Pitfalls of Thread Synchronization

Consider the scenario that  you trying to update the list item by Item.update method and you get this happens in 10sec. It works perfectly with you and with 10 more developers.But it start becoming severe when number of users grows try to update the same item with multiple thread at same time. You must it add the lock on the code to happen it in sequence.   

 Coding practice with list and folders

Developers write the code to fetch the list item or update list item in regular development practice. Following are some important points must need to remember while doing the above mentioned operations

Dont fetch the list items using SPList.Items- It selects all items from all sub folders, including all fields in the list. Use the following alternatives for each use case. Use the below given syntax instead of it
SPList.GetItems(SPQuery query)

Paginate the items while fetching it from large lists - When you try to fetch the items from large list always remember to add the row limit  to the items. This will fetch the items with row item size and you will get good performance using this 

Getting items by identifierInstead of using SPList.Items.GetItemById-

SPList.GetItemById(int id, string field1, params string[] fields). Specify the item identifier and the field that you want.

Do not enumerate entire SPList.Items collections or SPFolder.Files collections -
Accessing the methods and properties that are listed in the left column of the following table will enumerate the entire SPList.Items collection, and cause poor performance and throttling for large lists. Instead, use the alternatives listed in the right column.

Table from MSDN
Poor Performing Methods and Properties Better Performing Alternatives
SPList.Items.Count SPList.ItemCount
SPList.Items.XmlDataSchema Create an SPQuery object to retrieve only the items you want.
SPList.Items.NumberOfFields Create an SPQuery object (specifying the ViewFields) to retrieve only the items you want.
SPList.Items[System.Guid] SPList.GetItemByUniqueId(System.Guid)
SPList.Items[System.Int32] SPList.GetItemById(System.Int32)
SPList.Items.GetItemById(System.Int32) SPList.GetItemById(System.Int32)
SPList.Items.ReorderItems(System.Boolean[],System.Int32[],System.Int32) Perform a paged query by using SPQuery and reorder the items within each page.
SPFolder.Files.Count SPFolder.ItemCount

 Deleting Multiple Versions of a List Item

When you delete multiple versions of a list item, use the DeleteByID method; do not use the Delete method. You will experience performance problems if you delete each SPListItemVersion object from an SPListItemVersionCollection object. The recommended practice is to create an array that contains the ID properties of each version and then delete each version by using the SPFileVersionCollection.DeleteByID method.

 

Using SPQuery Objects

SPQuery objects can cause performance problems whenever they return large result sets. The following suggestions will help you optimize your code so that performance will not suffer greatly whenever your searches return large numbers of items.

Do not use an unbounded SPQuery object.An SPQuery object without a value for RowLimit will perform poorly and fail on large lists. Specify a RowLimit between 1 and 2000 and, if necessary, page through the list.
Use indexed fields.
If you query on a field that is not indexed, the query will be blocked whenever it would result in a scan of more items than the query threshold (as soon as there are more items in the list than are specified in the query threshold). Set SPQuery.RowLimit to a value that is less than the query threshold.
If you know the URL of your list item and want to query by FileRef, use SPWeb.GetListItem(string strUrl, string field1, params string[] fields) instead.
Following are the important questions  that you can check while developing any artifact in SP using SOM
  • Does my code properly dispose of SharePoint objects?
  • Does my code cache objects properly?
  • Does my code cache the correct types of objects?
  • Does my code use thread synchronization when necessary?
  • Does my code work as efficiently for 1,000 users as it does for 10 users?
     


 

 


Tuesday, December 24, 2013

Creating and consuming web service in Share Point Hosted environment




The service-oriented applications can be build using WCF ( windows communication foundation). Using WCF, data can be sent in asynchronous way from one service endpoint to another.
The WCF is mostly used in following scenarios.
A Silverlight application to poll a service for the latest data feeds
A chat service that allows two people to communicate or exchange data in real time.
A secure service to process business transactions.
A service that supplies current data to others, such as a traffic report or other monitoring service.
A dashboard application that polls one or more services for data and presents it in a logical presentation.
Exposing a workflow implemented using Windows Workflow Foundation as a WCF service.

The WCF can be created as one of the feature and can be deployed to hosted share point environment. It has to deploy to ISAPI folder as WSP package or under web application vti_bin folder. Once it’s added to share point then it can used in any web application, Silver light application or any other application as interface to share point.
Below some description provided for creating share point hosted WCF and consuming it in your application.
To prepare this article I have taken the help from MSDN.
To create a SharePoint Foundation project for the WCF service, open the ProjectTracker solution in Visual Studio. In Solution Explorer, click the solution. On the File menu, point to Add, and then click New Project. In the Installed Templates tab of the Add New Project dialog box, expand Visual C# node, select SharePoint, select Empty SharePoint Project, and then type ChangeTitleWCFProject as the name of the project. Click OK.
In the SharePoint Customization Wizard, verify that the correct local site is specified for debugging. Because sandboxed solutions do not support WCF services, select Deploy as a farm solution, and then click Finish.
To create the external WCF project to obtain its IService1 and Service1 .cs files, click the ProjectTracker solution again, and follow the same procedure as in Step 1 to open the Add New Project dialog box. Expand Visual C# node, select WCF, select WCF Service Library, type ChangeTitleWCF as the name, and then click OK.

Copy the generated IService1 and Service1 files into the ChangeTitleWCFProject project. Because you no longer need the WCF Service Library project, you can remove it from the solution by right-clicking the WCF Service Library and clicking Remove.

Add references in the ChangeTitleWCFProject to the System.Runtime.Serialization and System.ServiceModel WCF assemblies, and to Microsoft.SharePoint, the main assembly of the server object model. Right-click the ChangeTitleWCFProject, click Add Reference, and select each of these assemblies on the .NET tab.

To add a reference to Microsoft.SharePoint.Client.ServerRuntime, which contains the service factories that are provided by SharePoint Foundation, use the Browse tab of the Add Reference box to navigate to the Microsoft.SharePoint.Client.ServerRuntime.dll file in %Windows%\assembly\GAC_MSIL\Microsoft.SharePoint.Client.ServerRuntime, select the DLL, and then click OK.

To specify the contract of your custom WCF service in IService1.cs replace the auto-generated service contract with the following interface definition, where the ChangTitle method accepts the name of the list in which to change the title of the item






  Now that the implementation of the service is ready, you can deploy the service to SharePoint Foundation. Right-click the ChangeTitleWCFProject project, point to Add, and click SharePoint Mapped Folder. In the Add SharePoint Mapped Folder dialog box, select ISAPI, and then click OK to map the ISAPI folder of the SharePoint Foundation hive to the ChangeTitleWCFProject project. If Visual Studio creates a ChangeTitle subfolder in the ISAPI folder of the ChangeTitleWCFProject, right-click the subfolder and click Remove to delete it.
 To create a registration file for your service in the ISAPI folder, click the ISAPI folder in your project, and on the Project menu, click Add New Item. Under Installed Templates, select General. Select Text File, name the file Revert.svc, and then click Add.
 

Add the following service declaration to ChangeTItle.svc, which specifies the SharePoint Foundation factories and the namespace that contains them. In the example, MultipleBaseAddressBasicHttpBindingServiceHostFactory specifies the service factory for the SOAP type of web service. The service class declaration also specifies the name of the service class and uses a token to specify the strong name of the assembly.

<%@ServiceHost Language="C#" Debug="true"
    Service="WcfService.ChangeTitleService, $SharePoint.Project.AssemblyFullName$"
    Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory,
Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=80e7sde143e94929r" %>

After you add the previous tag, save the project and close the .csproj file. In Solution Explorer, right-click the ChangeTitleWCFProject project, and then click Reload Project.

 To deploy the custom web service to SharePoint Foundation, in Solution Explorer, right-click the ChangeTitleWCFProject project, and then click Deploy. Visual Studio compiles the project’s code, builds a WSP file, and deploys the file to the front-end web server.

  To use the custom web service from your ProjectTracker client application, right-click the Service References node of the application in Solution Explorer, and then click Add Service Reference. In the Add Service Reference dialog box, type the URL of your custom WCF service in the Address box, and specify MEX as the standard name for the metadata exchange endpoint, as follows: http://Server/sites/SiteCollection/MyWebSite/_vti_bin/Revert.svc. Click Go to download the service information, and then click OK to add the reference.


  Double-click the Change button and add to its Click event the following standard WCF proxy setup code with a call to your custom WCF service. Resolve references to assemblies by right-clicking red underlined elements in the code, pointing to Resolve, and accepting recommended assembly references for the System.ServiceModel namespace and for the namespace of your custom WCF service (ProjectTracker.ServiceReference2).
This is how it’s get used in the separate application.


Sunday, November 10, 2013

Important points to remember while estmating software projects

Estimating the project with 100 % accuracy is the big challenge to project managers.By doing the exact estimation of the project will lead the project to successful path. There are multiple project estimation techniques available but none of them provides the accurate estimation for  project.
Each estimation technique has different parameters to consider and each technique gives the different estimates. 

I am trying here to put some light as per my project management experience on different points those must need to be considered while doing the estimation of the project.

I will talk about various estimation techniques in my next blog/ 

#1. Define the project management practice before doing the estimation
Lot of managers ignore this point while doing the estimation. Ignorance of this leads to more problems and issues in the project development stage. If the project is not estimated by considering which project management to follow then there will be lot of wish list from client side in each development module. It become very hard to control the project as your development time goes in decreasing and new CRs makes it more complex and time consuming. So your previously estimated time and cost never matches with you estimation and mostly project moves in to controversies.

 
 Define the project methodology and make it clear to stakeholder and then estimate it.

#2.Try the estimation with available different estimation techniques
Estimation is one of the important stage in any project life cycle  which allow to help in decision making. Stake holder always like to know that all his money going in the right direction with accurate efforts or not. They always try to push you back on big amount and ask for clarification and justification for on big amount tasks. PM must have to be prepared for this because accurate reasons will only satisfy the client.PM must need to compared the estimation with different available techniques before coming to conclusion. Using different techniques will help in understanding the difference and almost able to reach to approximate estimation. 

#3.Plan for bombshell buffer
None of the project can be planned with out buffer.You never no what will happen in the future. Some times your planned resource will leave or resource will not come up with results on time. There could be some technical problems which could delay your planned tasks.And likewise there are lot of things which could delay your planned tasks. So its always essential to have right buffer time allocated with each task.
Allocating buffer time  also have lot of  parameters to think of. Some of them are task complexity, technology illiteracy and resource experience etc.
So PM has to always prepared for such bombshells and need to have proper buffer shield to get protected from this effect.

#4. Allocate proper time for training
Training is not always required but in some projects you need to learn and develop and here it becomes very  important. While doing the estimation PM should think of this point and depending on the requirement allocate proper time for it.

#5.Estimate the project based on the task not on the calendar time
Stake holder always concentrates on the project delivery date. He  is never interested in understanding how big and complex is the project.Once requirements are over then every one right from CTO to VP and client are eager to know the go live date. Here PM has to give exact date and have to complete the project before provided date. So for having the smooth delivery of the project  its important to estimate the project on micro level task and add each micro task with proper time line in the plan.

Hope above five points could help PMs for providing the right estimation on the project. Finally estimations are approximate not exact.  :)



Thursday, October 17, 2013

Few exciting fetures for Users and Developers from Share Point 2013



Share Point 2013 is launched with many features and all these features are useful to the users. These changes are definitely going to make users and developers life very easy in case of the share point usability. Some of the new features are listed below with its short description.

Easy Migration Process
Now it’s very easy to migrate from old versions of the share point to the new Share Point 2013.MS have not only brought the simplicity to migration but also increased its scope by allowing the other platforms content to migrate in share Point. Now you can migrate the content from lotus notes, document rooms, file system and MOSS 2007.

Email Classification
This is completely new feature in Share point 2013. The Site Mailbox is the new feature introduced in 2013 which allows us to classify the mail with category, we can forward these mails to share point, drag drop options from mail box to share point sites and same with mail attachments to document library folders 

Simple and standard Programming Model
Share Point 2013 introduced some more programing approaches with existing server object model and client side object model. Share Point Apps is mainly developed with HTML, CSS and JS and this Web standard. So now it’s not required to have share point developer knowledge to design and develop share point features. Its worry point for specialized SP developers..! :)
Share Point supports OData and OAuth standard protocol for communicating with share point data model

Yameer… Integration
The acquisition of Yameer to MS has made tremendous impact in social collaboration. It has now brought all the people more closely and people can not only chat but micro blog with reply, likes dislikes comments like FB. This interaction will definitely impact in accurate project delivery and revenue increase.

Thursday, September 19, 2013

CRUD operations using Share Point 2013 REST API's

Share Point 2013 REST (Representational State Transfer)API can be used to communicate with share point remotely. Its similar like what we learned in CSOM (Client Side Object Modal) share point 2010

To access share point list library data you need to implement REST FUL requests using OData (Open Data Protocol)  standard. Share Point 2013 provides some commands to be used with REST services for performing CRUD operations.



Operation
Command
 Description
Read a resource
GET
Read data from share point
Create or update a resource
POST
Write data to share point
Update or insert a resource
PUT
Use PUT and MERGE operations to update existing SharePoint objects.
Delete a resource
DELETE
Use the HTTP DELETE command against the specific endpoint URL to delete the SharePoint object represented by that endpoint.
 
CRUD operation done on list using the REST

Use below JS reference to for REST API 





Hope this will help in enhancing your share point knowledge..!


Thursday, September 5, 2013

New Era in Share Point 2013 workflows



In Share point 2013 workflow has changed drastically, it’s very  impacting change,We can say that its now new era for Share Point workflows. You can check more information at Technet.
SharePoint Designer 2013 now includes everything you need to build these new workflows, with some nice improvements over the previous version:

  • Visual development tools using a Visio 2013
  • New building blocks like App Step, Stage and Loop
  •  Ability to call web services  without writing any code

Workflow runs under Windows Azure Workflow. This will take the workflow processing out of share Point and creating a Workflow farm.

The SharePoint farm(s) now have less processing to do. The WAW environment will manage the workload and update SharePoint via web service connections. SharePoint has plenty of loads to manage and SharePoint 2013 introduces multiple features that are, or can be, offloaded to other environments outside of SharePoint.
One more important ability to use WAW for multi- and cross-platform workflow. This will allow developer to host all your .NET workflows, regardless of if they’re SharePoint, for Windows applications, or Web applications. There’s also the ability to reuse the same workflow for multiple platforms.

Workflow Manager capabilities
Workflow Manager brings a new class of workflow to SharePoint Server 2013. Workflows built by using Workflow Manager can take advantage of several new capabilities. These include enterprise features such as:

  • High Density and Multi-Tenancy
  • Elastic Scale
  • Activity / Workflow Artifact Management
  • Tracking and Monitoring
  • Instance Management
  • Fully Declarative Authoring
  • REST and Service Bus Messaging
  • Managed Service Reliability