protected override void ExecuteInternal(CmdExecutionContext context, CancellationToken token)
        {
            InitializeProgress();

            //Cancel if requested;
            token.ThrowIfCancellationRequested();

            String sourceFullPath = Command.SourcePath.GetAbsoluteOrPrependIfRelative(context.InstallerSourceDirectory);

            if (!File.Exists(sourceFullPath))
            {
                throw new CmdExecutionFailedException(
                          String.Format("One of the commands refers to a non-existing source file: \"{0}\" ", Command.SourcePath),
                          DefaultExecutionErrorMsg);
            }

            String targetfullPath = Command.TargetPath.GetAbsoluteOrPrependIfRelative(context.InstallerTargetDirectory);

            if (!File.Exists(targetfullPath))
            {
                throw new CmdExecutionFailedException(
                          String.Format("One of the commands refers to a non-existing target file: \"{0}\"", Command.TargetPath),
                          DefaultExecutionErrorMsg);
            }

            String contentPath = Command.NestedTargetPath.LastPart;

            if (contentPath == null)
            {
                throw new CmdExecutionFailedException(
                          "One of the commands has an invalid targetContentPath value.",
                          DefaultExecutionErrorMsg);
            }

            //var containerFileReader = new EdataFileReader();
            //var containerFile = CanGetTargetContainerFromContext(context) ?
            //    GetTargetContainerFromContext(context) :
            //    containerFileReader.Read(targetfullPath, false);

            var containerFile = GetTargetContainerFromContext(context);
            var data          = new CmdsExecutionData
            {
                ContainerFile = containerFile,
                //ContainerPath = targetfullPath,
                ContentPath            = contentPath,
                ModificationSourcePath = sourceFullPath,
            };

            ExecuteCommandsLogic(data);

            //if (!CanGetTargetContainerFromContext(context))
            //{
            //    SaveTargetContainerFile(containerFile, token);
            //}

            SetMaxProgress();
        }
        protected IContainerFile GetTargetContainerFromContext(CmdExecutionContext context)
        {
            var sharedContainerContext = context as SharedContainerCmdExecContext;

            if (sharedContainerContext == null ||
                sharedContainerContext.ContainerFile == null)
            {
                throw new InvalidOperationException("Cannot obtain a container file from the given execution context.");
            }

            return(sharedContainerContext.ContainerFile);
        }
        /// <summary>
        /// Executes a wrapped command.
        /// </summary>
        /// <param name="context">Context of execution.</param>
        /// <param name="token"></param>
        public virtual void Execute(CmdExecutionContext context, CancellationToken token)
        {
            try
            {
                ExecuteInternal(context, token);
            }
            catch (Exception ex)
            {
                if (Command.IsCritical)
                {
                    throw;
                }

                WargameModInstaller.Common.Logging.LoggerFactory.Create(this.GetType()).Error(ex);
            }
        }
Esempio n. 4
0
 public abstract void Execute(CmdExecutionContext context, CancellationToken token);
Esempio n. 5
0
 public virtual void Execute(CmdExecutionContext context)
 {
     Execute(context, CancellationToken.None);
 }
 protected abstract void ExecuteInternal(CmdExecutionContext context, CancellationToken token);