MissingManifestResourceException when using Portable Class Libraries within WinRT
Our team recently ran into a strange issue. Our Windows Phone application targets Silverlight 8.1 but we have several WinRT 8.1 based background tasks. Recen...
In an earlier post I discussed LINQ to DASL, part of the Office Interop API Extensions, which is one of the forthcoming VSTO Power Tools. LINQ to DASL allows you to write LINQ expressions against Outlook item collections. I also mentioned that many known DASL properties were not mapped to their Outlook item equivalents in this initial release. So how do you write LINQ expressions using DASL properties that weren't included? The answer is: by extending the base LINQ to DASL classes. Let's start with a non-LINQ example:office" />
Outlook.Folder folder = (Outlook.Folder) this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
var topics = new List<string>();
foreach (object item in folder.Items)
{
Outlook.MailItem mailItem = item as Outlook.MailItem;
if (mailItem != null)
{
if (mailItem.ConversationTopic.Contains("VSTO"))
{
topics.Add(mailItem.ConversationTopic);
}
}
}
foreach (var topic in topics)
{
System.Diagnostics.Debug.WriteLine(String.Format("Conversation Topic: {0}", topic));
}
The example shows our first attempt to find all mail items with a conversation index containing the acronym "VSTO". It simply iterates over each item in the folder, checks whether it's a mail item, then checks whether it has a matching conversation topic. Iterating over each and every item in the folder is not very efficient. We can have Outlook perform the filtration in its own native (and presumably more efficient) way. We do this by creating a DASL query string and passing it to the Items.Restrict() method. Here is the updated example:
Outlook.Folder folder = (Outlook.Folder) this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
string filter = @"@SQL=(""urn:schemas:httpmail:thread-topic"" LIKE '%VSTO%')";
Outlook.Items items = folder.Items.Restrict(filter);
var topics = new List<string>();
foreach (object item in items)
{
Outlook.MailItem mailItem = item as Outlook.MailItem;
if (mailItem != null)
{
topics.Add(mailItem.ConversationTopic);
}
}
foreach (var topic in topics)
{
System.Diagnostics.Debug.WriteLine(String.Format("Conversation Topic: {0}", topic));
}
The collection returned by Items.Restrict() is the subset of items matching the filter. It may be more efficient, but it certainly doesn't simplify the code. It would be nice if we could use a strongly-typed LINQ expression. Unfortunately, the Mail class in the initial LINQ to DASL implementation does not have a property which maps to the "urn:schemas:httpmail:thread-topic" DASL property. We can extend the Mail class to do so, however, as shown below:
internal class MyMail : Mail
{
[OutlookItemProperty("urn:schemas:httpmail:thread-topic")]
public string ConversationTopic
{ get { return Item.ConversationTopic; } }
}
We create a new class, MyMail, which inherits from the existing LINQ to DASL Mail class. We then add a ConversationTopic property which simply delegates to the ConversationTopic property on the Outlook.MailItem reference held by the Mail class. The key piece is the OutlookItemPropertyAttribute attached to the property. This attribute provides the mapping between the property as used in a LINQ expression and the DASL property in the query string. With that, we can finally write our LINQ expression:
Outlook.Folder folder = (Outlook.Folder) this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
var topics =
from item in folder.Items.AsQueryable<MyMail>()
where item.ConversationTopic.Contains("VSTO")
select item.ConversationTopic;
foreach (var topic in topics)
{
System.Diagnostics.Debug.WriteLine(String.Format("Conversation Topic: {0}", topic));
}
Extensions to LINQ to DASL are not limited to the addition of new DASL properties. You can also extend the LINQ to DASL classes to allow strongly-typed query expressions using custom user properties. I'll discuss that topic in a future post.
<P class=MsoNormal style=”MARGIN: 0in 0in 0pt”>
<FONT face="Times New Roman" size=3> </FONT>
</P>This post was migrated from my MSDN blog, Visual Studio Tools and Anything Else I Can Think Of, and written as a Microsoft employee.
Our team recently ran into a strange issue. Our Windows Phone application targets Silverlight 8.1 but we have several WinRT 8.1 based background tasks. Recen...
In a previous post I introduced the concept of Role Content Folders and how they can be used to deploy additional content (e.g. configuration files, runtime ...
The latest versions of the Windows Azure Tools for Visual Studio have the ability to maintain multiple versions of the Service Configuration (.cscfg) file.&n...
When a package fails to deploy to Windows Azure (or deploys but its roles fail to start properly) it can be difficult to determine what went wrong. In many c...
Windows Azure applications often need to package and deploy additional content. This could be advanced configuration files such as the diagnostics.wadcfg for...
The LINQ-to-DASL provider of the Office Interop API Extensions provides a very limited set of mappings between its query types and their associated DASL prop...
When your LINQ-to-DASL queries do not return the results you expect, how do you determine where the problem is? The issue could be that the query simpl...
I received an email over the weekend asking why the following LINQ to DASL query threw an exception: Outlook.Folder folder = (Outlook.Folder)Application.Se...
Now that the Office Interop API Extensions have been released, I thought I would post a complete walkthrough of a simple LINQ to DASL application. Let's star...
One of the disadvantages of C# compared with VB is its lack of support for parameterized properties. Instead, parameterized properties in C# are exposed as ...
As announced in Andrew Whitechapel’s post, version 1.0 of the VSTO Power Tools have been released! One of those tools is the Office Interop API Extensions, a...
In an earlier post I discussed LINQ to DASL, part of the Office Interop API Extensions, which is one of the forthcoming VSTO Power Tools. LINQ to DASL ...
In my last post I talked about LINQ to DASL, a LINQ provider that converts query expressions into their DASL equivalent in order to efficiently filter item c...
Quick, tell me what the following code does:
I like VSTO. I like C#. What I don’t like is having to write VSTO code in C# like:
Yesterday I gave a presentation on VSTO at the third annual Portland Code Camp. I demonstrated an Outlook 2007 add-in that used Outlook Form Regions, WCF, an...