I got a "a non-generated template is already present" error using TcmUploadAssembly - tridion

We've been using TcmUploadAssembly to update the C# TBBs in a Tridion 2013 installation, and have recently come across:
Error: Cannot generate template with name Correct Self Closing Elements,
since a non-generated template is already present.
In our case "Correct Self Closing Elements" is the name of a C# class. It is contained in an assembly that had previously been uploaded and was working correctly. At this point the C# project compiles properly, the assembly is included as a TBB, and the class is included as a TBB that references the assembly.

One of our users had manually created the TBB entry within Tridion. He had the code entered as:
<%RunTemplate Template="tcm:14-29653-2048"
Class="Tridion.AccountCenter.TemplateBuildingBlocks.CorrectSelfClosingElements"%>
What he had left out, from his copy & paste, was a seemingly innocuous comment above that. The code that he pasted should have read:
/* This template was generated through the Tridion Assembly Template Upload */
<%RunTemplate Template="tcm:14-29653-2048"
Class="Tridion.AccountCenter.TemplateBuildingBlocks.CorrectSelfClosingElements"%>
TcmUploadAssembly looks for that comment explicitly, and throws the "non-generated" error if it doesn't find it.

Related

How edit code template ASP MVC 4 CRUD Generator?

I want to alter the default code genaration of MVC CRUD ASP . NET.
Visual Studio.It generates pages of "Edit.cshtml/Insert.cshtml/Delete.cshtml"
I want to translate "Edit" to "Alterar" - "Insert" to "Inserir", and I would like that the razor file to be called "Alterar.cshtml" instead of "Edit.cshtml"
How can I do that?
Is it possible?
Yes, you can.
Based on this excellent blogpost by Scott Hanselman I changed the default template in a few steps. The difference between Scott's approach and mine is that he apparently made it in a way that keeps the global default but gives him a separate generator for each project. Since I didn't get it working immediately, I opted to instead just change the global template.
Go to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddController (some parts of the URI may vary in your situation
Optionally: grant yourselves write privileges on Controller.tt
Open Controller.tt in an editor of your choice and change what you want to change. Note that these are T4 templates so you have a wide variety of tools to your disposition if you want to do more advanced stuff.
Create a new ASP.NET MVC project
Go to the "Controllers" folder and add a new controller (not an api controller)
You don't have to change anything to get a differently named view: the view, including the file in which it is stored, is generated based on the name of the action method that creates it. If you generate the view from Alterar then the popup window will present you with the name "Alterar" for the file.

Including CSS File in my Plone add-on

I want to add a simple stylesheet to a plone 4 product. Therfore I added
<browser:resourceDirectory
name="groovecubes.portlet.gallery.css"
directory="css"
/>
to [product dir]/browser/configure.zcml, which should me enable to browse stylesheets in this folder with this syntax: ++resource++groovecubes.portlet.gallery.css/mycss.css. But it doesn't. Not even after a buildout.
Every declaration in [product dir]/profiles/default/cssregistry.xml are therefore not found. What am I missing? Is it the package name?
The packages main configure.zcml contains the line
<include package=".browser" />
which should execute browser/configure.zcml
But is does not. I pasted the packages configure.zcml and browser/configure.zcml
Update II:
It gets even weirder. When I modifiy the head of browser/configure.zcml the file is recognized as malformed when I try to start the instance. But when I modify the relevant entry, startup continues normal.
Update III:
I've tested various things now, but what I found out, is that any malformed tags in .zcml files is ignored by the SaxParser. In every product on my dev and productive instance (Plone 4.2 / Plone 4.1). Is that maybe a new feature, I may have missed?
Update IV:
Solved: I removed the interface declaration from browser/configure.zcml that accidently used the same name. That made my .css available. But I'm still wondering about the described parser behaviour.
You declare the name groovecubes.portlet.gallery.css but try to access it as ++resource++groovecubes.portlet.gallery instead (note the missing .css there).
Either use ++resource++groovecubes.portlet.gallery.css/mycss.css or remove the .css part from the resourceDirectory registration.
If that was just a typo, check that the ZCML file is actually being loaded; the registration itself is fine if the names match.

ASP.NET System.Anything is not defined

I ran Debugging and got a ton of "is not defined" errors in all the namespaces under System. The System and System.Web references are in the References folder.
Trying to back track the things I've changed since the last debug, I reduced my root namespace from the default to a three letter abbreviation. Changing it back didn't do anything. Everything else I've been working on has been individual pages.
Most (not all) of the errors go away if I add Global.System to all the namespaces or if I reduce them to the child namespace. i.e. these don't throw errors:
Global.System.Web.UI.Page
Page
But this does:
System.Web.UI.Page
Disclaimer: I'm a .NET novice.
You tried closing and reopening Visual Studio, or doing a Full Rebuild?
Do you have a class named "System"? Or "Global"?

Returning razor-parsed Javascript as a ViewResult from a controller

I've successfully created an mvc/razor web application that returns css files that have been parsed by razor. Each time there's a background-image I have a razor snippet that writes the URL prefix to the image file name. The CSS now looks like this:
body { background-image: url(#LookupUrl.Image("background.gif")); }
Css files now work fine and I've moved onto trying to get javascript .js files to function the same way but these aren't playing ball.
The code is identical to the css code and it successfully finds the .js file, but razor seems to parse it differently. Here's an example js file:
function testFunction() { alert('test function hit!'); }
testFunction();
Razor seems to think it's code that it should compile, and gives the error:
Compiler Error Message: JS1135: Variable 'alert' has not been declared
> Source Error:
>
> Line 1: function testFunction() {
> Line 2: alert('test function
> hit!'); Line 3: } Line 4:
> testFunction();
After renaming the same file to .css it works fine.
Is there a way of getting razor to function with .js files in the same way as it does for .css?
Here's how I registered the file handlers for razor:
RazorCodeLanguage.Languages.Add("js", new CSharpRazorCodeLanguage());
RazorCodeLanguage.Languages.Add("css", new CSharpRazorCodeLanguage());
WebPageHttpHandler.RegisterExtension(".js");
WebPageHttpHandler.RegisterExtension(".css");
The build provider is registered in PreApplicationStart via the method Haacked outlines in his blog post.
Do I need to remove a handler that mvc adds for .js files?
UPDATE 2 days on
While I got working what I wanted to get working, I would not recommend this method to others. Using Razor to parse css/javascript is flawed without the use of <text><text/> - it's the simplicity of razor using the # ampersand that messes it up. Consider the CSS3 #font-face. Razor hits the # and thinks it should use it as a function. The same thing can happen with javascript, and happened with Jquery 1.5.1.
Instead, I'll probably go back to aspx webforms for dynamic css/javascript, where there's less chance of the <% %> code blocks appearing naturally.
I couldn't understand why CSS worked while JS didn't, especially after the copy+pasted JS code worked inside the CSS file.
I used the find/replace dialogue within visual studio on the System.Web.WebPages.Razor source to search for the string '.js' within the project. There was nothing helpful there so I then went to the System.Web.WebPages project. It found a match in System.Web.WebPages.Util, which is a static class with a few helper methods.
One of those methods is 'EnsureValidPageType' and within there is a try/catch block. Inside the 'catch' block is a comment:
// If the path uses an extension registered with codedom, such as Foo.js,
// then an unfriendly compilation error might get thrown by the underlying compiler.
// Check if this is the case and throw a simpler error.
It made me believe .js has got some special built-in handler with it.
I googled for a bit, couldn't find anything, then looked in the web.config that's within \Windows\Microsoft.NET\Framework64{version}\Config.
In there is a buildProvider mapping for the extension .js to
System.Web.Compilation.ForceCopyBuildProvider
After removing this buildprovider in the website's web.config, .js files get compiled and work as they should!
I'm still not too sure what the ForceCopyBuildProvider does or is for but I wonder if it's for visual studio. Various extensions have different Copy/Ignore build providers registered.
Once again apologies for answering my own question but I hope the comprehensive(waffley) answer might help others out.
You could try using the special <text> node to indicate to the Razor parser to treat the content literally:
<text>
function testFunction() { alert('test function hit!'); }
testFunction();
</text>
The default Razor parser uses the HtmlMarkupParser to handle the markup components of your template. There isn't currently any alternative parsers that support other markup languages (which you would need to treat the javascript code language as). If you did create a new markup parser, I would imagine it would be quite difficult to separate the code and markup (i.e. the C# and the Javascript).
What you could do, is use the <text></text> wrapping elements to enforce the parser switches to markup mode when that section of the template is reached, e.g.
<text>function testFunction() { alert('test function hit!'); }</text>
It's not pretty, but it should do the trick.

Customize List.aspx for One Table in ASP Dynamic Data

I have just meticulously followed MS instructions for customising a dynamic data page template for one table. Create the folder CustomPages/MyTable/List.aspx, and copy PageTemplates/List.aspx into that folder, but I now get compiler error because I have duplicated methods in both List.aspx files.
What am I doing wrong?
Just in: I found another, non-MS page that I can't find again now, but he suggested the almost obvious: to change the class name in thej 3 files of my custom list page.
I'm not sure what it says in the instructions, but you'll need to change the namespace in the two codebehind files (List.aspx.cs and List.aspx.designer.cs) and in the "inherits" reference in the .aspx file or yes, you will have duplicate methods (same namespace, same class name, same method name).
You should change the namespace to reflect the path that the custom page is in - this will help ensure it stays unique.

Resources