From: Vásáry Dániel Date: Fri, 13 Oct 2017 15:07:37 +0000 (+0000) Subject: git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube... X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=3bf227aca096dbecf8fd1338094f9d9c7c65d828;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C30619 --- diff --git a/client/IntegrationTests/App.config b/client/IntegrationTests/App.config index 30273041..c7ada3f3 100644 --- a/client/IntegrationTests/App.config +++ b/client/IntegrationTests/App.config @@ -1,4 +1,4 @@ - +
@@ -6,10 +6,38 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/IntegrationTests/IntegrationTests.csproj b/client/IntegrationTests/IntegrationTests.csproj index 32dd0456..de381e8a 100644 --- a/client/IntegrationTests/IntegrationTests.csproj +++ b/client/IntegrationTests/IntegrationTests.csproj @@ -81,11 +81,32 @@ ..\packages\RestSharp.105.2.3\lib\net46\RestSharp.dll + + ..\packages\SharpCifs.Std.0.2.11\lib\netstandard1.3\SharpCifs.Std.dll + + + ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + + + ..\packages\System.Net.NameResolution.4.3.0\lib\net46\System.Net.NameResolution.dll + + + ..\packages\System.Net.NetworkInformation.4.3.0\lib\net46\System.Net.NetworkInformation.dll + + + ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + diff --git a/client/IntegrationTests/MaestroIT.cs b/client/IntegrationTests/MaestroIT.cs index 3cea20c3..4ccfe3d7 100644 --- a/client/IntegrationTests/MaestroIT.cs +++ b/client/IntegrationTests/MaestroIT.cs @@ -3,11 +3,43 @@ using Maestro.Targets; using Maestro; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; +using Commons; +using Maestro.Commons; +using System.Diagnostics; +using SharpCifs.Smb; namespace IntegrationTests { [TestClass] public class MaestroTests { + private CopyProgressResult CopyProgressHandler(long total, long transferred, long streamSize, long StreamByteTrans, uint dwStreamNumber, CopyProgressCallbackReason reason, IntPtr hSourceFile, IntPtr hDestinationFile, IntPtr lpData) { + if (transferred > 0) + Debug.WriteLine((int)((double)transferred * 100 / total)); + return CopyProgressResult.PROGRESS_CONTINUE; + } + + protected virtual void UploadFile() { + int pbCancel = 0; + Win32File.CopyFileEx("\\\\10.10.1.100\\BRAAVOS\\_TEST_\\_ECHO\\magazin\\170806_korkep_itthonrol.MXF", "\\\\10.10.1.100\\BRAAVOS\\_TEST_\\_ECHO\\magazin\\170806_korkep_itthonrol1.MXF", new CopyProgressRoutine(this.CopyProgressHandler), IntPtr.Zero, ref pbCancel, CopyFileFlags.COPY_FILE_RESTARTABLE); + } + + [TestMethod] + public void TestSambaClient() { + //SambaClient.Impersonate(null, "root", "Broadca5T", delegate + //{ + // UploadFile(); + //}); + + SmbFile from = new SmbFile("smb://mediacube:Broadca5T@10.10.1.100/BRAAVOS/_TEST_/_ECHO/magazin/170806_korkep_itthonrol.MXF"); + SmbFile to = new SmbFile("smb://mediacube:Broadca5T@10.10.1.100/BRAAVOS/_TEST_/_ECHO/magazin/170806_korkep_itthonrol1.MXF"); + try { + long l = from.Length(); + from.CopyTo(to); + } + catch (Exception e) { + } + } + [TestMethod] public void TestFTPTarget() { Target configuration = new Target() { diff --git a/client/IntegrationTests/packages.config b/client/IntegrationTests/packages.config index 9d5a51e0..6d7e4746 100644 --- a/client/IntegrationTests/packages.config +++ b/client/IntegrationTests/packages.config @@ -7,5 +7,13 @@ + + + + + + + + \ No newline at end of file diff --git a/client/Maestro/Commons/SambaClient.cs b/client/Maestro/Commons/SambaClient.cs new file mode 100644 index 00000000..30b10970 --- /dev/null +++ b/client/Maestro/Commons/SambaClient.cs @@ -0,0 +1,84 @@ +using System; +using System.Runtime.ConstrainedExecution; +using System.Runtime.InteropServices; +using System.Security; +using System.Security.Permissions; +using System.Security.Principal; +using Microsoft.Win32.SafeHandles; + + +namespace Commons { + public sealed class SafeTokenHandle : SafeHandleZeroOrMinusOneIsInvalid { + private SafeTokenHandle() + : base(true) { + } + + [DllImport("kernel32.dll")] + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] + [SuppressUnmanagedCodeSecurity] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool CloseHandle(IntPtr handle); + + protected override bool ReleaseHandle() { + return CloseHandle(handle); + } + } + + public class SambaClient { + [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, + int dwLogonType, int dwLogonProvider, out SafeTokenHandle phToken); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + private extern static bool CloseHandle(IntPtr handle); + + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + public static void Impersonate(string domainName, string userName, string userPassword, Action actionToExecute) { + SafeTokenHandle safeTokenHandle; + try { + + const int LOGON32_PROVIDER_DEFAULT = 0; + //This parameter causes LogonUser to create a primary token. + const int LOGON32_LOGON_INTERACTIVE = 2; + + // Call LogonUser to obtain a handle to an access token. + bool returnValue = LogonUser(userName, domainName, userPassword, + LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, + out safeTokenHandle); + //Facade.Instance.Trace("LogonUser called."); + + if (returnValue == false) { + int ret = Marshal.GetLastWin32Error(); + //Facade.Instance.Trace($"LogonUser failed with error code : {ret}"); + + throw new System.ComponentModel.Win32Exception(ret); + } + + using (safeTokenHandle) { + //Facade.Instance.Trace($"Value of Windows NT token: {safeTokenHandle}"); + //Facade.Instance.Trace($"Before impersonation: {WindowsIdentity.GetCurrent().Name}"); + + // Use the token handle returned by LogonUser. + using (WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle())) { + using (WindowsImpersonationContext impersonatedUser = newId.Impersonate()) { + //Facade.Instance.Trace($"After impersonation: {WindowsIdentity.GetCurrent().Name}"); + //Facade.Instance.Trace("Start executing an action"); + + actionToExecute(); + + //Facade.Instance.Trace("Finished executing an action"); + } + } + //Facade.Instance.Trace($"After closing the context: {WindowsIdentity.GetCurrent().Name}"); + } + + } + catch (Exception ex) { + //Facade.Instance.Trace("Oh no! Impersonate method failed."); + //ex.HandleException(); + //On purpose: we want to notify a caller about the issue /Pavel Kovalev 9/16/2016 2:15:23 PM)/ + throw; + } + } + } +} \ No newline at end of file diff --git a/client/Maestro/Configuration/configuration-editor.json b/client/Maestro/Configuration/configuration-editor.json new file mode 100644 index 00000000..d142ae26 --- /dev/null +++ b/client/Maestro/Configuration/configuration-editor.json @@ -0,0 +1,117 @@ +{ + "title": "Szerkesztő", + "active": true, + "startInTray": false, + "enableCustomMetadataId": true, + "player": { + "enabled": true, + "autoStart": false, + "segmentEditor": true + }, + "source": { + "$type": "UNCSource", + "filter": "avi,wav,mxf", + "local": { + "address": "file://c:/x" + } + }, + "metadatas": [ + { + "$type": "OctopusMetadata", + "server": { + "address": "http://10.10.1.28/services/rest/octopus/", + "timeout": 1000 + } + }, + { + "$type": "TrafficMetadata", + "server": { + "address": "Data Source=10.10.1.45\\sql16;Initial Catalog=PA_Echo;Persist Security Info=True;", + "userName": "MAM", + "password": "Echotv.hu", + "timeout": 1000 + } + }, + { + "$type": "MediaCubeMetadata", + "server": { + "address": "http://10.10.1.28/services/rest/jobengine/", + "timeout": 1000 + } + } + ], + "targets": [ + { + "label": "Nyersanyag betöltés", + "processor": "UNCTargetProcessor", + "outputFormat": "%ID%-%SOURCENAME%", + "tag": "Betöltés", + "createSubFolder": true, + "killDateDays": 7, + "remote": { + "address": "file://10.10.1.100/BRAAVOS/OCTOPUS", + "timeout": 1000 + } + }, + { + "label": "Stúdióba küldés", + "processor": "FTPTargetProcessor", + "outputFormat": "%ID%", + "tag": "Betöltés", + "remote": { + "address": "ftp://10.10.1.56:2098", + "userName": "administaror", + "password": "system", + "timeout": 1000 + } + }, + { + "label": "Hír nyersanyag betöltés", + "processor": "UNCTargetProcessor", + "outputFormat": "%ID%-%SOURCENAME%", + "tag": "Betöltés", + "createSubFolder": true, + "killDateDays": 7, + "useMetadata": false, + "remote": { + "address": "file://10.10.1.100/BRAAVOS/OCTOPUS", + "timeout": 1000 + } + }, + { + "label": "Magazin nyersanyag betöltés", + "processor": "UNCTargetProcessor", + "outputFormat": "%ID%-%SOURCENAME%", + "tag": "Betöltés", + "createSubFolder": true, + "killDateDays": 7, + "useMetadata": false, + "remote": { + "address": "file://10.10.1.100/BRAAVOS/PLAYOUT_NLE", + "timeout": 1000 + } + }, + { + "label": "Lebonyba küldés", + "processor": "UNCTargetProcessor", + "outputFormat": "%ID%", + "tag": "Betöltés", + "killDateDays": 7, + "remote": { + "address": "file://10.10.1.100/BRAAVOS/PLAYOUT_CHECK", + "timeout": 1000 + } + }, + { + "label": "Archiválás", + "processor": "UNCTargetProcessor", + "outputFormat": "%ID%", + "tag": "Archiválás", + "useMetadata": true, + "remote": { + "address": "file://10.10.1.100/BRAAVOS/ARCHIVE", + "timeout": 1000 + } + } + ] +} diff --git a/client/Maestro/Configuration/configuration-ingest2.json b/client/Maestro/Configuration/configuration-nle.json similarity index 77% rename from client/Maestro/Configuration/configuration-ingest2.json rename to client/Maestro/Configuration/configuration-nle.json index f9eed359..04a2d15c 100644 --- a/client/Maestro/Configuration/configuration-ingest2.json +++ b/client/Maestro/Configuration/configuration-nle.json @@ -1,5 +1,5 @@ { - "title": "Betöltés", + "title": "NLE", "active": true, "startInTray": false, "enableCustomMetadataId": true, @@ -42,20 +42,31 @@ ], "targets": [ { - "label": "Híranyag betöltés", + "label": "Nyersanyag betöltés", "processor": "UNCTargetProcessor", "outputFormat": "%ID%-%SOURCENAME%", "tag": "Betöltés", "createSubFolder": true, "killDateDays": 7, - "useMetadata": false, "remote": { "address": "file://10.10.1.100/BRAAVOS/OCTOPUS", "timeout": 1000 } }, { - "label": "Adásanyag betöltés", + "label": "Stúdióba küldés", + "processor": "FTPTargetProcessor", + "outputFormat": "%ID%", + "tag": "Betöltés", + "remote": { + "address": "ftp://10.10.1.56:2098", + "userName": "administaror", + "password": "system", + "timeout": 1000 + } + }, + { + "label": "Lebonyba küldés", "processor": "UNCTargetProcessor", "outputFormat": "%ID%", "tag": "Betöltés", diff --git a/client/Maestro/Configuration/configuration-playout.json b/client/Maestro/Configuration/configuration-playout.json index fa5e1cb1..fd0ad3b2 100644 --- a/client/Maestro/Configuration/configuration-playout.json +++ b/client/Maestro/Configuration/configuration-playout.json @@ -1,5 +1,5 @@ { - "title": "Ellenőrzés", + "title": "Adáslebony", "active": true, "startInTray": false, "enableCustomMetadataId": true, @@ -56,7 +56,7 @@ "outputFormat": "%ID%", "tag": "Újravágás", "remote": { - "address": "file://10.10.1.100/BRAAVOS/PLAYOUT_NLE1" + "address": "file://10.10.1.100/BRAAVOS/PLAYOUT_NLE" }, "sendSEmailOnSuccess" : true, "successEmailRecipient": "vasary@elgekko.net", diff --git a/client/Maestro/Configuration/configuration-control.json b/client/Maestro/Configuration/configuration-studio.json similarity index 90% rename from client/Maestro/Configuration/configuration-control.json rename to client/Maestro/Configuration/configuration-studio.json index e232a942..2933e813 100644 --- a/client/Maestro/Configuration/configuration-control.json +++ b/client/Maestro/Configuration/configuration-studio.json @@ -1,5 +1,5 @@ { - "title": "Lebonyolítás", + "title": "Stúdió", "active": true, "startInTray": false, "enableCustomMetadataId": true, @@ -49,7 +49,7 @@ "outputFormat": "%ID%", "tag": "Adáskész", "remote": { - "address": "ftp://10.10.1.100:21/PLAYOUT_CHECK1", + "address": "ftp://10.10.1.100:21/PLAYOUT_CHECK", "userName": "mediacube", "password": "Broadca5T" } diff --git a/client/Maestro/Configuration/configuration-ingest.json b/client/Maestro/Configuration/configuration-sxs.json similarity index 73% rename from client/Maestro/Configuration/configuration-ingest.json rename to client/Maestro/Configuration/configuration-sxs.json index 196bf694..40127a92 100644 --- a/client/Maestro/Configuration/configuration-ingest.json +++ b/client/Maestro/Configuration/configuration-sxs.json @@ -1,5 +1,5 @@ { - "title": "Betöltés", + "title": "SxS", "active": true, "startInTray": false, "enableCustomMetadataId": true, @@ -42,7 +42,7 @@ ], "targets": [ { - "label": "Híranyag betöltés", + "label": "Hír nyersanyag betöltés", "processor": "UNCTargetProcessor", "outputFormat": "%ID%-%SOURCENAME%", "tag": "Betöltés", @@ -55,13 +55,26 @@ } }, { - "label": "Adásanyag betöltés", + "label": "Magazin nyersanyag betöltés", "processor": "UNCTargetProcessor", - "outputFormat": "%ID%", + "outputFormat": "%ID%-%SOURCENAME%", "tag": "Betöltés", + "createSubFolder": true, + "killDateDays": 7, + "useMetadata": false, + "remote": { + "address": "file://10.10.1.100/BRAAVOS/PLAYOUT_NLE", + "timeout": 1000 + } + }, + { + "label": "Lebonyba küldés", + "processor": "UNCTargetProcessor", + "outputFormat": "%ID%", + "tag": "Lebony", "killDateDays": 7, "remote": { - "address": "file://10.10.1.100/BRAAVOS/PLAYOUT_CHECK1", + "address": "file://10.10.1.100/BRAAVOS/PLAYOUT_CHECK", "timeout": 1000 } }, diff --git a/client/Maestro/Connected Services/packages.config b/client/Maestro/Connected Services/packages.config new file mode 100644 index 00000000..9d5a51e0 --- /dev/null +++ b/client/Maestro/Connected Services/packages.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/client/Maestro/Maestro.csproj b/client/Maestro/Maestro.csproj index 89dd49a8..829a37f0 100644 --- a/client/Maestro/Maestro.csproj +++ b/client/Maestro/Maestro.csproj @@ -172,6 +172,7 @@ + @@ -255,9 +256,13 @@ Form - + PreserveNewest + + PreserveNewest + + PreserveNewest @@ -288,10 +293,10 @@ PreserveNewest - + PreserveNewest - + PreserveNewest diff --git a/client/Maestro/MaestroForm.Target.cs b/client/Maestro/MaestroForm.Target.cs index 71c25848..8fbc5258 100644 --- a/client/Maestro/MaestroForm.Target.cs +++ b/client/Maestro/MaestroForm.Target.cs @@ -44,7 +44,7 @@ namespace Maestro { private void CreateTarget(Target target) { logger.Debug("Creating target {0}", target); CheckBox checkBox = new CheckBox() { - Appearance = Appearance.Button, + Appearance = Appearance.Normal, Text = target.Label, UseVisualStyleBackColor = true, Dock = DockStyle.Top diff --git a/client/Maestro/Targets/FTPTargetProcessor.cs b/client/Maestro/Targets/FTPTargetProcessor.cs index ca068c90..a7c0cc25 100644 --- a/client/Maestro/Targets/FTPTargetProcessor.cs +++ b/client/Maestro/Targets/FTPTargetProcessor.cs @@ -6,6 +6,7 @@ using System.IO; using System.Net; using System.Windows.Forms; using Model; +using System.Threading; namespace Maestro.Targets { @@ -43,7 +44,14 @@ namespace Maestro.Targets { } protected override bool FileExists(string path) { - return targetFTP.FileExists(path); + long x = -1; + try { + x = targetFTP.GetFileSize(path); + } + catch (Exception e) { + logger.Warn(e.Message); + } + return x > -1; } protected override void EnsureDirectoryExistence(string path) { @@ -68,6 +76,7 @@ namespace Maestro.Targets { protected void TerminateClient(FtpClient ftpClient) { if (ftpClient != null) { + Thread.Sleep(500); ftpClient.Disconnect(); ftpClient.Dispose(); } diff --git a/client/Maestro/Targets/UNCTargetProcessor.cs b/client/Maestro/Targets/UNCTargetProcessor.cs index 7d751ab8..6dc8c9b2 100644 --- a/client/Maestro/Targets/UNCTargetProcessor.cs +++ b/client/Maestro/Targets/UNCTargetProcessor.cs @@ -52,7 +52,7 @@ namespace Maestro.Targets { workingDir = DetermineWorkingDirectory(parameters.TargetConfig.Remote); EnsureDirectoryExistence(workingDir); OutputName = CreateOutputFileName(); - Output = Path.Combine(workingDir, OutputName); + Output = "/".Equals(workingDir) ? OutputName : Path.Combine(workingDir, OutputName); workFlowAction.source = Input; workFlowAction.destination = Output; Status = "Folyamatban"; @@ -191,14 +191,15 @@ namespace Maestro.Targets { protected virtual string CreateOutputFileName() { string nameWithoutExtension = parameters.TargetConfig.OutputFormat.Replace("%ID%", ID).Replace("%SOURCENAME%", Path.GetFileNameWithoutExtension(InputName)); - string extension = InputName.Contains(".") ? InputName.Substring(InputName.LastIndexOf(".")) : DEFAULT_EXTENSION; string result = String.Format(FILENAME, nameWithoutExtension, extension); int version = 1; - while (FileExists(Path.Combine(workingDir, result))) { + string target = "/".Equals(workingDir) ? result : Path.Combine(workingDir, result); + while (FileExists(target)) { string versioned = String.Format(VERSIONED_FILENAME, nameWithoutExtension, version, extension); logger.Debug(ALREADY_EXISTS, result, versioned); result = versioned; + target = "/".Equals(workingDir) ? result : Path.Combine(workingDir, result); version++; } return result;