GithubHelp home page GithubHelp logo

cloudmelon / functions-dotnet-migrating-console-apps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/functions-dotnet-migrating-console-apps

0.0 2.0 0.0 290 KB

A generic azure function that can be used to convert any console application to an HTTP webservice

License: MIT License

C# 100.00%

functions-dotnet-migrating-console-apps's Introduction

services platforms author
functions
dotnet
muralivp

Best viewed in GitHub

Run Console Apps on Azure Functions

tldr: Here is an easy way of getting any .exe running as a web service. You just specify the input parameters to your exe in a configuration file. You can use binary files as inputs to the exe by specifying a URL to download it from.

More details: This sample is a generic function (.csx file) that can be used to convert any console application to an HTTP webservice in Azure Functions. All you have to do is edit a configuration file and specify what input parameters will be passed as arguments to the .exe.

Azure functions is an offering from Microsoft that allows you to create serverless "compute on demand" applications.

Features

  • You can use binary files as input (specify the URL and the binary file will be downloaded to a temporary location on the virtual environment hosting your Azure Function)
  • You choose which file is sent back to the user as output
  • Here's what the configuration file looks like (more details later)
{
    "name": "consoleAppToFunctions",
    "input": {
        "command": "ffmpeg.exe -i {inputFile} {output1}",
        "arguments": {
            "inputFile": {
                "url": "https://1drv.ms/v/<link-to-file>"
                //binary file input
            },
            "output1": {
                "localfile": "out.mp3"
                //stored in a temp folder
            }
        }
    },
    "output": {
        "folder": "outputFolder",
        "binaryFile": {
            "returnFile": "*.mp3",
            "returnFileName": "yourFile.mp3"
        }
    }
}

Getting Started - Creating a new Function App

  1. Login to - Azure Portal
  2. Create a function app by specifying an App Name and storage account

Create a Function App

  1. Go to the function code editor and Create a New Function

Creating a New Function

  1. Select HTTPTrigger - C# and name your function ConsoleAppToFunction with the right Authorization Level

Create an Http Trigger

Adding Code

TL;DR
If you don't care about the details, just go to your function's "Your Files > Upload Files" (top right) and upload the 3 files in the code sample along with the .exe (and .dll's it requires)

The following are steps that you should follow if you want to fimiliarinze yourself with the using Azure functions interface.

  1. Select the run.csx file under View files

Adding code to run.csx

  1. Replace the code in Run.csx with ConsoleApp Function Code

  2. Since the code uses Json.Net, create a Project.Json file.

Configuring the Sample

We have now created a generic function that can run any console application. You can specify which console app to run in a file called FunctionConfig.json in the following example config we specify the function to run FFMpeg.exe

{
    "name": "consoleAppToFunctions",
    "input": {
        "command": "ffmpeg.exe -i {inputFile} {output1}",
        "arguments": {
            "inputFile": {
                "url": "https://1drv.ms/v/<link-to-file>"
            },
            "output1": {
                "localfile": "out.mp3"
            }
        }
    },
    "output": {
        "folder": "outputFolder",
        "binaryFile": {
            "returnFile": "*.mp3",
            "returnFileName": "yourFile.mp3"
        }
    }
}

We needed a way to pass binary input files to our function. For this we define an argument of type url, where we expect the user to upload a file to Onedrive (or whatever service that hosts a binary file) and provide the link in the query string.

Once these changes are done, the function should have the following files as shown below:

Final configuration

Interacting with the function

  1. Upload your test input file(s) to OneDrive
  2. Get a link to the file using the OneDrive Share menu - something like https://1drv.ms/v/
  3. Interact with the function providing the inputs as querystring. Note that inputFile here is defined in the FunctionConfig.json file above

Example URL:

https://[the URL when you click 'Get Function URL']&inputFile=<link-to-onedrive-file>

The function will process this request by invoking the specified console app and provide the output as a file download.

functions-dotnet-migrating-console-apps's People

Contributors

efficienthacks avatar muralivp avatar microsoftopensource avatar msftgits avatar peterblazejewicz avatar

Watchers

Mélony QIN avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.