Computers, Programming, Technology, Music, Literature

Posts Tagged ‘visual studio

TranslateMaid – Translate text right inside Visual Studio

leave a comment »

 

Working on a foreign language Code base in Visual Studio? Try TranslateMaid for Visual Studio.

http://translatemaid.codeplex.com/ – Download, install with a few clicks, see translated text right within Visual Studio.

TranslateMaid-HowToUse3 

With the release of Internet Explorer 8, Microsoft introduced Accelerators, and one of the accelerators were ‘Translate with Bing’. TranslateMaid.TryTranslate uses the same Microsoft Translator Preview Service.

I don’t know why I like IE, but sometimes it is just so hard to break a habit. While Chrome offers you a feature to translate the entire webpage, IE also allows you to translate just a selected text. I was thinking about bringing the same interface inside Visual Studio, and I pretty much achieved it. I had a tough time switching between a translator and visual studio understanding a lot of Dutch comments.

If you have some comments in your project files, I hope now you could save a couple of seconds switching between Google translate and Visual Studio.

Features:

1. Source Language is Auto Detected.
2. After the Translator window opens, you could convert the translated text to a variety of other languages.
3. Adds buttons to the Tools menu and Code Window’s context menu.
4. Keyboard Shortcuts enabled Ctrl+`, and more. Full documentation here.

KeyboardSnapForShortcutUsage

Try it. Pass it on. If you are curious about how it’s done, feel free to look through the source code at CodePlex. Tested thoroughly with VS 2012, VS2010, VS 2008 (inclusive of Business Intelligence Development Studio) on Windows 7 x64, and Windows Vista x86, but guaranteed to work with other versions of Windows as well.

If there is another version of this add-in, it might support an Options dialog with transparency control when the translation is shown, choice to switch between Google and Microsoft Translator Service. If you stumble on any bugs, bring to my attention.

 

What did it take to complete?

1. A Fiddler trace while IE is running that yielded me http://www.microsofttranslator.com/DefaultPrev.aspx?ref=IE8Activity

2. Visual Studio’s Addin template for the starters.

3. Classic WinForms tricks, and the interesting Mouse Hook in C#.

4. Extensive articles, code samples from MZTools.com  

5. and some long nights..

Spread the joy Winking smile Develop some apps, Make the world a better place Winking smile

Advertisements

Written by gmaran23

August 30, 2013 at 4:40 pm

Incorrect MSDN documentation: The space after Global:: should be removed

leave a comment »

 

Code sample posted at http://msdn.microsoft.com/en-us/library/ms228766(v=vs.100).aspx would not work and would yield you an ArgumentException with an error message as below:

Error message:

System.ArgumentException

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

   at EnvDTE.Command.set_Bindings(Object pVar)

 

Fix:

Fix it by removing the extra space after Global::

Code in the sample above should be changed to

//Notice there is no space after Global::
bindings[0] = "Global::CTRL+SHIFT+ALT+Y"; 
bindings[1] = "Global::CTRL+SHIFT+ALT+X"; 

 

Three hours for a triviality. Nothing unusual.

Related Links:

  1. Binding Add-In Commands to Keys – http://msdn.microsoft.com/en-us/library/5x1f46hd(v=vs.100).aspx 
  2. Visual Studio Add in Error Number 80070057 – http://www.codeproject.com/Articles/463969/Visual-Studio-Add-in-Error-Numbers-Troubleshooting#80070057

Written by gmaran23

August 27, 2013 at 7:45 pm

x64 Application Debugging: Edit and Continue not allowed, but you need a Stopwatch

with one comment

 

This article was originally published for www.prowareness.com and could be located at http://www.prowareness.com/blog/x64-application-debugging-edit-and-continue-not-allowed-but-you-need-a-stopwatch/.

Here’s a scenario. You are debugging some 64 bit code to improve performance, say it’s a pretty long running method with a bunch of IO operations and conditional loops, something like shown in Listing 1. You have started a debugging session or attached a running process to your solution, and when you try to Edit the code to insert a Stopwatch, you’d get the error message: Changes to 64-bit applications are not allowed. This feature to Edit the code and continue debugging for a 64 bit application is not supported by CLR (though a recent version supports it). You might try changing the project’s target platform temporarily to Any CPU or x86, but let’s say you are debugging a huge project, and in order to get to the code snippet where you want to put a Stopwatch, it takes half an hour or you just don’t want to re-enter a new debugging session because you have a good retrospective and trace in the current debugging session.

            viewModel.FunctionList = functionManager.ListAll();

            foreach (var item in viewModel.FunctionList)
            {
                item.FunctionName = MultiLingualHelper.GetCustomerText(item.FunctionName, item.FunctionName, "CDT");
            }

            viewModel.TeamList = teamManager.ListAll();

            foreach (var item in viewModel.TeamList)
            {
                item.TeamName = MultiLingualHelper.GetCustomerText(item.TeamName, item.TeamName, "RMOCDT");
            }

            viewModel.DepartmentManagerList = departmentManager.ListAll();

            foreach (var item in viewModel.DepartmentManagerList)
            {
                item.DepartmentName = MultiLingualHelper.GetCustomerOrSystemText(item.DepartmentName, item.DepartmentName, "RPDCDT");
            }

Listing 1

imageFig 1

How would you put a Stopwatch to measure what time a snippet takes in the middle of an x64 debugging session?

Okay it could be done in 2 or 3 very simple steps, I will describe them one by one.

  1. You could set and query properties, fields and methods of an object via the Immediate Window; but you could also create a new object for the current debugging session via the Immediate Window.
  2. You could query a property or a field via a Watch Window; but you could also call some methods via the Watch Window.
  3. You could break at a breakpoint; but you could also access properties or an object field when a breakpoint is hit.

Point 3, might be optional, but you may like to use it. Anyways that’s the gist, let’s see them in action.

Listing 2 shows a typical Stopwatch code when you want to measure the time took to execute the method FooBar(). We will have to separate the initialization to be a part of the Immediate Window, and all other method, property calls to be a part of the Watch window.

            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            FooBar();
            sw.Stop();
            MessageBox.Show(string.Format("FooBar() took {0} seconds to run.", sw.ElapsedMilliseconds / 1000));

Listing 2

 

#1. Create a Stopwatch object named stopWatch1 inside Immediate Window. Just one line, and hit Enter.

image

Fig 2

var stopWatch1 = new System.Diagnostics.Stopwatch();

Listing 3

#2. Now, that our stopWatch1 is created, let’s pull up a Watch Window, and try to access the commonly used properties and methods. Couple of lines below, copy and paste or type them in.

image

Fig 3

stopWatch1.Reset();
stopWatch1.Start();
stopWatch1.Stop();
stopWatch1.ElapsedMilliseconds
stopWatch1.ElapsedMilliseconds/1000

Listing 4

You are pretty much done here if you are just stepping through the code via F11 or F10, all you should do is, before entering the code region that you want to profile, call the stopWatch1.Start() via the Watch Window – Hit the green refresh icon, and soon as you have started the stopWatch1, continue stepping through or steping over, or continue execution to another breakpoint; but once the critical code is executed, you should go back to the Watch Window, and call the stopWatch1.Stop() method (i.e. Hit the green refresh Icon next to stopWatch1.Stop()). After you have stopped the stopwatch, the values for ElapsedMilliseconds would be refreshed automatically, if not, hit the green refresh icon next to it.

image

Fig 4

That’s how I did it first, and then I thought about breakpoint options, came up with Point 3.

#3. Create a break point (we will call this, breakpointX), after the critical region (or the code snippet whose time you want to measure). Right click on breakpointX, and select When Hit…

image

Fig 5

Make sure Print a message: is checked and Continue execution is unchecked.

image

Fig 6

In the Print a message: text box, type in the below code.

Elapsed Seconds: {stopWatch1.ElapsedMilliseconds/1000} Elapsed Milliseconds: {stopWatch1.ElapsedMilliseconds}

Listing 5

Now once this breakpointX is hit, a message will be printed to the Output Window.

imageFig 7


That’s how you do it. Or to say the least, that’s how I figured to do it. If there are better options, please let me know. In my next post, I will show you how to play a sound when a Breakpoint is hit.

Written by gmaran23

July 23, 2013 at 1:38 pm

Visual Studio 2010 – Step into (F11) a property – How?

leave a comment »

 

I don’t think the internet hates redundancy.

So, How to Step into (F11) a property or an operator in Visual Studio (2010)? Answer borrowed directly from http://stackoverflow.com/questions/4873225/visual-studio-2010-step-into-property-functionf11-doesnt-work-as-expected.

 

 

In VS 2010 it is the default setting that you step over properties and operators(like F10) even if you want to step into(F11). So here is the solution:

  • Go to Tools > Options menu in Visual Studio.
  • Go to Debugging > General menu item in left pane.
  • In right view you will see an option Step over properties and operators (Managed only). Uncheck this option and then you are all set.

enter image description here

Finally found it here: http://www.netomatix.com/post/2010/06/25/Enable-step-into-properties-in-Visual-Studio-Debugger.aspx

Written by gmaran23

May 28, 2013 at 2:30 pm

Posted in .Net, C#

Tagged with , , ,