From 30740057382596732a6dfe53c5accbc1fe6cabb3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Tue, 3 Oct 2017 11:22:22 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C30513 --- client/Maestro/ArchiveMetadata.Designer.cs | 49 +++++++++--------- client/Maestro/MaestroForm.Target.cs | 2 +- client/Maestro/Targets/FTPTargetProcessor.cs | 52 +++++++++++--------- client/Maestro/Targets/TargetProcessor.cs | 6 +-- 4 files changed, 58 insertions(+), 51 deletions(-) diff --git a/client/Maestro/ArchiveMetadata.Designer.cs b/client/Maestro/ArchiveMetadata.Designer.cs index d8a9a7f3..01206e43 100644 --- a/client/Maestro/ArchiveMetadata.Designer.cs +++ b/client/Maestro/ArchiveMetadata.Designer.cs @@ -47,7 +47,7 @@ // label_stuffID // this.label_stuffID.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.label_stuffID.Location = new System.Drawing.Point(3, 7); + this.label_stuffID.Location = new System.Drawing.Point(8, 12); this.label_stuffID.Name = "label_stuffID"; this.label_stuffID.Size = new System.Drawing.Size(87, 13); this.label_stuffID.TabIndex = 0; @@ -56,7 +56,7 @@ // label_stuffDescription // this.label_stuffDescription.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.label_stuffDescription.Location = new System.Drawing.Point(3, 87); + this.label_stuffDescription.Location = new System.Drawing.Point(8, 92); this.label_stuffDescription.Name = "label_stuffDescription"; this.label_stuffDescription.Size = new System.Drawing.Size(66, 13); this.label_stuffDescription.TabIndex = 2; @@ -65,7 +65,7 @@ // label_mediaID // this.label_mediaID.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.label_mediaID.Location = new System.Drawing.Point(3, 161); + this.label_mediaID.Location = new System.Drawing.Point(8, 166); this.label_mediaID.Name = "label_mediaID"; this.label_mediaID.Size = new System.Drawing.Size(86, 13); this.label_mediaID.TabIndex = 3; @@ -74,7 +74,7 @@ // label_mediaTitle // this.label_mediaTitle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.label_mediaTitle.Location = new System.Drawing.Point(3, 201); + this.label_mediaTitle.Location = new System.Drawing.Point(8, 206); this.label_mediaTitle.Name = "label_mediaTitle"; this.label_mediaTitle.Size = new System.Drawing.Size(57, 13); this.label_mediaTitle.TabIndex = 4; @@ -84,7 +84,7 @@ // this.label_mediaDescription.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label_mediaDescription.AutoSize = true; - this.label_mediaDescription.Location = new System.Drawing.Point(3, 241); + this.label_mediaDescription.Location = new System.Drawing.Point(8, 246); this.label_mediaDescription.Name = "label_mediaDescription"; this.label_mediaDescription.Size = new System.Drawing.Size(65, 13); this.label_mediaDescription.TabIndex = 5; @@ -93,59 +93,59 @@ // textBox_stuffID // this.textBox_stuffID.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox_stuffID.Location = new System.Drawing.Point(3, 23); + this.textBox_stuffID.Location = new System.Drawing.Point(8, 28); this.textBox_stuffID.Name = "textBox_stuffID"; - this.textBox_stuffID.Size = new System.Drawing.Size(295, 20); + this.textBox_stuffID.Size = new System.Drawing.Size(549, 20); this.textBox_stuffID.TabIndex = 6; // // textBox_stuffTitle // this.textBox_stuffTitle.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox_stuffTitle.Location = new System.Drawing.Point(3, 63); + this.textBox_stuffTitle.Location = new System.Drawing.Point(8, 68); this.textBox_stuffTitle.Name = "textBox_stuffTitle"; - this.textBox_stuffTitle.Size = new System.Drawing.Size(295, 20); + this.textBox_stuffTitle.Size = new System.Drawing.Size(549, 20); this.textBox_stuffTitle.TabIndex = 7; // // textBox_stuffDescription // this.textBox_stuffDescription.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox_stuffDescription.Location = new System.Drawing.Point(3, 103); + this.textBox_stuffDescription.Location = new System.Drawing.Point(8, 108); this.textBox_stuffDescription.Multiline = true; this.textBox_stuffDescription.Name = "textBox_stuffDescription"; this.textBox_stuffDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.textBox_stuffDescription.Size = new System.Drawing.Size(295, 48); + this.textBox_stuffDescription.Size = new System.Drawing.Size(549, 48); this.textBox_stuffDescription.TabIndex = 8; // // textBox_mediaID // this.textBox_mediaID.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox_mediaID.Location = new System.Drawing.Point(3, 177); + this.textBox_mediaID.Location = new System.Drawing.Point(8, 182); this.textBox_mediaID.Name = "textBox_mediaID"; - this.textBox_mediaID.Size = new System.Drawing.Size(295, 20); + this.textBox_mediaID.Size = new System.Drawing.Size(549, 20); this.textBox_mediaID.TabIndex = 9; // // textBox_mediaTitle // this.textBox_mediaTitle.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox_mediaTitle.Location = new System.Drawing.Point(3, 217); + this.textBox_mediaTitle.Location = new System.Drawing.Point(8, 222); this.textBox_mediaTitle.Name = "textBox_mediaTitle"; - this.textBox_mediaTitle.Size = new System.Drawing.Size(295, 20); + this.textBox_mediaTitle.Size = new System.Drawing.Size(549, 20); this.textBox_mediaTitle.TabIndex = 10; // // textBox_mediaDescription // this.textBox_mediaDescription.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox_mediaDescription.Location = new System.Drawing.Point(3, 257); + this.textBox_mediaDescription.Location = new System.Drawing.Point(8, 262); this.textBox_mediaDescription.Multiline = true; this.textBox_mediaDescription.Name = "textBox_mediaDescription"; this.textBox_mediaDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.textBox_mediaDescription.Size = new System.Drawing.Size(295, 153); + this.textBox_mediaDescription.Size = new System.Drawing.Size(549, 87); this.textBox_mediaDescription.TabIndex = 11; // // label_stuffTitle // this.label_stuffTitle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.label_stuffTitle.Location = new System.Drawing.Point(3, 47); + this.label_stuffTitle.Location = new System.Drawing.Point(8, 52); this.label_stuffTitle.Name = "label_stuffTitle"; this.label_stuffTitle.Size = new System.Drawing.Size(58, 13); this.label_stuffTitle.TabIndex = 1; @@ -156,16 +156,16 @@ this.groupBox1.Controls.Add(this.button_Ok); this.groupBox1.Controls.Add(this.buttonCancel); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.groupBox1.Location = new System.Drawing.Point(0, 413); + this.groupBox1.Location = new System.Drawing.Point(0, 357); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(301, 48); + this.groupBox1.Size = new System.Drawing.Size(565, 48); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; // // button_Ok // this.button_Ok.Anchor = System.Windows.Forms.AnchorStyles.Right; - this.button_Ok.Location = new System.Drawing.Point(224, 19); + this.button_Ok.Location = new System.Drawing.Point(488, 19); this.button_Ok.Name = "button_Ok"; this.button_Ok.Size = new System.Drawing.Size(75, 23); this.button_Ok.TabIndex = 1; @@ -176,7 +176,7 @@ // buttonCancel // this.buttonCancel.Anchor = System.Windows.Forms.AnchorStyles.Right; - this.buttonCancel.Location = new System.Drawing.Point(145, 19); + this.buttonCancel.Location = new System.Drawing.Point(409, 19); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 0; @@ -203,6 +203,7 @@ this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.Padding = new System.Windows.Forms.Padding(5); this.tableLayoutPanel1.RowCount = 12; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); @@ -216,14 +217,14 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 54F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(301, 413); + this.tableLayoutPanel1.Size = new System.Drawing.Size(565, 357); this.tableLayoutPanel1.TabIndex = 3; // // ArchiveMetadata // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(301, 461); + this.ClientSize = new System.Drawing.Size(565, 405); this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.groupBox1); this.Icon = global::Maestro.Properties.Resources.AppIcon; diff --git a/client/Maestro/MaestroForm.Target.cs b/client/Maestro/MaestroForm.Target.cs index 5af541b8..fb4c2964 100644 --- a/client/Maestro/MaestroForm.Target.cs +++ b/client/Maestro/MaestroForm.Target.cs @@ -98,7 +98,7 @@ namespace Maestro { private void ApplyProcessorButtonsLogic() { ClearSelectedProcessors(); - if (!String.IsNullOrEmpty(textSelectedMetadata.Text) && !String.IsNullOrEmpty(textSelectedMetadata.Text)) { + if (!String.IsNullOrEmpty(textSelectedSource.Text) && !String.IsNullOrEmpty(textSelectedMetadata.Text)) { ChangeProcessButtonsState(true); } else { ChangeProcessButtonsState(false); diff --git a/client/Maestro/Targets/FTPTargetProcessor.cs b/client/Maestro/Targets/FTPTargetProcessor.cs index e3d59b0f..636bfd1e 100644 --- a/client/Maestro/Targets/FTPTargetProcessor.cs +++ b/client/Maestro/Targets/FTPTargetProcessor.cs @@ -10,6 +10,7 @@ using TrafficClient; using Model; using JobEngineClient; using Maestro.Metadata; +using System.Text; namespace Maestro.Targets { @@ -22,7 +23,8 @@ namespace Maestro.Targets { 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 KILLDATE_FILE = "{0}.{1}.killdate"; + private const string METADATA_FILE = "{0}.json"; protected FtpClient targetFTP; protected FileInfo inputFile; private string workingDir; @@ -48,18 +50,14 @@ namespace Maestro.Targets { workFlowAction.started = Started; bool result = false; try { - SetSubFolder(targetConfig.Remote); targetFTP = CreateClient(targetConfig.Remote); + workingDir = DetermineWorkingDirectory(targetConfig.Remote); EnsureDirectoryExistence(targetFTP, workingDir); Status = ProcessStatus.Progress; Output = CreateOutputFileName(); - workFlowAction.destination = Path.Combine(workingDir, Output).Replace("\\", "/"); workFlowAction.source = Input; + workFlowAction.destination = Path.Combine(workingDir, Output).Replace("\\", "/"); UploadFile(Output); - if (targetConfig.KillDateDays > 0) - UploadKillDateFile(targetConfig.Remote, Output); - if (targetConfig.UseMetadata) - UseMetadata(); ExecuteCompleted(); Status = ProcessStatus.Completed; Message = SUCCESS; @@ -81,18 +79,12 @@ namespace Maestro.Targets { return result; } - private void UseMetadata() { - if (model != null) { - string path = String.Format("{0}//.store", workingDir); - string fileName = "metadata.json"; - EnsureDirectoryExistence(targetFTP, path); - string finalFileName = GetVersionedFileName(fileName); - using (Stream ostream = targetFTP.OpenWrite(finalFileName)) { - string s = model.ToString(); - byte[] content = System.Text.Encoding.UTF8.GetBytes(s); - ostream.Write(content, 0, content.Length); - } - } + 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) { @@ -118,18 +110,20 @@ namespace Maestro.Targets { } } - private void SetSubFolder(Connection connection) { + private String DetermineWorkingDirectory(Connection connection) { + string result = null; Uri address = connection.Address; if (targetConfig.CreateSubFolder) - workingDir = Path.Combine(address.PathAndQuery, ID).Replace("\\", "/"); + result = Path.Combine(address.PathAndQuery, ID).Replace("\\", "/"); else - workingDir = address.PathAndQuery; + result = address.PathAndQuery; + return result; } private void UploadKillDateFile(Connection connection, string output) { Uri address = connection.Address; string statusWorkDir = Path.Combine(address.PathAndQuery, STATUS_FOLDER).Replace("\\", "/"); - EnsureDirectoryExistence(targetFTP, workingDir); + EnsureDirectoryExistence(targetFTP, statusWorkDir); DateTime date = DateTime.Now; date = date.AddDays(targetConfig.KillDateDays); string fileName = String.Format(KILLDATE_FILE, output, date.ToString("yyyyMMdd")); @@ -142,6 +136,18 @@ namespace Maestro.Targets { } } + 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; diff --git a/client/Maestro/Targets/TargetProcessor.cs b/client/Maestro/Targets/TargetProcessor.cs index 18b935d0..febbaa4f 100644 --- a/client/Maestro/Targets/TargetProcessor.cs +++ b/client/Maestro/Targets/TargetProcessor.cs @@ -23,11 +23,11 @@ namespace Maestro.Targets { protected Target targetConfig; protected TrafficAPI client; protected List segments; - protected ArchiveMetadataModel model; + protected ArchiveMetadataModel metadataModel; public TargetProcessor(Control parent, Target targetConfig, List segments, ArchiveMetadataModel model) { this.parent = parent; - this.model = model; + 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); @@ -44,7 +44,7 @@ namespace Maestro.Targets { public abstract bool Execute(); - protected void ExecuteCompleted() { + protected virtual void ExecuteCompleted() { if (targetConfig.SaveSegments) SaveSegments(); } -- 2.54.0