From 22906001bdd1fa5ca1107e166d34ccb1fa900846 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Wed, 4 Oct 2017 21:34:10 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C30530 --- client/Maestro/ArchiveMetadata.cs | 24 +-- client/Maestro/Commons/Win32File.cs | 55 +++++ .../Configuration/ConfigurationInfo.cs | 2 +- client/Maestro/Maestro.csproj | 3 +- client/Maestro/MaestroForm.Designer.cs | 79 +++---- client/Maestro/MaestroForm.Metadata.cs | 1 + client/Maestro/MaestroForm.Target.cs | 32 ++- client/Maestro/MaestroForm.cs | 4 +- client/Maestro/MaestroForm.resx | 12 +- client/Maestro/Metadata/ArchiveMetadata.cs | 12 +- .../Resources/configuration-nexio.json | 4 +- .../Maestro/Resources/configuration-unc.json | 23 +- client/Maestro/StringResources.Designer.cs | 24 +-- client/Maestro/StringResources.resx | 10 +- client/Maestro/Targets/FTPTargetProcessor.cs | 167 ++------------- client/Maestro/Targets/FXPTargetProcessor.cs | 6 +- client/Maestro/Targets/ITargetProcessor.cs | 2 +- client/Maestro/Targets/ProcessStatus.cs | 5 - client/Maestro/Targets/TargetProcessor.cs | 57 ++--- client/Maestro/Targets/UNCTargetProcessor.cs | 200 ++++++++++++++++++ 20 files changed, 422 insertions(+), 300 deletions(-) create mode 100644 client/Maestro/Commons/Win32File.cs delete mode 100644 client/Maestro/Targets/ProcessStatus.cs create mode 100644 client/Maestro/Targets/UNCTargetProcessor.cs diff --git a/client/Maestro/ArchiveMetadata.cs b/client/Maestro/ArchiveMetadata.cs index 694209b9..c21aab2b 100644 --- a/client/Maestro/ArchiveMetadata.cs +++ b/client/Maestro/ArchiveMetadata.cs @@ -16,21 +16,21 @@ namespace Maestro { } private void FillTheTextBoxes() { - textBox_stuffID.Text = model.StuffID; - textBox_stuffTitle.Text = model.StuffTitle; - textBox_stuffDescription.Text = model.StuffDescription; - textBox_mediaID.Text = model.MediaID; - textBox_mediaTitle.Text = model.MediaTitle; - textBox_mediaDescription.Text = model.MediaDescription; + textBox_stuffID.Text = model.itemHouseId; + textBox_stuffTitle.Text = model.itemTitle; + textBox_stuffDescription.Text = model.itemDescription; + textBox_mediaID.Text = model.mediaHouseId; + textBox_mediaTitle.Text = model.mediaTitle; + textBox_mediaDescription.Text = model.mediaDescription; } private void button_Ok_Click_1(object sender, System.EventArgs e) { - model.StuffID = textBox_stuffID.Text; - model.StuffTitle = textBox_stuffTitle.Text; - model.StuffDescription = textBox_stuffDescription.Text; - model.MediaID = textBox_mediaID.Text; - model.MediaTitle = textBox_mediaTitle.Text; - model.MediaDescription = textBox_mediaDescription.Text; + model.itemHouseId = textBox_stuffID.Text; + model.itemTitle = textBox_stuffTitle.Text; + model.itemDescription = textBox_stuffDescription.Text; + model.mediaHouseId = textBox_mediaID.Text; + model.mediaTitle = textBox_mediaTitle.Text; + model.mediaDescription = textBox_mediaDescription.Text; Dispose(); } diff --git a/client/Maestro/Commons/Win32File.cs b/client/Maestro/Commons/Win32File.cs new file mode 100644 index 00000000..dd846a50 --- /dev/null +++ b/client/Maestro/Commons/Win32File.cs @@ -0,0 +1,55 @@ +using System; +using System.Runtime.InteropServices; + +namespace Maestro.Commons { + public enum CopyProgressResult : uint { + PROGRESS_CONTINUE = 0, + PROGRESS_CANCEL = 1, + PROGRESS_STOP = 2, + PROGRESS_QUIET = 3 + } + + public enum CopyProgressCallbackReason : uint { + CALLBACK_CHUNK_FINISHED = 0x00000000, + CALLBACK_STREAM_SWITCH = 0x00000001 + } + + [Flags] + public enum CopyFileFlags : uint { + COPY_FILE_FAIL_IF_EXISTS = 0x00000001, + COPY_FILE_RESTARTABLE = 0x00000002, + COPY_FILE_OPEN_SOURCE_FOR_WRITE = 0x00000004, + COPY_FILE_ALLOW_DECRYPTED_DESTINATION = 0x00000008 + } + + public delegate CopyProgressResult CopyProgressRoutine( + long TotalFileSize, + long TotalBytesTransferred, + long StreamSize, + long StreamBytesTransferred, + uint dwStreamNumber, + CopyProgressCallbackReason dwCallbackReason, + IntPtr hSourceFile, + IntPtr hDestinationFile, + IntPtr lpData); + + public class Win32File { + + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] + [return: MarshalAs(UnmanagedType.Bool)] + static public extern bool CopyFileEx(string lpExistingFileName, string lpNewFileName, + CopyProgressRoutine lpProgressRoutine, IntPtr lpData, ref Int32 pbCancel, + CopyFileFlags dwCopyFlags); + + + int pbCancel; + + private void XCopy(string oldFile, string newFile) { + CopyFileEx(oldFile, newFile, new CopyProgressRoutine(this.CopyProgressHandler), IntPtr.Zero, ref pbCancel, CopyFileFlags.COPY_FILE_RESTARTABLE); + } + + private CopyProgressResult CopyProgressHandler(long total, long transferred, long streamSize, long StreamByteTrans, uint dwStreamNumber, CopyProgressCallbackReason reason, IntPtr hSourceFile, IntPtr hDestinationFile, IntPtr lpData) { + return CopyProgressResult.PROGRESS_CONTINUE; + } + } +} diff --git a/client/Maestro/Configuration/ConfigurationInfo.cs b/client/Maestro/Configuration/ConfigurationInfo.cs index 79e2103e..0b484174 100644 --- a/client/Maestro/Configuration/ConfigurationInfo.cs +++ b/client/Maestro/Configuration/ConfigurationInfo.cs @@ -25,9 +25,9 @@ namespace Maestro.Configuration { public bool StartInTray { get; set; } public bool Active { get; set; } public string Title { get; set; } - public bool IsAdmin { get; set; } public Player Player { get; set; } public Source Source { get; set; } + public bool EnableCustomMetadataId { get; set; } public MetadataProvider[] Metadatas { get; set; } public Target[] Targets { get; set; } } diff --git a/client/Maestro/Maestro.csproj b/client/Maestro/Maestro.csproj index 300d80af..e536122b 100644 --- a/client/Maestro/Maestro.csproj +++ b/client/Maestro/Maestro.csproj @@ -109,6 +109,7 @@ + @@ -157,12 +158,12 @@ + - ArchiveMetadata.cs diff --git a/client/Maestro/MaestroForm.Designer.cs b/client/Maestro/MaestroForm.Designer.cs index c3e88588..cba2bd62 100644 --- a/client/Maestro/MaestroForm.Designer.cs +++ b/client/Maestro/MaestroForm.Designer.cs @@ -66,15 +66,15 @@ namespace Maestro { this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.groupActions = new System.Windows.Forms.GroupBox(); this.dataGridJobs = new System.Windows.Forms.DataGridView(); + this.bindingSourceJobs = new System.Windows.Forms.BindingSource(this.components); + this.metadataInfoBindingSource = new System.Windows.Forms.BindingSource(this.components); this.columnID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.columnStatus = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.columnProgress = new Maestro.Commons.DataGridViewProgressColumn(); this.columnStarted = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.columnFinished = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.columnInput = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.columnOutput = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.columnProgress = new Maestro.Commons.DataGridViewProgressColumn(); - this.columnStatus = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.bindingSourceJobs = new System.Windows.Forms.BindingSource(this.components); - this.metadataInfoBindingSource = new System.Windows.Forms.BindingSource(this.components); this.groupSource.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).BeginInit(); @@ -545,12 +545,12 @@ namespace Maestro { this.dataGridJobs.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridJobs.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.columnID, + this.columnStatus, + this.columnProgress, this.columnStarted, this.columnFinished, this.columnInput, - this.columnOutput, - this.columnProgress, - this.columnStatus}); + this.columnOutput}); this.dataGridJobs.DataSource = this.bindingSourceJobs; dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle8.BackColor = System.Drawing.SystemColors.Window; @@ -581,6 +581,10 @@ namespace Maestro { this.dataGridJobs.TabIndex = 0; this.dataGridJobs.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridJobs_CellEnter); // + // metadataInfoBindingSource + // + this.metadataInfoBindingSource.DataSource = typeof(Maestro.Metadata.MetadataInfo); + // // columnID // this.columnID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; @@ -592,6 +596,31 @@ namespace Maestro { this.columnID.Name = "columnID"; this.columnID.Width = 44; // + // columnStatus + // + this.columnStatus.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; + this.columnStatus.DataPropertyName = "Status"; + dataGridViewCellStyle6.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.columnStatus.DefaultCellStyle = dataGridViewCellStyle6; + this.columnStatus.Frozen = true; + this.columnStatus.HeaderText = "Status"; + this.columnStatus.Name = "columnStatus"; + this.columnStatus.Width = 66; + // + // columnProgress + // + this.columnProgress.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; + this.columnProgress.DataPropertyName = "Progress"; + dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle7.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + dataGridViewCellStyle7.NullValue = null; + this.columnProgress.DefaultCellStyle = dataGridViewCellStyle7; + this.columnProgress.HeaderText = "Progress"; + this.columnProgress.Name = "columnProgress"; + this.columnProgress.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.columnProgress.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + this.columnProgress.Width = 200; + // // columnStarted // this.columnStarted.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; @@ -624,34 +653,6 @@ namespace Maestro { this.columnOutput.Name = "columnOutput"; this.columnOutput.Width = 68; // - // columnProgress - // - this.columnProgress.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; - this.columnProgress.DataPropertyName = "Progress"; - dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle6.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - dataGridViewCellStyle6.NullValue = null; - this.columnProgress.DefaultCellStyle = dataGridViewCellStyle6; - this.columnProgress.HeaderText = "Progress"; - this.columnProgress.Name = "columnProgress"; - this.columnProgress.Resizable = System.Windows.Forms.DataGridViewTriState.True; - this.columnProgress.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; - this.columnProgress.Width = 200; - // - // columnStatus - // - this.columnStatus.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; - this.columnStatus.DataPropertyName = "Status"; - dataGridViewCellStyle7.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.columnStatus.DefaultCellStyle = dataGridViewCellStyle7; - this.columnStatus.HeaderText = "Status"; - this.columnStatus.Name = "columnStatus"; - this.columnStatus.Width = 66; - // - // metadataInfoBindingSource - // - this.metadataInfoBindingSource.DataSource = typeof(Maestro.Metadata.MetadataInfo); - // // MaestroForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -734,15 +735,15 @@ namespace Maestro { private System.Windows.Forms.Label label1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private TrafficClient.TrafficIDSelector trafficIDSelector; + private System.Windows.Forms.Button buttonMetadata; + private System.Windows.Forms.TextBox txtSorceFilter; private System.Windows.Forms.DataGridViewTextBoxColumn columnID; + private System.Windows.Forms.DataGridViewTextBoxColumn columnStatus; + private Commons.DataGridViewProgressColumn columnProgress; private System.Windows.Forms.DataGridViewTextBoxColumn columnStarted; private System.Windows.Forms.DataGridViewTextBoxColumn columnFinished; private System.Windows.Forms.DataGridViewTextBoxColumn columnInput; private System.Windows.Forms.DataGridViewTextBoxColumn columnOutput; - private Commons.DataGridViewProgressColumn columnProgress; - private System.Windows.Forms.DataGridViewTextBoxColumn columnStatus; - private System.Windows.Forms.Button buttonMetadata; - private System.Windows.Forms.TextBox txtSorceFilter; } } diff --git a/client/Maestro/MaestroForm.Metadata.cs b/client/Maestro/MaestroForm.Metadata.cs index b42fc3e3..88cba312 100644 --- a/client/Maestro/MaestroForm.Metadata.cs +++ b/client/Maestro/MaestroForm.Metadata.cs @@ -31,6 +31,7 @@ namespace Maestro { InitializeOctopusSelector(); InitializeTrafficSelector(); InitializeMediaCubeApi(); + textSelectedMetadata.ReadOnly = !Configuration.EnableCustomMetadataId; } private void InitializeTrafficSelector() { diff --git a/client/Maestro/MaestroForm.Target.cs b/client/Maestro/MaestroForm.Target.cs index cfb0243e..17a16d91 100644 --- a/client/Maestro/MaestroForm.Target.cs +++ b/client/Maestro/MaestroForm.Target.cs @@ -23,8 +23,6 @@ namespace Maestro { CreateTarget(target); } - textSelectedSource.ReadOnly = !Configuration.IsAdmin; - textSelectedMetadata.ReadOnly = !Configuration.IsAdmin; ApplyProcessorButtonsLogic(); segmentConverter = new SegmentConverter(); } @@ -45,7 +43,7 @@ namespace Maestro { string typeName = string.Format("{0}.{1}", typeof(ITargetProcessor).Namespace, target.Processor); Type type = Type.GetType(typeName); ISourceItem selectedFile = GetSourceItemFromBindingSource(fileName);//bindingSource.Current as ISourceItem; - string id = selectedMetadata.ID; + string id = selectedMetadata == null ? textSelectedMetadata.Text : selectedMetadata.ID; object[] parameters = new object[] { this, Configuration.Source, target, selectedFile.Name, id, segments, mediaCubeApi, model }; ITargetProcessor processor = (ITargetProcessor)Activator.CreateInstance(type, parameters); processors.Add(processor); @@ -141,12 +139,12 @@ namespace Maestro { TrafficAPI api = trafficIDSelector.trafficAPI; List result = api.SearchArchiveMetadata(id); ; ArchiveMatadataWrapper actualResult = result[0]; - model.StuffID = actualResult.ProgID; - model.StuffTitle = actualResult.ProgTitle; - model.StuffDescription = actualResult.ProgDescription; - model.MediaID = actualResult.EpisodeID; - model.MediaTitle = !String.IsNullOrEmpty(actualResult.EpisodeTitle) ? actualResult.EpisodeTitle : actualResult.ProgTitle; - model.MediaDescription = actualResult.EpisodeDescription; + model.itemHouseId = actualResult.ProgID; + model.itemTitle = actualResult.ProgTitle; + model.itemDescription = actualResult.ProgDescription; + model.mediaHouseId = actualResult.EpisodeID; + model.mediaTitle = !String.IsNullOrEmpty(actualResult.EpisodeTitle) ? actualResult.EpisodeTitle : actualResult.ProgTitle; + model.mediaDescription = actualResult.EpisodeDescription; } private void FillTheModelFromOctopus(ArchiveMetadataModel model) { @@ -172,21 +170,21 @@ namespace Maestro { return; List storyFolders = storyFoldersEnum.ToList(); StoryFolder folder = storyFolders[0]; - model.StuffID = folder.ID; - model.StuffTitle = folder.Name; + model.itemHouseId = folder.ID; + model.itemTitle = folder.Name; } else if (story.Rundowns != null) { IEnumerable rundownsEnum = api.GetRundownsByStoryID(story.ID); if (rundownsEnum == null) return; List rundowns = rundownsEnum.ToList(); Rundown rundown = rundowns[0]; - model.StuffID = rundown.ID; - model.StuffTitle = rundown.Name; - model.StuffDescription = rundown.Start; + model.itemHouseId = rundown.ID; + model.itemTitle = rundown.Name; + model.itemDescription = rundown.Start; } - model.MediaID = story.ID; - model.MediaTitle = story.Name; - model.MediaDescription = story.Script; + model.mediaHouseId = story.ID; + model.mediaTitle = story.Name; + model.mediaDescription = story.Script; } private void IsSelectedFileAnID() { diff --git a/client/Maestro/MaestroForm.cs b/client/Maestro/MaestroForm.cs index 8ccfa29f..a3c13d1c 100644 --- a/client/Maestro/MaestroForm.cs +++ b/client/Maestro/MaestroForm.cs @@ -58,8 +58,8 @@ namespace Maestro { groupActions.Text = StringResources.AKCIOK; columnStarted.HeaderText = StringResources.KEZDES; columnFinished.HeaderText = StringResources.BEFEJEZES; - columnInput.HeaderText = StringResources.BEMENET; - columnOutput.HeaderText = StringResources.KIMENET; + columnInput.HeaderText = StringResources.FORRAS; + columnOutput.HeaderText = StringResources.CEL; columnProgress.HeaderText = StringResources.ALLAPOT; columnStatus.HeaderText = StringResources.STATUSZ; ctxiDefineSegments.Text = StringResources.SZEGMENS_LETREHOZASA; diff --git a/client/Maestro/MaestroForm.resx b/client/Maestro/MaestroForm.resx index 93ab1e2f..6323a0bb 100644 --- a/client/Maestro/MaestroForm.resx +++ b/client/Maestro/MaestroForm.resx @@ -126,22 +126,22 @@ True - + True - + True - + True - + True - + True - + True diff --git a/client/Maestro/Metadata/ArchiveMetadata.cs b/client/Maestro/Metadata/ArchiveMetadata.cs index ee33487b..dd8dbaeb 100644 --- a/client/Maestro/Metadata/ArchiveMetadata.cs +++ b/client/Maestro/Metadata/ArchiveMetadata.cs @@ -4,12 +4,12 @@ namespace Maestro.Metadata { public class ArchiveMetadataModel { //todo rename a Stuffra?? - public string StuffID { get; set; } - public string StuffTitle { get; set; } - public string StuffDescription { get; set; } - public string MediaID { get; set; } - public string MediaTitle { get; set; } - public string MediaDescription { get; set; } + public string itemHouseId { get; set; } + public string itemTitle { get; set; } + public string itemDescription { get; set; } + public string mediaHouseId { get; set; } + public string mediaTitle { get; set; } + public string mediaDescription { get; set; } public override string ToString() { return JsonConvert.SerializeObject(this); diff --git a/client/Maestro/Resources/configuration-nexio.json b/client/Maestro/Resources/configuration-nexio.json index fc4a75a7..e31b2a03 100644 --- a/client/Maestro/Resources/configuration-nexio.json +++ b/client/Maestro/Resources/configuration-nexio.json @@ -51,7 +51,7 @@ { "label": "Archive", "processor": "FTPTargetProcessor", - "outputFormat": "{0}-{1}-{2}", + "outputFormat": "%ID%-%SOURCENAME%", "killDateDays": 1, "remote": { "address": "ftp://localhost:21/out", @@ -62,7 +62,7 @@ { "label": "Ready", "processor": "FXPTargetProcessor", - "outputFormat": "{0}-{1}-{2}", + "outputFormat": "%ID%-%SOURCENAME%", "remote": { "address": "ftp://localhost:22/out", "userName": "dani", diff --git a/client/Maestro/Resources/configuration-unc.json b/client/Maestro/Resources/configuration-unc.json index 48fa4693..4bf60fc1 100644 --- a/client/Maestro/Resources/configuration-unc.json +++ b/client/Maestro/Resources/configuration-unc.json @@ -3,6 +3,7 @@ "active": true, "startInTray": false, "enableNameOverride": false, + "enableCustomMetadataId": true, "player": { "enabled": true, "autoStart": false, @@ -50,12 +51,12 @@ "targets": [ { "label": "Archiválandó", - "processor": "FTPTargetProcessor", - "outputFormat": "{0}-{1}", + "processor": "UNCTargetProcessor", + "outputFormat": "%ID%-%SOURCENAME%", "tag": "Archiválásra kijelöl", "useMetadata": true, "remote": { - "address": "ftp://10.10.1.100:21/ARCHIVE", + "address": "file://10.10.1.100/BRAAVOS/ARCHIVE", "userName": "mediacube", "password": "Broadca5T" } @@ -63,16 +64,16 @@ { "label": "Adáskész", "processor": "FTPTargetProcessor", - "outputFormat": "{0}-{1}", - "saveSegments": true, - "killDateDays": 1, - "tag": "Adáskész", - "createSubFolder": true, - "useMetadata": true, + "outputFormat": "%ID%-%SOURCENAME%", + "saveSegments": true, + "killDateDays": 1, + "tag": "Adáskész", + "createSubFolder": true, + "useMetadata": true, "remote": { "address": "ftp://10.10.1.100:21/READY", - "userName": "dani", - "password": "dani" + "userName": "mediacube", + "password": "Broadca5T" } } ] diff --git a/client/Maestro/StringResources.Designer.cs b/client/Maestro/StringResources.Designer.cs index b889828e..6855d6b3 100644 --- a/client/Maestro/StringResources.Designer.cs +++ b/client/Maestro/StringResources.Designer.cs @@ -106,11 +106,11 @@ namespace Maestro { } /// - /// Looks up a localized string similar to Bemenet. + /// Looks up a localized string similar to Cél. /// - internal static string BEMENET { + internal static string CEL { get { - return ResourceManager.GetString("BEMENET", resourceCulture); + return ResourceManager.GetString("CEL", resourceCulture); } } @@ -133,29 +133,29 @@ namespace Maestro { } /// - /// Looks up a localized string similar to Forrás fájl. + /// Looks up a localized string similar to Forrás. /// - internal static string FORRAS_FAJL { + internal static string FORRAS { get { - return ResourceManager.GetString("FORRAS_FAJL", resourceCulture); + return ResourceManager.GetString("FORRAS", resourceCulture); } } /// - /// Looks up a localized string similar to Kezdés. + /// Looks up a localized string similar to Forrás fájl. /// - internal static string KEZDES { + internal static string FORRAS_FAJL { get { - return ResourceManager.GetString("KEZDES", resourceCulture); + return ResourceManager.GetString("FORRAS_FAJL", resourceCulture); } } /// - /// Looks up a localized string similar to Kimenet. + /// Looks up a localized string similar to Kezdés. /// - internal static string KIMENET { + internal static string KEZDES { get { - return ResourceManager.GetString("KIMENET", resourceCulture); + return ResourceManager.GetString("KEZDES", resourceCulture); } } diff --git a/client/Maestro/StringResources.resx b/client/Maestro/StringResources.resx index 4aa791b6..cbbbbab7 100644 --- a/client/Maestro/StringResources.resx +++ b/client/Maestro/StringResources.resx @@ -132,8 +132,8 @@ Befejezés - - Bemenet + + Cél Cél akció @@ -141,15 +141,15 @@ Felvétel dátuma + + Forrás + Forrás fájl Kezdés - - Kimenet - Kiválasztott forrás diff --git a/client/Maestro/Targets/FTPTargetProcessor.cs b/client/Maestro/Targets/FTPTargetProcessor.cs index 4c39ade1..5265c543 100644 --- a/client/Maestro/Targets/FTPTargetProcessor.cs +++ b/client/Maestro/Targets/FTPTargetProcessor.cs @@ -10,33 +10,16 @@ using TrafficClient; using Model; using JobEngineClient; using Maestro.Metadata; -using System.Text; namespace Maestro.Targets { - public class FTPTargetProcessor : TargetProcessor { + public class FTPTargetProcessor : UNCTargetProcessor { private readonly Logger logger = LogManager.GetCurrentClassLogger(); - private const string SUCCESS = "Successfully completed."; - private const string PROCESSING = "Processing {0}"; - private const string PROCESSING_COMPLETED = "Finished processing {0}"; - private const string FILENAME = "{0}{1}"; - private const string VERSIONED_FILENAME = "{0}-{1}{2}"; - private const string ALREADY_EXISTS = "File {0} already exists, trying {1}"; - private const string STATUS_FOLDER = ".STATUS"; - private const string KILLDATE_FILE = "{0}.{1}.killdate"; - private const string METADATA_FILE = "{0}.json"; protected FtpClient targetFTP; - protected FileInfo inputFile; - private string workingDir; - private MediaCubeApi mediaCubeApi; - public WorkflowAction workFlowAction { get; set; } - - public FTPTargetProcessor(Control parent, Source sourceConfig, Target targetConfig, string inputFileName, string id, List segments, MediaCubeApi mediaCubeApi, ArchiveMetadataModel model) - : base(parent, targetConfig, segments, model) { + public FTPTargetProcessor(Control parent, Source sourceConfig, Target targetConfig, string inputFileName, string id, List segments, MediaCubeApi mediaCubeApi, ArchiveMetadataModel archiveMetadata) + : base(parent, sourceConfig, targetConfig, inputFileName, id, segments, mediaCubeApi, archiveMetadata) { FtpTrace.LogFunctions = false; - this.mediaCubeApi = mediaCubeApi; - this.targetConfig = targetConfig; Uri inputUri = new Uri(String.Format("{0}/{1}", sourceConfig.Local.Address.LocalPath, inputFileName)); inputFile = new FileInfo(inputUri.LocalPath); Input = inputFile.FullName; @@ -44,147 +27,33 @@ namespace Maestro.Targets { workFlowAction = new WorkflowAction() { houseId = ID, tag = targetConfig.Tag, touched = DateTime.Now }; } - public override bool Execute() { - logger.Info(PROCESSING, inputFile.Name); - Started = DateTime.Now; - workFlowAction.started = Started; - bool result = false; - try { - targetFTP = CreateClient(targetConfig.Remote); - workingDir = DetermineWorkingDirectory(targetConfig.Remote); - EnsureDirectoryExistence(targetFTP, workingDir); - Status = ProcessStatus.Progress; - Output = CreateOutputFileName(); - workFlowAction.source = Input; - workFlowAction.destination = Path.Combine(workingDir, Output).Replace("\\", "/"); - UploadFile(Output); - ExecuteCompleted(); - Status = ProcessStatus.Completed; - Message = SUCCESS; - workFlowAction.successful = true; - } - catch (Exception e) { - Status = ProcessStatus.Error; - Message = e.Message; - workFlowAction.description = Message; - logger.Error(e); - } - finally { - TerminateClient(targetFTP); - Finished = DateTime.Now; - workFlowAction.finished = Finished; - SendWorkFlowAction(); - } - logger.Info(PROCESSING_COMPLETED, inputFile.Name); - return result; - } - - protected override void ExecuteCompleted() { - base.ExecuteCompleted(); - if (targetConfig.KillDateDays > 0) - UploadKillDateFile(targetConfig.Remote, Output); - if (targetConfig.UseMetadata && metadataModel != null) - CreateMetadata(targetConfig.Remote, Output); - } - - private string GetVersionedFileName(string fileName) { - string result = fileName; - string nameWithoutExtension = String.Format(Path.GetFileNameWithoutExtension(fileName)); - string extension = Path.GetExtension(fileName); - int version = 0; - while (targetFTP.FileExists(result)) { - string versioned = String.Format(VERSIONED_FILENAME, nameWithoutExtension, version, extension); - logger.Debug(ALREADY_EXISTS, result, versioned); - result = versioned; - version++; - } - return result; - } - - private void SendWorkFlowAction() { - try { - mediaCubeApi.Create(workFlowAction); - } - catch (Exception e) { - MessageBox.Show(parent, e.Message); - } - } - - private String DetermineWorkingDirectory(Connection connection) { - string result = null; - Uri address = connection.Address; - if (targetConfig.CreateSubFolder) - result = Path.Combine(address.PathAndQuery, ID).Replace("\\", "/"); - else - result = address.PathAndQuery; - return result; + protected override void BeforeExecute() { + base.BeforeExecute(); + targetFTP = CreateClient(targetConfig.Remote); } - private void UploadKillDateFile(Connection connection, string output) { - Uri address = connection.Address; - string statusWorkDir = Path.Combine(address.PathAndQuery, STATUS_FOLDER).Replace("\\", "/"); - EnsureDirectoryExistence(targetFTP, statusWorkDir); - DateTime date = DateTime.Now; - date = date.AddDays(targetConfig.KillDateDays); - string fileName = String.Format(KILLDATE_FILE, output, date.ToString("yyyyMMdd")); - logger.Debug("Creating KILLDATE status file {0}", fileName); - //fileName = Path.Combine(statusWorkDir, fileName).Replace("\\", "/"); - byte[] bytes = new byte[1]; - bytes[0] = 0; - using (Stream ostream = targetFTP.OpenWrite(fileName)) { - ostream.Write(bytes, 0, 0); - } + protected override void AfterExecute() { + base.AfterExecute(); + TerminateClient(targetFTP); } - private void CreateMetadata(Connection connection, string output) { - Uri address = connection.Address; - string statusWorkDir = Path.Combine(address.PathAndQuery, STATUS_FOLDER).Replace("\\", "/"); - EnsureDirectoryExistence(targetFTP, statusWorkDir); - string fileName = String.Format(METADATA_FILE, output); - logger.Debug("Creating METADATA file {0}", fileName); - byte[] content = Encoding.UTF8.GetBytes(metadataModel.ToString()); - using (Stream ostream = targetFTP.OpenWrite(fileName)) { - ostream.Write(content, 0, content.Length); - } - } - - private void CopyStream(Stream istream, long ilength, Stream ostream) { - byte[] buffer = new byte[32768]; - int read, overall = 0; - while ((read = istream.Read(buffer, 0, buffer.Length)) > 0) { - ostream.Write(buffer, 0, read); - overall += read; - Progress = (int)((double)overall / ilength * 100); - } - } - protected virtual void UploadFile(string outputFileName) { - using (FileStream istream = File.OpenRead(inputFile.FullName)) { - using (Stream ostream = targetFTP.OpenWrite(outputFileName)) { + protected override void UploadFile() { + using (FileStream istream = File.OpenRead(Input)) { + using (Stream ostream = targetFTP.OpenWrite(Output)) { CopyStream(istream, inputFile.Length, ostream); } } } - protected virtual string CreateOutputFileName() { - string nameWithoutExtension = targetConfig.OutputFormat.Replace("%ID%", ID).Replace("%SOURCENAME%", Path.GetFileNameWithoutExtension(inputFile.Name)); - string result = String.Format(FILENAME, nameWithoutExtension, inputFile.Extension); - int version = 1; - if (targetFTP != null) - while (targetFTP.FileExists(result)) { - string versioned = String.Format(VERSIONED_FILENAME, nameWithoutExtension, version, inputFile.Extension); - logger.Debug(ALREADY_EXISTS, result, versioned); - result = versioned; - version++; - } - return result; + protected override bool FileExists(string path) { + return targetFTP.FileExists(path); } - - private void EnsureDirectoryExistence(FtpClient client, string path) { - if (!client.DirectoryExists(path)) - client.CreateDirectory(path, true); - client.SetWorkingDirectory(path); + protected override void EnsureDirectoryExistence(string path) { + if (!targetFTP.DirectoryExists(path)) + targetFTP.CreateDirectory(path, true); + targetFTP.SetWorkingDirectory(path); } protected FtpClient CreateClient(Connection connection) { diff --git a/client/Maestro/Targets/FXPTargetProcessor.cs b/client/Maestro/Targets/FXPTargetProcessor.cs index abdb796b..51d47dd1 100644 --- a/client/Maestro/Targets/FXPTargetProcessor.cs +++ b/client/Maestro/Targets/FXPTargetProcessor.cs @@ -22,7 +22,7 @@ namespace Maestro.Targets { this.sourceConfig = sourceConfig; } - protected override void UploadFile(string outputFileName) { + protected override void UploadFile() { FtpClient sourceFTP = null; FtpClient monitorFTP = null; @@ -46,7 +46,7 @@ namespace Maestro.Targets { if (!replyTYPE.Success) throw new Exception(replyTYPE.ErrorMessage); - FtpReply replySTOR = targetFTP.Execute("STOR " + outputFileName); + FtpReply replySTOR = targetFTP.Execute("STOR " + OutputName); if (!replySTOR.Success) throw new Exception(replySTOR.ErrorMessage); @@ -62,7 +62,7 @@ namespace Maestro.Targets { long overall = 0; while (overall != ilength) { - overall = monitorFTP.GetFileSize(outputFileName); + overall = monitorFTP.GetFileSize(OutputName); Progress = (int)((double)overall / ilength * 100); Thread.Sleep(100); } diff --git a/client/Maestro/Targets/ITargetProcessor.cs b/client/Maestro/Targets/ITargetProcessor.cs index 0f8424de..7da7a2d0 100644 --- a/client/Maestro/Targets/ITargetProcessor.cs +++ b/client/Maestro/Targets/ITargetProcessor.cs @@ -12,7 +12,7 @@ namespace Maestro.Targets { string Output { get; set; } - ProcessStatus Status { get; set; } + string Status { get; set; } string Message { get; set; } diff --git a/client/Maestro/Targets/ProcessStatus.cs b/client/Maestro/Targets/ProcessStatus.cs deleted file mode 100644 index d403aa15..00000000 --- a/client/Maestro/Targets/ProcessStatus.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Maestro.Targets { - public enum ProcessStatus { - Idle, Progress, Completed, Error - } -} diff --git a/client/Maestro/Targets/TargetProcessor.cs b/client/Maestro/Targets/TargetProcessor.cs index febbaa4f..a6fe6e5c 100644 --- a/client/Maestro/Targets/TargetProcessor.cs +++ b/client/Maestro/Targets/TargetProcessor.cs @@ -1,37 +1,25 @@ using Maestro.Commons; using System; -using System.Linq; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows.Forms; -using System.Collections.Generic; -using Maestro.Configuration; -using TrafficClient; -using Maestro.Metadata; namespace Maestro.Targets { public abstract class TargetProcessor : ITargetProcessor { - private ProcessStatus status; + private string status; private string message; private string id; private DateTime started; private DateTime finished; private string input; private string output; + private string inputName; + private string outputName; private int progress; protected Control parent; - protected Target targetConfig; - protected TrafficAPI client; - protected List segments; - protected ArchiveMetadataModel metadataModel; - public TargetProcessor(Control parent, Target targetConfig, List segments, ArchiveMetadataModel model) { + public TargetProcessor(Control parent) { this.parent = parent; - this.metadataModel = model; - MaestroForm maestroForm = parent as MaestroForm; - TrafficMetadata metadata = maestroForm.Configuration.Metadatas.Where(m => { return m is TrafficMetadata; }).FirstOrDefault() as TrafficMetadata; - client = new TrafficAPI(metadata.Server.Address.OriginalString, metadata.Server.UserName, metadata.Server.Password, metadata.Server.Timeout); - this.segments = segments; } public event PropertyChangedEventHandler PropertyChanged; @@ -45,20 +33,9 @@ namespace Maestro.Targets { public abstract bool Execute(); protected virtual void ExecuteCompleted() { - if (targetConfig.SaveSegments) - SaveSegments(); } - private void SaveSegments() { - MaestroForm maestroForm = parent as MaestroForm; - client.DeleteSegments(maestroForm.SelectedMetadata.VariantID); - if (segments != null) - foreach (Segment actual in segments) { - Segment segment = client.AddSegmentToCopia(maestroForm.SelectedMetadata.VariantID, actual.Comment, actual.TCIn, actual.TCOut, actual.Optional); - } - } - - public ProcessStatus Status { + public string Status { get { return status; } @@ -118,6 +95,30 @@ namespace Maestro.Targets { } } + public string InputName { + get { + return inputName; + } + set { + if (inputName != value) { + inputName = value; + NotifyPropertyChanged(); + } + } + } + + public string OutputName { + get { + return outputName; + } + set { + if (outputName != value) { + outputName = value; + NotifyPropertyChanged(); + } + } + } + public string Message { get { return message; diff --git a/client/Maestro/Targets/UNCTargetProcessor.cs b/client/Maestro/Targets/UNCTargetProcessor.cs new file mode 100644 index 00000000..e8ed691b --- /dev/null +++ b/client/Maestro/Targets/UNCTargetProcessor.cs @@ -0,0 +1,200 @@ +using Maestro.Configuration; +using NLog; +using System; +using System.Linq; +using System.IO; +using System.Windows.Forms; +using System.Collections.Generic; +using TrafficClient; +using Model; +using JobEngineClient; +using Maestro.Metadata; +using System.Text; +using Maestro.Commons; + +namespace Maestro.Targets { + + public class UNCTargetProcessor : TargetProcessor { + private readonly Logger logger = LogManager.GetCurrentClassLogger(); + private const string SUCCESS = "Successfully completed."; + private const string PROCESSING = "Processing {0}"; + private const string PROCESSING_COMPLETED = "Finished processing {0}"; + private const string FILENAME = "{0}{1}"; + private const string VERSIONED_FILENAME = "{0}-{1}{2}"; + private const string ALREADY_EXISTS = "File {0} already exists, trying {1}"; + private const string STATUS_FOLDER = ".STATUS"; + private const string KILLDATE_FILE = "{0}.{1}.killdate"; + private const string METADATA_FILE = "{0}.json"; + private MediaCubeApi mediaCubeApi; + protected Target targetConfig; + protected FileInfo inputFile; + protected string workingDir; + protected List segments; + protected ArchiveMetadataModel archiveMetadata; + public WorkflowAction workFlowAction { get; set; } + + public UNCTargetProcessor(Control parent, Source sourceConfig, Target targetConfig, string inputFileName, string id, List segments, MediaCubeApi mediaCubeApi, ArchiveMetadataModel archiveMetadata) + : base(parent) { + this.mediaCubeApi = mediaCubeApi; + this.targetConfig = targetConfig; + this.archiveMetadata = archiveMetadata; + this.segments = segments; + InputName = inputFileName; + Input = Path.Combine(sourceConfig.Local.Address.LocalPath, inputFileName); + inputFile = new FileInfo(Input); + ID = id; + workFlowAction = new WorkflowAction() { houseId = ID, tag = targetConfig.Tag, touched = DateTime.Now }; + } + + protected virtual void BeforeExecute() { + Started = DateTime.Now; + workFlowAction.started = Started; + } + + public override bool Execute() { + logger.Info(PROCESSING, inputFile.Name); + bool result = false; + try { + BeforeExecute(); + workingDir = DetermineWorkingDirectory(targetConfig.Remote); + EnsureDirectoryExistence(workingDir); + OutputName = CreateOutputFileName(); + Output = Path.Combine(workingDir, OutputName); + workFlowAction.source = Input; + workFlowAction.destination = Output; + Status = "Folyamatban"; + UploadFile(); + ExecuteCompleted(); + } + catch (Exception e) { + Status = "Hiba"; + Message = e.Message; + workFlowAction.description = Message; + logger.Error(e); + } + finally { + AfterExecute(); + } + logger.Info(PROCESSING_COMPLETED, inputFile.Name); + return result; + } + + protected override void ExecuteCompleted() { + base.ExecuteCompleted(); + Status = "Kész"; + Message = SUCCESS; + workFlowAction.description = SUCCESS; + workFlowAction.successful = true; + if (targetConfig.KillDateDays > 0) + UploadKillDateFile(); + if (targetConfig.UseMetadata && archiveMetadata != null) + CreateMetadata(); + if (targetConfig.SaveSegments && segments != null && segments.Count > 0) + SaveSegments(); + } + + private void SaveSegments() { + MaestroForm maestroForm = parent as MaestroForm; + TrafficMetadata metadata = maestroForm.Configuration.Metadatas.Where(m => { return m is TrafficMetadata; }).FirstOrDefault() as TrafficMetadata; + TrafficAPI client = new TrafficAPI(metadata.Server.Address.OriginalString, metadata.Server.UserName, metadata.Server.Password, metadata.Server.Timeout); + client.DeleteSegments(maestroForm.SelectedMetadata.VariantID); + foreach (Segment actual in segments) { + Segment segment = client.AddSegmentToCopia(maestroForm.SelectedMetadata.VariantID, actual.Comment, actual.TCIn, actual.TCOut, actual.Optional); + } + } + + protected virtual void AfterExecute() { + Finished = DateTime.Now; + workFlowAction.finished = Finished; + SendWorkFlowAction(); + } + + protected virtual bool FileExists(string path) { + return File.Exists(path); + } + + private void SendWorkFlowAction() { + try { + mediaCubeApi.Create(workFlowAction); + } + catch (Exception e) { + MessageBox.Show(parent, e.Message); + } + } + + private String DetermineWorkingDirectory(Connection connection) { + string result = null; + if (targetConfig.CreateSubFolder) + result = Path.Combine(connection.Address.LocalPath, ID); + else + result = connection.Address.LocalPath; + return result; + } + + private void UploadKillDateFile() { + Uri address = targetConfig.Remote.Address; + string statusWorkDir = Path.Combine(address.LocalPath, STATUS_FOLDER); + EnsureDirectoryExistence(statusWorkDir); + DateTime date = DateTime.Now; + date = date.AddDays(targetConfig.KillDateDays); + string fileName = String.Format(KILLDATE_FILE, OutputName, date.ToString("yyyyMMdd")); + logger.Debug("Creating KILLDATE status file {0}", fileName); + UploadContent(Path.Combine(statusWorkDir, fileName), null); + } + + private void CreateMetadata() { + Uri address = targetConfig.Remote.Address; + string statusWorkDir = Path.Combine(address.LocalPath, STATUS_FOLDER); + EnsureDirectoryExistence(statusWorkDir); + string fileName = String.Format(METADATA_FILE, OutputName); + logger.Debug("Creating METADATA file {0}", fileName); + byte[] content = Encoding.UTF8.GetBytes(archiveMetadata.ToString()); + UploadContent(Path.Combine(statusWorkDir, fileName), content); + } + + + protected void CopyStream(Stream istream, long ilength, Stream ostream) { + byte[] buffer = new byte[32768]; + int read, overall = 0; + while ((read = istream.Read(buffer, 0, buffer.Length)) > 0) { + ostream.Write(buffer, 0, read); + overall += read; + Progress = (int)((double)overall / ilength * 100); + } + } + + protected virtual void UploadContent(string outputPath, byte[] content) { + File.WriteAllBytes(outputPath, content); + } + + private CopyProgressResult CopyProgressHandler(long total, long transferred, long streamSize, long StreamByteTrans, uint dwStreamNumber, CopyProgressCallbackReason reason, IntPtr hSourceFile, IntPtr hDestinationFile, IntPtr lpData) { + Progress = (int)((double)total / transferred * 100); + return CopyProgressResult.PROGRESS_CONTINUE; + } + + protected virtual void UploadFile() { + int pbCancel = 0; + Win32File.CopyFileEx(Input, Output, new CopyProgressRoutine(this.CopyProgressHandler), IntPtr.Zero, ref pbCancel, CopyFileFlags.COPY_FILE_RESTARTABLE); + } + + protected virtual string CreateOutputFileName() { + string nameWithoutExtension = targetConfig.OutputFormat.Replace("%ID%", ID).Replace("%SOURCENAME%", Path.GetFileNameWithoutExtension(inputFile.Name)); + string result = String.Format(FILENAME, nameWithoutExtension, inputFile.Extension); + int version = 1; + while (FileExists(Path.Combine(workingDir, result))) { + string versioned = String.Format(VERSIONED_FILENAME, nameWithoutExtension, version, inputFile.Extension); + logger.Debug(ALREADY_EXISTS, result, versioned); + result = versioned; + version++; + } + return result; + } + + protected virtual void EnsureDirectoryExistence(string path) { + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + } + + + } +} -- 2.54.0