diff --git a/AddOrChangeAssetPage.xaml b/AddOrChangeAssetPage.xaml
index 254f4a6..6b05c2d 100644
--- a/AddOrChangeAssetPage.xaml
+++ b/AddOrChangeAssetPage.xaml
@@ -19,6 +19,7 @@
+
diff --git a/AddOrChangeAssetPage.xaml.cs b/AddOrChangeAssetPage.xaml.cs
index 147e520..542eea4 100644
--- a/AddOrChangeAssetPage.xaml.cs
+++ b/AddOrChangeAssetPage.xaml.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
+using Windows.Storage.Pickers;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -22,6 +24,8 @@ public sealed partial class AddOrChangeAssetPage : Page
public List> MimeTypes { get; set; }
private bool IsAnUpdate { get; set; }
+ private byte[] UploadedFile { get; set; }
+
private Windows.ApplicationModel.Resources.ResourceLoader Loader;
public AddOrChangeAssetPage()
@@ -37,9 +41,14 @@ public AddOrChangeAssetPage()
new Tuple("video", this.Loader.GetString("Video"))
};
+ this.UploadedFile = null;
+
this.InitializeComponent();
- this.DatePickerEnd.Date = DateTime.Now.AddDays(1);
+ this.DatePickerStart.Date = DateTime.Now;
+ this.TimePickerStart.Time = DatePickerStart.Date.TimeOfDay;
+ this.DatePickerEnd.Date = this.DatePickerStart.Date.AddDays(1);
+ this.TimePickerEnd.Time = this.TimePickerStart.Time;
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
@@ -108,7 +117,10 @@ private async void ButtonSubmit_Click(object sender, RoutedEventArgs e)
{
Asset a = this.AssetToUpdate;
a.Name = this.TextBoxName.Text;
- a.Uri = this.TextBoxUrl.Text;
+ if (this.TextBoxUrl.Text.StartsWith("{"))
+ a.LocalToken = this.TextBoxUrl.Text;
+ else
+ a.Uri = this.TextBoxUrl.Text;
a.StartDate = (this.DatePickerStart.Date.Date + this.TimePickerStart.Time).ToUniversalTime();
a.EndDate = (this.DatePickerEnd.Date.Date + this.TimePickerEnd.Time).ToUniversalTime();
a.Duration = this.TextBoxDuration.Text;
@@ -131,7 +143,7 @@ private async void ButtonSubmit_Click(object sender, RoutedEventArgs e)
{
var devicesSelected = this.GridViewDevices.SelectedItems.ToList();
foreach (var device in devicesSelected)
- await (device as Device).CreateAsset(a);
+ await (device as Device).CreateAssetAsync(a);
}
else
{
@@ -172,5 +184,23 @@ private void DatePickerStart_DateChanged(object sender, DatePickerValueChangedEv
{
this.DatePickerEnd.Date = this.DatePickerStart.Date.AddDays(1);
}
+
+ private async void ButtonFile_Click(object sender, RoutedEventArgs e)
+ {
+ var picker = new FileOpenPicker();
+ picker.ViewMode = PickerViewMode.Thumbnail;
+ picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
+ picker.FileTypeFilter.Add(".jpg");
+ picker.FileTypeFilter.Add(".jpeg");
+ picker.FileTypeFilter.Add(".png");
+ picker.FileTypeFilter.Add(".mp4");
+ picker.FileTypeFilter.Add(".avi");
+ picker.FileTypeFilter.Add(".mkv");
+
+ Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
+ if (file != null)
+ // Application now has read/write access to the picked file
+ this.TextBoxUrl.Text = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
+ }
}
}
diff --git a/Asset.cs b/Asset.cs
index c4cde81..f4881e3 100644
--- a/Asset.cs
+++ b/Asset.cs
@@ -38,6 +38,9 @@ public bool IsEnabledSwitch
}
}
+ [Newtonsoft.Json.JsonIgnore]
+ public string LocalToken { get; set; }
+
[Newtonsoft.Json.JsonProperty(PropertyName = "nocache")]
public Int32 NoCache { get; set; }
diff --git a/Device.cs b/Device.cs
index 217b859..28b1378 100644
--- a/Device.cs
+++ b/Device.cs
@@ -8,6 +8,8 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
+using Windows.Storage;
+using Windows.Storage.AccessCache;
namespace ScreenlyManager
{
@@ -244,8 +246,18 @@ public async Task UpdateOrderAssetsAsync(string newOrder)
///
/// New asset to create on Raspberry
///
- public async Task CreateAsset(Asset a)
+ public async Task CreateAssetAsync(Asset a)
{
+ if (a.LocalToken != null)
+ {
+ var localFile = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(a.LocalToken);
+ Stream stream = await localFile.OpenStreamForReadAsync();
+ byte[] result = new byte[(int)stream.Length];
+ await stream.ReadAsync(result, 0, (int)stream.Length);
+ a.Uri = await this.PostFileAssetAsync(result, localFile.Name, localFile.ContentType);
+ a.Name += $" - {localFile.Name}";
+ }
+
Asset returnedAsset = new Asset();
JsonSerializerSettings settings = new JsonSerializerSettings();
IsoDateTimeConverter dateConverter = new IsoDateTimeConverter
@@ -325,6 +337,40 @@ public async Task GetAssetAsync(string assetId)
return null;
}
+ ///
+ /// Send file to create asset (image or video)
+ ///
+ /// Byte array of the file
+ /// File's name
+ /// File's content type
+ ///
+ public async Task PostFileAssetAsync(byte[] itemToSend, string fileName, string contentType)
+ {
+ string resultJson = string.Empty;
+ string parameters = $"/api/{this.ApiVersion}file_asset";
+
+ try
+ {
+ HttpClient request = new HttpClient();
+ var content = new MultipartFormDataContent();
+ var itemContent = new ByteArrayContent(itemToSend);
+ itemContent.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType);
+ content.Add(itemContent, "file_upload", fileName);
+ using (HttpResponseMessage response = await request.PostAsync(this.HttpLink + parameters, content))
+ {
+ resultJson = await response.Content.ReadAsStringAsync();
+ }
+
+ if (!resultJson.Equals(string.Empty))
+ return JsonConvert.DeserializeObject(resultJson);
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"[Device = {this.Name}; IP = {this.IpAddress}] Error while sending file.", ex);
+ }
+ return null;
+ }
+
#endregion
}
}
diff --git a/Strings/de-DE/Resources.resw b/Strings/de-DE/Resources.resw
index 00c66ed..7b8fbc4 100644
--- a/Strings/de-DE/Resources.resw
+++ b/Strings/de-DE/Resources.resw
@@ -401,4 +401,8 @@
Asset kopieren "{0}"
AddOrChangeAssetPage.xaml
+
+ Kies een bestand
+ AddOrChangeAssetPage.xaml
+
\ No newline at end of file
diff --git a/Strings/en-US/Resources.resw b/Strings/en-US/Resources.resw
index 911c1c2..0f8e45c 100644
--- a/Strings/en-US/Resources.resw
+++ b/Strings/en-US/Resources.resw
@@ -186,7 +186,7 @@
AddOrChangeAssetPage.xaml
- e.g. https://www.screenly.io/
+ e.g. https://www.screenly.io/ or choose a file below
AddOrChangeAssetPage.xaml
@@ -401,4 +401,8 @@
Duplicate asset "{0}"
AddOrChangeAssetPage.xaml
+
+ Choose a file
+ AddOrChangeAssetPage.xaml
+
\ No newline at end of file
diff --git a/Strings/fr-FR/Resources.resw b/Strings/fr-FR/Resources.resw
index 6b5b033..d2130ec 100644
--- a/Strings/fr-FR/Resources.resw
+++ b/Strings/fr-FR/Resources.resw
@@ -186,7 +186,7 @@
AddOrChangeAssetPage.xaml
- Exemple : https://www.screenly.io/
+ Exemple : https://www.screenly.io/ ou choisir un fichier ci-dessous
AddOrChangeAssetPage.xaml
@@ -401,4 +401,8 @@
Dupliquer l'affichage "{0}"
AddOrChangeAssetPage.xaml
+
+ Choisir un fichier
+ AddOrChangeAssetPage.xaml
+
\ No newline at end of file
diff --git a/Strings/nl-NL/Resources.resw b/Strings/nl-NL/Resources.resw
index 453cfab..40a131a 100644
--- a/Strings/nl-NL/Resources.resw
+++ b/Strings/nl-NL/Resources.resw
@@ -401,4 +401,8 @@
Dubbele asset "{0}"
AddOrChangeAssetPage.xaml
+
+ Wählen Sie eine Datei
+ AddOrChangeAssetPage.xaml
+
\ No newline at end of file