How to access backstage checkbox value in an Office addin? - outlook

I have a boolean property Settings.Default.MarkAsRead in the Setting.settings file, which I can access in my Ribbon class. What I'd like to do is set the value of a check box in my backstage section depending on the value of this property. Also if the user modifies it, I'll need to save the new value.
Any way I can do this?
This is my (simplified) xml:
<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load"
xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<backstage>
<tab id="MyBackstageSection" label="MyBackstageSection"
columnWidthPercent="30" insertAfterMso="TabInfo" visible="true" >
<firstColumn>
<group id="grpOne" label="Configuration">
<bottomItems>
<checkBox id="markAsRead" label="Mark as read"
getPressed="markAsRead_GetPressed" />
<button id="save" label="Save Preferences" onAction="save_Click"/>
</bottomItems>
</group>
</firstColumn>
</tab>
</backstage>
</customUI>

I didn't find a way to access the xml elements from the Ribbon_Load method, so I've created a boolean property in the ribbon class that I update using the GetPressed and OnAction callbacks:
xml:
<checkBox id="markAsRead" label="Mark as read"
onAction="markAsRead_OnAction" getPressed="markAsRead_GetPressed"/>
c#:
private bool MarkAsRead { get; set; }
public bool markAsRead_GetPressed(Office.IRibbonControl control)
{
this.MarkAsRead = Settings.Default.MarkAsRead;
return this.MarkAsRead;
}
public void markAsRead_OnAction(Office.IRibbonControl control, bool isPressed)
{
this.MarkAsRead = isPressed;
}

Related

Xamarin.Forms.Xaml.XamlParseException exception in Xamarineforms

I am new to Xamarine.
I had created new blank Xamarine project in Visual studio 2019.
I am using this link to create demo native views in Xamarine forms : https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/native-views/xaml
MainPage.Xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"
xmlns:androidLocal="clr-namespace:App1.Android;assembly=App1.Android;targetPlatform=Android"
mc:Ignorable="d"
x:Class="App1.MainPage">
<StackLayout>
<!-- Place new controls here -->
<ios:UILabel Text="Hello World" TextColor="{x:Static ios:UIColor.Red}" View.HorizontalOptions="Start" />
<androidWidget:TextView Text="Hello World" x:Arguments="{x:Static androidLocal:MainActivity.Instance}" />
</StackLayout>
</ContentPage>
I had added skip Xamlcomplitation in MainPage.xaml.cs file.
[XamlCompilation(XamlCompilationOptions.Skip)]
Added in MainActivity.cs in App1.Android file.
internal static MainActivity Instance { get; private set; } // define Instance
Bit it shows error for
( 8976): Assembly Ref addref System.Xml[0xd1e768c0] -> System[0xe4b32b00]: 5
**Xamarin.Forms.Xaml.XamlParseException:** 'Position 15:52. Type MainActivity not found in xmlns clr-namespace:App1.Android;assembly=App1.Android;targetPlatform=Android'
[XamlCompilation(XamlCompilationOptions.Skip)]
Is something that you add to the Xaml backend code. Adding it to something else like in your case is likely to cause problems.

How to separate CustomUI tags in Excel-DNA from OnAction methods?

In my .dna file I have:
<DnaLibrary Name="First Add-In" RuntimeVersion="v4.0" Language="C#">
<ExternalLibrary Path="MyLibrary.dll" Pack="true"/>
<Image Name="M" Path="M.png" Pack="true" />
<CustomUI>
<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' loadImage='LoadImage'>
<ribbon>
<tabs>
<tab id='CustomTab' label='My 2010 Tab'>
<group id='SampleGroup' label='My Sample Group'>
<button id='Button1' label='My Second Button' image='M' size='normal' onAction='RunTagMacro' tag='ReformatSelection='/>
</group >
</tab>
</tabs>
</ribbon>
</customUI>
</CustomUI>
</DnaLibrary>
In my .cs file I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelDna.Integration;
using System.Runtime.InteropServices;
using ExcelDna.Integration.CustomUI;
using System.Windows.Forms;
namespace MyLibrary
{
[ComVisible(true)]
public class Class1 : ExcelRibbon
{
public void ReformatSelection(IRibbonControl control)
{
MessageBox.Show("Hello");
}
}
}
When I load the addin the button and tab appears fine in the Ribbon, but clicking the button does not run the ReformatSelection method. In the example files provided with Excel-DNA all the subs and functions that are hooked to the onAction events are in the .dna file. I am trying to move them out of the .dna file and into the .cs file. What am I doing wrong?
Your signature for ReformatSelection() is not right for the onAction handler of a ribbon button.
It should be:
public void ReformatSelection(IRibbonControl control) {...}
You can get a list of all the Office Ribbon callbacks signatures here: http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx

Getting the file version of a native exe in MSBuild

I have a number of Visual C++ projects in a Visual Studio 2010 solution. Also in this solution is a WiX project that builds the installer for the executable that is the product of one of the C++ projects.
The executable has a resource file in its project which writes the version of the program to the executable.
Now I'd like to version the WiX-built installer with the same number as the one written to the executable by the resource file. I've searched the WiX related posts on StackOverflow and found this post:
Referencing a WixVariable defined in a WiX Library Project from a WiX Setup Project
The accepted answer to which, seems to indicate that a possible solution is to use MSBuild and the GetAssemblyIdentity task in the BeforeBuild Target to acquire the version number from another file (in the case of the SO question a DLL, in my case the executable) and expose it to WiX before WiX builds the installer.
I tried adding this to the MSBuild portion of my .wixproj file but when I try to build the installer I get an error returned saying:
error MSB3441: Cannot get assembly name for "<ExePath>". Could not load file or assembly '<ExeName>.exe' or one of its dependencies. The module was expected to contain an assembly manifest.
I can't seem to find any information on MSDN about this error as it relates to MSBuild. I've checked the built executable and it definitely has a version number on it (as well as the rest of the information from the .rc file) and the WiX project depends on the project that outputs the executable; so I assume its BeforeBuild task is running after the project it depends on has been built completely.
Should I be using a different task instead of GetAssemblyIdentity to retrieve the version number from the .exe in MSBuild, are there other requirements to satisfy before GetAssemblyIdentity will work, or is it just not possible to get this type of information about .exe files in MSBuild?
EDIT :
I accepted Rob's answer since I was misunderstanding the difference between ProductVersion and FileVersion, and the WiX technique that he suggested was working as intended and is a step towards the solution I needed.
FileVersion is an attribute of executables only. Msi files are essentially databases and ProductVersion is an entry in that database; they have no FileVersion attribute to set. The method he suggests correctly sets ProductVersion in the .msi database.
The title of this question is now not really related to what the problem I actually had was, since I was asking for a solution I believed I needed at the time. I've now solved the root problem which was simply getting access to the ProductVersion of the installer. I found a cscript script posted online here: http://kentie.net/article/wixnameversion/index.htm that shows how to access the ProductVersion of the .msi. Using that has allowed me to extract the ProductVersion and use it in other tools.
An easier solution, if you don't need the version in MSBuild, is to just reference the version of the file directly in your .wxs file. Here's a snippet that shows what to do:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Version="!(bind.fileVersion.ExeWithVersion)" ...>
...
<Component ...>
<File Id="ExeWithVersion" Source="path\to\your\versioned\file.exe" />
</Component>
...
</Product>
</Wix>
The magic is that the !(bind.fileVersion.Xxx) says to look up the File element with Id='Xxx' and get its version. This is far away the easiest way to get the version of the file into your MSI package.
I needed the file version one time, and I ended up writing a custom task to get the FileVersion because I couldn't find anything.
namespace GranadaCoder.Framework.CrossDomain.MSBuild.Tasks.IO//.FileVersionTask
{
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Globalization;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Security;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class FileVersionTask : FileBasedTaskBase
{
private static readonly string ROOT_DIRECTORY = "myrootdir";
private static readonly string FULL_PATH = "myfullpath";
private static readonly string FILE_NAME = "myfilename";
private static readonly string DIRECTORY = "mydirectory";
private static readonly string EXTENSION = "myextension";
private static readonly string VERSION = "myfileversion";
/// <summary>
/// Gets or sets the source files.
/// </summary>
/// <value>The source files.</value>
[Required]
public string SourceFiles { get; set; }
/// <summary>
/// Gets the file versions as a Task Output property.
/// </summary>
/// <value>The file versions.</value>
[Output]
public ITaskItem[] FileVersions
{ get; private set; }
/// <summary>
/// Task Entry Point.
/// </summary>
/// <returns></returns>
protected override bool AbstractExecute()
{
InternalExecute();
return !Log.HasLoggedErrors;
}
/// <summary>
/// Internal Execute Wrapper.
/// </summary>
private void InternalExecute()
{
IList<string> files = null;
if (String.IsNullOrEmpty(this.SourceFiles))
{
Log.LogWarning("No SourceFiles specified");
return;
}
if (!String.IsNullOrEmpty(this.SourceFiles))
{
Console.WriteLine(this.SourceFiles);
files = base.ConvertSourceFileStringToList(this.SourceFiles);
}
//List<string> fileVersions = new List<string>();
ArrayList itemsAsStringArray = new ArrayList();
foreach (string f in files)
{
FileInfoWrapper fiw = null;
fiw = this.DetermineFileVersion(f);
IDictionary currentMetaData = new System.Collections.Hashtable();
currentMetaData.Add(ROOT_DIRECTORY, fiw.RootDirectory);
currentMetaData.Add(FULL_PATH, fiw.FullPath);
currentMetaData.Add(FILE_NAME, fiw.FileName);
currentMetaData.Add(DIRECTORY, fiw.Directory);
currentMetaData.Add(EXTENSION, fiw.Extension);
currentMetaData.Add(VERSION, fiw.Version);
itemsAsStringArray.Add(new TaskItem(fiw.Version, currentMetaData));
}
this.FileVersions = (ITaskItem[])itemsAsStringArray.ToArray(typeof(ITaskItem));
}
/// <summary>
/// Determines the file version.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <returns>File version or 0.0.0.0 if value cannot be determined</returns>
private FileInfoWrapper DetermineFileVersion(string fileName)
{
FileInfoWrapper fiw = new FileInfoWrapper();
fiw.Directory = string.Empty;
fiw.Extension = string.Empty;
fiw.FileName = string.Empty;
fiw.FullPath = string.Empty;
fiw.RootDirectory = string.Empty;
fiw.Version = "0.0.0.0";
try
{
if (System.IO.File.Exists(fileName))
{
fiw.Extension = System.IO.Path.GetExtension(fileName);
fiw.FileName = System.IO.Path.GetFileNameWithoutExtension(fileName);
fiw.FullPath = fileName;// System.IO.Path.GetFileName(fileName);
fiw.RootDirectory = System.IO.Path.GetPathRoot(fileName);
//Take the full path and remove the root directory to mimic the DotNet default behavior of '%filename'
fiw.Directory = System.IO.Path.GetDirectoryName(fileName).Remove(0, fiw.RootDirectory.Length);
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileName);
if (null != fvi)
{
if (null != fvi.FileVersion)
{
fiw.Version = fvi.FileVersion;
}
}
}
}
catch (Exception ex)
{
if (ex is IOException
|| ex is UnauthorizedAccessException
|| ex is PathTooLongException
|| ex is DirectoryNotFoundException
|| ex is SecurityException)
{
Log.LogWarning("Error trying to determine file version " + fileName + ". " + ex.Message);
}
else
{
Log.LogErrorFromException(ex);
throw;
}
}
return fiw;
}
/// <summary>
/// Internal wrapper class to hold file properties of interest.
/// </summary>
internal sealed class FileInfoWrapper
{
public string Directory { get; set; }
public string Extension { get; set; }
public string FileName { get; set; }
public string FullPath { get; set; }
public string RootDirectory { get; set; }
public string Version { get; set; }
}
}
}
.msbuild example
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="AllTargetsWrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="GranadaCoder.Framework.CrossDomain.MSBuild.dll" TaskName="FileVersionTask"/>
<Target Name="AllTargetsWrapper">
<CallTarget Targets="FileVersionTask1" />
<CallTarget Targets="FileVersionTask2" />
</Target>
<PropertyGroup>
<WorkingCheckout>c:\Program Files\MSBuild</WorkingCheckout>
</PropertyGroup>
<ItemGroup>
<MyTask1ExcludeFiles Include="$(WorkingCheckout)\**\*.rtf" />
<MyTask1ExcludeFiles Include="$(WorkingCheckout)\**\*.doc" />
</ItemGroup>
<ItemGroup>
<MyTask1IncludeFiles Include="$(WorkingCheckout)\**\*.exe" Exclude="#(MyTask1ExcludeFiles)" />
</ItemGroup>
<Target Name="FileVersionTask1">
<FileVersionTask SourceFiles="#(MyTask1IncludeFiles)" >
<Output TaskParameter="FileVersions" ItemName="MyFileVersionItemNames"/>
</FileVersionTask>
<Message Text=" MyFileVersionItemNames MetaData "/>
<Message Text=" ------------------------------- "/>
<Message Text=" "/>
<Message Text="directory: "/>
<Message Text="#(MyFileVersionItemNames->'%(mydirectory)')"/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text="extension: "/>
<Message Text="#(MyFileVersionItemNames->'%(myextension)')"/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text="filename: "/>
<Message Text="#(MyFileVersionItemNames->'%(myfilename)')"/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text="fullpath: "/>
<Message Text="#(MyFileVersionItemNames->'%(myfullpath)')"/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text="rootdir: "/>
<Message Text="#(MyFileVersionItemNames->'%(myrootdir)')"/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text="fileversion: "/>
<Message Text="#(MyFileVersionItemNames->'%(myfileversion)')"/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text="rootdir + directory + filename + extension: "/>
<Message Text="#(MyFileVersionItemNames->'%(myrootdir)%(mydirectory)%(myfilename)%(myextension)')"/>
<Message Text=" "/>
<Message Text=" "/>
<Message Text="List of files using special characters (carriage return)"/>
<Message Text="#(MyFileVersionItemNames->'"%(myfullpath)"' , '%0D%0A')"/>
<Message Text=" "/>
<Message Text=" "/>
</Target>
<ItemGroup>
<MyTask2IncludeFiles Include="c:\windows\notepad.exe" />
</ItemGroup>
<Target Name="FileVersionTask2">
<FileVersionTask SourceFiles="#(MyTask2IncludeFiles)" >
<Output TaskParameter="FileVersions" PropertyName="SingleFileFileVersion"/>
</FileVersionTask>
<Message Text="SingleFileFileVersion = $(SingleFileFileVersion) "/>
</Target>
</Project>

Why does MVC sitemap hide menu items where actions exist on the controller?

I'm using MVC sitemap for MVC3 but having problems with it.
Consider the following sitemap file:
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
<mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal" Description="Test HOME">
<mvcSiteMapNode title="Today" controller="Dashboard" action="Today" />
<mvcSiteMapNode title="Today1" controller="Dashboard" action="Today1" />
<mvcSiteMapNode title="Today2" controller="Dashboard" action="Today2" />
<mvcSiteMapNode title="Today3" controller="Dashboard" action="Today3" />
<mvcSiteMapNode title="Today4" controller="Dashboard" action="Today4" />
</mvcSiteMapNode>
</mvcSiteMap>
When I load my web page up I only get the following options:
Today1, Today2, Today3, Today4
But Today is not displayed. This is an action on a controller whereas the other actions don't exist. Why is it hiding the item which actually exists on the controller? I took off authorization on the controller to rule out it had anything to do with authorization but still same effect.
This is the sitemap config (set in web.config):
<siteMap defaultProvider="MvcSiteMapProvider" enabled="true">
<providers>
<clear />
<add name="MvcSiteMapProvider"
type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider"
siteMapFile="~/Mvc.Sitemap"
securityTrimmingEnabled="true"
cacheDuration="5"
enableLocalization="true"
scanAssembliesForSiteMapNodes="false"
includeAssembliesForScan=""
excludeAssembliesForScan=""
attributesToIgnore="visibility"
nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider"
controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider"
actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider"
aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider"
siteMapNodeUrlResolver="MvcSiteMapProvider.DefaultSiteMapNodeUrlResolver, MvcSiteMapProvider"
siteMapNodeVisibilityProvider="MvcSiteMapProvider.DefaultSiteMapNodeVisibilityProvider, MvcSiteMapProvider"
siteMapProviderEventHandler="MvcSiteMapProvider.DefaultSiteMapProviderEventHandler, MvcSiteMapProvider" />
</providers>
</siteMap>
</system.web>
I find out the problem.
The HttpContext user's InRole() method is used in the MvcSiteMapProvider.DefaultAclModule within the library code.
I am using Forms Authentication which means the InRole will never work as the roles property on the user context is not set (it doesn't know how roles are applied).
I could either write my own aclmodule provider which checks the authentication ticket for the roles stored within the ticket, or alternatively for every authentication request event in global.asax, set the context with the roles set. In the end I chose the latter:
e.g.
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity formsId = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = formsId.Ticket;
// need to do this so MVC sitemap IsInRole works inside default acl module: MvcSiteMapProvider.DefaultAclModule
var authData = new AuthenticationModel(ticket.UserData);
var roles = new List<string>(authData.EffectiveRoles).ToArray();
HttpContext.Current.User = new GenericPrincipal(formsId, roles);
}
}
}
#jaffa, your approach helped me !! thanks. Here, is how I implemented it.. maybe it can help others too!
public class MenuVisibilityController : Controller, ISiteMapNodeVisibilityProvider
{
public bool IsVisible(SiteMapNode Node, HttpContext context, IDictionary<string, object> sourceMetadata)
{
return context.User.Identity.IsAuthenticated;
}
}
Implemented Visibility Provider for MVC sitemap and then used it for visibility of a particular node like below:
<mvcSiteMapNode title="Test Menu" controller="Account" action="Index" visibilityProvider="MyProject.Controllers.MenuVisibilityController, MyProject">
<mvcSiteMapNode title="Test Item 1" controller="Account" action="GetItems" />
</mvcSiteMapNode>
specifying implemented controller in VisibilityProvider should serve the purpose.

Listening for dataChange event in AdvancedDataGrid

This is my code:
<controls:AdvancedDataGrid id="adg" dataChange="adg_dataChangeHandler(event)">
<!-- other stuff goes here -->
</controls:AdvancedDataGrid>
and in my ActionScript code:
protected function adg_dataChangeHandler(event:FlexEvent):void
{
trace(1);
}
When I edit a cell in advancedDataGrid (making the columns editable of course) it never dispatches an event. Or, in other words, my function is never called. How can I fix this?
I think that the better option for my scenario is to use an itemEditor, that has a listener put on the change event. Code looks like :
<controls:AdvancedDataGrid id="adg">
<controls:groupedColumns>
<adgs:AdvancedDataGridColumn headerText="A" wordWrap="true" dataField="name" editable="false" itemEditor="Aaa"/>
</controls:groupedColumns>
</controls:AdvancedDataGrid>
and the item editor class is here :
<?xml version="1.0" encoding="utf-8"?>
<mx:TextInput xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" change="textinput1_changeHandler(event)" restrict="0-9">
<fx:Script>
<![CDATA[
protected function textinput1_changeHandler(event:Event):void
{
trace("ha");
}
]]>
</fx:Script>
</mx:TextInput>

Resources