Sunday, November 25, 2012

dynamic keyword in C# 4


The "dynamic" keyword-Working with compiled .NET types is easy in C#
-Type information is available through Reflection
-- It is possible to make runtime calls dynamically
When a decision about calls and call targets is made at runtime, we talk about “dynamic dispatch", or “late binding"
Other language platforms have their own dynamic dispatch techniques (Python, Ruby, but also Automation, Web Services, ...)
--"dynamic" builds a bridge to the Dynamic Language Runtime (DLR)
--The DLR unifies different dynamic dispatch approaches

First Impressions

dynamic i=4
dynamic s="Hi there";
i.DoS0methingImpossible();
Foreach (dynamic thing in things)
DoFal1(thing);


-"dynamic" is used in place of a type
-"dynamic" does NOT correspond to any type
-Runtime types of variables are similar to what you'd expect when using "var"
-Member access on variables declared "dynamic" IS deferred to runtime


Things that don't work
Deriving from "dynamic"
Implementing lEnumerab|e
Extension methods for “dynamic”
Remember: "dynamic" is not a type


Demo:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynamicBasics
{
    class Program
    {
        static void Main(string[] args)
        {
            dynamic i = 42;
            dynamic s = "Hi thcrl";
            Console.WriteLine("Length of my string " + s.Length);
            //i.DoSomethingImp05sible( );
            var things = new dynamic[] { 42, "text value" };
            //dynamic k;
            foreach (dynamic item in things)
            {
                Console.WriteLine(item);
            }
            foreach (dynamic item in GetEnu())
            {
                Console.WriteLine(item);
            }

        }
        static IEnumerable GetEnu()
        {
            yield return "Hi there..";
            yield return 42;
            yield return true;
        }
        static void UseDynamicThing(dynamic thing)
        {
        }


        // The following code snippet is invalid
        //static void UseDynamicThing(var thing)
        //{
        //}
    }
    ///Inheriying from dynamic is not allowed
    ///
    //public class test : dynamic
    //{
    //}
}



The Reflection Misconception
-Dynamic dispatch through the DLR is quite fast
-The idea is obvious to replace mechanisms like Reflection with DLR dynamic dispatch
-The AP|s offered by the DLR don't make this easy
-The "dynamic" keyword makes it easy because the compiler does the work
-If information relevant to the dispatch is not available at compile time "dynamic" can't help

 

XHTML

What  is XHTML?
The advantages of XHTML are:
-Since it is XML syntax, tools can easily parse and work with a XHTML document
-Tools can easily validate the structure of a XHTML document
-The structure of the document can be easily manipulated by the JavaScript DOM API to create
powerful and rich client side applications
-- This is the primary reason for us to use XHTML with AJAX applications
-XHTML provides a way to extend the default markup language This can lead to more specialized
languages


The DTD and MIME Type
- There are three separate DTD files to capture three types of structures
- -XHTML strict — Proper XHTML syntax. IE does not support this very well
- -XHTML transitional — The syntax matches HTML 4 more closely. Supported by all browsers. Recommended for now
- - XHTML frameset — Use this if you are using frames.
- The MIME type of XHTML should ideally be "application/xhtml+xml“
- However, IE does not support this. So, keep using the MIME type "text/html" until IE supports the actual MIME


The Basic Syntax
- The document should start with an XML preamble
-
- Next, the document must have a DOCWPE element and specify the DTD location
- "http://www.w3.org/TR/xhtml1lDTD/xhtm|1-
transitional .dtd" >

- Next, the root level element must be
- This and all other XHTML elements are defined in the "http://www.w3.org/1999/xhtml" namespace.
- It is recommended that you use an empty prefix for this namespace to simplify the document



"http://www.w3.org/TR/xhtm11/DTD/xhtm11-transitional.dtd“>





Differences With HTML 4
- In XHTML, all element names are in lower case
- - Valid in XHTML
- - Valid in HTML 4
- All elements must be nested properly
- Hel|o World.
- Valid
- Hel|o World
.
- Invalid XHTML- Some XHTML elements must have a body. They must have an end tag
- Hello World.
- Valid
- Hello World. - Invalid
- Some XHTML elements must not have any body
-
or

- Valid
-
or

- Invalid

- Attribute values must be quoted
- - Valid
- - Invalid
- An attribute must have a value
-



- In HTML 4, some elements (such as form and img) used the attribute "name" and "id" interchangeably to identify the element
- In XHTML, only the "id" attribute should be used
-

- In HTML 4, values of enumerated attributes were case insensitive. In XHTML, they must be
in lower case
- - Valid
- - Invalid for XHTML


Embedding Scripts and Styles
- The
-

XHTML

What  is XHTML?
The advantages of XHTML are:
-Since it is XML syntax, tools can easily parse and work with a XHTML document
-Tools can easily validate the structure of a XHTML document
-The structure of the document can be easily manipulated by the JavaScript DOM API to create
powerful and rich client side applications
-- This is the primary reason for us to use XHTML with AJAX applications
-XHTML provides a way to extend the default markup language This can lead to more specialized
languages


The DTD and MIME Type
- There are three separate DTD files to capture three types of structures
- -XHTML strict — Proper XHTML syntax. IE does not support this very well
- -XHTML transitional — The syntax matches HTML 4 more closely. Supported by all browsers. Recommended for now
- - XHTML frameset — Use this if you are using frames.
- The MIME type of XHTML should ideally be "application/xhtml+xml“
- However, IE does not support this. So, keep using the MIME type "text/html" until IE supports the actual MIME


The Basic Syntax
- The document should start with an XML preamble
-
- Next, the document must have a DOCWPE element and specify the DTD location
- "http://www.w3.org/TR/xhtml1lDTD/xhtm|1-
transitional .dtd" >

- Next, the root level element must be
- This and all other XHTML elements are defined in the "http://www.w3.org/1999/xhtml" namespace.
- It is recommended that you use an empty prefix for this namespace to simplify the document



"http://www.w3.org/TR/xhtm11/DTD/xhtm11-transitional.dtd“>





Differences With HTML 4
- In XHTML, all element names are in lower case
- - Valid in XHTML
- - Valid in HTML 4
- All elements must be nested properly
- Hel|o World.
- Valicl
- Hel|o World
.
- Invalid XHTML- Some XHTML elements must have a body. They must have an end tag
- Hello World.
- Valid
- Hello World. - Invalid
- Some XHTML elements must not have any body
-
or
- Valid
-
or
- Invalid

- Attribute values must be quoted
- - Valid
- - Invalid
- An attribute must have a value
-

- In HTML 4, some elements (such as form and img) used the attribute "name" and "id" interchangeably to identify the element
- In XHTML, only the "id" attribute should be used
-

- In HTML 4, values of enumerated attributes were case insensitive. In XHTML, they must be
in lower case
- - Valid
- - Invalid for XHTML


Embedding Scripts and Styles
- The
-

XHTML

What  is XHTML?
The advantages of XHTML are:
-Since it is XML syntax, tools can easily parse and work with a XHTML document
-Tools can easily validate the structure of a XHTML document
-The structure of the document can be easily manipulated by the JavaScript DOM API to create
powerful and rich client side applications
-- This is the primary reason for us to use XHTML with AJAX applications
-XHTML provides a way to extend the default markup language This can lead to more specialized
languages


The DTD and MIME Type
- There are three separate DTD files to capture three types of structures
- -XHTML strict — Proper XHTML syntax. IE does not support this very well
- -XHTML transitional — The syntax matches HTML 4 more closely. Supported by all browsers. Recommended for now
- - XHTML frameset — Use this if you are using frames.
- The MIME type of XHTML should ideally be "application/xhtml+xml“
- However, IE does not support this. So, keep using the MIME type "text/html" until IE supports the actual MIME


The Basic Syntax
- The document should start with an XML preamble
-
- Next, the document must have a DOCWPE element and specify the DTD location
- "http://www.w3.org/TR/xhtml1lDTD/xhtm|1-
transitional .dtd" >

- Next, the root level element must be
- This and all other XHTML elements are defined in the "http://www.w3.org/1999/xhtml" namespace.
- It is recommended that you use an empty prefix for this namespace to simplify the document



"http://www.w3.org/TR/xhtm11/DTD/xhtm11-transitional.dtd“>





Differences With HTML 4
- In XHTML, all element names are in lower case
- - Valid in XHTML
- - Valid in HTML 4
- All elements must be nested properly
- Hel|o World.
- Valid
- Hel|o World
.
- Invalid XHTML- Some XHTML elements must have a body. They must have an end tag
- Hello World.
- Valid
- Hello World. - Invalid
- Some XHTML elements must not have any body
-
or

- Valid
-
or

- Invalid

- Attribute values must be quoted
- - Valid
- - Invalid
- An attribute must have a value
-



- In HTML 4, some elements (such as form and img) used the attribute "name" and "id" interchangeably to identify the element
- In XHTML, only the "id" attribute should be used
-

- In HTML 4, values of enumerated attributes were case insensitive. In XHTML, they must be
in lower case
- - Valid
- - Invalid for XHTML


Embedding Scripts and Styles
- The
-

Saturday, November 24, 2012


Web Application Architecture

Web front end-Hosts web applications that users access with a browser or other types of client
Application Services - hosts service applications and Central Admin
Sql Server - Database

File Locations and Storage
-Some resources always come from the file System
--Core list definitions
--Application pages
--Core user controls
--More
-Some always come from the content database
--List items
--Documents
-Sometimes it depends on the state of the resource (User customization)

Configure Management
-Do not directly edit files that SharePoint Installers
-Use solution packages
-SharePoint will keep the servers in the form in sync.

Security, Safety and scalability.
-SharePoint Designer based customization could be dangerous
-Inline code blocks
-Unapproved controls and web parts
-Too many controls on a page

Sharepoint provide safety
-SPRequest HttpModule
-SPVirtualPathProvider
-SPPageParserFilter
-Safe Mode processing

-Adding a control is allowed but inline code block not allowed by default
-In order to allow inline code blocks, add following in in web.config in tag


entry in config to allow rendering the control.

Form and Sandbox
-Files in Sharepoint root are deployed as farm solution.
-Farm solution deployment requires admin access to the form.
-Problem for hosted and governed environmrnts
-Sandbox solutions provide a safe alternative
-Sandbox solution pages are subject to Safe mode
-Additional  restriction apply.


 

Friday, November 23, 2012

Deployment -Project properties -SharePoint Tab -Pre n Post deployment command -Deployment configuration --Run Pre deployment Command --Run Post Deployment command --Recycle IIS App Pool --Retract Solutions --Add Solution --Activate Feature Debugging Control, pages and Workflow -Press F5 -Debug as normal -Do not activate feature if debugging receiver assemblies Other scenario -Attach to process -W3wp.exe -SPUCWorkerProcess.exe Sandbox Solution -OWSTimer.exe Timer job Development by reverse engineering -Save site as template -Import into visual Studio -Select the feature of your choice to modify.
Exploring the object model
-Visual Studio 2010 Server Explorer
--Sanitized view of a site's contents
--Good high level view from Site collection down
-SharePoint Manager 2010
--Can be downloaded from https://spm.codeplex.com
--More complete view from farm dowwn
--Allow changing certain properties
-Visual Studio 2010 Object explorer
-Red Gate .net Reflector Core Foundation Assembly
-Located in 14\ISAPI
-Microsoft.Sharepoint Core classes
-Microdogy.sharepoint.Client
 - Core classes for client application
-Microsoft.Sharepoint.Linq
- Linq to SharePoint
-Microsoft.Sharepoint.WorkflowActions
- Sharepoint specific workflow actions

Core Classes
SPSite
-SPWeb
--SPField
--SPContenttype
--SPFile
--SPList
---SPListItem
--SPUser 

SPContext Access to current request context via SPContext.Current
-Site
-Web
-List
-Listitem
-More SPContext is governed by the security context of Web.CurrentUser Security exception if code tries to access what use can't

 Common Conventions
Item name is title property
-SPWeb.Title
-SPList.Title
-SPContenttype.Title

 Collection Indexer Overload
-Ordinal overload
-GUID
-Title (If applicable)

Property changes persist by calling Update() 

Security, Identity and Impersonation
-Default runtime identity --Authenticated user
-Execution context --Current site collection
--SPContext.Current.Site
-Elevate Permission
--via impersonation
--New site collection object instance SPSecurity.RunWithElevatedPriviledge
-Delegate -Does not require user id or password
-Permission constrained by service account permission
-Require a new instance of SPSite for security context

 AllowUnsafeUpdate
-Property of
--SPSite
--SPWeb
-set to true to disable security validation on Update()
-Required if persisting anything within RunWithElevatedPriviledge
-Any exception, handled or otherwise, sets AllowUnsafeUpdates to false.
Best Practices
-SharePoint Avoiding memory leaks
-Use Dispose appropriately
-Use SPDidsposeCheck utility to identify issues
-General Rules
--No need to dispose from SPContext
--if you use new, you should use dispose()
--Use dispose when
---Enumerating AllWebs or Webs
---OpenWeb

-Don't use dispose with
 --ParentWeb
--RootWeb

 SPDisposeCheck to be installed and put. a post build event to fire it and specify the subdir filter the output to some text file and include it in the project.

Developer Dashboard
-Metrics and trace of page load
-can be activated via stsadm or powershell script
---stsadm -o setproperty -pn developer-Dashboard -pv OnDemand
 -Logs --14\logs --Correlation Id -Modify web.config file. -- --