public TargetDevicePS4(bool UseDevice, string Platform, string Role, string Name, string Address, string Username, string Password, int CpuAffinity, string DeploymentPath, string CmdLineArguments)
     : base(UseDevice, Platform, Role, Name, Address, Username, Password, CpuAffinity, DeploymentPath, CmdLineArguments)
 {
     this.Logger        = new FileLogger(this);
     this.OrbisCtrlProc = null;
     this.TargetManager = new ORTMAPI();
     this.TargetManager.CheckCompatibility((uint)eCompatibleVersion.BuildVersion);
 }
        private bool DistributedCopy(OrbisCtrl OrbisCtrlProc, string Hostname, string SourcePath, string DestPath, int RetryCount = 5) //, Utils.SystemHelpers.CopyOptions Options = Utils.SystemHelpers.CopyOptions.Copy, int RetryCount = 5)
        {
            bool IsDirectory = false;

            if (Directory.Exists(SourcePath))
            {
                IsDirectory = true;
            }

            if (!File.Exists(SourcePath) && !IsDirectory)
            {
                return(false);
            }

            // Setup dcopy arguments
            List <string> CopyArgs = new List <string>()
            {
                "dcopy"
            };

            // Source path
            CopyArgs.Add(string.Format("\"{0}\"", SourcePath.Trim(new char[] { ' ', '"' })));

            // Destination path
            CopyArgs.Add(string.Format("\"{0}\"", DestPath));

            // Directory options
            if (IsDirectory)
            {
                CopyArgs.Add("/recursive");

                //if ((Options & Utils.SystemHelpers.CopyOptions.Mirror) == Utils.SystemHelpers.CopyOptions.Mirror)
                {
                    CopyArgs.Add("/mirror");
                }
            }

            if (RetryCount > 0)
            {
                CopyArgs.Add(String.Format("/retry-count:{0}", Math.Min(RetryCount, 5)));
            }

            // This forces copy whether source and dest are reported matching or not...
            // (enable if issues with src/dst matches are being incorrectly identified
            // CopyArgs.Add("/force");

            // @todo: support device copy for same build to multiple devices
            CopyArgs.Add(Hostname);

            // @todo: we could generate a copy time estimate based on file sizes and gigabit copy or add option
            // This is currently set to 45 minutes due to current network issue, should be more like 15 minutes
            //const int WaitTimeMinutes = 45 * 60;

            // don't warn on dcopy timeouts, these are generally due to slow network conditions and are not actionable
            // for other failures, an exception is raised
            if (!OrbisCtrlProc.Execute(String.Join(" ", CopyArgs)))
            {
                return(false);
            }

            int ExitCode = 0;

            while (!OrbisCtrlProc.HasExited(out ExitCode))
            {
                if (Token.IsCancellationRequested)
                {
                    OrbisCtrlProc.Kill();

                    Callback.OnBuildDeployedAborted(this, Build);

                    return(false);
                }

                //Callback.OnFileDeployed(this, "Dummy");

                Logger.Info(string.Format("Copying files to PS4 device {0}", Address));

                Thread.Sleep(1000);
            }

            return(true);
        }
        public override bool DeployBuild(BuildNode Build, IDeploymentSession Callback, CancellationToken Token)
        {
            try
            {
                this.Build    = Build;
                this.Callback = Callback;
                this.Token    = Token;

                OrbisCtrlProc = new OrbisCtrl(this, Logger, Callback, Token);

                if (!ResetProgress())
                {
                    return(CheckCancelationRequestAndReport());
                }

                Build.Progress++;

                // Add PS4 to Neighborhood.
                ITarget Target = TargetManager.AddTarget(Address);

                SetMappedDirectory(Target);

                LogDeviceDetails(Target);

                Build.Progress++;

                if (Target.PowerStatus != ePowerStatus.POWER_STATUS_ON)
                {
                    Target.PowerOn();
                }

                if (!OrbisCtrlProc.Execute("pkill"))
                {
                    return(false);
                }

                int ExitCode = 0;
                while (!OrbisCtrlProc.HasExited(out ExitCode))
                {
                    if (Token.IsCancellationRequested)
                    {
                        OrbisCtrlProc.Kill();

                        Callback.OnBuildDeployedAborted(this, Build);

                        return(false);
                    }

                    Logger.Info(string.Format("Waiting for PS4 process to exit on PS4 device {0}", Address));
                }

                Build.Progress++;

                if (!InstallPackage())
                {
                    return(CheckCancelationRequestAndReport());
                }

                Build.Progress++;

                Callback.OnBuildDeployed(this, Build);
            }
            catch (Exception e)
            {
                Callback.OnBuildDeployedError(this, Build, e.Message);

                Logger.Error(string.Format("Failed to deploy build to PS4 device '{0}'. Ex: {1}", Address, e.Message));
            }
            return(false);
        }