From 8154be6c7d0d80a82da5ceabc70bb9c63cad2cb5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Wed, 22 Jul 2020 13:24:53 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C31903 --- .../{editor-hirtv.json => -editor-hirtv.json} | 0 ...-configuration.json => configuration.json} | 13 ++--- client/Maestro/Maestro.csproj | 4 +- client/Maestro/MaestroForm.Target.cs | 16 ++++-- .../MaestroShared/Commons/CustomFileCopier.cs | 57 +++++++++++++++++++ .../Configuration/ConfigurationInfo.cs | 1 + client/MaestroShared/MaestroShared.csproj | 1 + .../MaestroShared/Properties/AssemblyInfo.cs | 4 +- .../Targets/UNCTargetProcessor.cs | 49 +++++++++++++++- 9 files changed, 125 insertions(+), 20 deletions(-) rename client/Maestro/Configuration/{editor-hirtv.json => -editor-hirtv.json} (100%) rename client/Maestro/Configuration/{-configuration.json => configuration.json} (90%) create mode 100644 client/MaestroShared/Commons/CustomFileCopier.cs diff --git a/client/Maestro/Configuration/editor-hirtv.json b/client/Maestro/Configuration/-editor-hirtv.json similarity index 100% rename from client/Maestro/Configuration/editor-hirtv.json rename to client/Maestro/Configuration/-editor-hirtv.json diff --git a/client/Maestro/Configuration/-configuration.json b/client/Maestro/Configuration/configuration.json similarity index 90% rename from client/Maestro/Configuration/-configuration.json rename to client/Maestro/Configuration/configuration.json index 98b39068..03c635ad 100644 --- a/client/Maestro/Configuration/-configuration.json +++ b/client/Maestro/Configuration/configuration.json @@ -1,6 +1,6 @@ { "title": "Development", - "active": false, + "active": true, "startInTray": false, "enableCustomMetadataId": true, "filter": "avi", @@ -12,6 +12,7 @@ "source": { "$type": "UNCSource", "filter": "avi,wav,mxf,mts", + "useAlternateCopy": true, "local": { "address": "file://c:/_video", "userName": "mediacube", @@ -102,18 +103,14 @@ } }, { - "label": "Teszt", - "processor": "FTPTargetProcessor", + "label": "UNC Teszt", + "processor": "UNCTargetProcessor", "outputFormat": "%ID%-%SOURCENAME%", "tag": "Betöltés", "killDateDays": 7, "saveArchiveMetadata": false, - "sendEmailOnSuccess": true, - "successEmailPattern": "%JSON%", - "successEmailSubject": "%ID% - %ITEMTITLE% - %FORMAT% sikeres feltöltése", - "successEmailRecipient": "vasary@elgekko.net", "remote": { - "address": "ftp://10.10.1.105/TESZT/CHECK", + "address": "file://c:/opt1", "userName": "mediacube", "password": "Dn8t4gfHcK98o8hyPgLDhr5SgSji4JCxsfpMJsODikUp3nXgrM0UNCi45lLAK8ZOnmEneO44P9qpJ4QDqhctN6MxZodjJgdZTyoZKmSa+ECzEzLr/wPYNgxVaXrVotEy", "timeout": 1000 diff --git a/client/Maestro/Maestro.csproj b/client/Maestro/Maestro.csproj index 0deee7ee..612aa9a6 100644 --- a/client/Maestro/Maestro.csproj +++ b/client/Maestro/Maestro.csproj @@ -294,7 +294,7 @@ Always - + Always @@ -303,7 +303,7 @@ Always - + Always diff --git a/client/Maestro/MaestroForm.Target.cs b/client/Maestro/MaestroForm.Target.cs index 8332eb8d..628ced8b 100644 --- a/client/Maestro/MaestroForm.Target.cs +++ b/client/Maestro/MaestroForm.Target.cs @@ -182,12 +182,16 @@ namespace Maestro { force |= target.SuccessEmailPattern == null ? false : target.SuccessEmailPattern.Contains("%"); force |= target.SaveArchiveMetadata || target.SaveMorpheusMetadata || target.NexioServer; if (force && (ArchiveMetadata == null || !ArchiveMetadata.IsFilled)) { - ArchiveMetadata = GetArchiveMetadata(); - if (SelectedMetadata != null && String.IsNullOrEmpty(SelectedMetadata.MetadataText)) - SelectedMetadata.MetadataText = ArchiveMetadata.itemTitle; - if (ArchiveMetadata == null) { - MessageBox.Show(String.Format("A {0} folyamat nem futtatható kísérő adatok nélkül.", target.Label)); - return false; + //TODO eddig itt elszallt es adott hibauzenetet + try { + ArchiveMetadata = GetArchiveMetadata(); + if (SelectedMetadata != null && string.IsNullOrEmpty(SelectedMetadata.MetadataText)) + SelectedMetadata.MetadataText = ArchiveMetadata.itemTitle; + if (ArchiveMetadata == null) { + MessageBox.Show(String.Format("A {0} folyamat nem futtatható kísérő adatok nélkül.", target.Label)); + return false; + } + } catch (Exception e) { } } //szegmens informaciook hozzaadasa diff --git a/client/MaestroShared/Commons/CustomFileCopier.cs b/client/MaestroShared/Commons/CustomFileCopier.cs new file mode 100644 index 00000000..45a0767f --- /dev/null +++ b/client/MaestroShared/Commons/CustomFileCopier.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MaestroShared.Commons { + public delegate void ProgressChangeDelegate(double Persentage, ref bool Cancel); + public delegate void Completedelegate(); + + class CustomFileCopier { + public CustomFileCopier(string Source, string Dest) { + this.SourceFilePath = Source; + this.DestFilePath = Dest; + + OnProgressChanged += delegate { }; + OnComplete += delegate { }; + } + + public void Copy() { + byte[] buffer = new byte[10 * 1024 * 1024]; // 1MB buffer + bool cancelFlag = false; + + using (FileStream source = new FileStream(SourceFilePath, FileMode.Open, FileAccess.Read)) { + long fileLength = source.Length; + using (FileStream dest = new FileStream(DestFilePath, FileMode.CreateNew, FileAccess.Write)) { + long totalBytes = 0; + int currentBlockSize = 0; + + while ((currentBlockSize = source.Read(buffer, 0, buffer.Length)) > 0) { + totalBytes += currentBlockSize; + double persentage = (double)totalBytes * 100.0 / fileLength; + + dest.Write(buffer, 0, currentBlockSize); + + cancelFlag = false; + OnProgressChanged(persentage, ref cancelFlag); + + if (cancelFlag == true) { + // Delete dest file here + break; + } + } + } + } + + OnComplete(); + } + + public string SourceFilePath { get; set; } + public string DestFilePath { get; set; } + + public event ProgressChangeDelegate OnProgressChanged; + public event Completedelegate OnComplete; + } +} diff --git a/client/MaestroShared/Configuration/ConfigurationInfo.cs b/client/MaestroShared/Configuration/ConfigurationInfo.cs index 800f58b4..b91e1357 100644 --- a/client/MaestroShared/Configuration/ConfigurationInfo.cs +++ b/client/MaestroShared/Configuration/ConfigurationInfo.cs @@ -147,6 +147,7 @@ namespace MaestroShared.Configuration { public class UNCSource : Source { public bool FoldersAutoExpand { get; set; } + public bool UseAlternateCopy { get; set; } } public class NEXIOSource : Source { diff --git a/client/MaestroShared/MaestroShared.csproj b/client/MaestroShared/MaestroShared.csproj index 68a8ab0e..aa910b7a 100644 --- a/client/MaestroShared/MaestroShared.csproj +++ b/client/MaestroShared/MaestroShared.csproj @@ -82,6 +82,7 @@ + diff --git a/client/MaestroShared/Properties/AssemblyInfo.cs b/client/MaestroShared/Properties/AssemblyInfo.cs index 5936c1a5..7f12ec86 100644 --- a/client/MaestroShared/Properties/AssemblyInfo.cs +++ b/client/MaestroShared/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.1.0.1")] -[assembly: AssemblyFileVersion("2.1.0.1")] +[assembly: AssemblyVersion("2.1.0.3")] +[assembly: AssemblyFileVersion("2.1.0.3")] diff --git a/client/MaestroShared/Targets/UNCTargetProcessor.cs b/client/MaestroShared/Targets/UNCTargetProcessor.cs index 39896b0d..56971554 100644 --- a/client/MaestroShared/Targets/UNCTargetProcessor.cs +++ b/client/MaestroShared/Targets/UNCTargetProcessor.cs @@ -6,7 +6,9 @@ using MaestroShared.Target; using NLog; using System; using System.IO; +using System.Net; using System.Text; +using System.Threading.Tasks; using System.Windows.Forms; namespace MaestroShared.Targets { @@ -430,12 +432,55 @@ namespace MaestroShared.Targets { string targetFilePath = Output; if (Parameters.TargetConfig.TemporaryCopy) targetFilePath = Output + ".tmp"; - if (Win32File.CopyFileEx(Input, targetFilePath, new CopyProgressRoutine(this.CopyProgressHandler), IntPtr.Zero, ref pbCancel, CopyFileFlags.COPY_FILE_RESTARTABLE) - && Parameters.TargetConfig.TemporaryCopy) { + + bool copyResult = false; + + if (Parameters.SourceConfig is UNCSource && ((UNCSource)Parameters.SourceConfig).UseAlternateCopy) + copyResult = doAlternateCopy(targetFilePath); + else + copyResult = doCopy(ref pbCancel, targetFilePath); + + + if (copyResult && Parameters.TargetConfig.TemporaryCopy) { File.Move(targetFilePath, Output); } } + private bool doCopy(ref int pbCancel, string targetFilePath) { + return Win32File.CopyFileEx(Input, targetFilePath, new CopyProgressRoutine(this.CopyProgressHandler), IntPtr.Zero, ref pbCancel, CopyFileFlags.COPY_FILE_RESTARTABLE); + } + + private bool doAlternateCopy(string targetFilePath) { + CustomFileCopier copier = new CustomFileCopier(Input, targetFilePath); + copier.OnProgressChanged += Copier_OnProgressChanged; + copier.Copy(); + Boolean result = true; + /* + var webClient = new WebClient(); + try { + webClient.DownloadProgressChanged += (s, e) => { + Progress = e.ProgressPercentage; + }; + + Task task = webClient.DownloadFileTaskAsync(new Uri(Input), targetFilePath); + task.Wait(); + result = task.Status == TaskStatus.RanToCompletion; + } catch (Exception e) { + result = false; + Message = e.Message; + } + */ + return result; + } + + private void Copier_OnProgressChanged(double Persentage, ref bool Cancel) { + Progress = (int)Persentage; + } + + private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { + throw new NotImplementedException(); + } + protected virtual string GetOutputFilePath(string path, string fileName) { return "/".Equals(workingDir) ? fileName : Path.Combine(path, fileName); } -- 2.54.0