I have a project which has recently been converted from studio 2008 to 2010. It makes significant use of DSL. I used the DslProjectsMigrationTool that comes with the SDK. While much of the functionality is working I have a few problems with menus. I have a custom toolbar with three buttons which my code. However the event handler doesn't seem to be working. I've one back and checked the 2008 version and this was working without a problem.
Unfortunately none of this code is my own and the person who originally wrote it has moved on and is unavailable to help.
In Commands.vsct I have
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<Commands package="guidPkg">
<Menus>
<Menu guid="guidCmdSet" id="blueprintToolbar" priority="0x0000" type="Toolbar">
<Parent guid="guidCmdSet" id="blueprintToolbar"/>
<CommandFlag>DefaultDocked</CommandFlag>
<CommandFlag>AlwaysCreate</CommandFlag>
<Strings>
<ButtonText>Blueprint Toolbar</ButtonText>
</Strings>
</Menu>
</Menus>
<Groups>
<Group guid="guidCmdSet" id="grpidTranslate" priority="0x0000">
<Parent guid="guidCmdSet" id="blueprintToolbar" />
</Group>
</Groups>
<Buttons>
<Button guid="guidCmdSet" id="cmdidReTranslateAllCmd" priority="0x0100" type="Button">
<Parent guid="guidCmdSet" id="grpidTranslate" />
<Icon guid="guidCmdSet" id="bmpPic1"/>
<CommandFlag>TextOnly</CommandFlag>
<Strings>
<ButtonText><Retranslate All></ButtonText>
</Strings>
</Button>
<Button guid="guidCmdSet" id="cmdidTranslateAllCmd" priority="0x0101" type="Button">
<Parent guid="guidCmdSet" id="grpidTranslate" />
<Icon guid="guidCmdSet" id="bmpPic1"/>
<CommandFlag>TextOnly</CommandFlag>
<Strings>
<ButtonText><Translate All></ButtonText>
</Strings>
</Button>
<Button guid="guidCmdSet" id="cmdidTranslateCurCmd" priority="0x0102" type="Button">
<Parent guid="guidCmdSet" id="grpidTranslate" />
<Icon guid="guidCmdSet" id="bmpPic1"/>
<CommandFlag>TextOnly</CommandFlag>
<Strings>
<ButtonText><Translate Current></ButtonText>
</Strings>
</Button>
</Buttons>
</Commands>
<Symbols>
<GuidSymbol name="guidCmdSet" value="Extern">
<!--Group IDs-->
<IDSymbol name="grpidTranslate" value="0x1050"/>
<!--Command IDs-->
<IDSymbol name="cmdidTranslateAllCmd" value="0x9100"/>
<IDSymbol name="cmdidTranslateCurCmd" value="0x9101"/>
<IDSymbol name="cmdidReTranslateAllCmd" value="0x9102"/>
<IDSymbol name="blueprintToolbar" value="0x1000"/>
<IDSymbol name="bmpPic1" value="1"/>
</GuidSymbol>
</Symbols>
</CommandTable>
Then in CommandSetOverride.cs I have
/// <summary>
/// Constants relating to commands
/// </summary>
partial class Constants
{
public const string CLSID_StandardCommandSet97 = "5efc7975-14bc-11cf-9b2b-00aa00573819";
#region Command Codes
const int cmdidTranslateAllCmd = 0x9100;
const int cmdidTranslateCurrentCmd = 0x9101;
const int cmdidReTranslateAllCmd = 0x9102;
#endregion
#region CommandIDs
public static readonly CommandID TranslateAllCommandID =
new CommandID(new Guid(Constants.BlueprintCommandSetId), cmdidTranslateAllCmd);
public static readonly CommandID TranslateCurrentCommandID =
new CommandID(new Guid(Constants.BlueprintCommandSetId), cmdidTranslateCurrentCmd);
public static readonly CommandID ReTranslateAllCommandID =
new CommandID(new Guid(Constants.BlueprintCommandSetId), cmdidReTranslateAllCmd);
#endregion
}
/// <summary>
/// Additions to the blueprint command set for context menu items and extra commands.
/// </summary>
partial class BlueprintCommandSet
{
/// <summary>
/// Retrieves the available menu commands
/// </summary>
/// <returns>List of menu commands</returns>
protected override IList<MenuCommand> GetMenuCommands()
{
IList<MenuCommand> commands = base.GetMenuCommands();
OleMenuCommand oleMenuCommand;
// Translate
if (null != MenuService)
{
MenuCommand menuCommand = new MenuCommand(new EventHandler(OnTranslateAll), Constants.TranslateAllCommandID);
MenuService.AddCommand(menuCommand);
menuCommand = new MenuCommand(new EventHandler(OnTranslateCurrent), Constants.TranslateCurrentCommandID);
MenuService.AddCommand(menuCommand);
menuCommand = new MenuCommand(new EventHandler(OnReTranslateAll), Constants.ReTranslateAllCommandID);
MenuService.AddCommand(menuCommand);
}
return commands;
}
#region Translation
/// <summary>
/// Handles the "ReTranslate All" toolbar button command.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnReTranslateAll(object sender, EventArgs e)
{
ReTranslateAll();
}
/// <summary>
/// Handles the "Translate All" toolbar button command.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTranslateAll(object sender, EventArgs e)
{
TranslateAll(false);
}
/// <summary>
/// Handles the "Translate Current" toolbar button command.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTranslateCurrent(object sender, EventArgs e)
{
TranslateCurrent();
}
#endregion
}
When i run the code either the installed version or when running in the hive the buttons appear in the toolbar no problem however click on them never calls OntranslateAll or similar. Any help would be very useful.
I found that the CommandSetId Guid was used explicitly in two places and then one version was updated for the 2010 version while the second wasn't. With different guids the event was been sent to the wrong place
Related
Can anyone tell Where can I get a JSON for Microsoft Sigin card for Teams bot and how to view it in a visualizer and can it be used to mask the password.
This is the OauthCard.cs file:
// <auto-generated>
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace Microsoft.Bot.Schema
{
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// A card representing a request to perform a sign in via OAuth
/// </summary>
public partial class OAuthCard
{
/// <summary>
/// Initializes a new instance of the OAuthCard class.
/// </summary>
public OAuthCard()
{
CustomInit();
}
/// <summary>
/// Initializes a new instance of the OAuthCard class.
/// </summary>
/// <param name="text">Text for signin request</param>
/// <param name="connectionName">The name of the registered
/// connection</param>
/// <param name="buttons">Action to use to perform signin</param>
public OAuthCard(string text = default(string), string connectionName = default(string), IList<CardAction> buttons = default(IList<CardAction>))
{
Text = text;
ConnectionName = connectionName;
Buttons = buttons;
CustomInit();
}
/// <summary>
/// An initialization method that performs custom operations like setting defaults
/// </summary>
partial void CustomInit();
/// <summary>
/// Gets or sets text for signin request
/// </summary>
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
/// <summary>
/// Gets or sets the name of the registered connection
/// </summary>
[JsonProperty(PropertyName = "connectionName")]
public string ConnectionName { get; set; }
/// <summary>
/// Gets or sets action to use to perform signin
/// </summary>
[JsonProperty(PropertyName = "buttons")]
public IList<CardAction> Buttons { get; set; }
}
}
It can be found here. That being said, AFAIK, there is no visualizer for it, it's not in JSON, and there's nothing there to mask.
You can create a Sign In card in c#
SigninCard signincard = new SigninCard()
{
Text = "Click here to sign in",
Buttons = new List<CardAction>() {
new CardAction()
{
Title = "Authentication Required",
Type = ActionTypes.OpenUrl,
Value = $"{authenticationUrl}?{encodedCookie}"
}
}
};
Please give a try.
I want to use some dictionary inside my linq query, however since LINQ to entities can't translate the use of the dictionary it throws an exception.
Actually the same problem was described in the following question:
linq to entity framework: use dictionary in query
I wasn't satisfied of the solution which was described there. I'm sure there is some other solution for this problem. I don't want to use the ToList/ToArray method - which will bring all data to memory.
What is the best way to solve this issue, without pulling the db data to memory?
Your example looks like you actually don't need the functionality of a dictionary, you simply want to have WHERE IN functionality.
You could use the following to achieve this:
var countries = Countries.WhereIn(x => x.CountryId, dict.Keys);
WhereIn is not a built in query operator, you need to write it yourself - or copy:
/// <summary>
/// Holds extension methods that simplify querying.
/// </summary>
public static class QueryExtensions
{
/// <summary>
/// Return the element that the specified property's value is contained in the specified values.
/// </summary>
/// <typeparam name="TElement"> The type of the element. </typeparam>
/// <typeparam name="TValue"> The type of the values. </typeparam>
/// <param name="source"> The source. </param>
/// <param name="propertySelector"> The property to be tested. </param>
/// <param name="values"> The accepted values of the property. </param>
/// <returns> The accepted elements. </returns>
public static IQueryable<TElement> WhereIn<TElement, TValue>(
this IQueryable<TElement> source,
Expression<Func<TElement, TValue>> propertySelector,
params TValue[] values)
{
return source.Where(GetWhereInExpression(propertySelector, values));
}
/// <summary>
/// Return the element that the specified property's value is contained in the specified values.
/// </summary>
/// <typeparam name="TElement"> The type of the element. </typeparam>
/// <typeparam name="TValue"> The type of the values. </typeparam>
/// <param name="source"> The source. </param>
/// <param name="propertySelector"> The property to be tested. </param>
/// <param name="values"> The accepted values of the property. </param>
/// <returns> The accepted elements. </returns>
public static IQueryable<TElement> WhereIn<TElement, TValue>(
this IQueryable<TElement> source,
Expression<Func<TElement, TValue>> propertySelector,
IEnumerable<TValue> values)
{
return source.Where(GetWhereInExpression(propertySelector, values.ToList()));
}
/// <summary>
/// Gets the expression for a "where in" condition.
/// </summary>
/// <typeparam name="TElement"> The type of the element. </typeparam>
/// <typeparam name="TValue"> The type of the value. </typeparam>
/// <param name="propertySelector"> The property selector. </param>
/// <param name="values"> The values. </param>
/// <returns> The expression. </returns>
private static Expression<Func<TElement, bool>> GetWhereInExpression<TElement, TValue>(
Expression<Func<TElement, TValue>> propertySelector, ICollection<TValue> values)
{
var p = propertySelector.Parameters.Single();
if (!values.Any())
return e => false;
var equals =
values.Select(
value =>
(Expression)Expression.Equal(propertySelector.Body, Expression.Constant(value, typeof(TValue))));
var body = equals.Aggregate(Expression.OrElse);
return Expression.Lambda<Func<TElement, bool>>(body, p);
}
}
my delegate: I typed over the delegate in VS2010 the 3 slashes "///" and the typical automatic comment appears.
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="?"></typeparam>
/// <param name="param"></param>
/// <returns></returns>
private delegate IEnumerable<T> SearchInputText<T, string>(string param)
Why does it make the 2nd name = "?" ??? should it not be STRING ?
Because this code is not compiled:
error CS0081: Type parameter declaration must be an identifier not a type
Can I in Visual Studio create keyboard shortcut to regionate method and auto-document it with GhostDoc?
From this:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
I want make this:
#region protected override void OnInit(EventArgs e)
/// <summary>
/// Raises the <see cref="E:Init"/> event.
/// </summary>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
#endregion
I am not sure about the GhostDoc auto documentation, but to regionate selected text you can use the "surround with" function in Visual Studio.
Select a portion of code and press Ctrl + K, S. This brings up the "surround with" context menu. Select "region" in the menu, type in your region name and you're all set.
This function can be used for a bunch of other stuff as well. If, for, while and try statements and so on.
Type three slashes to auto-generate the documentation
Where can I find a Visual Studio plug-in that automatically generates documentation header for methods and properties?
Example the comment to a property could look like this:
/// <summary>
/// Gets or sets the value of message
/// </summary>
public static string Message
{
get
{
return message;
}
set
{
message = value;
}
}
Ghostdoc from http://www.roland-weigelt.de/ghostdoc/
GhostDoc is the usual suspect.
As another poster mentioned, Visual Studio also does this to an extent by entering 3 '///' (forward slashes) on the line preceding a property/method/class definition.
Visual Studio does this automatically. Just position the cursor directly above the method and enter three '/'s
for example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcWidgets.Models
{
/// <summary>
/// This is a summary comment
/// </summary>
public class Comment
{
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="birthdate"></param>
/// <param name="website"></param>
/// <returns></returns>
public int SomeMethod(string name, DateTime birthdate, Uri website)
{
return 0;
}
}
}
You can then generate an XML comment file and then generate a Help file using SandCastle.
You may have to enable this feature in the Text Editor/C#/Advanced options dialog.