RSS Feed

SharePoint 2010 on the Laptop

Technorati Tags:

After a couple of tries, I have finally installed the SharePoint 2010 Foundation on my laptop. I need a development environment to play around with.

I tried installing everything on the virtual machine with Windows 7 host but 2gb ram wasn’t enough to even run the sql scripts. Don’t try installing the Sharepoint 2010 Enterprise it needs eight gb ram in the system.

My Specs:

Intel i5 Core 430M

4GB Ram

Here it is my own SharePoint 2010 \o/

sharepoint

The How To instruction  is on the MSDN page.

http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx


SPTimerJob parameters using the SPPersistedObject

Timer Job is a very useful service available in SharePoint. You can set a function which will be executed on the specific time. This scenario is useful in many SharePoint applications. It’s just like running SQL server job.

When working with the timer jobs, there is a little problem with parameters from the external source. Timer job doesn’t store passed parameters. In scenario, I have encountered in my job, there was a feature which was activating the TimerJob. On Feature parameters needed for the timer job were de-serialized from the xml file,  then they were passed to the timer job constructor. When executed timer job was returning the default values, not the values from the xml file.

I started looking for a solution, and found the SPPersistedObject class which gives us the ability to remember the parameters in SPFarm.

The SPPersistedObject class provides a base class for all administration objects. It serializes all fields marked with the Persisted attribute to XML and writes the XML blob to the configuration database. The SPPersistedObject class contains code to serialize all its members that are base types, other persisted objects, and collections of persisted objects. Configuration data that is stored in persisted objects is automatically made available to every process on every server in the farm.

Let’s assume we have a scenario with a feature activating our timer jobs. We need to fill it with various parameters. To activate the timer job, we are using the feature receiver class, and feature activate method. First of all, we need to get our parameters to the feature receiver. I am using the serialized settings’ class and an xml file. Parameters from the xml are then used to create the SPPersitedObject. Base class is doing all the work with de-serialization and serialization of data. I only had to call the proper function before job execution to get the parameters.

image

How to use the SPPersistedObject

First of all, we have to create our class with parameters. It has to extend the SPPersistedObject. Every field we want to be “persisted” should be marked by a [Persisted] attribute. We have to create the properties explicit because only fields can

be marked with this Attribute after creating this class all you have to do is to create the object fill it with parameters and then save it to the SPFarm.

1 public class TimerJobSet: SPPersistedObject 2 { 3 [Persisted] 4 public string siteName; 5 6 [Persisted] 7 public bool Debug; 8 9 public TimerJobSet(string name, SPPersistedObject parent) : base(name,parent) 10 {} 11 }

With this simple class, the first step is to create the Persisted Object on the SPFarm. It is really important to call the Update() method.

1 SPWeb web = properties.Feature.Parent; 2 SPSite site = web.Site; 3 4 SPPersistedObject parent = site.WebApplication; 5 CustomTimerJobSettings settings = new TimerJobSet("TimerJobSet", parent, Guid.NewGuid()); 6 settings.Debug = false; 7 settings.siteName= "host.com"; 8 settings.Update();

The object is serialized. Now while executing the Timer Job all we have to do is to get the parameters from the SPFarm.

1 TimerJobSet settings = this.WebApplication.GetChild<TimerJobSet>("TimerJobSet"); 2  string siteName = settings.SiteName; 3  bool debug = settings.Debug;

That’s all. Hope this will help someone in his work. Have fun with Timer Jobs.


Sharepoint – Exceptions

Today I was doing the “boring” stuff. Yeah , creating list definitions , field definitions and installing features it is … boooring. You have to “click click click”.

By the way a co-worker told me about a nice addin to Visual Studio InsertGuid it’s quite useful.

InsertGuid

Ok so while developing I encountered an exception “cannot complete this action please try again” when SPField.Update() was called. So, I started to check recent modifications. Nothing. Checked the Iist. Nothing. Restarted the Iist. Nothing . Recreated whole site on the sharepoint. Nothing. Then while inspecting schema I realized that my ContentType Definition had a typo in its ID parameter.

It was
0x01CBC435A1D27A418DA9AB503224F75CDA
but should be
0x0100CBC435A1D27A418DA9AB503224F75CDA
4 hours wasted …

Definitely the best one of those special Exceptions is “Unspecified Error” when calling Unmanaged classes. Very informative , elegant just cool. This one happened when I was calling Active Directory and performed a Check if a user exists which used the DirectorySearcher.FindAll() method …. couple hours wasted and solution ?? Application pool or user with permission to AD had too low security access.

Doh , You just have to love those “special” exceptions . I hope that this short post will be helpful to some poor soul trying to figure out “What the hell happened?” 😀


Remote deployment – Sharepoint

In software development job we are doing lots of repetitive tasks. Like recycling iis , copying files , connecting to remote server etc etc. On Sharepoint there are lots of „boring” things to do. One of those “things ” is deploying dll to a remote server. I hate this . You have to log in to a server, copy the file , open the gac and manually drag n drop it to a folder. You can’t just copy it by „Total Commander”.
Ok i aggree it is not a problem with 1 – 2 deploys in an hour but if you are testing something it can get to 10 – 20 times per hour.

I was looking for a tool to do the deploy phase faster and remotely without alt-tabing and Yey there is such a tool RemoteGcUtil. You can insert server address . Load the gac , explrore it and with just 2 simple clicks install new file to Gac.

Its gets better , if you want to reload the assembly file you don’t have to browse again to find the file the path to recent file is and you just need to click open again .It’s really great and it’s working flawless . I was using it today multiple times and it worked great.

After deploying the assembly we have to recycle the application pool. At the beginning i was using mouse clicking through the menus of iis manager. Later i discovered the command iisapp /a Poll Name /r. I created a bat file and this process became faster , but If I am remotely deploying files to gac there have to be a possibility to run this command remotely. This would cut the time to do the “boring” stuff significantly.

There is a Power Shell script to do this.
http://gallery.technet.microsoft.com/ScriptCenter/en-us/56962f03-0243-4c83-8cdd-88c37898ccc4

It looks promising, I have to test it soon.

Power Shell definitely next thing to learn.