How to get underlying code from a .dyn file - c#

I am trying to get the code from a dynamo file so that I can use it in a C# plugin for Revit. When I open the .dyn file all I see is a bunch of xml. I tried parsing it but this does not help. I am looking for a more automatic way than rewriting all the different methods in visual studio. Is there a way to extract the dynamo script code so that can be run from a plugin? I read that dynamo runs on the .NET framework so I am guessing it must be compiled into this type of code at some point? Any help is much appreciated

Related

Parse and rewrite Visual Studio C# source code document character by character

I've been working on learning Roslyn and have made great progress with using the CSharpSyntaxRewriter mechanism to work on code. My goal in the end is to have a customizable coding standards enforcer. As such, I started with Microsoft's code formatter project from https://github.com/dotnet/codeformatter/releases. Right now what I'm working on is formatting white space.
The goal here is to learn Roslyn, so I want to write the code to format all of the whitespace instead of using the Formatter built into Visual Studio and Roslyn.
Formatter.FormatAsync(document, cancellationToken: cancellationToken);
I'm able to parse syntax trees and know I can implement the code necessary to do this using the CSharpSyntaxRewriter, but what I'd like to do is somehow simply get the raw source text for the code, do whatever manipulations are necessary character by character in the source file, and then put the new text back as the document.
However, I cannot figure out if it's even possible to do what I'm trying to do with Roslyn/Visual Studio. I would have thought so, since the source is simply a text file that's already loaded into Visual Studio, and the 'document' object can be acquired for it.
Edit
The optimum solution would be a drop down (or context) menu for C# source files that then ran all modifications on the file. I was unable to link MEF/MPF to any sort of hook that would allow whole-scale modifications of a source file. As such, I went to a console application.
From what I understand, MEF/MPF can provide single entry points to the source file, whereas the Roslyn interface allows simultaneous access to the entire source file at one time. I believe that's why Microsoft used Roslyn in order to implement their coding standards enforcer.
As I said, I've only been looking at Roslyn for about a month, so I may be missing something obvious.

How to compile C# file without a project?

Is there a way in VS2013 to compile a C# file without a project or solution?
This is useful, e.g. in editing some C# code quickly while preparing a Stack Overflow answer while scrubbing corporate IP from the file (without risking any harm to the "real project").
The build toolbar is grayed-out.
I know one can occasionally see squiggles for errors.
Any other simple ideas?
You can use https://dotnetfiddle.net/
You can specify different things in it. It is best for writing fast answers, also you can post link with your saved work. It is similar to jsfiddle if you aware of it.
You can use Snippet Compiler. You can download it from below URL.
http://www.sliver.com/dotnet/SnippetCompiler/
Its a stand alone light weight small application.
If you have Mono C# installed then C# REPL is awesome tool to execute small chunk of c# code.
http://www.mono-project.com/docs/tools+libraries/tools/repl/

Altering WatiN.Core dll to work with frames AND iframes

Alright so this may be a total n00b question but I'm using the WatiN 2.1 library with Visual Studio 2013 and I'm trying to automate a mostly javascript-based webpage. I've done this task already using VBA but I wanted to redo it in C#. The webpage has multiple AND elements and some necessary fields are contained in lower levels of each. In VBA, I was able to navigate the page by simple doing something like this:
ie.Document.frames("frameID1").Document.frames("frameID2").Document.getElementByID("target").Click
This line of code would work whether frameID1 or frameID2 were frames or iframes. It didn't seem to matter to VBA. I tried a similar approach in C# using WatiN but it seems like the Frame feature in WatiN only recognizes as frame elements and simply recognizes a element as a simple HTML element.
That being said, I have read the question regarding this found here
but this is where my questoin arises. They say the solution is to alter the code for the AllFramesProcessor method and that fixes it. But how exactly do you access and modify this code? This code is contained in a .dll which I've tried to modify using .NET Reflector. I've export the source code, opened it in Visual Studio, found the code to modify and did so, but when I tried to build a new release, it threw multiple errors. Any suggestions on how to modify this block of code properly and get a version of WatiN that can handle elements?

Convert WinForms design to XML

I'm building a generic survey engine where end users can generate and design their own surveys (including UI design). I'm interested in building (or perhaps even buying) a custom WinForms designer which would be able to output design in XML format. I'd then save the XML to database and when users load a survey, XML would be parsed and the form would be dynamically generated based on the XML data.
Building my own C# to XML converter is an option, but I'd like to avoid it since users would have to use Visual Studio to get ahold of WinForms code and then run a custom tool to generate XML output, which is a pretty clumsy solution (besides I can't force customers to buy VS).
I'd appreciate it if anyone could point me in the right direction.
Thanks!
The bits of the WinForms Designer are exposed by the .NET framework: Design surface, toolbox, property grids,...
This MSDN article and this CodeProject article should help you get started.
Of course, this is only the start of the story.
Your second problem is to make the designer emit XML rather than C#/VB code. Last but not least, you'll have to create the form at runtime, which is usually done by compiling the code generated by the designer. Needless to say that compiling XML is another story.
It would certainly be easier to store the C# code in your DB rather than some XML model. You can then compile it programmatically at runtime (no need to have VS installed on the client's computer. The .NET runtime is enough) and instantiate the form class dynamically. BTW, whether you complie the code in the designer or in runtime is up to you.
However, other routes may be easier, such as Hans' suggestion: InfoPath.
The Mono project has a Winforms Designer. I don't know how easy it would be to re-use as a componant. Here it is in action:
I don't know how you would go about serializing the output to XML and deserializing it again. Maybe you could even store the C# in your database?
Check this post on how to create xml files in C#: Working with XML
Then use sp_xml_preparedocument/sp_xml_removedocument in SQL to create/parse xml files (use stored procedures to do this)
Traverse and use the generated xml in your winform (I suggest you use LINQ to XML to do this)
Probably the hardest thing you'll encounter here is the creating xml part and traversing the xml nodes, but aside from that everything will be a breeze.
We're already implementing this structure/architecture at work but on webforms not winforms. But I think the flow/logic is the same. HTH.
Edit: This post might help you. Cheers.

Translating comments and region names in source code

Does anyone know of a batch processor or a VS 2010 plugin/script that would let me translate comments and region names from Chinese into English?
The only ones I've found either process all strings or only one string at a time.
I have two large C# projects that I am trying to read through.
Thanks.
Use PrepTags to prepare your file for translation. It will allow you to select the text to be translated based on regex.
www.preptags.com
You can work file by file for free, or process the files as batch using the pro version (€39)
In your case, it's pretty simple to prepare. You just mark everything as protected, then unprotect the content of the comments & region names.
Disclosure: I develop PrepTags.
As was noted, you can use Google Translate API or alternatively Bing Translator API. You can detect comments and regions in your files using System.CodeDom.
I'm not too sure if this is possible. What you can do to help would be the following:
1) Make sure that both C# projects have the Properties > Build > Xml document file check box checked.
2.1) Write an application that reads in the generated xml file.
2.2) Parse the file, and for each value make a call to Google Translate to get the translated value.
2.3) Place the translated value within another xml file that has the same structure as the one created from building the project.
This wouldn't solve the your desire to translate the region names, but its a start. At least you would have intelligence when using the two projects.
This is actually a good idea for a small open source project. I may decide to pick it up. If I do, I'll let you know.

Categories