Managed AddIn Framework (MAF)
- Managed Add-in Framework
- The assemblies for these segments are not required to be in the same application domain. You can load an add-in into its own new application domain, into an existing application domain, or even into the host’s application domain. You can load multiple add-ins into the same application domain, which enables the add-ins to share resources and security contexts.
The add-in model supports, and recommends, an optional boundary between the host and the add-in, which is called the isolation boundary (also known as a remoting boundary). This boundary can be an application domain or process boundary.
The contract segment in the middle of the pipeline is loaded into both the host’s application domain and the add-in’s application domain. The contract defines the virtual methods that the host and the add-in use to exchange types with each other.
To pass through the isolation boundary, types must be either contracts or serializable types. Types that are not contracts or serializable types must be converted to contracts by the adapter segments in the pipeline.
The view segments of the pipeline are abstract base classes or interfaces that provide the host and the add-in with a view of the methods that they share, as defined by the contract. Source : MSDN
Filed under: Add-in Development, Managed Addin Framework | 1 Comment
Tags: MAF, Managed Addin Framework
It is quite likely that many of you get requirements to extend the MS Office applications’ capabilities based on your business needs. Well, we are talking about the .NET development and the framework provides you capabilities for developing Office based solutions using Visual Studio Tools for Office.
This portal (Office Development with Visual Studio) provides many resources related to Office Solutions development using .NET framework including Add-In development for MS Office 2003 and Office 2007
How does Add-Ins work with MS Word, Excel etc?
Add-ins that are created by using Visual Studio Tools for Office consist of an assembly that is loaded into a Microsoft Office application as an add-in. Add-ins that are created by using Visual Studio Tools for Office have access to the Microsoft .NET Framework as well as the application’s object model. When you build an add-in project, Visual Studio compiles the assembly into a .dll file and creates a separate application manifest file. The application manifest points to the assembly, or to the deployment manifest if the solution uses one.
Visual Studio Tools for Office provides a loader for add-ins that are created by using Visual Studio Tools for Office. This loader is named AddinLoader.dll. When a user starts the Microsoft Office application, this loader starts the common language runtime (CLR) and the Visual Studio Tools for Office runtime, and then loads the add-in assembly. The assembly can capture events that are raised in the application.
The CLR enables the use of managed code that is written in a language supported by the Microsoft .NET Framework. In your solution, you can do the following:
- Respond to events that are raised in the application itself (for instance, when a user clicks a menu item).
- Write code against the object model to automate the application.
After the assembly has been loaded, the add-in has access to the application’s objects, such as documents or mail. The managed code communicates with the application’s COM components through the primary interop assembly in your add-in project.
Filed under: .NET Framework, Office Solutions | 1 Comment
Tags: .NET Framework, Add-in Development, Development for Microsoft Office using .NET framework
Windows vista does not have .NET framework 1.1 in it. If you want to run a legacy application developed using .NET framework 1.1, you need to download and install. But you often end up getting the following error:
“Application has generated an exception that could not be handled”
Resolution:
I found this link as a workaround to get this done. Yes, it works!
Filed under: General | 1 Comment
Tags: .NET framework 1.1, framework 1.1 installation error, Windows Vista
New to .NET integration in SQL Server? Here is some useful information put together for you:
· .NET integration is one of the key feature in SQL Server 2005
· The CLR is hosted by SQL server thereby executing the stored procedures in SQL Server’s process space
· CLR stored procedures uses ADO.NET objects (SqlCommand, SqlConnection, DataSet etc) to retrieve data from and write data into SQL Server
· Microsoft.SqlServer.Server namespace provides the classes and attributes for supporting the managed CLR routines
· An object called ‘SqlContext’ represents the connection instantiated by the CLR stored procedure and manages passing of parameters
· ‘SqlContext’ is defined in the Microsoft.SqlServer.Server namespace
· To create a CLR stored procedure
o Create a Database Project in Visual Studio
o Add a database reference
o Add à Stored procedure to the project
· The steps for creating the CLR stored procedure is explained in my blog here
· The default entries created when you add a CLR stored procedure using visual studio are shown below. (Stored procedure name is given as ‘GetSales’):
using System;
using System.Data;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void GetSales()
{
// your code here
}
};
· The [Microsoft.SqlServer.Server.SqlProcedure] attribute specifies that this method is a stored procedure
· The method GetSales() is static, as it needs to be invoked without instantiation
· The namespace System.Data.SqlTypes provides all the data types that correspond to each of the SQL Server data types (Example: SqlTypes.SqlDateTime, SqlTypes.SqlInt32 etc.)
CLR Stored Procedure Parameters
· The parameters are passed by specifying them in the stored procedure method. Example is given below
[Microsoft.SqlServer.Server.SqlProcedure]
public static void GetSales(SqlDateTime StartDate, SqlInt32 Days)
{
// your code here
}
· Output parameters can be passed by using the ref keyword
SqlPipe
· SqlPipe is an object that allows us to send data or commands to be executed from a CLR routine back to the caller.
· Send() method of the SqlPipe is used to send the data which has 3 overloads
Send(string message)
Send(SqlDataRecord record)
Send(SqlDatareader reader)
· Send() methods can be called any number of times during the course of a CLR stored procedure.
Example:
command.CommandText = “Select * from MonthlySales”;
SqlDataReader reader = command.EndExecuteReader();
SqlContext.Pipe.Send(reader);
· ExecuteAndSend() method of the SqlPipe does take care of the execution and subsequent return of the result back to the caller. So the last 2 lines of the above example can be replaced with:
SqlContext.Pipe.ExecuteAndSend(command);
· CLR stored procedure can return multiple result sets and multiple messages or errors
Error Handling
· Use Try{…} Catch{..}
· To throw custom exceptions, use RAISEERROR
Filed under: SQL Server, SQL Server 2005 | Leave a Comment
Tags: CLR Stored Procedure Basics, CLR Stored Procedures, Introduction to CLR stored Procedures, SQL Server 2005 CLR Routines, SQL Server 2005 CLR support, SqlContext, SqlPipe, SqlPipe.Send()
Having covered the query expressions, we need to look in to query operators. The standard query operators are the methods that form query pattern. Note that these methods operate on any object whose type implements the IEnumerable<T> or IQueryable<T> interfaces.
The methods that make up these standard query operators are implemented as Extension Methods. To understand this, some knowledge on Extension Methods introduced by C# are required. Refer msdn for more details.
Here is the summary of the LINQ query operators:
- Aggregation: Average, Count, LongCount, Max, Min, Sum
- Concatenation : Concat
- Conversion: Cast, OfType, ToArray, ToDictionary, ToList, ToLookup, ToSequence
- Element : DefaultIfEmpty, ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault
- Equality : SequenceEqual
- Generation : Empty, Range, Repeat
- Grouping : GroupBy
- Joining : GroupJoin, Join
- Ordering: OrderBy, ThenBy, OrderByDescending, ThenByDescending, Reverse
- Partitioning : Skip, SkipWhile, Take, TakeWhile
- Quantifiers: All, Any, Contains
- Restriction : Where
- Projection: Select, SelectMany
- Set: Distinct, Except, Intersect, Union
For the detailed information on this topic you can look at this msdn resource. The links below will help you to navigate to each set of operations directly.
Sorting | Set | Filtering | Quantifier | Projection | Partitioning | Join | Grouping | Generation | Equality | Element | Conversion | Concatenation |Aggregation
Filed under: LINQ | Leave a Comment
Tags: Extension Methods, LINQ, LINQ Basics, Standard Query Operators
Query Expressions
The main learning curve for an application developer who is new to LINQ is the query syntax. This declarative syntax requires minimum code by which you can even perform fairly complex queries. Let us look at some code snippets for example:
A simple select query – Selecting the marks from the array which are above 50
|
int[] marks = { 85, 40, 75, 60 };
var passedMarks = where m>50
Console.WriteLine(“Selected Marks :”);
Output:
Selected Marks : 85 75 60
|
MSDN tells about the three distinct parts of a LINQ query
- Obtain the data source.
- Create the query.
- Execute the query
Let us relate this to the first example:
Obtain the data source
int[] marks = { 85, 40, 75, 60 };
Create the query
var passedMarks =
from m in marks
where m>50
select m;
Execute the query
Console.WriteLine(“Selected Marks :”);
foreach (var i in passedMarks) {
Console.WriteLine(i);
}
Filed under: LINQ | 2 Comments
Tags: LINQ, LINQ Basics, Linq Query Expressions, Linq tutorial, Query Expressions, Understanding LINQ
LINQ Query Samples
You have seen basics of a LINQ query in my previous blog. It is time to look at some more samples. There are numerous resources in the web, but many of you must be interested in a single resource where you can get ‘everything’. Well, here is one msdn resource which puts together numerous examples on the following topics
Linq to Objects
Linq to Sql
Linq to DataSet
Linq to Xml
Filed under: LINQ | Leave a Comment
Tags: 101 LINQ Samples, LINQ, LINQ Basics, Linq Queries, LINQ Samples


