Skip to content

Commit

Permalink
Merge pull request #14 from ebu/new-stmoritz17-features
Browse files Browse the repository at this point in the history
New stmoritz17 features
  • Loading branch information
mhabegger committed Mar 1, 2017
2 parents 14cc8e0 + 2227817 commit 80794d6
Show file tree
Hide file tree
Showing 64 changed files with 9,929 additions and 1,143 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -109,3 +109,4 @@ Backup*/
UpgradeLog*.XML
*Thumbs.db
io.ebu.eis.contentmanager/*.config
io.ebu.eis.worker/*.config
30 changes: 29 additions & 1 deletion content-manager.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "io.ebu.eis.contentmanager", "io.ebu.eis.contentmanager\io.ebu.eis.contentmanager.csproj", "{4DADE0BE-C6E6-4B62-B24A-D9EC3A935B11}"
EndProject
Expand Down Expand Up @@ -41,6 +41,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "img", "img", "{F32CFC1B-843
doc\img\cm_screenshot.png = doc\img\cm_screenshot.png
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "io.ebu.eis.worker", "io.ebu.eis.worker\io.ebu.eis.worker.csproj", "{46CF9C05-18DE-404C-A6BB-19920276B4B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "io.ebu.eis.shared", "io.ebu.eis.shared\io.ebu.eis.shared.csproj", "{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -141,6 +145,30 @@ Global
{02A3FD2C-6DC9-434F-A28A-CB8AFF8D50EA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{02A3FD2C-6DC9-434F-A28A-CB8AFF8D50EA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{02A3FD2C-6DC9-434F-A28A-CB8AFF8D50EA}.Release|x86.ActiveCfg = Release|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Debug|x86.ActiveCfg = Debug|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Debug|x86.Build.0 = Debug|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Release|Any CPU.Build.0 = Release|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Release|x86.ActiveCfg = Release|Any CPU
{46CF9C05-18DE-404C-A6BB-19920276B4B9}.Release|x86.Build.0 = Release|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Debug|x86.ActiveCfg = Debug|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Debug|x86.Build.0 = Debug|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Release|Any CPU.Build.0 = Release|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Release|x86.ActiveCfg = Release|Any CPU
{88FBE6F3-7FC9-4940-8403-BBCF93BE6EDC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
26 changes: 25 additions & 1 deletion doc/Configuration.md
Expand Up @@ -30,13 +30,37 @@ You should edit the following values:
| FtpServer | ftp.server.ch | Address to your FTP server |
| FtpUsername | username | Username to your FTP server |
| FtpPassword | password | Password for the FTP account |
| Subfolder | generated-images | Subfolder on the FTP server |
| Subfolder | generated-images | Subfolder on the FTP server (does not require prefix or suffix slash) |
| PublicUriBase | http://public.server.ch/subfolder/ | The prefix that will be appended to all images uploaded as public url address for the RadioVIS distribution |
| StompUri | stomp:tcp://radio.ebu.io:61613 | The stomp URL to your stomp server, this example is one of the EBU RadioVIS servers |
| StompUsername | username | The stomp username |
| StompPassword | password | The stomp password |
| StompTopic | /topic/dab/4e1/ffff/ffff/0/ | |

### Using Amazon S3 as storage backend
```
<UploadConfiguration Type="S3" AWSAccessKey="accesskey"
AWSSecretKey="secret"
S3BucketName="bucketname" Subfolder="generated-images"
LatestStaticImageName="current"
PublicUriBase="https://s3-eu-west-1.amazonaws.com/bucketname/">
<DispatchConfigurations>
<!-- ... -->
</DispatchConfigurations>
</UploadConfiguration>
```

You should edit the following values:

| Attribute | Example Value | Description |
|---------------|------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| AWSAccessKey | key | Access key from an Amazon AWS Account or IAM User |
| AWSSecretKey | secret | Secret key for the given access key |
| S3BucketName | bucketname | The amazon S3 bucket name |
| Subfolder | generated-images | Subfolder withing the S3 bucket i.e. the prefix (without /) |
| LatestStaticImageName | current | Optional parameter, (Default empty) which specifies a static image name which would be update on every image change |
| PublicUriBase | https://s3-eu-west-1.amazonaws.com/bucketname/ | The prefix that will be prepended to all images uploaded as public url address for the RadioVIS distribution |

If you need to publish the same image to multiple topics simply dupplicate the `DispatchConfiguration` Tag and update the settings accordingly
for the new dispatch.

Expand Down
77 changes: 60 additions & 17 deletions io.ebu.eis.canvasgenerator/HTMLRenderer.cs
Expand Up @@ -14,11 +14,11 @@ public static class HTMLRenderer
private const string PhantomArgumentProperties = "320px*240px"; //"640px*480px 2.0";//
private const int TimeToExit = 500;

public static BitmapImage Render(string file, string pathToWorkingDir)
private static string Render(string file, string pathToWorkingDir, string zoomFactorOptions = PhantomArgumentProperties)
{
try
{
var args = String.Format("{0} {1} {2}", PhantomPageGenerator, file, PhantomArgumentProperties);
var args = $"{PhantomPageGenerator} {file} {zoomFactorOptions}";
var startInfo = new ProcessStartInfo
{
FileName = PathToExe,
Expand All @@ -28,7 +28,7 @@ public static BitmapImage Render(string file, string pathToWorkingDir)
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
WorkingDirectory = pathToWorkingDir // PDF Tool Path
WorkingDirectory = pathToWorkingDir // Path to templatess
};
var p = new Process { StartInfo = startInfo };
p.Start();
Expand All @@ -38,21 +38,35 @@ public static BitmapImage Render(string file, string pathToWorkingDir)
// TODO If error not null or empty String the report error
// Read the Output:
var base64Image = p.StandardOutput.ReadToEnd().Trim();
var bytes = Convert.FromBase64CharArray(base64Image.ToCharArray(), 0, base64Image.Length);
if (bytes.Length > 0)
try
{
var test = Base64ToImage(base64Image);
return base64Image;
}
catch (Exception e1)
{
var image = GetBitmapImage(bytes);
return image;
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry($"EIS Content Manager failed to generate an image.\n{base64Image} - {e1.Message}\n" +
"Details workingPath: {pathToWorkingDir}" +
"Details args: {args}\n\n{e1.StackTrace}", EventLogEntryType.Error, 101, 1);
}
}

}
catch (Exception)
catch (Exception e)
{
// TODO Log
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry($"EIS Content Manager failed to generate an image.\n{e.Message}\n\n{e.StackTrace}", EventLogEntryType.Error, 101, 1);
}
}
return null;
}

public static BitmapImage RenderHtml(string html, string pathToWorkingDir)
public static string RenderHtml(string html, string pathToWorkingDir, string zoomFactorOptions = PhantomArgumentProperties)
{
// TODO Pass as argument and decode
var tempFilename = Guid.NewGuid() + ".html";
Expand All @@ -63,8 +77,13 @@ public static BitmapImage RenderHtml(string html, string pathToWorkingDir)
file.Flush();
file.Close();

if (string.IsNullOrEmpty(zoomFactorOptions))
{
zoomFactorOptions = PhantomArgumentProperties;
}

// TODO This is ugly but works : )
var image = Render(Path.GetFileName(tempfile), pathToWorkingDir);
var image = Render(Path.GetFileName(tempfile), pathToWorkingDir, zoomFactorOptions);

// TODO Remove
// Delete Temp file
Expand All @@ -80,15 +99,39 @@ public static BitmapImage RenderHtml(string html, string pathToWorkingDir)
return image;
}

public static BitmapImage GetBitmapImage(byte[] imageBytes)

public static BitmapImage Base64ToImage(string base64Image)
{
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(imageBytes);
bitmapImage.EndInit();
return bitmapImage;
if (!string.IsNullOrEmpty(base64Image))
{
var bytes = Convert.FromBase64String(base64Image);
if (bytes.Length > 0)
{
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(bytes);
bitmapImage.EndInit();
return bitmapImage;
}
}
return null;
}

//public string ImageToBase64(BitmapImage image, System.Drawing.Imaging.ImageFormat format)
//{
// using (MemoryStream ms = new MemoryStream())
// {
// // Convert Image to byte[]
// image.Save(ms, format);
// byte[] imageBytes = ms.ToArray();

// // Convert byte[] to Base64 String
// string base64String = Convert.ToBase64String(imageBytes);
// return base64String;
// }
//}



}
}
3 changes: 1 addition & 2 deletions io.ebu.eis.canvasgenerator/io.ebu.eis.canvasgenerator.csproj
Expand Up @@ -47,7 +47,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\packages\PhantomJS.2.0.0\tools\phantomjs\phantomjs.exe">
<Content Include="..\packages\PhantomJS.2.1.1\tools\phantomjs\phantomjs.exe">
<Link>phantomjs.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -61,7 +61,6 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion io.ebu.eis.canvasgenerator/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="PhantomJS" version="2.0.0" targetFramework="net45" />
<package id="PhantomJS" version="2.1.1" targetFramework="net45" />
</packages>
16 changes: 10 additions & 6 deletions io.ebu.eis.contentmanager/MainWindow.xaml
@@ -1,11 +1,15 @@
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Utils="clr-namespace:io.ebu.eis.contentmanager.Utils"
xmlns:local="clr-namespace:io.ebu.eis.contentmanager"
xmlns:structures="clr-namespace:io.ebu.eis.datastructures;assembly=io.ebu.eis.datastructures"
xmlns:structures="clr-namespace:io.ebu.eis.datastructures;assembly=io.ebu.eis.datastructures"
xmlns:Utils="clr-namespace:io.ebu.eis.shared.Utils;assembly=io.ebu.eis.shared"
xmlns:shared="clr-namespace:io.ebu.eis.shared;assembly=io.ebu.eis.shared"
x:Class="io.ebu.eis.contentmanager.MainWindow"
Title="EBU - Content Manager" Height="708" Width="1300" MinHeight="600" MinWidth="1024" Foreground="{DynamicResource Brush02}" Background="{DynamicResource BackgroundKey}" Closing="Window_Closing" WindowStartupLocation="CenterScreen" Icon="Images/ebu_contentmanager.ico" MouseMove="Window_MouseMove">
Title="EBU - Content Manager" Height="708" Width="1300" MinHeight="600" MinWidth="1024"
Foreground="{DynamicResource Brush02}"
Background="{DynamicResource BackgroundKey}"
Closing="Window_Closing" WindowStartupLocation="CenterScreen" Icon="Images/ebu_contentmanager.ico" MouseMove="Window_MouseMove">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand All @@ -23,7 +27,7 @@
</ResourceDictionary.MergedDictionaries>

<RoutedUICommand x:Key="SaveCartCommand" Text="Save Cart" />

<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

<!-- Light Theme -->
Expand Down Expand Up @@ -168,7 +172,7 @@
<Button Content="Button" HorizontalAlignment="Stretch" Margin="3" VerticalAlignment="Stretch" Width="Auto" Height="35"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="RunningCartDataTemplate" DataType="local:ManagerImageReference">
<DataTemplate x:Key="RunningCartDataTemplate" DataType="shared:ManagerImageReference">
<Grid>
<Border x:Name="ImageBorder" BorderThickness="4" BorderBrush="#FFFF0000" HorizontalAlignment="Left" Width="{Binding ActualHeight, Converter={StaticResource AspectRatioConverter}, Mode=OneWay, RelativeSource={RelativeSource Self}}">
<Image x:Name="MainImg" Margin="0" Source="{Binding PreviewImageSource, Mode=OneWay, FallbackValue={StaticResource DefaultImage}, TargetNullValue={StaticResource DefaultImage}}"/>
Expand All @@ -191,7 +195,7 @@
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate x:Key="EditorCartDataTemplate" DataType="local:ManagerImageReference">
<DataTemplate x:Key="EditorCartDataTemplate" DataType="shared:ManagerImageReference">
<Grid PreviewMouseLeftButtonDown="TemplateList_MouseLeftButtonDown">
<Border x:Name="ImageBorder" BorderThickness="2" BorderBrush="#FFFF0000" HorizontalAlignment="Left" Width="{Binding ActualHeight, Converter={StaticResource AspectRatioConverter}, Mode=OneWay, RelativeSource={RelativeSource Self}}">
<Image x:Name="MainImg" Margin="0" Source="{Binding PreviewImageSource, Mode=OneWay, FallbackValue={StaticResource DefaultImage}, TargetNullValue={StaticResource DefaultImage}}"/>
Expand Down

0 comments on commit 80794d6

Please sign in to comment.