How to run external executables from an Appharbor application (HTML to PDF generation)? - c#

I have a requirement to produce PDF's for one my .Net web applications currently hosted on Appharbor.
Traditionally, I would simply install latex on the machine, and create PDF's on the fly with pdflatex. This requirement is to display sections in HTML to end users, but also have a downloadable PDF - so it's slightly different.
I have found several (free) external HTML to PDF converters which may be applicable in this instance. However, I haven't found any libraries allowing me to do this purely programatically.
What advice would you give if I plan to continue using Appharbor?
Should I set up a seperate EC2 (or similar) instance to run such an application from? Or is there a better alternative?

I'd recommend using something like DocRaptor. Note that you can probably continue with your current scheme if you place the relevant pdflatex executable (and it doesn't require the entire Latex runtime) alongside the code you push to AppHarbor. AppHarbor will also be introducing background workers, which might be a good fit for this sort of work.

Note that if you're trying to use Rotativa or using wkhtmltopdf with routes obtained from HttpContext you'll need to use this workaround:
http://support.appharbor.com/kb/getting-started/workaround-for-generating-absolute-urls-without-port-number
or install the premotion fix from Nuget:
https://github.com/trilobyte/Premotion-AspNet-AppHarbor-Integration

Related

Web application to manage CATIA files

A have a question for CATIA customization experts!
I'm intend to develop a web application able to perfoms the following tasks:
Modify some parameters into CATIA files. eg.: change the diameter or length of a part;
Convert theses CATIA files to STEP files.
So, I possible do these things using CATIA API and without have CATIA software instaled on my web server?
I did some research on the WEB and I found some APIs, like "CAD.ai" that I think solve these questions. But, these APIs look so sophisticated for my purpose and I looking for develop my own code.
Any suggestion?
Catvbs code can be incorporated in web pages and "talk' with CATIA, check Dassault Systems automation documentation which is in the installation folder of CATIA (be aware that there are differences between releases and versions of CATIA- v5, v6, 3DEx). You don't need to have CATIA but you need to check if CATIA is opened or not on client PC (and convince CATIA user to run your code from web).
By the way, from DS chm automation file you can run their codes directly in CATIA...

PHP (HTML5) based Windows Software

Is it possible to make from a HTML5-APP (PHP,SQLITE,HTML,CSS,JS) a installable Windows Software in c#?
The software must start PHP (5.4), and must just load the document-root in the webbrowser object.
In theory it should work without problems. But what about protecting this code? Is it possible to protect at least the PHP part? Will ioncube or zend-guard work on PHP 5.4's embeded server? And is it possible to hide the shell window, which will open everytime, when i start the PHP Webserver via cmd?
Or do you know an alternate, how i can make a software from a HTML-5 (with PHP) App?
Your choosing the wrong language. PHP, HTML, JS, CSS and SQLLite are separate technologies.
I'd suggest writing the app in another language capable of producing an executable like C / C++ (and one that can plug into to SQLITE fairly easy).
If you want to create a installer out of HTML5-APP (PHP,SQLITE,HTML,CSS,JS) , take a look at bitnami package, it may solve your problem, if you have any explicit reason to use C#, and then you have see its library or namespace which may give you installer capability. However your question is unclear, can be be more clear?
You can embed a Chrome browser in C# using the CefSharp project. You would also need to embed some webserver (php built-in webserver might work, but it's single threaded so it might be an issue).
If it doesn't necessarily need to be C#, then take a look at the PHP Desktop project that is using C++ to embed a Chrome engine, a multithreaded webserver Mongoose and a PHP interpreter. Sources can be protected using many available php encoders, see the KnowledgeBase wiki page on the project site for details.

Using photoshop files from web application

I want to interact with a Photoshop file and create images using its actions and smart objects.
Is there any php or C# API to can do it?
First of all, I would like you to reflect on the legality of such a thing. Would Adobe let you practically just proxy their application to the web? I see they have a lot of licenses so maybe one of them actually grants you permission to do this (however, there could still be caveats so I suggest you read up on that). As that's not the question, I won't talk about this anymore, I just wanted to to mention it as it should be relevant.
Now, for the actual question - if you look at Microsoft Office Interop, Microsoft states that it is unsupported in a server-side environment. Go to this Microsoft page and read Problems using server-side Automation of Office in the More information section.
There are several issues if you decide to run a regular client application server-side, as stated on the mentioned page, but one of the most significant issues is the following:
Interactivity with the desktop:
Office applications assume that they are being run under an interactive desktop. In some circumstances, applications may need to be made visible for certain Automation functions to work correctly. If an unexpected error occurs, or if an unspecified parameter is needed to complete a function, Office is designed to prompt the user with a modal dialog box that asks the user what the user wants to do. A modal dialog box on a non-interactive desktop cannot be dismissed. Therefore, that thread stops responding (hangs) indefinitely. Although certain coding practices can help reduce the likelihood of this issue, these practices cannot prevent the issue entirely. This fact alone makes running Office Applications from a server-side environment risky and unsupported.
While this is written by Microsoft for their product, these are more or less applicable to any regular client application. And even if you still decided to go with this approach, as Neville K already suggested, it would be a very resource-hungry task.
Considering the above, I would maybe ask a different question, along the lines of "What library or server-side app to use for doing whatever you need to do with images".
Based on this link, you can do this things with Photoshop SDK:
"With the Photoshop SDK, you can enable your apps to drive and/or communicate with Photoshop CS6 (version 13.0.0 or later) via a TCP connection. It’s now possible to create an eBook of Photoshop tutorials that allows users to drive actions in Photoshop CS6 from within the eBook"
This sound like hard but some companies seems to make it work. Xee can read PSD too (and has an epic comment about this format in the source code).
But to quote someone over at HN:
PSD was never intended to be a data interchange format: it is the
serialization format of a single program that has more individual
unrelated features that actual people rely on than almost any other
piece of software and has maintained striking amounts of backwards
compatibility and almost unbroken forwards compatibility during its
over two decades of existence. This product's "file format" needs to
be critiqued in this context, along with similar mega-programs like
Office. I am thereby having a difficult time fathoming why anyone
would think that a PSD file is thereby going to be some well-organized
file format that they should easily be able to parse from their own
application is just naively wishful thinking: even other products
from Adobe have limitations while opening these files; to truly
manipulate these files you really need to be highly-compatible with
Photoshop's particular editing model (hence the conceptual
difference between these two classes of file format).
I would recommand to look at Xee for a server side utility.
Good luck.
You can use the scripting interface to kick off "Shell" tasks from any web language if you really want to.
However, I'd seriously worry about this approach - the memory requirements for Photoshop are such that you could only support a couple of users, and you'd need a fairly complex polling mechanism to check for the results of the "shell" task. Photoshop was simply not designed to power web sites in this way.
Consider using graphics libraries instead - I've used ImageMagick with great effect in the past.
Heed the warnings that you really can't process more than 1 or 2 images at a time with photoshop without crashing your server, so just putting it on your webserver is a non-starter. A lighter weight image library is much better for most tasks.
But you could queue up jobs from your web application and then process them on another computer, or limit it to just one at a time.
Adobe has macros and a full action/javascript based scripting environment that you could kick off from commandline or com.
Adobe Scripting Guide
http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/photoshop_cs5_scripting_guide.pdf
For older versions of photoshop you can use the macro functionality to Record an action. Then, create a droplet from the action. Call the droplet from the command line with an image file as the sole parameter. The path to the image file probably needs to be an absolute one.

Online updating a C# program

Greetings,
I'm sorry if this question has been asked already. I've tried using the search function but couldn't find any answer that suited my situation.
I have a real simple C# form application of only 1 file, a exe.
I distributed this currently by 4shared where people can download it as pleased.
However, every time I make changes to the program people will have to download the new version from 4shared.
Now this isn't a ideal situation and I'm a noob when it comes to creating upgrade but the situation I wish is that the program looks at a website / ftp server where I deploy a new version.
I'm looking for a way inside my program to look at the file on that website / ftp server and decide wether there's a new version available.
If there is a new version available in the website / ftp server I would like for the program to update itself to the newest version.
Hope you guys can help me out with this and I hope I explained my situation enough !
NetSparkle is a nice alternative to click-once with more deployment options. http://netsparkle.codeplex.com/
Have a look at ClickOnce. It will do this for you.
When I'm developing and publishing such applications, I usually do it the following way:
Develop a .NET Windows Forms application
Develop a tiny ASP.NET application with an ASMX web service.
Publish the ASMX web service to my public web site.
Add a WSDL reference for the web service to my Windows Forms application.
Create a setup (I prefer Unicode NSIS over ClickOnce).
The logic I implement in the SOAP web service is basically a single function:
[WebMethod]
public string CheckUpdateAvailable( string currentVersion )
{
...
}
The Windows Forms application calls this method (e.g. from a background thread upon program start), passing its current assembly version as a string to the function.
The WSDL function in turn checks the passed version against the newest setup version (e.g. being stored inside web.config or extracted live from the setup.exe on the server). If a newer version exists, it return a string with the URL to download from; otherwise it returns NULL.
When the caller of the WSDL function gets a non-NULL string, it can show a message to the user, asking whether he wants to download and install the executable and then simply execute the URL (via Process.Start).
WyUpdate is the way to go here. We've been using it for over a year with great results (they have excellent support too).
It actually uses patches to update files so that when a 5MB executable only has a small change, the client only has to download a file in the order of kilobytes.
They supply an automatic update component for either Windows Forms or WPF that looks nice and works great.
You can host the update files on either an FTP server or a normal website without any server-side configuration.
There's plenty more to it, and the best place to start is with their video tutorial of how to set up an update.
Here's an open-source library I wrote to address specific needs we had for WinForms and WPF apps. The general idea is to have the greatest flexibility, at the lowest overhead possible. All you'll have to do is create an update feed and reference the library from your app.
So, integration is super-easy, and the library does pretty much everything for you, including synchronizing operations. It is also highly flexible, and lets you determine what tasks to execute and on what conditions - you set the rules (or use some that are there already). Last by not least is the support for any updates source (web, BitTorrent, etc) and any feed format - whatever is not implemented you can just write for yourself.
Cold updates (requiring an application restart) is also supported, and done automatically unless "hot-swap" is specified for the task.
This all boils down to one DLL, less than 70kb in size.
More details at http://www.code972.com/blog/2010/08/nappupdate-application-auto-update-framework-for-dotnet/
Code is at http://github.com/synhershko/NAppUpdate (Licensed under the Apache 2.0 license)
I plan on extending it more when I'll get some more time, but honestly you should be able to quickly enhance it yourself for whatever it currently doesn't support.

Minifying and combining files in .net

I am looking at implementing some performance optimization around my javascript/css. In particular looking to achieve the minification and combining of such. I am developing in .net/c# web applications.
I have a couple of options and looking for feedback on each:
First one is this clever tool I came across Chirpy which via visual studio combines, minifies etc -> http://chirpy.codeplex.com/ This is a visual studio add in but as I am in a team environment, this tool isnt ideal.
My next option is to use an Msbuild task (http://yuicompressor.codeplex.com/) to minify the files and also combine them (maybe read from an xml file what needs to be combined). While this works for minifying fine, the concern I have is that I will have to maintain what must be combined which could be a headache.
3rd option is to use msbuild task just for the minifying and at runtime using some helper classes, combine the files on a per page basis. This would combine the files, give it a name and add a version to it.
Any other options I could consider? My concern with the last option is that it may have performance issues as I would have to open the file from the local drive, read its contents and then combine the files. This is alot of processing at run time. I was looking at something like Squishit - https://github.com/jetheredge/SquishIt/downloads This minifies the files at run time but I would look at doing this at compile time.
So any feedback on my approaches would be great? If the 3rd option would not cause performance issues, I am leading towards it.
We have done something similar with several ASP.NET web applications. Specifically, we use the Yahoo Yui compressor, which has a .NET library version which you can reference in your applications.
The approach we took was to generate the necessary merged/minified files at runtime. We wrapped all this logic up into an ASP.NET control, but that isn't necessary depending on your project.
The first time a request is made for a page, we process through the list of included JS and CSS files. In a separate thread (so the original request returns without delay) we then merged the included files together (1 for JS, 1 for CSS), and then apply the Yui compressor.
The result is then written to disk for fast reference in the future
On subsequent requests, the page first looks for the minified versions. If found, it just serves those up. If not, it goes through the process again.
As some icing to the cake:
For debug purposes, if the query string ?debug=true is present, the merged/minified resources are ignored and the original individual files are served instead (since it can be hard to debug optimized JS)
We have found this process to work exceptionally well. We built it into a library so all our ASP.NET sites can take advantage. The post-build scripts can get complicated if each page has different dependencies, but the run-time can determine this quite easily. And, if someone needs to make a quick fix to a CSS file, they can do so, delete the merged versions of the file, and the process will automatically start over without need to do post-build processing with MSBuild or NAnt.
RequestReduce provides a really nice solution for combining and minifying javascript and css at run time. It will also attempt to sprite your background images. It caches the processed files and serves them using custom ETags and far future headers. RequestReduce uses a response filter to transform the content so no code or configuration is needed for basic functionality. It can be configured to work in a web farm environment and sync content accross several servers and can be configured to point to a CDN. It can be downloaded at http://www.RequestReduce.com or from Visual Studio via Nuget. The source is available at https://github.com/mwrock/RequestReduce.
have you heard of Combres ?
go to : http://combres.codeplex.com and check it out
it minifies your CSS and JS files at Runtime meaning you can change any file and upload it and each request the client does it minifies it.
all you gotta do is add the files u wanna compress to a list in the combres XML file and just call the list from your page / masterpage.
if you are using VS2010 you can easily install it on your project using NuGet
here's the Combres NuGet link: http://combres.codeplex.com/wikipage?title=5-Minute%20Quick%20Start
I did a really nice solution to this a couple of years back but I don't have the source left. The solution was for webforms but it should work fine to port it to MVC. I'll give it a try to explain what I did in some simple step. First we need to register the scripts and we wrote a special controller that did just that. When the controller was rendered it did three things:
Minimize all the files, I think we used the YUI compression
Combine all the files and store as string
Calculate a hash for the string of the combined files and use that as a virtual filename. You store the string of combined files in a cached dictionary on the server with the hash value as key, the html that is rendered needs to point to a special folder where the "scripts" are located.
The next step is to implement a special HttpHandler that handles request for files in the special folder. When a request is made to that special folder you make a lookup in the cached dictionary and returns the string bascially.
One really nice feature of this is that the returned script is always valid so the user will never have to ask you for an update of the script. The reason for that is when you make a change to any of the script files the hash value will change and the client will ask for a new script.
You can use this for css-files as well with no problems. I remebered making it configurable so you could turn off combine files, minimize files, or just exclude one file from the process if you wanted to do some debugging.
I might have missed some details, but it wasn't that hard to implement and it turned out very well.
Update: I've implemented a solution for MVC and released it on nuget and have the source up on github.
Microsoft’s Ajax minifier is suprisingly good as a minification tool. I wrote a blog post on combining files and using their minifier in a javascript and stylesheet handler:
http://www.markistaylor.com/javascript-concatenating-and-minifying/
It's worthwhile combining the files at run time to avoid having to synchronise new versions. However, once they are programmatically combined, cache them to disk. Then the code which runs each time the files are fetched need only check that the files haven't changed before serving the cached version.
If they have changed, then the compression code can run as a one-off.
Whilst there will be a slight performance cost, you will also receive a performance benefit from fewer file requests.
This is the approach that the Minify tool uses to compress JS/CSS, which has worked really well for me. It's Linux/PHP only, but you might get some more ideas there too.
I needed a solution for combining/minifying CSS/JS on a .NET 2.0 web app and SquishIt and other tools I found weren't .NET 2.0-compatible, I created my own solution that uses a syntax similar to SquishIt but is compatible with .NET 2.0. Since I thought other people might find it useful I put it up on Github. You can find it here: https://github.com/AlliterativeAlice/simpleyui

Categories

Resources