From 05d7d56cd10b8fd48b5b0b6f8f8e4151ed7eda86 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Fri, 17 Aug 2018 13:23:41 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C31243 --- client/AudioRecorder/AudioRecorder.csproj | 3 + .../Configuration/audiorecorder.json | 10 +- .../Configuration/audiorecorder.json1 | 68 ++++ .../Configuration/ConfigurationInfo.cs | 4 +- .../MetadataIDSelector.Designer.cs | 50 +-- client/MetadataSelector/MetadataIDSelector.cs | 23 +- client/NativeOctopusClient/Model/Rundown.cs | 9 +- client/NativeOctopusClient/Model/Story.cs | 27 +- .../NativeOctopusClient/NativeOctopusAPI.cs | 325 ++++++++++-------- .../NativeOctopusIDSelector.Designer.cs | 7 +- .../NativeOctopusIDSelector.cs | 194 ++++------- .../NativeOctopusParameters.cs | 2 +- 12 files changed, 378 insertions(+), 344 deletions(-) create mode 100644 client/AudioRecorder/Configuration/audiorecorder.json1 diff --git a/client/AudioRecorder/AudioRecorder.csproj b/client/AudioRecorder/AudioRecorder.csproj index 08654bc1..aa436763 100644 --- a/client/AudioRecorder/AudioRecorder.csproj +++ b/client/AudioRecorder/AudioRecorder.csproj @@ -180,6 +180,9 @@ ResXFileCodeGenerator Resources.Designer.cs + + Always + Designer PreserveNewest diff --git a/client/AudioRecorder/Configuration/audiorecorder.json b/client/AudioRecorder/Configuration/audiorecorder.json index 8355ad25..8cb6ec83 100644 --- a/client/AudioRecorder/Configuration/audiorecorder.json +++ b/client/AudioRecorder/Configuration/audiorecorder.json @@ -31,21 +31,13 @@ } }, "metadatas": [ - { - "$type": "OctopusMetadata", - "disableStoryCheck": true, - "server": { - "address": "http://10.10.1.27/services/rest/octopus/", - "timeout": 1000 - } - }, { "$type": "NativeOctopusMetadata", "server": { "address": " http://10.10.1.11/api/v1/", "userName": "mam", "password": "fPLnV9N5gc7aC9ICvspjzJkGLnTWxAgEhwGOrXilAiD8+/IXviRlNJA0lrZ3ZX+7WG5EE3ZlaIitAhRGk+QIPGEOF3fEJCBJI2I9NN1e2JGi/my3WwXt0fu7dgbMxVid", - "timeout": 1000 + "timeout": 3000 } }, { diff --git a/client/AudioRecorder/Configuration/audiorecorder.json1 b/client/AudioRecorder/Configuration/audiorecorder.json1 new file mode 100644 index 00000000..c2cc507f --- /dev/null +++ b/client/AudioRecorder/Configuration/audiorecorder.json1 @@ -0,0 +1,68 @@ +{ + "deviceName": "", + "workingDirectory": "file://C:\\temp", + "peekMeterStep": 200, + "octopusTarget": { + "label": "Octopus mappába küldés", + "processor": "FTPTargetProcessor", + "tag": "Betöltés", + "outputFormat": "%ID%", + "subFolderFormat": "%IDROOT%-%TEXT%", + "killDateDays": 7, + "remote": { + "address": "ftp://10.10.1.100/OCTOPUS", + "userName": "mediacube", + "password": "Dn8t4gfHcK98o8hyPgLDhr5SgSji4JCxsfpMJsODikUp3nXgrM0UNCi45lLAK8ZOnmEneO44P9qpJ4QDqhctN6MxZodjJgdZTyoZKmSa+ECzEzLr/wPYNgxVaXrVotEy", + "timeout": 1000 + } + }, + "trafficTarget": { + "label": "Traffic mappába küldés", + "processor": "FTPTargetProcessor", + "tag": "Betöltés", + "outputFormat": "%ID%", + "subFolderFormat": "%IDROOT%-%TEXT%", + "killDateDays": 7, + "remote": { + "address": "ftp://10.10.1.100/PLAYOUT_NLE", + "userName": "mediacube", + "password": "Dn8t4gfHcK98o8hyPgLDhr5SgSji4JCxsfpMJsODikUp3nXgrM0UNCi45lLAK8ZOnmEneO44P9qpJ4QDqhctN6MxZodjJgdZTyoZKmSa+ECzEzLr/wPYNgxVaXrVotEy", + "timeout": 1000 + } + }, + "metadatas": [ + { + "$type": "OctopusMetadata", + "disableStoryCheck": true, + "server": { + "address": "http://10.10.1.27/services/rest/octopus/", + "timeout": 1000 + } + }, + { + "$type": "NativeOctopusMetadata", + "server": { + "address": " http://10.10.1.11/api/v1/", + "userName": "mam", + "password": "fPLnV9N5gc7aC9ICvspjzJkGLnTWxAgEhwGOrXilAiD8+/IXviRlNJA0lrZ3ZX+7WG5EE3ZlaIitAhRGk+QIPGEOF3fEJCBJI2I9NN1e2JGi/my3WwXt0fu7dgbMxVid", + "timeout": 3000 + } + }, + { + "$type": "TrafficMetadata", + "server": { + "address": "Data Source=10.10.1.45;Initial Catalog=PA_Echo;Persist Security Info=True;", + "userName": "MAM", + "password": "7RKZYBzumKjL40SJwuwiFCvX57xuCN8zay6OttUm2wbrgImyYZBHyZTUUYrXX31Ge2Uwew07HYsqh2uzdJeDBDwcVntxaHg3nIpv9Dyq/odVoiC4tUF/K+lgvKWANcrZ", + "timeout": 1000 + } + }, + { + "$type": "MediaCubeMetadata", + "server": { + "address": "http://10.10.1.27/services/rest/jobengine/", + "timeout": 1000 + } + } + ] +} \ No newline at end of file diff --git a/client/MaestroShared/Configuration/ConfigurationInfo.cs b/client/MaestroShared/Configuration/ConfigurationInfo.cs index f0826a55..67bee0e9 100644 --- a/client/MaestroShared/Configuration/ConfigurationInfo.cs +++ b/client/MaestroShared/Configuration/ConfigurationInfo.cs @@ -175,11 +175,11 @@ namespace MaestroShared.Configuration { public class OctopusMetadata : MetadataProvider { public bool DisablePlaceHolderCheck { get; set; } public bool DisableStoryCheck { get; set; } - public string RundownStoryFormat { get; set; } public ProjectSettings ProjectSettings { get; set; } } - public class NativeOctopusMetadata : OctopusMetadata { + public class NativeOctopusMetadata : MetadataProvider { + public ProjectSettings ProjectSettings { get; set; } } public class TrafficMetadata : MetadataProvider { diff --git a/client/MetadataSelector/MetadataIDSelector.Designer.cs b/client/MetadataSelector/MetadataIDSelector.Designer.cs index b69fed4a..dfa74a37 100644 --- a/client/MetadataSelector/MetadataIDSelector.Designer.cs +++ b/client/MetadataSelector/MetadataIDSelector.Designer.cs @@ -27,19 +27,19 @@ this.tabMetadata = new System.Windows.Forms.TabControl(); this.tpOctopus = new System.Windows.Forms.TabPage(); this.octopusIDSelector = new OctopusClient.OctopusIDSelector(); + this.tpNativeOctopus = new System.Windows.Forms.TabPage(); + this.nativeOctopusIDSelector = new NativeOctopusClient.NativeOctopusIDSelector(); this.tpTraffic = new System.Windows.Forms.TabPage(); this.trafficIDSelector = new TrafficClient.TrafficIDSelector(); this.pMetadataDisplay = new System.Windows.Forms.TableLayoutPanel(); this.btnLookupMetadata = new System.Windows.Forms.Button(); this.labelSelectedMetadata = new System.Windows.Forms.Label(); this.textSelectedMetadata = new System.Windows.Forms.TextBox(); - this.tpNativeOctopus = new System.Windows.Forms.TabPage(); - this.nativeOctopusIDSelector = new NativeOctopusClient.NativeOctopusIDSelector(); this.tabMetadata.SuspendLayout(); this.tpOctopus.SuspendLayout(); + this.tpNativeOctopus.SuspendLayout(); this.tpTraffic.SuspendLayout(); this.pMetadataDisplay.SuspendLayout(); - this.tpNativeOctopus.SuspendLayout(); this.SuspendLayout(); // // tabMetadata @@ -76,6 +76,27 @@ this.octopusIDSelector.Size = new System.Drawing.Size(359, 422); this.octopusIDSelector.TabIndex = 0; // + // tpNativeOctopus + // + this.tpNativeOctopus.BackColor = System.Drawing.Color.Transparent; + this.tpNativeOctopus.Controls.Add(this.nativeOctopusIDSelector); + this.tpNativeOctopus.Location = new System.Drawing.Point(4, 24); + this.tpNativeOctopus.Name = "tpNativeOctopus"; + this.tpNativeOctopus.Padding = new System.Windows.Forms.Padding(3); + this.tpNativeOctopus.Size = new System.Drawing.Size(365, 428); + this.tpNativeOctopus.TabIndex = 2; + this.tpNativeOctopus.Text = "Octopus"; + // + // nativeOctopusIDSelector + // + this.nativeOctopusIDSelector.BackColor = System.Drawing.Color.Transparent; + this.nativeOctopusIDSelector.Dock = System.Windows.Forms.DockStyle.Fill; + this.nativeOctopusIDSelector.IDChangedEvent = null; + this.nativeOctopusIDSelector.Location = new System.Drawing.Point(3, 3); + this.nativeOctopusIDSelector.Name = "nativeOctopusIDSelector"; + this.nativeOctopusIDSelector.Size = new System.Drawing.Size(359, 422); + this.nativeOctopusIDSelector.TabIndex = 0; + // // tpTraffic // this.tpTraffic.BackColor = System.Drawing.Color.Transparent; @@ -159,27 +180,6 @@ this.textSelectedMetadata.TextChanged += new System.EventHandler(this.OnSelectedMetadataIDChanged); this.textSelectedMetadata.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnSelectedMetadataIDKeyDown); // - // tpNativeOctopus - // - this.tpNativeOctopus.Controls.Add(this.nativeOctopusIDSelector); - this.tpNativeOctopus.Location = new System.Drawing.Point(4, 24); - this.tpNativeOctopus.Name = "tpNativeOctopus"; - this.tpNativeOctopus.Padding = new System.Windows.Forms.Padding(3); - this.tpNativeOctopus.Size = new System.Drawing.Size(365, 428); - this.tpNativeOctopus.TabIndex = 2; - this.tpNativeOctopus.Text = "Octopus"; - this.tpNativeOctopus.UseVisualStyleBackColor = true; - // - // nativeOctopusIDSelector - // - this.nativeOctopusIDSelector.BackColor = System.Drawing.Color.Transparent; - this.nativeOctopusIDSelector.Dock = System.Windows.Forms.DockStyle.Fill; - this.nativeOctopusIDSelector.IDChangedEvent = null; - this.nativeOctopusIDSelector.Location = new System.Drawing.Point(3, 3); - this.nativeOctopusIDSelector.Name = "nativeOctopusIDSelector"; - this.nativeOctopusIDSelector.Size = new System.Drawing.Size(359, 422); - this.nativeOctopusIDSelector.TabIndex = 0; - // // MetadataIDSelector // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -191,11 +191,11 @@ this.Size = new System.Drawing.Size(373, 513); this.tabMetadata.ResumeLayout(false); this.tpOctopus.ResumeLayout(false); + this.tpNativeOctopus.ResumeLayout(false); this.tpTraffic.ResumeLayout(false); this.tpTraffic.PerformLayout(); this.pMetadataDisplay.ResumeLayout(false); this.pMetadataDisplay.PerformLayout(); - this.tpNativeOctopus.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); diff --git a/client/MetadataSelector/MetadataIDSelector.cs b/client/MetadataSelector/MetadataIDSelector.cs index 0f6e5a7f..a576628b 100644 --- a/client/MetadataSelector/MetadataIDSelector.cs +++ b/client/MetadataSelector/MetadataIDSelector.cs @@ -124,36 +124,45 @@ namespace MaestroShared.Controls { config = MetadataProvider.Get(Providers); if (config == null) return; - tabMetadata.SelectedIndex = tabMetadata.TabCount > 1 ? 1 : 0; + tabMetadata.SelectedTab = tpTraffic; trafficIDSelector.LookupByMaterialID(id); break; case MetadataType.TrafficPromo: config = MetadataProvider.Get(Providers); if (config == null) return; - tabMetadata.SelectedIndex = tabMetadata.TabCount > 1 ? 1 : 0; + tabMetadata.SelectedTab = tpTraffic; trafficIDSelector.LookupByPromoID(id); break; case MetadataType.TrafficAD: config = MetadataProvider.Get(Providers); if (config == null) return; - tabMetadata.SelectedIndex = tabMetadata.TabCount > 1 ? 1 : 0; + tabMetadata.SelectedTab = tpTraffic; trafficIDSelector.LookupByADID(id); break; case MetadataType.OctopusPlaceHolder: config = MetadataProvider.Get(Providers); if (config == null) return; - tabMetadata.SelectedIndex = 0; + tabMetadata.SelectedTab = tpOctopus; octopusIDSelector.LookupByPlaceHolder(id); break; case MetadataType.OctopusStory: config = MetadataProvider.Get(Providers); - if (config == null) + if (config != null) { + tabMetadata.SelectedTab = tpOctopus; + octopusIDSelector.LookupByStory(id); + return; + } + + config = MetadataProvider.Get(Providers); + if (config != null) { + tabMetadata.SelectedTab = tpNativeOctopus; + nativeOctopusIDSelector.LookupByStory(id); return; - tabMetadata.SelectedIndex = 0; - octopusIDSelector.LookupByStory(id); + } + break; } } diff --git a/client/NativeOctopusClient/Model/Rundown.cs b/client/NativeOctopusClient/Model/Rundown.cs index c1954dbc..4951bbae 100644 --- a/client/NativeOctopusClient/Model/Rundown.cs +++ b/client/NativeOctopusClient/Model/Rundown.cs @@ -1,6 +1,5 @@ using Newtonsoft.Json.Linq; using System; -using System.Globalization; namespace NativeOctopusClient.Model { public class Rundown { @@ -17,15 +16,17 @@ namespace NativeOctopusClient.Model { public static Rundown Create(JToken d) { String scheduledStart = d["scheduledStart"]?.ToString(); - Rundown result = new Rundown { + Rundown result = null; + result = new Rundown { ID = d["id"]?.ToString(), Name = d["name"]?.ToString() ?? "unnamed", - Start = DateTime.Parse(scheduledStart.Length > 0 ? scheduledStart : DateTime.MinValue.ToString()), + Start = DateTime.Parse(scheduledStart != null && scheduledStart.Length > 0 ? scheduledStart : DateTime.MinValue.ToString()), }; if (result.Start == null) result.FormattedStart = "?"; else - result.FormattedStart = result.Start.ToString("HH:mm:ss", new CultureInfo("hu-HU")); + result.FormattedStart = result.Start.ToString("HH:mm:ss"); + //result.FormattedStart = result.Start.ToString("HH:mm:ss", new CultureInfo("hu-HU")); return result; } } diff --git a/client/NativeOctopusClient/Model/Story.cs b/client/NativeOctopusClient/Model/Story.cs index d45d04a2..006d0f87 100644 --- a/client/NativeOctopusClient/Model/Story.cs +++ b/client/NativeOctopusClient/Model/Story.cs @@ -13,8 +13,7 @@ namespace NativeOctopusClient.Model { public string Format { get; set; } public int? Position { get; set; } public MosObject[] MosObjects { get; set; } - public StoryFolder[] StoryFolders { get; set; } - public Rundown[] Rundowns { get; set; } + public DateTime ScheduleFrom { get; set; } public override String ToString() { string displayName = Name?.ToString() ?? NativeOctopusAPI.UNNAMED; @@ -28,12 +27,12 @@ namespace NativeOctopusClient.Model { return null; mosObjects.ToList().ForEach(t => { - var mosObject = MosObject.Create(t); - if (mosObject != null) { - if (result == null) - result = new List(); - result.Add(mosObject); - } + var mosObject = MosObject.Create(t); + if (mosObject != null) { + if (result == null) + result = new List(); + result.Add(mosObject); + } }); return result; } @@ -48,17 +47,23 @@ namespace NativeOctopusClient.Model { public static Story Create(JToken slug) { Story result = null; var story = JExtensions.ParseObject(slug, "story"); + if (story == null) + story = slug as JObject; if (story != null) { + String scheduleFrom = story["scheduleFrom"]?.ToString(); result = new Story { ID = story["id"]?.ToString(), Name = story["name"]?.ToString() ?? "unnamed", Format = story["format"]?.ToString(), Position = slug["position"]?.Value(), - ParentStoryID = GetParentStoryID(story), - MosObjects = GetMosObjects(story)?.ToArray() + //ParentStoryID = GetParentStoryID(story), + //MosObjects = GetMosObjects(story)?.ToArray(), + ScheduleFrom = DateTime.Parse(scheduleFrom != null && scheduleFrom.Length > 0 ? scheduleFrom : DateTime.MinValue.ToString()), }; - result.ParentStoryID = result.ParentStoryID ?? result.ID; } + //result.ParentStoryID = result.ParentStoryID ?? result.ID; + result.ParentStoryID = result.ID; + return result; } diff --git a/client/NativeOctopusClient/NativeOctopusAPI.cs b/client/NativeOctopusClient/NativeOctopusAPI.cs index 2c57c480..dd5a22b5 100644 --- a/client/NativeOctopusClient/NativeOctopusAPI.cs +++ b/client/NativeOctopusClient/NativeOctopusAPI.cs @@ -6,8 +6,8 @@ using RestSharp; using RestSharp.Authenticators; using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; +using System.Net; namespace NativeOctopusClient { @@ -19,7 +19,6 @@ namespace NativeOctopusClient { private string user; private string pwd; private IMessageBus messageBus; - private IEnumerable rundowns; public NativeOctopusAPI(string address, string user, string pwd, int timeout, IMessageBus messageBus) { this.user = user; @@ -31,6 +30,135 @@ namespace NativeOctopusClient { this.messageBus = messageBus; } + private List GetRundownStoryIDs(String id) { + List result = null; + try { + var request = new RestRequest("Rundown/{id}", Method.GET); + request.AddParameter(ID, id, ParameterType.UrlSegment); + request.AddParameter("fields", "id,slugs,Slug.storyId", ParameterType.QueryString); + request.AddParameter("Octopus-Device-Name", user, ParameterType.HttpHeader); + request.AddParameter("Octopus-Device-Id", pwd, ParameterType.HttpHeader); + var response = client.Execute(request); + if (!CheckResponse(response)) + return null; + var resultObject = JExtensions.ParseObject(JExtensions.ParseObject(response.Content), "result"); + if (resultObject == null) + return null; + var resultList = JExtensions.ParseArray(resultObject, "slugs"); + if (resultList == null) + return null; + + resultList.Children().ToList().ForEach(d => { + var storyId = d["storyId"]?.ToString(); + if (storyId != null) { + if (result == null) + result = new List(); + result.Add(storyId); + } + }); + } catch (Exception e) { + OnError(e); + } + return result; + } + + public Rundown GetRundownByStoryID(String id) { + Rundown result = null; + try { + var request = new RestRequest("Rundown", Method.GET); + request.AddParameter("fields", "id,name,scheduledStart", ParameterType.QueryString); + request.AddParameter("Octopus-Device-Name", user, ParameterType.HttpHeader); + request.AddParameter("Octopus-Device-Id", pwd, ParameterType.HttpHeader); + var response = client.Execute(request); + if (!CheckResponse(response)) + return null; + var resultList = JExtensions.ParseArray(JExtensions.ParseObject(response.Content), "result"); + if (resultList == null) + return null; + foreach (JObject d in resultList) { + var rundownId = d["id"]?.ToString(); + if (rundownId == null) + continue; + //logger.Debug($"Checking rundown {rundownId}"); + List ids = GetRundownStoryIDs(rundownId); + if (ids == null || ids.Count == 0) + continue; + if (ids.Contains(id)) { + result = Rundown.Create(d); + break; + } + } + } catch (Exception e) { + OnError(e); + } + return result; + } + + private List GetStoryFolderStoryIDs(String id) { + List result = null; + try { + var request = new RestRequest("StoryFolder/{id}", Method.GET); + request.AddParameter(ID, id, ParameterType.UrlSegment); + request.AddParameter("fields", "id,stories,Story.id", ParameterType.QueryString); + request.AddParameter("Octopus-Device-Name", user, ParameterType.HttpHeader); + request.AddParameter("Octopus-Device-Id", pwd, ParameterType.HttpHeader); + var response = client.Execute(request); + if (!CheckResponse(response)) + return null; + var resultObject = JExtensions.ParseObject(JExtensions.ParseObject(response.Content), "result"); + if (resultObject == null) + return null; + var resultList = JExtensions.ParseArray(resultObject, "stories"); + if (resultList == null) + return null; + + resultList.Children().ToList().ForEach(d => { + var storyId = d["id"]?.ToString(); + if (storyId != null) { + if (result == null) + result = new List(); + result.Add(storyId); + } + }); + } catch (Exception e) { + OnError(e); + } + return result; + } + + public StoryFolder GetStoryFolderByStoryID(String id) { + StoryFolder result = null; + try { + var request = new RestRequest("StoryFolder", Method.GET); + request.AddParameter("fields", "id,name", ParameterType.QueryString); + request.AddParameter("Octopus-Device-Name", user, ParameterType.HttpHeader); + request.AddParameter("Octopus-Device-Id", pwd, ParameterType.HttpHeader); + var response = client.Execute(request); + if (!CheckResponse(response)) + return null; + var resultList = JExtensions.ParseArray(JExtensions.ParseObject(response.Content), "result"); + if (resultList == null) + return null; + foreach (JObject d in resultList) { + var storyFolderId = d["id"]?.ToString(); + if (storyFolderId == null) + continue; + + logger.Debug($"Checking story folder {storyFolderId}"); + List ids = GetStoryFolderStoryIDs(storyFolderId); + if (ids == null || ids.Count == 0) + continue; + if (ids.Contains(id)) { + result = StoryFolder.Create(d); + break; + } + } + } catch (Exception e) { + OnError(e); + } + return result; + } + public List GetRundowns(DateTime scheduledDate) { List result = null; try { @@ -44,11 +172,10 @@ namespace NativeOctopusClient { var resultList = JExtensions.ParseArray(JExtensions.ParseObject(response.Content), "result"); if (resultList == null) return null; - rundowns = resultList.Children().Select(d => Rundown.Create(d)).ToList(); + List rundowns = resultList.Children().Select(d => Rundown.Create(d)).ToList(); DateTime end = scheduledDate + new TimeSpan(1, 0, 0, 0); result = rundowns.Where(r => r.Start >= scheduledDate && r.Start < end).OrderBy(r => r.Start).ToList(); - } - catch (Exception e) { + } catch (Exception e) { OnError(e); } return result; @@ -56,10 +183,11 @@ namespace NativeOctopusClient { public List GetRundownStories(string id) { List result = null; + logger.Info($"Selected rundown ID is {id}"); try { var request = new RestRequest("Rundown/{id}", Method.GET); request.AddParameter(ID, id, ParameterType.UrlSegment); - request.AddParameter("fields", "slugs,Slug.story,Slug.position,Story.id,Story.name,Story.format,Story.mosObjects,Story.customColumns,CustomColumn.label,CustomColumn.value", ParameterType.QueryString); + request.AddParameter("fields", "slugs,Slug.story,Slug.position,Story.id,Story.name,Story.format,Story.scheduleFrom,Story.customColumns,CustomColumn.label,CustomColumn.value", ParameterType.QueryString); request.AddParameter("Octopus-Device-Name", user, ParameterType.HttpHeader); request.AddParameter("Octopus-Device-Id", pwd, ParameterType.HttpHeader); var response = client.Execute(request); @@ -79,7 +207,7 @@ namespace NativeOctopusClient { } }); if (result != null) - result = result.OrderBy(s=>s.Position).ToList(); + result = result.OrderBy(s => s.Position).ToList(); } catch (Exception e) { OnError(e); } @@ -106,57 +234,52 @@ namespace NativeOctopusClient { return result; } - public List GetStoryFolderStories(string id) { - List result = null; + private Story GetStory(string id) { + Story result = null; try { - var request = new RestRequest("storyFolderStories/{id}", Method.GET); + var request = new RestRequest("Story/{id}", Method.GET); request.AddParameter(ID, id, ParameterType.UrlSegment); + request.AddParameter("fields", "id,name,format,scheduleFrom,customColumns,CustomColumn.label,CustomColumn.value", ParameterType.QueryString); + request.AddParameter("Octopus-Device-Name", user, ParameterType.HttpHeader); + request.AddParameter("Octopus-Device-Id", pwd, ParameterType.HttpHeader); var response = client.Execute(request); if (!CheckResponse(response)) return null; - JArray resultObject = JArray.Parse(response.Content); - result = resultObject.Children().Select(d => { - Story r = ToStoryFolderStory(d, id); - //logger.Debug($"{r}"); - return r; - }).OrderBy(r => { - return r.ID; - }).ToList(); + var resultObject = JExtensions.ParseObject(JExtensions.ParseObject(response.Content), "result"); + result = Story.Create(resultObject); } catch (Exception e) { OnError(e); } return result; } - public IEnumerable GetRundownsByParentStoryID(String id) { - IEnumerable result = null; + public List GetStoryFolderStories(string id) { + List result = null; try { - var request = new RestRequest("rundownsByParentStoryID/{id}", Method.GET); + var request = new RestRequest("StoryFolder/{id}", Method.GET); request.AddParameter(ID, id, ParameterType.UrlSegment); + request.AddParameter("fields", "stories,Story.id,Story.name,Story.format,Story.scheduleFrom,Story.customColumns,CustomColumn.label,CustomColumn.value", ParameterType.QueryString); + request.AddParameter("Octopus-Device-Name", user, ParameterType.HttpHeader); + request.AddParameter("Octopus-Device-Id", pwd, ParameterType.HttpHeader); var response = client.Execute(request); if (!CheckResponse(response)) return null; - JArray resultObject = JArray.Parse(response.Content); - //result = resultObject.Children().Select(d => ToRundown(d)); - } - catch (Exception e) { - OnError(e); - } - return result; - } - - public IEnumerable GetRundownsByPlaceHolderId(string id) { - IEnumerable result = null; - try { - var request = new RestRequest("rundownsByPlaceHolderID/{id}", Method.GET); - request.AddParameter(ID, id, ParameterType.UrlSegment); - var response = client.Execute(request); - if (!CheckResponse(response)) + var resultObject = JExtensions.ParseObject(JExtensions.ParseObject(response.Content), "result"); + var resultList = JExtensions.ParseArray(resultObject, "stories"); + if (resultList == null) return null; - JArray resultObject = JArray.Parse(response.Content); - //result = resultObject.Children().Select(d => ToRundown(d)); - } - catch (Exception e) { + + resultList.Children().ToList().ForEach(d => { + Story s = Story.Create(d); + if (s != null) { + if (result == null) + result = new List(); + result.Add(s); + } + }); + if (result != null) + result = result.OrderBy(s => s.ScheduleFrom).ToList(); + } catch (Exception e) { OnError(e); } return result; @@ -171,15 +294,14 @@ namespace NativeOctopusClient { if (!CheckResponse(response)) return null; JArray resultObject = JArray.Parse(response.Content); - result = resultObject.Children().Select(d => { - Story r = ToRundownStory(d, id); - //logger.Debug($"{r}"); - return r; - }).OrderBy(r => { - return r.ID; - }); - } - catch (Exception e) { + //result = resultObject.Children().Select(d => { + // //Story r = ToRundownStory(d, id); + // //logger.Debug($"{r}"); + // return null; + //}).OrderBy(r => { + // return r.ID; + //}); + } catch (Exception e) { OnError(e); } return result; @@ -199,8 +321,7 @@ namespace NativeOctopusClient { //logger.Debug($"{r}"); return r; }); - } - catch (Exception e) { + } catch (Exception e) { OnError(e); } return result; @@ -222,8 +343,7 @@ namespace NativeOctopusClient { }).OrderBy(r => { return r.ID; }); - } - catch (Exception e) { + } catch (Exception e) { OnError(e); } return result; @@ -243,46 +363,19 @@ namespace NativeOctopusClient { //logger.Debug($"{r}"); return r; }); - } - catch (Exception e) { - OnError(e); - } - return result; - } - - public IEnumerable GetStoryFoldersByParentStoryID(String id) { - IEnumerable result = null; - try { - var request = new RestRequest("storyFoldersByParentStoryID/{id}", Method.GET); - request.AddParameter(ID, id, ParameterType.UrlSegment); - var response = client.Execute(request); - if (!CheckResponse(response)) - return null; - JArray resultObject = JArray.Parse(response.Content); - result = resultObject.Children().Select(d => { - StoryFolder r = new StoryFolder { - ID = d[ID].ToString(), - Name = String.IsNullOrEmpty(d["name"].ToString()) ? NativeOctopusAPI.UNNAMED : d["name"].ToString() - }; - - //logger.Debug($"{r}"); - return r; - }); - } - catch (Exception e) { + } catch (Exception e) { OnError(e); } return result; } private bool CheckResponse(IRestResponse response) { + if (response.StatusCode == HttpStatusCode.NotFound || response.ErrorException != null) + throw new Exception(response.ErrorMessage); if (String.IsNullOrEmpty(response.Content)) return false; - //if (response.ContentLength != 0) - // return false; - if (response.ErrorException != null) - throw new Exception(response.ErrorMessage); - else return true; + else + return true; } private void OnError(Exception e) { @@ -291,66 +384,6 @@ namespace NativeOctopusClient { messageBus.Send(new NativeOctopusAPIMessage("Sikertelen OCTOPUS lekérdezés. Rendszerüzenet: " + e.Message)); } - - private IEnumerable GetPartialStoryFolderFromStory(JToken d) { - return d["story_folder"]?.Select(t => ToPartialStoryFolder(t)); - } - - private IEnumerable GetPartialRundownFromStory(JToken d) { - return d["rundown"]?.Select(t => ToPartialRundown(t)); - } - - private IEnumerable GetStoryFolderFromStory(JToken d) { - return d["story_folder"]?.Select(t => StoryFolder.Create(t)); - } - - private IEnumerable GetRundownFromStory(JToken d) { - return d["rundown"]?.Select(t => Rundown.Create(t)); - } - - private StoryFolder ToPartialStoryFolder(JToken d) { - return new StoryFolder() { - ID = d.Value(ID), - StoryPosition = d.Value("position") - }; - } - - private Rundown ToPartialRundown(JToken d) { - return new Rundown() { - ID = d.Value(ID), - StoryPosition = d.Value("position") - }; - } - - private Story ToRundownStory(JToken d, string id) { - Story result = Story.Create(d); - result.Position = result.Rundowns.Where(r => id.Equals(r.ID)).FirstOrDefault()?.StoryPosition; - return result; - } - - private Story ToStoryFolderStory(JToken d, string id) { - Story result = Story.Create(d); - result.Position = result.StoryFolders.Where(r => id.Equals(r.ID)).FirstOrDefault()?.StoryPosition; - return result; - } - - //private Story ToStory(JToken d) { - // Story result = new Story { - // ID = d[ID]?.ToString(), - // ParentStoryID = d["parentStoryId"]?.ToString(), - // Name = d["name"]?.ToString() ?? UNNAMED, - // Format = d["format"]?.ToString(), - // Script = d["script"]?.ToString(), - // ScriptContent = d["script_content"]?.ToString(), - // MosObjects = GetMosObjectsFromStory(d)?.ToArray(), - // StoryFolders = GetStoryFolderFromStory(d)?.ToArray(), - // Rundowns = GetRundownFromStory(d)?.ToArray() - // }; - // return result; - //} - - - } public static class JExtensions { diff --git a/client/NativeOctopusClient/NativeOctopusIDSelector.Designer.cs b/client/NativeOctopusClient/NativeOctopusIDSelector.Designer.cs index 961235ec..54d021eb 100644 --- a/client/NativeOctopusClient/NativeOctopusIDSelector.Designer.cs +++ b/client/NativeOctopusClient/NativeOctopusIDSelector.Designer.cs @@ -34,7 +34,7 @@ namespace NativeOctopusClient { this.rbStoryFolder = new System.Windows.Forms.RadioButton(); this.txtFilter = new System.Windows.Forms.TextBox(); this.noFocusCueButton1 = new MaestroShared.Controls.NoFocusCueButton(); - this.treeOctopus = new CheckableTreeView(); + this.treeOctopus = new MaestroShared.Controls.CheckableTreeView(); this.pSearch.SuspendLayout(); this.pFolderType.SuspendLayout(); this.SuspendLayout(); @@ -171,6 +171,7 @@ namespace NativeOctopusClient { this.treeOctopus.BackColor = System.Drawing.Color.White; this.treeOctopus.BorderStyle = System.Windows.Forms.BorderStyle.None; this.treeOctopus.CheckBoxes = true; + this.treeOctopus.DisableCheckBoxLevels = null; this.treeOctopus.Dock = System.Windows.Forms.DockStyle.Fill; this.treeOctopus.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText; this.treeOctopus.Location = new System.Drawing.Point(0, 77); @@ -182,7 +183,7 @@ namespace NativeOctopusClient { this.treeOctopus.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeOctopus_NodeMouseDoubleClick); this.treeOctopus.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeContent_KeyDown); // - // OctopusIDSelector + // NativeOctopusIDSelector // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -190,7 +191,7 @@ namespace NativeOctopusClient { this.Controls.Add(this.treeOctopus); this.Controls.Add(this.pSeparator); this.Controls.Add(this.pSearch); - this.Name = "OctopusIDSelector"; + this.Name = "NativeOctopusIDSelector"; this.Size = new System.Drawing.Size(300, 400); this.pSearch.ResumeLayout(false); this.pSearch.PerformLayout(); diff --git a/client/NativeOctopusClient/NativeOctopusIDSelector.cs b/client/NativeOctopusClient/NativeOctopusIDSelector.cs index 1e5b688f..a26c8686 100644 --- a/client/NativeOctopusClient/NativeOctopusIDSelector.cs +++ b/client/NativeOctopusClient/NativeOctopusIDSelector.cs @@ -26,7 +26,6 @@ namespace NativeOctopusClient { public NativeOctopusParameters Parameters { set { parameters = value; - treeOctopus.DisableCheckBoxLevels = new[] { parameters.Configuration.DisableStoryCheck, parameters.Configuration.DisablePlaceHolderCheck }; client = new NativeOctopusAPI(value.Configuration.Server.Address.OriginalString, value.Configuration.Server.UserName, value.Configuration.Server.Password, value.Configuration.Server.Timeout, value.MessageBus); rbRundown.Checked = true; RefreshFolders(); @@ -114,17 +113,10 @@ namespace NativeOctopusClient { TreeNode storyNode = treeOctopus.Nodes.Add(parentStoryID, label); storyNode.Tag = story; - if (parameters.Configuration.DisableStoryCheck) - HideCheckBox(treeOctopus, storyNode); - bool selectFirstChild = false; if (lookupStoryId != null && lookupStoryId.Equals(parentStoryID)) { - if (parameters.Configuration.DisableStoryCheck) - selectFirstChild = true; - else { - storyNode.Checked = true; - } + storyNode.Checked = true; } MosObject[] mosObjects = story.MosObjects; @@ -133,17 +125,13 @@ namespace NativeOctopusClient { foreach (MosObject mosObject in mosObjects) { TreeNode placeHolderNode = storyNode.Nodes.Add(mosObject.ObjID, String.Format($"{mosObject.ObjID}")); placeHolderNode.Tag = story; - if (parameters.Configuration.DisablePlaceHolderCheck) - HideCheckBox(treeOctopus, placeHolderNode); - else { - if ((lookupPlaceHolderId != null && lookupPlaceHolderId.Equals(mosObject.ObjID)) || selectFirstChild) { - if (selectFirstChild && selectedNode != null) { - selectFirstChild = false; - MsgBox.Warning("Fokozott flehasználói figyelemre van szükség. Az anyag kiválasztás le van tiltva a konfigurációban, így az első elérhető bejátszó került kiválasztásra."); - continue; - } - placeHolderNode.Checked = true; + if ((lookupPlaceHolderId != null && lookupPlaceHolderId.Equals(mosObject.ObjID)) || selectFirstChild) { + if (selectFirstChild && selectedNode != null) { + selectFirstChild = false; + MsgBox.Warning("Fokozott flehasználói figyelemre van szükség. Az anyag kiválasztás le van tiltva a konfigurációban, így az első elérhető bejátszó került kiválasztásra."); + continue; } + placeHolderNode.Checked = true; } } } @@ -158,23 +146,6 @@ namespace NativeOctopusClient { private void OnTreeAfterCheck(object sender, TreeViewEventArgs e) { //logger.Debug("Handling {0} {1} {2}", e.Node.Name, e.Node.Text, e.Node.Checked); - - if (parameters.Configuration.DisableStoryCheck && e.Node.Level == 0) { - if (e.Node.Checked) { - e.Node.Checked = false; - HideCheckBox(treeOctopus, e.Node); - } - return; - } - - if (parameters.Configuration.DisablePlaceHolderCheck && e.Node.Level == 1) { - if (e.Node.Checked) { - e.Node.Checked = false; - HideCheckBox(treeOctopus, e.Node); - } - return; - } - if (!e.Node.Equals(selectedNode)) { ClearSelection(); selectedNode = e.Node; @@ -205,100 +176,6 @@ namespace NativeOctopusClient { SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); } - public void LookupByStory(string storyId) { - if (String.IsNullOrEmpty(storyId)) - return; - ClearSelection(); - lookupStoryId = null; - lookupPlaceHolderId = null; - var rundown = client.GetRundownsByParentStoryID(storyId)?.FirstOrDefault(); - if (rundown == null) { - var storyFolder = client.GetStoryFoldersByParentStoryID(storyId)?.FirstOrDefault(); - if (storyFolder != null) { - refreshDisabled = true; - bool forceRefresh = rbStoryFolder.Checked; - rbStoryFolder.Checked = true; - refreshDisabled = false; - RefreshFolders(); - List storyFolders = cbFolders.DataSource as List; - if (storyFolders != null) { - var folderToSelect = storyFolders.Where(f => f.ID.Equals(storyFolder.ID)).FirstOrDefault(); - if (folderToSelect != null) { - lookupStoryId = storyId; - cbFolders.SelectedItem = folderToSelect; - } - } - } - } else { - refreshDisabled = true; - dtScheduled.Value = rundown.Start; - rbRundown.Checked = true; - refreshDisabled = false; - RefreshFolders(); - List rundowns = cbFolders.DataSource as List; - if (rundowns != null) { - var rundownToSelect = rundowns.Where(f => f.ID.Equals(rundown.ID)).FirstOrDefault(); - if (rundownToSelect != null) { - lookupStoryId = storyId; - cbFolders.SelectedItem = rundownToSelect; - } - } - } - txtFilter.Text = storyId; - if (selectedNode == null) - MsgBox.Info("Az azonosító jelenleg nem található a rendszerben. Kérem próbálja újra."); - else - treeOctopus.Focus(); - } - - public void LookupByPlaceHolder(string placeHolderId) { - if (String.IsNullOrEmpty(placeHolderId)) - return; - ClearSelection(); - lookupStoryId = null; - lookupPlaceHolderId = null; - var rundown = client.GetRundownsByPlaceHolderId(placeHolderId)?.FirstOrDefault(); - if (rundown == null) { - var storyFolder = client.GetStoryFoldersByPlaceHolderID(placeHolderId)?.FirstOrDefault(); - if (storyFolder != null) { - refreshDisabled = true; - bool forceRefresh = rbStoryFolder.Checked; - rbStoryFolder.Checked = true; - refreshDisabled = false; - RefreshFolders(); - List storyFolders = cbFolders.DataSource as List; - if (storyFolders != null) { - var folderToSelect = storyFolders.Where(f => f.ID.Equals(storyFolder.ID)).FirstOrDefault(); - if (folderToSelect != null) { - lookupPlaceHolderId = placeHolderId; - cbFolders.SelectedItem = folderToSelect; - } - } - } - - } else { - refreshDisabled = true; - dtScheduled.Value = rundown.Start; - rbRundown.Checked = true; - refreshDisabled = false; - RefreshFolders(); - List rundowns = cbFolders.DataSource as List; - if (rundowns != null) { - var rundownToSelect = rundowns.Where(f => f.ID.Equals(rundown.ID)).FirstOrDefault(); - if (rundownToSelect != null) { - lookupPlaceHolderId = placeHolderId; - cbFolders.SelectedItem = rundownToSelect; - } - } - - } - txtFilter.Text = placeHolderId; - if (selectedNode == null) - MsgBox.Info("Az azonosító jelenleg nem található a rendszerben. Kérem próbálja újra."); - else - treeOctopus.Focus(); - } - private void OnTypeCheckChanged(object sender, EventArgs e) { RefreshFolders(); } @@ -351,14 +228,12 @@ namespace NativeOctopusClient { Rundown rundown = cbFolders.SelectedValue as Rundown; if (rundown == null || ZERO.Equals(rundown.ID)) return; - //logger.Info("Selected rundown {0} {1}", rundown.ID, rundown.Name); stories = client.GetRundownStories(rundown.ID); } else { StoryFolder storyFolder = cbFolders.SelectedValue as StoryFolder; if (storyFolder == null || ZERO.Equals(storyFolder.ID)) return; - //logger.Info("Selected StoryFolder {0} {1}", storyFolder.ID, storyFolder.Name); - stories = client.GetStoryFolderStories(storyFolder.ID).OrderBy(s => s.StoryFolders[0].StoryPosition); + stories = client.GetStoryFolderStories(storyFolder.ID); } if (stories == null) @@ -377,12 +252,59 @@ namespace NativeOctopusClient { } private void Lookup() { - if (txtFilter.Text.Contains("_")) - LookupByPlaceHolder(txtFilter.Text); + LookupByStory(txtFilter.Text); + } + + public void LookupByStory(string storyId) { + if (String.IsNullOrEmpty(storyId)) + return; + Cursor = Cursors.WaitCursor; + ClearSelection(); + lookupStoryId = null; + lookupPlaceHolderId = null; + var rundown = client.GetRundownByStoryID(storyId); + if (rundown == null) { + var storyFolder = client.GetStoryFolderByStoryID(storyId); + if (storyFolder != null) { + refreshDisabled = true; + bool forceRefresh = rbStoryFolder.Checked; + rbStoryFolder.Checked = true; + refreshDisabled = false; + RefreshFolders(); + List storyFolders = cbFolders.DataSource as List; + if (storyFolders != null) { + var folderToSelect = storyFolders.Where(f => f.ID.Equals(storyFolder.ID)).FirstOrDefault(); + if (folderToSelect != null) { + lookupStoryId = storyId; + cbFolders.SelectedItem = folderToSelect; + } + } + } + } else { + refreshDisabled = true; + dtScheduled.Value = rundown.Start; + rbRundown.Checked = true; + refreshDisabled = false; + RefreshFolders(); + List rundowns = cbFolders.DataSource as List; + if (rundowns != null) { + var rundownToSelect = rundowns.Where(f => f.ID.Equals(rundown.ID)).FirstOrDefault(); + if (rundownToSelect != null) { + lookupStoryId = storyId; + cbFolders.SelectedItem = rundownToSelect; + } + } + } + txtFilter.Text = storyId; + Cursor = Cursors.Default; + + if (selectedNode == null) + MsgBox.Info("Az azonosító jelenleg nem található a rendszerben. Kérem próbálja újra."); else - LookupByStory(txtFilter.Text); + treeOctopus.Focus(); } + private void treeOctopus_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { } diff --git a/client/NativeOctopusClient/NativeOctopusParameters.cs b/client/NativeOctopusClient/NativeOctopusParameters.cs index ead7d2d4..ac12a47b 100644 --- a/client/NativeOctopusClient/NativeOctopusParameters.cs +++ b/client/NativeOctopusClient/NativeOctopusParameters.cs @@ -3,7 +3,7 @@ using MaestroShared.Configuration; namespace NativeOctopusClient { public class NativeOctopusParameters { - public OctopusMetadata Configuration { get; set; } + public NativeOctopusMetadata Configuration { get; set; } public string UserName { get; set; } public IMessageBus MessageBus { get; set; } } -- 2.54.0