Esempio n. 1
0
        protected override IEnumerable <CommandParameters> Execute(IEnumerable <CommandParameters> inParametersList)
        {
            foreach (var inParameters in inParametersList)
            {
                //inParameters = GetCurrentInParameters();
                string sourceFile       = inParameters.GetValue <string>("SourceFile");
                string targetDirectory  = inParameters.GetValueOrDefault <string>("TargetDirectory", Path.Combine(Path.GetDirectoryName(sourceFile), @"\{yyyy}\{MM}\"));
                string zipName          = inParameters.GetValueOrDefault <string>("ZipName", Path.GetFileNameWithoutExtension(sourceFile) + ".zip");
                string password         = inParameters.GetValue <string>("Password");
                bool   removeSourceFile = inParameters.GetValueOrDefault <bool>("RemoveSourceFile", true);

                zipName = TokenProcessor.ReplaceToken(zipName, "SourceFileName", Path.GetFileName(sourceFile));

                DirectoryUtil.CreateDirectoryIfNotExists(targetDirectory);

                var targetFile = Path.Combine(targetDirectory, zipName);
                this.ZipFile(sourceFile, targetFile, password);

                if (removeSourceFile)
                {
                    File.Delete(sourceFile);
                }

                this.LogDebug(string.Format("Zipping archive='{0}'", targetFile));

                var outParameters = this.GetCurrentOutParameters();
                outParameters.SetOrAddValue("File", targetFile);
                yield return(outParameters);
            }
        }
        private string ApplyDataMappings(string sql, IDictionary <string, object> parameters)
        {
            // prepare the sql and set the values
            if (this.DataMappings.Any())
            {
                foreach (var dataMapping in this.DataMappings)
                {
                    if (dataMapping.Value != null)
                    {
                        // replace token in the datamapping value e.g. ["Filename"]="{Filename}" -> ["Filename"]="C:\Temp\Test.txt"
                        string value = TokenProcessor.ReplaceTokens(dataMapping.Value.ToStringOrEmpty(), parameters);
                        // Replace the tokens in the sql template e.g. "SELECT * FROM tb_test WHERE ID = {Id}"
                        sql = TokenProcessor.ReplaceToken(sql, dataMapping.Name, value);
                    }
                }
            }
            else
            {
                sql = TokenProcessor.ReplaceTokens(sql, parameters);
            }

            return(sql);
        }