Automate text replace in Visual Studio [closed] - performance

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a web project that I am ripping out all the inline styling and adding it to a CSS file, and I can't help but think there is an easier way to do this.
My current process is:
Search Solution for style=", if none selected, goto: 9
Cut all the text between the quote marks
Create new class in CSS file
Paste code in class
Copy class name
Return to html line and paste class name in between quote marks
Rename style to class
goto: 1
Rejoice!
I would really like to rejoice, but there seems to be a never ending supply of inline styling.
Is there a way to automate this process in Visual Studio 2010? If it requires writing a plugin, that is totally fine! I have this same task to do on many a project.
Also, I'd like to be able to do this for arbitrary tags. For example, I'm also taking all of the data-* tags and doing roughly the same thing, but adding a line of jQuery to add it back in. Something like:
$('SELECTOR').attr('data-bind','visible: IsValid');
The work is too repetitious for me not to believe there is an automated (or at least faster/better/less time consuming) way of doing this.
The project is an MVC project if that changes anything.

If you're looking for tool to replace inline style to css class, there are tools available:
http://www.voodoobytes.info/humbles-tools/
http://www.tinytool.net/96002/inline_css_extractor

You will need a macro. There are hints for realization in one file:
1/ Edit point
Dim EditPt As EditPoint
EditPt = CType(DTE.ActiveDocument.Object, EnvDTE.TextDocument).StartPoint.CreateEditPoint
2/ Searching and replacing
While EditPt.FindPattern("style="".*""")
End While
You can read text EditPt.GetText(6) (returns 'style=') delete text EditPt.Delete(6) (removes 'style=') EditPt.Insert("_") (inserts _ before 'style=').

I don't use CodeRush myself, but they seem to have what you are looking for, if this link is anything to be believed.
Move Style Attributes to External CSS
You may need to write your own plugin to do the other, but CodeRush do support this.
I was unable to find similar functionality in Resharper, although it does support plugins as well..

Related

newbie - Best patterns and tools for a real asp.net mvc3 application [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm studing how to build a mvc 3 web application and I am very confused.
I spent the last few days reading about DDD, DI, IoC, TDD, EF (and tools like castle mapper, automapper, windsor, ecc) but I need your experience to make up my mind and choose a path to follow.
What I know:
- I want to use MVC 3.0
- I want to use EF 4.1 or 4.2
- I don't want to use Unit Tests for the moment but I want the structure of my project to support them in the future with few modification.
- I want to heavily use jQuery (the application need to be "very ajax")
- I obviously don't want my controllers and views to directly use EF objects
- I don't want to write duplicate code (ie: if I have a "person" db table with a "FirstName" property, I don't want to create a class for each layer of the software [dal, bll, ui, ...] with the same "person" data. Adding a field to the database should not need to add a property to way to many classes)
What I'd like to know:
- Which pattern(s) would you use?
- Best way of organizing projects inside the vs2010 solution?
- Code first or database first?
Last but not least: Is it possible to use all the cool features of mvc (data annotation, validation, ecc) with a heavily ajaxed site?
Of course I don't expect a fully detailed answer: I just need some pointers/help/link to go in the right direction and study what I need.
Thanks in advance.
To describe your situation: You want to use a couple of frameworks and want to use as much of the best practices/patterns out there. You will fail. Your job is to build working software and not to use as much patterns as possible for your job.
Some "high level advice":
DDD: don't do it! It does make sense in some projects but that often as people would think
TDD: go for it to improve your design
Patterns: When you have a solution for something or a design idea, check out if there is a pattern that describes that idea and not the other way round.
Avoid some patterns: Singleton, facade under some conditions,...
Take a look at SOLID and read Clean Code
Well. I've seen a lot of overdesigned applications which makes maintenance a nightmare. I would advice you to start by just following seperated interface pattern and Single Responsibility Principle. Those two combined makes it easy to maintain and refactor code in future versions.
Unit testing is also a good thing. Not just to make sure that your application work, but to make you rethink your design. A class that is hard to test is most likely badly designed. The most common solution is to break down the class into smaller classes with more clear responsibilites.
I usually try to use blackbox testing when writing unit tests. That is to try to NOT look in the class that the tests are for. If I can't figure out how a class is working by looking at the contract (method definitions), I might have to refactor it.

Compiling code when only the comments change [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Do you compile your code before committing it to the repository, even when you only change a few comments? I know comments are typically ignored by compilers, but I find myself doing this often out of habit.
It's good practice to compile the code every time prior to commit. Sometimes you accidentially edit something except the comments and thus break the code. Compiling is usually very quick and helps avoid needless pain. That's why I try to compile every time prior to commit.
I always compile before committing, the working compiled assembly should always match the working source code. In practice, you don't need to compile if you're just changing comments. But how often are comments the only thing you would change?
Remember, in .NET you can add XML comments which the compiler may read to create assembly documentation. Obviously when changing these types of comments a compile would need to be done.
I commit to git and then push my changes to an svn server everyone else uses, so I have a script that automatically rebuilds and runs tests and pushes to svn if everything passed
I can see why someone might not want to go through a compile cycle if it takes five minutes. But if that's the case, maybe you can collect all of your changes into a single compile/commit operation.
Every Commit Should Build the Mainline on an Integration Machine
e.g. in .Net, you could mess up the XML-comments and check in an unnecessary compiler warning if you are careless. So it's a good idea to compile your code every time prior to commit (as it is to run your tests before committing).
And any half decent compiler will take almost-zero time to recompile code when only comments have changed.
The first parser pass should notice that no functions have changed and stop.
From personal experience, an overworked brain has tendency to key in more than just comments and not notice it. It is probably just better to compile it even if it takes a while. Will save others the headache and protect your credibility.

What are the most commonly use web development policies in software companies? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Having the best forum website among developers, I think I will find a very good consensus of what policies and best practices make good coding. I will put some of them here, so I give the idea, but I will like to hear your opinion and the votes will probably be the judge of the best policies around.
Specific Indentation for coding between development teams
Specific comments before each method, before each variable declaration
Naming conventions, camel case or any other.
In HTML commenting after each container tag.
In CSS, using each declaration only once.
You get the idea. I will like to know what things company ask us to do, and what of those really work to obtain maintainable and beautiful code.
I would focus any policies around development practices rather than code formatting. Some examples are:
Always use parameterized SQL queries. Never concatenate user input into a query.
Keep HTML, CSS and JavaScript in separate files.
Use jslint or an equivalent tool every time you commit code.
Pick an HTML standard (such as HTML 4.01 strict). All HTML must validate.
And don’t be a policy-nazi. Sometimes rules have to be broken—but there should be a very good reason for doing so.
Code doesn't exist if it's not under version control. More specifically, NOTHING is on a production server unless it's committed to the repository.
If a project presents an opportunity to refactor old code, take that opportunity.
Maintain a wiki or similar to document procedures, standards and use of library code (when such documentation is too much for code comments)
(For PHP projects, at least -- note that PHP is open-source and has an important community ; so, many things are quite driven by what's done in the community)
First of all, when using a Framework on a project (ie, always), we try to stick to its policy, if clearly defined (it's the case for Zend Framework, at least) : it ensures anyone who will come to work on this project can :
find a definition of the standard
re-use it on any other projects that use the same framework
even when going to another company, or working for another client
or when coming from another company ;-)
Considering we are only using between 3 and 5 frameworks for PHP projects in the company I work for, and that many rules defined in their standards are the same, it's not a real problem.
Same applies if coding inside/arround some kind of CMS, for instance, of course.
When not using a specific framework, we try to stick to a common set of rules widely accepted amongst the PHP community : same way, it ensure those rules are well-known (even by new-comers to our company), easy to find, and that many people did try them and enhanced them.
About comments, there is one tool that is well-used in PHP : phpDocumentor (about the same thing as javadoc) ; it defines a standard -- this one is the de-facto standard, as there is no other tool that is used that much.
About specific comment-tags :
we always use #param / #return : they are integrated in the IDE, to provide type-hinting, so are useful
else, we don't use much : a couple of lines to say what the method does if it's not obvious ; a couple of lines if a difficult algorithm is used.
Camel-case or other : we stick to what is common amongst both the PHP community and frameworks :
this_is_a_function
And
ThisIsAClassName
And
thisIsAMethodName
In HTML : as much as possible, we don't use HTML comments, because they are sent to the browser :
means bigger pages (ok, not that much)
means giving away informations the user doesn't need
If possible, we use comments from the templating-engine.
In CSS : we comment when needed ; more important thing is to use several small CSS files, quite specific (even if using a merge-tool during the build process)
But, maybe more important than all this : we try to use "clean" code, with small methods that only do a small "unit" thing, with self-describing names and all
It doesn't do magic, but it helps understanding the code... And, also, testing it, re-using it, ...
Also, as Nate said : these are mostly guidelines -- except if specifically required by a client... In which case you have to put some automatic tool (In your build process, for instance) to verify they are followed by the letter.

Best XPath tools [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
What tools are you guys using for XPath and why?
Right now I'm using
SketchPath because its totally awesome, but its a windows app that needs to be installed
WhiteBeam online XPath test bedbecause you can test expressions from the website
SketchPath seems to stand out the most to me because it actually helps you create the xpath and it is very advanced. If you haven't tried it you should.
Cons to SketchPath: you have to install it on the machine, otherwise it is fantastic.
Cons to WhiteBeam: you have to upload your file which I don't always want to do for security reasons and the file size you can upload has some limit on it, and uploading a file is annoying anyways. Also I think there might be some subtle differences between the xpath used for that tool and when running a .NET app. But don't remember any right now. Just keep it in mind.
[Update] XMLQuire was originally recommended in this answer. It was a free XML editor for Windows with the SketchPath XPath Editor built in for XPath testing.
XMLQuire has not been maintained for a few years and has now been retired.
For XPath experimentation etc. XMLQuire's author now recommends the XPath Notebook extension for Visual Studio Code. Developed by the same author, this now supports XPath 3.1 courtesy of Saxonica's Saxon-JS processor.
If you're in a web dev environment, Firefox has a number of great tools for XPath support and analysis:
Firebug has built-in XPath support
XPath Checker I have found to be great
and also maybe of use:
XPath Runner
FireXPath
Be careful with Firebug - the right-click "copy XPath" command copies the path as all lower-case, and some XML parsers (like the MXSML parser used in FinalBuilder) are case-sensitive - so you'll need to correct the casing of your Firebug-copied XPath statement otherwise your parser won't find any matching nodes.
with this xpath tester you can test standard XPath expressions
You can also save your XPath's and XMLs at any point of time to return to it later or post a link in web or email, which is a really handy feature.
SketchPath is the best tool for XPath that I have used so far. I have used oXygen as well, but prefer SketchPath to oXygen for XPath.
I like XPather, a Firefox plugin. It's simple and easy-to-use and it's not a separate program to run as long as you have Firefox running which is when and where I'm usually using XPath.
I use oXygen for xpath work. It's rather easy to test your expression against xml on file. You set the target xml file once and then it's just a button to click to test your expression.

Tool or method to download any section of MSDN documentation and convert to pdf? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Reading the online MSDN docs is a great way to learn more about .NET and other MS technologies. However sometimes I need to read it in an offline mode, like when using an eReader.
Is there a tool, software or some code which can be used to download a section of the MSDN library and convert it to a pdf, by starting from a url in the msdn docs?
Say i want to download the whole section about WCF and the tool would, intelligently, download that part of the MSDN and convert it to pdf? The hyperlinks in the docs need not be followed. They usually point to other subsections in the main section and they will get downloaded during the process.
Update:
App and code is available at http://soofflinereader.codeplex.com/
the solution to convert html to pdf book was simple enough:
https://sitereader.codeplex.com/
Usage:
Download the release build and execute as shown below:
Fluid.SiteReader.Console msdn ms731190
Will convert all documentation underneath the path http://msdn.microsoft.com/en-us/library/ms731190.aspx and create a pdf based on the title of the page stated.
Note:
Will use a sub-folder called 'temp' as a working folder, inspect config file for more details.
See the answers on this forum. May be of help to you.
For single entries you can:
Install PDFCreator from http://sourceforge.net/projects/pdfcreator/
It will then give you a virtual printer driver, that will appear like a normal printer.
From your print option in your browser print your document to a pdf file (or actually any of the other formats on offer).
Don't know any easy way to grab larger subsections.
If you printed multiple sections this way you could then merge them together into a single pdf by using http://www.accesspdf.com/pdftk/.
I paid someone to create one for me.

Resources