Sending control keys with DDeltaSolution UIDeskAutomationSpy - c#

I have been using DDeltaSolution's UIDeskAutomationSpy to enhance some of my Coded UI testing, initially based on the MS Code UI test (cuit) framework.
However there is very limited documentation and even after using dotNetPeek to inspect the internals of the UIDeskAutomationSpy exe and associated dll, I can't see how to send control keys (Shift/Control/Alt) to a component.
There are two relevant methods
SendKeys()
SimulateSendKeys()
but both just take a string as input.
I've even got as far as thinking about trying to use Cecil to try and modify the binaries (is this possible?), but this is a desperate measure. Does anyone know any better, or know of any better documentation?
This is a surprisingly powerful tool, but no-one seems to have heard about it.

I'm not positive, but if I were you I'd try using the list of control key strings found HERE since automation spy is based on .NET. Let me know if it works!

Related

Is there something better than preprocessor directives (#if, etc) in C#?

Most questions of this type are seeking to alter the program behavior (things that could be decided at run time) or want to deal directly with debug printing. This is a bit different.
I have code that depends on a peripheral (like a card reader). Sometimes I don't use it, which means the library isn't present. (And I'm being nice, because "library" turns out to mean installing a 2GB software suite). When I remove the library, I can't open the device. If I can't open the device, I can't create the class member that uses it. With the class inoperative, I can't call its methods from within the code. Therefore, I can't just choose not to execute it; I need it to go away since it will not compile without the library.
Preprocessor directives like #if and all that are ok, maybe; but these things appear in more than one file, which means independently maintaining a #define at the top of each. I come from a simpler place (meaning, C) where one header file can be used to control this. I note that C# is rather hostile about #define (either the label exists, or not; no constants or calculations allowed), and that makes me think there's another way.
How do you handle this?
---Follow-up(s)---
I did read the "duplicate" Q/A's, and have a fairly good picture of what I'm dealing with. I didn't find those questions in my original search, but sometimes that's just how it is.
#Amy suggests that #define at the top is "not how it's done" but rather "put it on the command line". So, (if I realize we are sticking with this mechanism) the discussion might go to examining ways to have that happen . One does not simply drop to a terminal and do that. It happens as "IDE features" or "IDE hacks".
#Alexei Levenkov asks what I really want. I really want to (a) not get compile errors, and (b) do it by selectively leaving out the code. And, find the C# equivalent to the way I proposed.
Some more constraints are addressed by the fact that I haven't been using VS or C# for all that long. So I know a lot less than you all do. Considering I got the code from the last person and have to deal with what I see, I don't want to set up the person after me to have to figure out what "interesting" thing I might have done to make it work. Thus, things like hand-editing a project file may work but will also cause consternation down the line.
# Eric Lippert suggests "hostile" is really "sensible". I may have had my tongue too far into my cheek on that one. VS seems to be telling me I'm doing it wrong, so I sensed there's a "right way" I simply don't know about. As for the 2GB supporting application, I will go to various computers and pull down the repository and try out something, and so this "overhead" wants to propagate with it. It's worse if I'm linked through my phone to do the download. And if I build the application with everything included, the end user is then required to install that software suite before the program will run. In theory, they could be required to buy the software. If I sent you a tic-tac-toe game, and told you it wouldn't run until you installed Oracle, you'd probably pass on the whole thing.
I considered the "stub out the interface" idea, but there seemed to be more hooks into the class than I wanted to deal with. Plus, I don't know what these things do, so I have to know something about them in order to "fake" them.
In the end I decided that we're still largely using the #if scheme to get this done, and the replacement feature I imagined might exist, doesn't. And I'm using the provision in the project file(s) as cited by #Jim G. as it gets the job done and is only a little imperfect. It's good enough.
As #BJ Safdie said here:
Set them in your Compilation Properties or Build options.
You get to the build options by right-clicking the project and selecting
properties from the menu.

How to upload data to Cloudsearch programmatically .Net

I am attempting to use Cloudsearch in lieu of SQL-based full-text indexing. However, I have had little luck thus far. Their API documentation is just horrendous, with almost no examples and no mention of using the SDK to do it. All they provide are some shoddy command line scripts.
My use-case is that I am decompiling an ALD file and need to store the resulting text data up there. The only listed methods involve using the command line or the web console, which won't do, seeing as I have tens of thousands of documents to manage. Surely there is a way I can pass it an index and some text data via the C# SDK.
You are right, there is not much sample code and I am not a C# programmer so I won't really try to code it but in an effort to get you in the right direction it seems you just need to instantiate an UploadDocumentsRequest object, populate the Documents property then pass it to AmazonCloudSearchDomainClient.UploadDocuments.
Their documentation to upload is http://docs.aws.amazon.com/sdkfornet/v3/apidocs/Index.html
The request is documented here http://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudSearchDomain/TCloudSearchDomainUploadDocumentsRequest.html
I ended up using the Comb wrapper to handle the uploading, as it handles everything pretty handily in .NET. Pretty sure it uses the methods enumerated by dotcomly under the hood.

How to make a "Call stack diagram"

Creating a call stack diagram
We have just recently been thrown into a big project that requires us to get into the code (duh).
We are using different methods to get acquainted with it, breakpoints etc. However we found that one method is to make a call tree of the application, what is the easiest /fastest way to do this?
By code? Plugins? Manually?
The project is a C# Windows application.
With the static analyzer NDepend, you can obtain a static method call graph, like the one below. Disclaimer: I am one of the developers of the tool
For that you just need to export to the graph the result of a CQLinq code query:
Such a code query, can be generated actually for any method, thanks to the right-click menu illustrated below.
Whenever I start a new job (which is frequently as I am a contractor) I spend two to three days reading through every single source file in the repository, and keep notes against each class in a simple text file. It is quite laborious but it means that you get a really good idea how the project fits together and you have a trusty map when you need to find the class that does somethnig.
Altought I love UML/diagramming when starting a project I, personally, do not find them at all useful when examining existing code.
Not a direct answer to your question, but NDepend is a good tool to get a 100ft view of a codebase, and it enables you to drill down into the relationships between classes (and many other features)
Edit: I believe the Microsoft's CLR Profiler is capable of displaying a call tree for a running application. If that is not sufficient I have left the link I posted below in case you would like to start on a custom solution.
Here is a CodeProject article that might point you in the right direction:
The download offered here is a Visual
Studio 2008 C# project for a simple
utility to list user function call
trees in C# code.
This call tree lister seems to work OK
for my style of coding, but will
likely be unreliable for some other
styles of coding. It is offered here
with two thoughts: first, some
programmers may find it useful as is;
second, I would be appreciative if
someone who is up-to-speed on C#
parsing would upgrade it by
incorporating an accurate C# parser
and turn out an improved utility that
is reliable regardless of coding style
The source code is available for download - perhaps you can use this as a starting point for a custom solution.
You mean something like this: http://erik.doernenburg.com/2008/09/call-graph-visualisation-with-aspectj-and-dot/
Not to be a stuck record, but if I get it running and pause it a few times, and each time capture the call stack, that gives me a real good picture of the call structure that accounts for the most time. It doesn't give me the call structure for things that happen real fast, however.

NOVAS for .NET

Any astronomers out there? I'm wondering if anyone has produced or stumbled upon a .NET (preferably C#) implementation of the US Naval Observatoru Vector Astrometry Subroutines (NOVAS).
I know nothing (of consequence) about astronomy, and absolutely nothing about NOVAS, so please take this with a grain of salt.
But, I did look at the website, and it looks like they have a C implementation. You could always take the C implementation, access it via pinvoke, and write a C# wrapper around it.
Are you only interested in a port of that library or anything usable from C# for astronomy?
I don't have anything for the first part, but for the second I would take a look at AGI's Components. Their libraries provide ways to compute all kind of astronomical data. The Dynamic Geometry Library lets you model everything including planets and such rather easily.
This download contains a very useful astronomical library in C#.
Sorry that I don't remember where I got it but perhaps it is documented in there somewhere.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8399&lngWId=10
Sidenote: The NOVAS library is not very complete. You would be better off to pursue the SOFA lib from the International Astronomy Union. Here's the link:
http://www.iausofa.org/
Urania is an astronomy library in C#:
http://www.smokycogs.com/blog/tutorials/astronomical-calculations-in-c-sharp/
The download is the non-obvious "here" link on the page that combines all of the sample code into a single app called Urania.
Once downloaded, you will also need to modify the Urania.sln file to fix the paths of the different libraries that he uses (MathLib, UraniaLib, etc.) and then it will compile correctly. (Open Urania.sld in notepad and delete: "..\Libs\" out of the 3 project paths)

Is there an existing way to turn source code back into a CodeCompileUnit?

We use the DesignSurface and all that good IDesignerHost goodness in our own designer. The designed forms are then persisted in our own bespoke format and all that works great. WE also want to export the forms to a text-based format (which we've done as it isn't that difficult).
However, we also want to import that text back into a document for the designer which involves getting the designer code back into a CodeCompileUnit. Unfortunately, the Parse method is not implemented (for, no doubt, good reasons). Is there an alternative? We don't want to use anything that wouldn't exist on a standard .NET installation (like .NET libraries installed with Visual Studio).
My current idea is to compile the imported text and then instantiate the form and copy its properties and controls over to the design surface object, and just capture the new CodeCompileUnit, but I was hoping there was a better way. Thanks.
UPDATE: I though some might be interested in our progress. So far, not so good. A brief overview of what I've discovered is that the Parse method was not implemented because it was deemed too difficult, open source parsers exist that do the work but they're not complete and therefore aren't guaranteed to work in all cases (NRefactory is one of those from the SharpDevelop project, I believe), and the copying of controls across from an instance to the designer isn't working as yet. I believe this is because although the controls are getting added to the form instance that the designer surface wraps, the designer surface is not aware of their inclusion. Our next attempt is to mimic cut/paste to see if that solves it. Obviously, this is a huge nasty workaround, but we need it working so we'll take the hit and keep an eye out for alternatives.
You could always write your own C# parser. That way you can be sure of it's completeness.
In your case, because you don't need anything like intellisense, you could probably get away with just using a parser generator.
Even if you wrote one by hand, however, it probably wouldn't take you more than about a month.
It's not exactly what you asked for, but you could try to use the CodeDomComponentSerializationService class to generate the CodeDom graph based on the current state of the design surface.
We use that class to handle copy/paste functionality in our built-in designer.

Categories