Friday, January 27, 2012

SharePoint : How to run Code on All Web Servers -A Timer Job or multi-server jobs

How to run Code on All Web Servers (All WFE for instance) : A Timer Job or multi-server jobs:




To define a timer job

  1. In Visual Studio, start an Empty SharePoint Project. Make it a farm solution, not a sandboxed solution.
  2. Highlight the project name in Solution Explorer and be sure that Include Assembly in Package in the Properties pane is set to true.
  3. Add a C# or Visual Basic class file to the project.
  4. Open the class file and add using statements (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Administration namespaces. You may need to add other using statements depending on what namespaces are called by the code that you want to execute on all servers. For the running example in this topic, add using statements for System.Xml.Linq, System.Xml.XPath, System.IO, and System.Runtime.InteropServices.
  5. Change the namespace to conform to the guidelines in Namespace Naming Guidelines; for example, Contoso.SharePoint.Administration.
  6. Change the class declaration to specify that the class inherits from SPJobDefinition or from some class that derives from SPJobDefinition.
  7. Decorate the class declaration with a GuidAttribute attribute. This is a requirement for any class that derives directly or indirectly from SPPersistedObject.
  8. Add a default (parameterless) constructor to the class that simply calls the base constructor.
  9. Add a constructor with parameters of types String, SPWebApplication, SPServer, and SPJobLockType. Its implementation should call the base constructor SPJobDefinition(String, SPWebApplication, SPServer, SPJobLockType). The following shows what your code should look like in C# at this point.
...Read on...

    Programming the SharePoint Foundation 2010 Mobile Adaption Framework

    Saturday, January 21, 2012

    ASP.NET MVC 4, HTML5, and jQuery Mobile

    What ASP.Net MVC 4 is doing to make mobile web dev better easier.
     In this session, learn how ASP.NET MVC 4 leverages these next generation technologies enabling developers to build a single solution that targets multiple platforms and form factors such as mobile, tablet and desktop devices

    -Adaptive rendering, CSS3 media queries

    Few things i'm exploring

    -Nodes.js/azure
    -NoSQL/RavenDB
    -SQLFire -

    NoSQL/RavenDB:
    -Written in .Net
    -A document database, based on JSON
    -Schema-less JSON
    -Non-relational data store

    -ASP.Net MVC 4

    Nuget

    NuGet Overview

    NuGet is a Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects that use the .NET Framework. When you add a library or tool, NuGet copies files to your solution and automatically makes whatever changes are needed in your project, such as adding references and changing your app.config or web.config file. When you remove a library, NuGet removes files and reverses whatever changes it made in your project so that no clutter is left.

    NuGet provides a quick and easy way to add features to an existing application while ensuring that those features are integrated into source control. After installing a library, you can commit changes to your source control repository, and then another developer can perform a get operation against the repository in order to start working with the new features....Read on

    Building Web APIs in Windows Azure with WCF to reach any device

    A very cool and interesting session on Building Web APIs in Windows Azure with WCF to reach any device : from http://channel9.msdn.com

    Few things to note:
    -JSONObject, a new type that gets shipped as part of Web API

    SharePoint 2010 AppFabric Distributed Caching & Session Management

    I had an opportunity to explore a bit on AppFabric (Distributed Caching  & Session Management) back in July 2011. I wanna share what i have learned:


    Overview
    Caching is very beneficial for web applications that need to maintain state, especially when that state needs to be maintained in a scaled Web Farm scenario. However, there are two problems with the classic implementation. The first is that when using the local machine to cache state, you need to ensure that the client gets routed back to the same machine to get back the state (sticky routing a.k.a sticky session). If you decide to put the state in a database, you incur additional overhead and performance drag in managing this state across servers. The AppFabric cache can help to solve both these challenges.
      
    App Fabric Distributed Caching & Session State
    • We are developing a very large SharePoint farm, that would be used by over 90k users,  with a lot of information, custom components and various different sub-systems .
    • We were considering to use Windows Server AppFabric Caching for distributed caching to  manage some of the not-so-frequently updated information in the Cache store instead of accessing them from database.  Though,  we were using the local machine to cache state,  but you need to ensure that the client gets routed back to the same machine to get back the state (sticky routing a.k.a sticky session).   The AppFabric distributed  Caching can help to solve this issue. 
    • Besides,  we also wanted to figure out the need to maintain  users's session(session state), especially when that state needs to be maintained in a scaled Web Farm scenario.  If you decide to put the state in a database, you incur additional overhead and performance drag in managing this state across servers. AppFabric works just fine with ASP.NET Session State and I assumed that it would work as fine as with SharePoint 2010.
    Architecture
    The architecture of the SharePoint application is typical of a SharePoint  web application and can be summarized as follows:


    • A database stores application data from a Content management system, containing tables with users, content, with security, and targeting information for the content.
    • Horizontally scalable web servers (WFE) perform the basic functions of authentication (Security), authorization (content-targeting), searching (content searching), etc.,. These WFEs has got custom Web Parts that are working with REST-based service layer which are hosted on these servers.
    • Each request to the web server (WFE) generates a request to the database followed by some additional processing of raw data and applying domain logic on the data-layer.
    Setup and Configuration
    Installing AppFabric Cache
    In this task you will install and configure Windows Server AppFabric Cache.

    1.       Downloaded AppFabric setup application from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=15848
    WindowsServerAppFabricSetup_x64_6.1.exe

    2.       Selected and Installed Caching Services and Cache Administration.

    3.       Configured Caching Service and created to New cluster with 1-5 machines . 
    Using the Cache API

    I have created a new named Cache, we are going to write a simple SharePoint Web Part that reads/writes data in the cache. You can of course store any serializable .NET object in the cache. To use the Cache you need to reference the Cache client assemblies.

    1.       Microsoft.ApplicationServer.Caching.Core.dll is the Cache’s base library, referenced by both the Cache’s client layer and server layer. It contains things like the configuration libraries and base Cache types.

    2.       Microsoft.ApplicationServer.Caching.Client.dll  contains the Cache’s client library, which is the API that connects to the Cache cluster to store and retrieve data.

    AppFabric cache configuration inthe web.config file

    XML
    <configSections>
    <section name="dataCacheClient"
     type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </configSections>
    <dataCacheClient>
    <hosts>
    <host name="hostname" cachePort="22233" />
    </hosts>
    </dataCacheClient>

    3.  There's a public method named GetCachedName that returns a string. Inside of that method, you will get the DataCacheFactory , and then look for a key in the Lab1Cache named  

    C#
    public string GetCachedName()
        {
        string name = null;
        string key = "ApplicationName";
                 dcf = new DataCacheFactory();
                if (dcf != null)
                {
                    var cache = dcf.GetCache("Lab1Cache");
                    name = cache.Get(key) as string;
                    if (name == null)
                    {
                        name = "Windows Server App Fabric Cache Lab";
                        cache.Put(key, name);
                    }
                    else
                    {
                        name += " From Cache!";
                    }
                }
        return name;
    }
    Using the AppFabric Cache ASP.NET Session State Provider in SharePoint 2010

    ·         If you have already used ASP.NET session state to store user activity data, you can just change the web.config sessionState binding and have the Cache take over storing ASP.NET Session State across the cache cluster. This enables you to simply add scale and performance without any code changes to your existing web applications.

    1.       Execute the Get-CacheHost cmdlet to see the state of your cache cluster.
    ·   PowerShell

    ·   Get-CacheHost

    You should see something that looks similar to the following Figure. Note that the Service Status is Down


    1.       Use the $myhost.HostName and $myhost.PortNo properties as the input to Start-CacheHost. 

    ·   PowerShell

    ·   $myhost = Get-CacheHost

    ·   Start-CacheHost $myhost.HostName $myhost.PortNo

    You should see something that looks similar to following Figure . Note that the Service Status is UP

    ·          


    ·        

    2.       Configure the underlined SharePoint Web App to use the AppFabric Cache ASP.NET Session State Provider. Web.Config file
             XML

    ·            <sessionState mode="Custom" customProvider="SessionStoreProvider">

    ·               <providers>

    ·                 <add name="SessionStoreProvider" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider, Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" cacheName="Lab1Cache" />

    ·               </providers>

    ·             </sessionState>

    Understand the ramifications of moving session out of process. 

    Once you move session state outside of the web server process, all the objects you put in the Session need to be serializable.





     

    Wednesday, January 18, 2012

    SharePoint Diagnostics Studio 2010

    SharePoint Diagnostics Studio 2010 on Technet.
    Its free and it can monitor just about anything SharePoint.

    Tuesday, January 17, 2012

    Windows 8 Secure Boot

    Secure Boot stops a computer from loading an operating system that hasn’t been signed by the publisher (in this case, Microsoft or an OEM), and its signature added to the computer’s firmware...from Read On>>>

    Monday, January 16, 2012

    HTML 5 or Silverlight?

    Article pays close attention to details of similarities and dissimilarities between HTML 5 and Silverlight. The discussions and comments were really interesting by itself than the article.

    I like this part though:
    "Applying the Best
    Microsoft has no control over the mobile market right now since they have to support HTML5 strongly. They’re not dictating terms, and it’s questionable whether they would if they could. Microsoft’s strategy is to apply the best tools and platform possible, regardless of whether it is proprietary."
    Read on: http://www.infoq.com/articles/Html5-or-Silverlight

    Reverse engineering Win8 Apps

    A very interesting blog post on reverse engineering Win8 Apps:
    Talks about a bit of internals of Metro style Apps, especially the apps that came with Win 8 Dev Preview
    http://justinangel.net/ReverseEngineerWin8Apps

    Building cross-platform mobile apps

    Thanks to, my friend, 'KK' for being an eye-opener for me to point this out recently. From http://phonegap.com/

    Get cross-platform mobile apps in three easy steps

    1. Write your app using HTML, CSS and JavaScript
    2. Upload it to the PhoneGap Build service
    3. Get back app-store ready apps for Apple iOS, Google Android, Palm, Symbian, Blackberry and more.

    What is PhoneGap?

    PhoneGap is a standards-based, open-source development framework for building cross-platform mobile apps with HTML, CSS and JavaScript for iPhone/iPad, Google Android, Palm, Symbian, BlackBerry, Windows Mobile and more.
    Write a PhoneGap app once with HTML and Javascript and deploy it to any mobile device without losing features of a native app. Learn more

    Sunday, January 15, 2012

    WinRT replaces Win32API

    Win8 : WinRT replaces Win32API

    "Developing for Windows 7: Classic platforms:
    · HTML/JavaScript on Internet Explorer
    · C/C++ on Win32
    · C#/VB on .NET and Silverlight
    Developing for Windows 8: Metro Style
    Windows Kernel is still at the bottom of the stack
    WinRT is the new OS-level API layer. This is the new native API for Windows, it isn’t a new layer on top of Win32.
    You can access WInRT from C/C++, C#/VB, or JavaScript. XAML is the UI layer for C, C++, C#, and Visual Basic. HTML/CSS will continue to be used as the UI layer for JavaScript." from www.infoq.com/news/2011/09/WinRT

    Windows 8 and Metro style apps

    Windows 8 Developer Preview: I run into this very interesting blog:
    http://arstechnica.com/microsoft/news/2011/06/windows-8-for-software-developers-the-longhorn-dream-reborn.ars

    There appears to be concerns around disregarding years of windows development knownledge and experience, in favor of HTML 5 and JavaScript.

    While its true that you can build Metro style apps using HTML 5 and JavaScript, but you still can have your app logic (code-behind) build using XAML with C++, C# or VB.Net.
    http://msdn.microsoft.com/library/windows/apps/br211386


    Also, you can build reusable component libraries using C++, C# or VB.Net and use them from JavaScript or any supported languages.

    I happen to notice a lot of talk about WinRT.

    Whats WinRT ?
    WinRT stands for Windows Runtime. The WinRT is a set of client side API’s which target the new Windows 8 shell experience. The Windows Runtime (WinRT) is a straightforward set of APIs used to build Metro style apps. WinRT lets you build apps that look great and are intuitive for your customers to use.


    WinRT APIs are available to developers in multiple languages, including JavaScript, C++, C#, and Visual Basic. The new Windows SDK for Metro style apps also includes a subset of traditional Win32, Component Object Model (COM), and .NET Framework APIs, as well as HTML5 and CSS3 APIs that are accessible to Metro style app developers.

    Made me think that HTML 5 with JavaScript is just another feather in the hat. Below dipicts templates in VS2011 in different Metro style app development languages.




    WebMatrix

    Just wanna share what i have learned about WebMatrix.

    What's WebMatrix?
    Microsoft WebMatrix a free open source web design tool that includes a database (SQL Server Compact) and a Web server for testing (IIS Express), along with other tools to help you create and manage sites.

    Where do i use WebMatrix?
    • A great tool to build ASP.Net style small - midsize Web Apps and open source
    • A good startup tool for Classic ASP/PHP developers to transition to ASP.Net
    http://rachelappel.com/webmatrix/webmatrix-what-is-it-why-use-it-and-who-rsquo-s-it-for/
    http://www.computerweekly.com/cgi-bin/mt-search.cgi?blog_id=109&tag=hosting&limit=20