├── VideoProcessorV2
├── host.json
├── VideoFileInfo.cs
├── ApprovalInfo.cs
├── Approval.cs
├── local.settings.example.json
├── VideoProcessorV2.csproj
├── ProcessVideoStarter.cs
├── .gitignore
├── ProcessVideoActivities.cs
└── ProcessVideoOrchestrators.cs
├── VideoProcessorV2.sln
├── README.md
├── .gitattributes
└── .gitignore
/VideoProcessorV2/host.json:
--------------------------------------------------------------------------------
1 | {
2 | }
--------------------------------------------------------------------------------
/VideoProcessorV2/VideoFileInfo.cs:
--------------------------------------------------------------------------------
1 | namespace VideoProcessor;
2 |
3 | public class VideoFileInfo
4 | {
5 | public string Location { get; set; }
6 | public int BitRate { get; set; }
7 | }
8 |
--------------------------------------------------------------------------------
/VideoProcessorV2/ApprovalInfo.cs:
--------------------------------------------------------------------------------
1 | namespace VideoProcessor;
2 |
3 | public class ApprovalInfo
4 | {
5 | public string OrchestrationId { get; set; }
6 | public string VideoLocation { get; set; }
7 | }
8 |
--------------------------------------------------------------------------------
/VideoProcessorV2/Approval.cs:
--------------------------------------------------------------------------------
1 | namespace VideoProcessor;
2 |
3 | public class Approval
4 | {
5 | public string PartitionKey { get; set; }
6 | public string RowKey { get; set; }
7 | public string OrchestrationId { get; set; }
8 | }
9 |
--------------------------------------------------------------------------------
/VideoProcessorV2/local.settings.example.json:
--------------------------------------------------------------------------------
1 | {
2 | "IsEncrypted": false,
3 | "Values": {
4 | "AzureWebJobsStorage": "UseDevelopmentStorage=true",
5 | "TranscodeBitRates": "1010,2020,3030",
6 | "SendGridKey": "Your-SendGrid-Key-Here",
7 | "ApproverEmail": "video-approver@mailinator.com",
8 | "SenderEmail": "your@email.here",
9 | "Host": "http://localhost:7071",
10 | "FUNCTIONS_WORKER_RUNTIME": "dotnet"
11 | }
12 | }
--------------------------------------------------------------------------------
/VideoProcessorV2/VideoProcessorV2.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net6.0
4 | v4
5 | VideoProcessor
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | PreserveNewest
18 |
19 |
20 | PreserveNewest
21 | Never
22 |
23 |
24 |
--------------------------------------------------------------------------------
/VideoProcessorV2.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27428.2043
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VideoProcessorV2", "VideoProcessorV2\VideoProcessorV2.csproj", "{C0D36682-1501-4599-B1D0-8EDBEA5C42B5}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DA5924BD-2BC6-4B47-8378-028618F0CC84}"
9 | ProjectSection(SolutionItems) = preProject
10 | README.md = README.md
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {C0D36682-1501-4599-B1D0-8EDBEA5C42B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {C0D36682-1501-4599-B1D0-8EDBEA5C42B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {C0D36682-1501-4599-B1D0-8EDBEA5C42B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {C0D36682-1501-4599-B1D0-8EDBEA5C42B5}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {A796C390-A284-4AA2-8D47-5711BB764F9E}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Durable Functions Video Processor Demo
2 |
3 | This demo shows a very simple video processing workflow using the Azure Durable Functions extension and using version 3 of the Azure Functions runtime. It is based on the demo application in my [Durable Functions Fundamentals course on Pluralsight](https://pluralsight.pxf.io/c/1192349/424552/7490?u=www%2Epluralsight%2Ecom%2Fcourses%2Fazure-durable-functions-fundamentals)
4 |
5 | To run this locally from Visual Studio you will need to create your own `local.settings.json` file with the following contents (filling in your personal email address and SendGrid key in order to be able to send emails):
6 |
7 | ```
8 | {
9 | "IsEncrypted": false,
10 | "Values": {
11 | "AzureWebJobsStorage": "UseDevelopmentStorage=true",
12 | "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
13 | "TranscodeBitRates": "1010,2020,3030",
14 | "SendGridKey": "Your-SendGrid-Key-Here",
15 | "ApproverEmail": "your@email.here",
16 | "SenderEmail": "any@example.email",
17 | "Host": "http://localhost:7071",
18 | "FUNCTIONS_WORKER_RUNTIME": "dotnet"
19 | }
20 | }
21 | ```
22 |
23 | To run in the cloud, you will need to create a Function App, configure App Settings for each of the settings shown above, and push the code to it (you can use right-click publish in Visual Studio).
24 |
25 | To start an orchestration, you can simply call the starter function, making sure to include a video query string parameteter. When running locally, this URL will be: http://localhost:7071/api/ProcessVideoStarter?video=example.mp4
26 |
27 | If you are running in the cloud, the URL will look something like this: https://myfunctionapp.azurewebsites.net/api/ProcessVideoStarter?code=yoursecretfunctioncode&video=example.mp4 You can find your secret function authorization code by clicking the get URL link for your function in the portal.
28 |
29 | There is also a periodic task you can trigger with the `StartPeriodicTask` endpoint (available locally [here](http://localhost:7071/api/StartPeriodicTask)), but it will run forever, so remember to terminate the orchestration (you can use [`StopPeriodicTask`](http://localhost:7071/api/StopPeriodicTask), or delete the function app once you're done.
30 |
31 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/VideoProcessorV2/ProcessVideoStarter.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.AspNetCore.Http;
3 | using Microsoft.AspNetCore.Mvc;
4 | using Microsoft.Azure.WebJobs;
5 | using Microsoft.Azure.WebJobs.Extensions.DurableTask;
6 | using Microsoft.Azure.WebJobs.Extensions.Http;
7 | using Microsoft.Extensions.Logging;
8 |
9 | namespace VideoProcessor;
10 |
11 | public static class ProcessVideoStarter
12 | {
13 | [FunctionName("ProcessVideoStarter")]
14 | public static async Task Run(
15 | [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
16 | HttpRequest req,
17 | [DurableClient] IDurableOrchestrationClient starter,
18 | ILogger log)
19 | {
20 | // parse query parameter
21 | string video = req.GetQueryParameterDictionary()["video"];
22 |
23 | if (video == null)
24 | {
25 | return new BadRequestObjectResult(
26 | "Please pass the video location the query string");
27 | }
28 |
29 | log.LogInformation($"About to start orchestration for {video}");
30 |
31 | var orchestrationId = await starter.StartNewAsync("O_ProcessVideo", null, video);
32 | var payload = starter.CreateHttpManagementPayload(orchestrationId);
33 | return new OkObjectResult(payload);
34 | }
35 |
36 | [FunctionName("SubmitVideoApproval")]
37 | public static async Task SubmitVideoApproval(
38 | [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "SubmitVideoApproval/{id}")]
39 | HttpRequest req,
40 | [DurableClient] IDurableOrchestrationClient client,
41 | [Table("Approvals", "Approval", "{id}", Connection = "AzureWebJobsStorage")] Approval approval,
42 | ILogger log)
43 | {
44 | // nb if the approval code doesn't exist, framework just returns a 404 before we get here
45 | string result = req.GetQueryParameterDictionary()["result"];
46 |
47 | if (result == null)
48 | return new BadRequestObjectResult("Need an approval result");
49 |
50 | log.LogWarning($"Sending approval result to {approval.OrchestrationId} of {result}");
51 | // send the ApprovalResult external event to this orchestration
52 | await client.RaiseEventAsync(approval.OrchestrationId, "ApprovalResult", result);
53 |
54 | return new OkResult();
55 | }
56 |
57 | [FunctionName("StartPeriodicTask")]
58 | public static async Task StartPeriodicTask(
59 | [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
60 | HttpRequest req,
61 | [DurableClient] IDurableOrchestrationClient client,
62 | ILogger log)
63 | {
64 | var instanceId = "PeriodicTask"; // use a fixed id, making it easier for us to terminate
65 | await client.StartNewAsync("O_PeriodicTask", instanceId, 0);
66 | var payload = client.CreateHttpManagementPayload(instanceId);
67 | return new OkObjectResult(payload);
68 | }
69 |
70 | [FunctionName("StopPeriodicTask")]
71 | public static async Task StopPeriodicTask(
72 | [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
73 | HttpRequest req,
74 | [DurableClient] IDurableOrchestrationClient client,
75 | ILogger log)
76 | {
77 | var instanceId = "PeriodicTask"; // use a fixed id, making it easier for us to terminate
78 | await client.TerminateAsync(instanceId, "User requested termination");
79 | return new OkResult();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/VideoProcessorV2/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # Azure Functions localsettings file
5 | local.settings.json
6 |
7 | # User-specific files
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | [Ll]og/
27 |
28 | # Visual Studio 2015 cache/options directory
29 | .vs/
30 | # Uncomment if you have tasks that create the project's static files in wwwroot
31 | #wwwroot/
32 |
33 | # MSTest test Results
34 | [Tt]est[Rr]esult*/
35 | [Bb]uild[Ll]og.*
36 |
37 | # NUNIT
38 | *.VisualState.xml
39 | TestResult.xml
40 |
41 | # Build Results of an ATL Project
42 | [Dd]ebugPS/
43 | [Rr]eleasePS/
44 | dlldata.c
45 |
46 | # DNX
47 | project.lock.json
48 | project.fragment.lock.json
49 | artifacts/
50 |
51 | *_i.c
52 | *_p.c
53 | *_i.h
54 | *.ilk
55 | *.meta
56 | *.obj
57 | *.pch
58 | *.pdb
59 | *.pgc
60 | *.pgd
61 | *.rsp
62 | *.sbr
63 | *.tlb
64 | *.tli
65 | *.tlh
66 | *.tmp
67 | *.tmp_proj
68 | *.log
69 | *.vspscc
70 | *.vssscc
71 | .builds
72 | *.pidb
73 | *.svclog
74 | *.scc
75 |
76 | # Chutzpah Test files
77 | _Chutzpah*
78 |
79 | # Visual C++ cache files
80 | ipch/
81 | *.aps
82 | *.ncb
83 | *.opendb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 | *.VC.db
88 | *.VC.VC.opendb
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 | *.sap
95 |
96 | # TFS 2012 Local Workspace
97 | $tf/
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 |
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 |
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 |
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 |
116 | # NCrunch
117 | _NCrunch_*
118 | .*crunch*.local.xml
119 | nCrunchTemp_*
120 |
121 | # MightyMoose
122 | *.mm.*
123 | AutoTest.Net/
124 |
125 | # Web workbench (sass)
126 | .sass-cache/
127 |
128 | # Installshield output folder
129 | [Ee]xpress/
130 |
131 | # DocProject is a documentation generator add-in
132 | DocProject/buildhelp/
133 | DocProject/Help/*.HxT
134 | DocProject/Help/*.HxC
135 | DocProject/Help/*.hhc
136 | DocProject/Help/*.hhk
137 | DocProject/Help/*.hhp
138 | DocProject/Help/Html2
139 | DocProject/Help/html
140 |
141 | # Click-Once directory
142 | publish/
143 |
144 | # Publish Web Output
145 | *.[Pp]ublish.xml
146 | *.azurePubxml
147 | # TODO: Comment the next line if you want to checkin your web deploy settings
148 | # but database connection strings (with potential passwords) will be unencrypted
149 | #*.pubxml
150 | *.publishproj
151 |
152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
153 | # checkin your Azure Web App publish settings, but sensitive information contained
154 | # in these scripts will be unencrypted
155 | PublishScripts/
156 |
157 | # NuGet Packages
158 | *.nupkg
159 | # The packages folder can be ignored because of Package Restore
160 | **/packages/*
161 | # except build/, which is used as an MSBuild target.
162 | !**/packages/build/
163 | # Uncomment if necessary however generally it will be regenerated when needed
164 | #!**/packages/repositories.config
165 | # NuGet v3's project.json files produces more ignoreable files
166 | *.nuget.props
167 | *.nuget.targets
168 |
169 | # Microsoft Azure Build Output
170 | csx/
171 | *.build.csdef
172 |
173 | # Microsoft Azure Emulator
174 | ecf/
175 | rcf/
176 |
177 | # Windows Store app package directories and files
178 | AppPackages/
179 | BundleArtifacts/
180 | Package.StoreAssociation.xml
181 | _pkginfo.txt
182 |
183 | # Visual Studio cache files
184 | # files ending in .cache can be ignored
185 | *.[Cc]ache
186 | # but keep track of directories ending in .cache
187 | !*.[Cc]ache/
188 |
189 | # Others
190 | ClientBin/
191 | ~$*
192 | *~
193 | *.dbmdl
194 | *.dbproj.schemaview
195 | *.jfm
196 | *.pfx
197 | *.publishsettings
198 | node_modules/
199 | orleans.codegen.cs
200 |
201 | # Since there are multiple workflows, uncomment next line to ignore bower_components
202 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
203 | #bower_components/
204 |
205 | # RIA/Silverlight projects
206 | Generated_Code/
207 |
208 | # Backup & report files from converting an old project file
209 | # to a newer Visual Studio version. Backup files are not needed,
210 | # because we have git ;-)
211 | _UpgradeReport_Files/
212 | Backup*/
213 | UpgradeLog*.XML
214 | UpgradeLog*.htm
215 |
216 | # SQL Server files
217 | *.mdf
218 | *.ldf
219 |
220 | # Business Intelligence projects
221 | *.rdl.data
222 | *.bim.layout
223 | *.bim_*.settings
224 |
225 | # Microsoft Fakes
226 | FakesAssemblies/
227 |
228 | # GhostDoc plugin setting file
229 | *.GhostDoc.xml
230 |
231 | # Node.js Tools for Visual Studio
232 | .ntvs_analysis.dat
233 |
234 | # Visual Studio 6 build log
235 | *.plg
236 |
237 | # Visual Studio 6 workspace options file
238 | *.opt
239 |
240 | # Visual Studio LightSwitch build output
241 | **/*.HTMLClient/GeneratedArtifacts
242 | **/*.DesktopClient/GeneratedArtifacts
243 | **/*.DesktopClient/ModelManifest.xml
244 | **/*.Server/GeneratedArtifacts
245 | **/*.Server/ModelManifest.xml
246 | _Pvt_Extensions
247 |
248 | # Paket dependency manager
249 | .paket/paket.exe
250 | paket-files/
251 |
252 | # FAKE - F# Make
253 | .fake/
254 |
255 | # JetBrains Rider
256 | .idea/
257 | *.sln.iml
258 |
259 | # CodeRush
260 | .cr/
261 |
262 | # Python Tools for Visual Studio (PTVS)
263 | __pycache__/
264 | *.pyc
--------------------------------------------------------------------------------
/VideoProcessorV2/ProcessVideoActivities.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.Azure.WebJobs;
6 | using Microsoft.Azure.WebJobs.Extensions.DurableTask;
7 | using Microsoft.Extensions.Logging;
8 | using SendGrid.Helpers.Mail;
9 |
10 | namespace VideoProcessor;
11 |
12 | public static class ProcessVideoActivities
13 | {
14 | [FunctionName("A_GetTranscodeBitrates")]
15 | public static int[] GetTranscodeBitrates(
16 | [ActivityTrigger] object input)
17 | {
18 | var bitRates = Environment.GetEnvironmentVariable("TranscodeBitrates");
19 | return bitRates
20 | .Split(',')
21 | .Select(int.Parse)
22 | .ToArray();
23 | }
24 |
25 | [FunctionName("A_TranscodeVideo")]
26 | public static async Task TranscodeVideo(
27 | [ActivityTrigger] VideoFileInfo inputVideo,
28 | ILogger log)
29 | {
30 | log.LogInformation($"Transcoding {inputVideo.Location} to {inputVideo.BitRate}");
31 | // simulate doing the activity
32 | await Task.Delay(5000);
33 |
34 | var transcodedLocation = $"{Path.GetFileNameWithoutExtension(inputVideo.Location)}-" +
35 | $"{inputVideo.BitRate}kbps.mp4";
36 |
37 | return new VideoFileInfo
38 | {
39 | Location = transcodedLocation,
40 | BitRate = inputVideo.BitRate
41 | };
42 | }
43 |
44 | [FunctionName("A_ExtractThumbnail")]
45 | public static async Task ExtractThumbnail(
46 | [ActivityTrigger] string inputVideo,
47 | ILogger log)
48 | {
49 | log.LogInformation($"Extracting Thumbnail {inputVideo}");
50 |
51 | if (inputVideo.Contains("error"))
52 | {
53 | throw new InvalidOperationException("Could not extract thumbnail");
54 | }
55 |
56 | // simulate doing the activity
57 | await Task.Delay(5000);
58 |
59 | return "thumbnail.png";
60 | }
61 |
62 | [FunctionName("A_PrependIntro")]
63 | public static async Task PrependIntro(
64 | [ActivityTrigger] string inputVideo,
65 | ILogger log)
66 | {
67 | log.LogInformation($"Appending intro to video {inputVideo}");
68 | var introLocation = Environment.GetEnvironmentVariable("IntroLocation");
69 | // simulate doing the activity
70 | await Task.Delay(5000);
71 |
72 | return "withIntro.mp4";
73 | }
74 |
75 | [FunctionName("A_Cleanup")]
76 | public static async Task Cleanup(
77 | [ActivityTrigger] string[] filesToCleanUp,
78 | ILogger log)
79 | {
80 | foreach (var file in filesToCleanUp.Where(f => f != null))
81 | {
82 | log.LogInformation($"Deleting {file}");
83 | // simulate doing the activity
84 | await Task.Delay(1000);
85 | }
86 | return "Cleaned up successfully";
87 | }
88 |
89 | [FunctionName("A_SendApprovalRequestEmail")]
90 | public static void SendApprovalRequestEmail(
91 | [ActivityTrigger] ApprovalInfo approvalInfo,
92 | [SendGrid(ApiKey = "SendGridKey")] out SendGridMessage message,
93 | [Table("Approvals", "AzureWebJobsStorage")] out Approval approval,
94 | ILogger log)
95 | {
96 | var approvalCode = Guid.NewGuid().ToString("N");
97 | approval = new Approval
98 | {
99 | PartitionKey = "Approval",
100 | RowKey = approvalCode,
101 | OrchestrationId = approvalInfo.OrchestrationId
102 | };
103 | var approverEmail = new EmailAddress(Environment.GetEnvironmentVariable("ApproverEmail"));
104 | var senderEmail = new EmailAddress(Environment.GetEnvironmentVariable("SenderEmail"));
105 |
106 | log.LogInformation($"Sending approval request for {approvalInfo.VideoLocation}");
107 | var host = Environment.GetEnvironmentVariable("Host");
108 |
109 | var functionAddress = $"{host}/api/SubmitVideoApproval/{approvalCode}";
110 | var approvedLink = functionAddress + "?result=Approved";
111 | var rejectedLink = functionAddress + "?result=Rejected";
112 | var body = $"Please review {approvalInfo.VideoLocation}
"
113 | + $"Approve
"
114 | + $"Reject";
115 | message = new SendGridMessage();
116 | message.Subject = "A video is awaiting approval (V2)";
117 | message.From = senderEmail;
118 | message.AddTo(approverEmail);
119 | message.HtmlContent = body;
120 | log.LogWarning(body);
121 | }
122 |
123 | [FunctionName("A_PublishVideo")]
124 | public static async Task PublishVideo(
125 | [ActivityTrigger] string inputVideo,
126 | ILogger log)
127 | {
128 | log.LogInformation($"Publishing {inputVideo}");
129 | // simulate publishing
130 | await Task.Delay(1000);
131 | }
132 |
133 | [FunctionName("A_RejectVideo")]
134 | public static async Task RejectVideo(
135 | [ActivityTrigger] string inputVideo,
136 | ILogger log)
137 | {
138 | log.LogInformation($"Rejecting {inputVideo}");
139 | // simulate performing reject actions
140 | await Task.Delay(1000);
141 | }
142 |
143 | [FunctionName("A_PeriodicActivity")]
144 | public static void PeriodicActivity(
145 | [ActivityTrigger] int timesRun,
146 | ILogger log)
147 | {
148 | log.LogWarning($"Running the periodic activity, times run = {timesRun}");
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/VideoProcessorV2/ProcessVideoOrchestrators.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 | using Microsoft.Azure.WebJobs;
7 | using Microsoft.Azure.WebJobs.Extensions.DurableTask;
8 | using Microsoft.Extensions.Logging;
9 |
10 | namespace VideoProcessor;
11 |
12 | public static class ProcessVideoOrchestrators
13 | {
14 | [FunctionName("O_ProcessVideo")]
15 | public static async Task