// Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Delimiter.Expression != null)
            {
                targetCommand.AddParameter("Delimiter", Delimiter.Get(context));
            }

            if (PropertyNames.Expression != null)
            {
                targetCommand.AddParameter("PropertyNames", PropertyNames.Get(context));
            }

            if (TemplateFile.Expression != null)
            {
                targetCommand.AddParameter("TemplateFile", TemplateFile.Get(context));
            }

            if (TemplateContent.Expression != null)
            {
                targetCommand.AddParameter("TemplateContent", TemplateContent.Get(context));
            }

            if (IncludeExtent.Expression != null)
            {
                targetCommand.AddParameter("IncludeExtent", IncludeExtent.Get(context));
            }

            if (UpdateTemplate.Expression != null)
            {
                targetCommand.AddParameter("UpdateTemplate", UpdateTemplate.Get(context));
            }

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
        /// <summary>
        /// Execute Activity
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            var row        = Row.Get(context);
            var sourceText = string.Empty;

            if ((UTF8.Get(context) ? 1 : 0)
                + (Unicode.Get(context)? 1 : 0)
                + (Shift_JIS.Get(context) ? 1 : 0) != 1)
            {
                throw new ArgumentException("Invalid choice at Encoding");
            }

            Encoding enc;

            if (Shift_JIS.Get(context))
            {
                enc = Encoding.GetEncoding(932);
            }
            else if (Unicode.Get(context))
            {
                enc = Encoding.Unicode;
            }
            else
            {
                enc = Encoding.UTF8;
            }

            using (var reader = new System.IO.StreamReader(TemplateFile.Get(context), enc))
            {
                sourceText = reader.ReadToEnd();
            }

            foreach (DataColumn c in row.Table.Columns)
            {
                sourceText = sourceText.Replace("%%%_" + c.ColumnName + "_%%%", row[c].ToString());
            }

            if (CheckEscapeStringRemining.Get(context))
            {
                var r = new System.Text.RegularExpressions.Regex("^.*%%%_.*_%%%.*$");
                if (r.IsMatch(sourceText))
                {
                    throw new ApplicationException("Escape Characters is remining.");
                }
            }

            Result.Set(context, sourceText);
        }