Tool to convert inline C# into a code behind file - c#

I have a number of legacy web controls (ascx) that contains huge amounts of inline C#. The forms contain a number of repeated and duplicate code. Our first plan is to move the code into code behinds per file, then refactor etc... were doing this to upgrade the client to the latest version of their cms
At the moment we are going to have to manually copy and paste from hundreds of files, create a code behind, copy the code, add the namespaces based on the client-side imports and then do any tidying up
does anybody PLEASE know of a tool that can do the majority of this work for us ?
Thanks

The DMS Software Reengineering Toolkit is designed to support the the construction of automated mass change tools.
It can parse HTML, and C#, (and build corresponding ASTs) and could be configured parse .ascx files. With the parse trees, one could likely generate your desired results.
Is this easy? No. is is practical? Yes, if the amount of code you are reengineering is significant, as it seems in your case.

I think your best hope here is to create a custom conversion utility. I don't know of any tools that would do this out of the box.

Use a language like Perl or Rebol which can do parsing. Rebol is the easiest.

Resharper has many features for moving and locating code for different refactorings. I don't have it installed on the machine I'm at right now, so can't verify, but it may be able to at least speed up the process and make it more full proof, even if it can't be fully automated.

I think your best bet would be to look at the Codesmith tools, or just T4 templates in general..you shouldn't need to write a custom app...though it looks like someone on CodeProject did just that : http://www.codeproject.com/KB/aspnet/InlineCodeVSCodeBehind.aspx?msg=997793

Related

How to implement a mini language?

Environment
Windows 8.1 64bit
Microsoft Visual Studio
C#
What I'm trying to do
To implement a mini language in C#
My job in my company is to make a software which automates evaluation of the performance of company products. The evaluation involves opening valves, flowing chemicals, fetching signals from sensors, calculating some values, etc...
The issue is when a user wants to change the procedure and parameters like how long the reaction time is, the order of opening valves, whether reaction conduit is flushed out or not, the programmer has to change the source code and build another software every time the user requires it.
So I'm trying to implement a mini language in C#. A user can organize a procedure of measurement with the easy-to-understand language. The user writes a code in a txt file, my software reads it, parse each line of code, extract commands and parameters, call corresponding method in the software.
For example, a user writes a line of code like open_valve(3), my software reads the code and call an internal method send_commands_to_ADconverter(VALVE, 3) which sends appropriate commands to a target valve via an A/D converter connected to the computer. This is my conception.
However, due to lack of my programming skill, I have no idea where to start. What technology is available? What are the keywords to achieve the goal? How can I achieve this objective? Any help would be appreciated. Thanks.
Edit 1
c# - Adding scripting functionality to .NET applications - Stack Overflow doesn't refer to accessing external devices like sensors, valves via A/D converter which is crucial for my purpose, so it is unclear this is a duplicate question of the link above.
In order to create a language you need a "parser" of some sort. You will need to define a "grammar". Parsing your "progam" via the grammar will result in a structure that you can then call methods in your code that implement each feature of your language.
You are on a big learning curve here :) lots of strange things like EBNF. You will probably see lots of references to things like Gold and ANTLR. These are hugely capable but involve things like "compiler compilers" and add a level of complexity that can be confusing and require extra steps in you build pipeline.
Here are a couple of libraries I've used that allow you to define you grammar in c#.
https://github.com/picoe/Eto.Parse
https://irony.codeplex.com/
Irony is very good (I've used it for various projects) but hasn't been maintained for a while.
Eto.Parse is more recent. It also has built in parsers that allow you to create a Grammer by parsing BNF. This is very cool
If I understand, your goal is to parse a syntax written by your user and take a decision with what he typed.
I suggest you to use regular expression to match and split the user input.
There are several scripting languages which can be run directly from C#.
As your users doesn't seem to have programming knowledge it might help to use a verbose language like VBScript.
To run VBScript you can use the Scripting Control. See this question for samples: Use Microsoft Scripting Control to evaluate 'If' expressions (via c#)
IIRC the script control must be run as a 32bit application.
Well, the easiest option would be to use what you already have - C#.
You can compile C# code on the fly, and it's very easy and cheap with the new compiler, Roslyn. Then all you need to do is define your interface so that it's easy to use for the users, and put that code in a method you can call from your code. This allows you to easily support all the various development tools for C# as well, including Visual Studio/VS Code. In the simplest form, all you need to do is make your "script" implement some base class that has all the methods you want the users to have - there's certainly better approaches, but this one is very simple, which sounds like something you're looking for.
Of course, this only makes sense if you can trust your users. Making safely sand-boxed code in C# is a lot more complicated (though certainly possible), and you'd probably be better off using some ready scripting solution.

css builder for mac like VS2010's

I can't believe I can't find this. At work I use VS2010's CSS Builder tool. It isn't WYSIWYG, really all it does is help one remember the available CSS commands, and their possible values, and stuff it in a selector.
I can't seem to find a tool that does this as a standalone product. I believe CSS Edit did that, but it is now part of $80 Espresso.
I tried CSS3 Toolkit, which is really nothing more than a button generator, and a waste of my $2.99.
Coda does this as well, but again, I don't feel that this is an $80 tool.
Simple CSS does pretty much exactly what I need, and is free, but it is extremely clunky to use IMHO. You have to export the file every time before you can view changes in browser, no save button. Live preview isn't a requirement, but it bugs me that the one in Simple CSS is broken... it doesn't cascade.
Anyone know of a good simple CSS tool for mac? I am tempted to just code one. It is just a matter of taking all the available fields, and all options from W3, putting in a form, and spitting out a file.
You can go for Eclipse and Netbeans you could argue that these two are more geared towards programming in languages such as Java, they can just as well be used for HTML/CSS/javascript.
Bet you can try Aptana which is built specifically for web developers using the Eclipse engine. It is not only free but, it is quite robust, and it supports Eclipse plugins.
A good article that compares CSS editors (not all free bt a quick guide): http://css-tricks.com/reviews-of-mac-css-editors/
And not to miss here are some free CSS editors: http://speckyboy.com/2008/09/15/7-free-css-editors-which-is-the-best-you-choose/

Class Documentation Suggestions

We are a Microsoft shop, concentrated on using C#. We have several projects, including websites, Windows services, and class libraries, that incorporate XML comments.
I'm looking to generate MSDN-style HTML documentation for each project and deploy it to a centralized location that all of the developers can easily access. I also want to automate these steps so they can be run at regular intervals so I, and the other developers, don't need to worry about remembering to generate and deploy new documentation whenever a change is made. I've looked at Sandcastle and Doxygen and both look to be good options for generating the documentation that I want, but I need advice on a good way to automate the generation of it, like in a nightly job or something.
Anyone out there doing something like this? I'm not sold on the end result being HTML; especially if there is a better idea.
EDIT:
I appreciate all of the good ideas. There are a couple of routes now that I can investigate, but I won't know which will work best until I get my hands dirty. The Sandcastle Help File Builder seems to offer me the best options for what I'm looking to do, so I'll give the nod to that suggestion. However, if I had more time to work on the XSLT and CSS solution to get the XML data looking just right, I'd pursue that suggestion first.
Thanks again everyone!
Take a look at Sandcastle Help File Builder. This uses standalone projects, so you can build them as often as you like (for example nightly, or as part of your continuous integration system every time a change is checked in).
You don't need any third-party tools to generate nice documentation: C# compiler can output the documentation from XML-comments in XML and all you need is to design a nice CSS to show it in browser. If you are not satisfied, you can also generate your own XSLT-transoformation before applying CSS, as described here (look for an example of CSS in comments!).
Alternatively you can take this XML documentation and improve it using something like NDoc. Here is a nice article about how to do it, unfortunately somewhat outdated.
You can manually build only the documentation of your project into a single XML file by running the compiler with /doc:documentationfilename.xml parameter.
You can also indicate in Visual Studio (Project Properties -> Documentation) to add this option to every build of your project, so that XML file will be generated every time you build your project. You can then hook post-build events to copy the XML file to your repository.
You can also set up your MS Build on your Team Foundation Server to build your documentation and copy it to the repository in a similar way (/p:DocumentationFile=fileName.xml);
I do that with our projects. Basically we use doxywizard to set up the configuration Doxyfile, which will set the specifications for the generated html. Then, in a build server step I invoke "doxygen doxyfile".
Our Doxyfile is configured to generate the doxygen files in an area visible from our webserver. So, each commit to trunk causes documentation to be rebuilt automatically.

Generate sequence diagram using C#

Hello is there any tool/api available to generate a customize sequence diagram based on certain user input?
One way to attack this would be to use Visio (if your licensing scheme is compatible):
Here is a codeplex project that is supposed to make this easier from .NET (I haven't used it):
http://visioautomation.codeplex.com/
Another way to do this would be to just write some WPF code. I think that there are a number of open source projects that might help you in this effort as well.
A really expensive (but really good) implementation is from yWorks - it's yEd. I've used it and it's extremely powerful.
VS2010 provides such a feature, you might need the premium or ultimate version. If you need a whole bunch, you might write a macro or even an extension to VS.

C# SDK for non-IDE Java developer

I've been playing with Java for years as a means of developing quick and easy tools for repetitive tasks. I am not a true "developer" in the traditional sense, but I have lots of experience creating a wide assortment of tools and PoCs.
Unfortunately for me, I have noticed many shops are specifically looking for experience with C#, and not so many for Java. Even here on SO, there are more questions and more followers to C# related issues than Java. My preference will always be Java over C# simply for the cross-platform compatibility, but since the languages are so similar, I believe it would be beneficial for me to cross-train. I have already dabbled in other languages and scripts (VB and other BASIC flavors, Javascript, VBScript, ASP, JSP, PHP, etc.) so adding another isn't out of the question.
My current Java environment simply consists of a text editor (primarily jEdit for its plugins and layout) and homemade scripts to compile/jar my projects. I don't like to use IDEs because I want full control over my code and don't want a program writing code for me. (I also prefer to write my own code as opposed to using any sort of external library/package, if feasible. It helps me learn and greatly reduces unnecessary code.)
Therefore, what are my options for a non-IDE C# SDK? Libraries are obviously not that important to me. I've heard of Mono, which appears to separate the functions, but haven't tried it yet. What other SDKs exist that are similar to a simple Java SDK combined with a text editor?
Using an IDE doesn't have to mean anything writing code for you. I'm not generally keen on designer-generated code, but unless you decide to use a designer (or snippets etc), Visual Studio won't be writing code for you. Of course it will create a skeleton class for you when you create one, add the appropriate method signatures when you implement an interface etc - but is that boilerplate really something you want to write yourself?
I'd also suggest that your policy of not using external libraries is a bad one. I agree that it's useful for educational purposes to sometimes reimplement something, but it means that the code quality is likely to end up being worse... why would you not want to use code that has already been used and improved by many other people? Yes, you need to be careful about what libraries you use - but you really don't want to do everything yourself... not if you want to be productive, anyway.
I often use a text editor and command line myself for simple test code (e.g. for Stack Overflow questions) but I wouldn't dream of doing that for "real" code that I plan to keep.
Honestly, a lot of C# and .NET is about learning the tools; Visual Studio gives you a lot that you wouldn't be able to do with a text editor. There's a free version, and I highly suggest you check it out! People hiring will want to know that you're familiar with the tools they'll most likely be using.
You can just start with Notepad and csc.exe, the the command-line C# compiler that ships with the .NET SDK.
However, IDE is not necessarily synonym for code generator. I would download Visual Studio Express and start with empty Console projects.
Have fun!
Don't forget you can build/assemble C# projects using MSBuild and a .sln file if you really want. But the IDEs will make life a lot easier.
The IDE will not write code for you, it will help you writing code. Using libraries will help you concentrate on what you really want to program, not the things that already have been done.
Check into AvalonEdit, the text editor component of SharpDevelop. It is an open source text editor that has classes that could implement features such as intellisense and syntax highlighting. You would only have to use as much of it as you wanted and you could embed it anywhere you would use a text box control.
If you are familiar with Ant from Java then you could also check out NAnt to do your compile phase.
As far as I know, with Visual Studio you also get a command line C# compiler, csc. You could use a text editor and manually compile your C# code with that on the command line if you really want - that wouldn't be very practical however when your project contains more than a handful of source files.
If your project becomes bigger, you could use a tool like NAnt, which is a .NET version of the popular Java build tool Ant.
I agree with Jon Skeet about that your way of working is not very practical. If you are really looking for a software development job, you'd better learn to use the tools that other developers use. An employer will also not accept the fact that you'd want to write all the code yourself instead of using libraries. By using libraries instead of writing it all yourself you save lots of time, you are reusing well-tested code and your code will be much easier to maintain by other developers.

Categories