public string GetFileName(string filePath, IOutFileDef fileDef)
            {
                if (fileDef == null)
                {
                    Log.Warn(String.Format("Output FileDef is null for file '{0}'", filePath));
                    return(filePath.TrimStart(new[] { '/', '\\' }));
                }

                string folder = String.IsNullOrEmpty(filePath)? "/": Path.GetDirectoryName(filePath);

                folder = fileDef.Path ?? folder;
                folder = folder.Trim(new[] { '/', '\\' }) + "/";
                if (folder == "/")
                {
                    folder = "";
                }

                string fileName = fileDef.ExpectedName;

                if (String.IsNullOrEmpty(fileName))
                {
                    fileName = Path.GetFileName(filePath);
                }

                return((folder + fileName.TrimStart(new[] { '/', '\\' })).Replace('\\', '/'));
            }
            public string GetSlotName(IOutFileDef fileDef)
            {
                if (fileDef == null)
                {
                    Log.Warn("Output FileDef is null for some file. Setting slot name to 'none'");
                    return("none");
                }

                return(fileDef.Name);
            }
            public long OutputFileCopy(IOutFileDef fileDef, string filePath, DynamicContext ctx)
            {
                _filesToCopyFromFTP.Add(Tuple.Create(
                                            new TaskFileDescription {
                    FileName = GetFileName(filePath, fileDef),
                    SlotName = GetSlotName(fileDef)
                },
                                            filePath
                                            ));

                string ftpPath = _ftpRoot + filePath.TrimStart(new[] { '/', '\\' });

                return(IOProxy.Ftp.GetFileSize(ftpPath));
            }
            public OpenFileResult OutputFileOpenRead(IOutFileDef fileDef, string filePath, DynamicContext ctx)
            {
                string ftpPath     = _ftpRoot + filePath.TrimStart(new[] { '/', '\\' });
                string tmpFilePath = Path.GetTempFileName();

                Log.Debug("Downloading file for PB: " + ftpPath);
                IOProxy.Ftp.DownloadFile(ftpPath, tmpFilePath);
                Log.Debug("Downloading file done: " + ftpPath);
                _tmpFilesToDel.Add(tmpFilePath);

                var res = new OpenFileResult()
                {
                    FilePath = filePath,
                    Stream   = File.OpenRead(tmpFilePath)
                };

                return(res);
            }
            public string GetFileName(string filePath, IOutFileDef fileDef)
            {
                if (fileDef == null)
                {
                    Log.Warn(String.Format("Output FileDef is null for file '{0}'", filePath));
                    return filePath.TrimStart(new[] { '/', '\\' });
                }

                string folder = String.IsNullOrEmpty(filePath)? "/": Path.GetDirectoryName(filePath);
                folder = fileDef.Path ?? folder;
                folder = folder.Trim(new[] { '/', '\\' }) + "/";
                if (folder == "/")
                    folder = "";

                string fileName = fileDef.ExpectedName;
                if (String.IsNullOrEmpty(fileName))
                    fileName = Path.GetFileName(filePath);

                return (folder + fileName.TrimStart(new[] { '/', '\\' })).Replace('\\', '/');
            }
            public OpenFileResult OutputFileOpenWrite(IOutFileDef fileDef, DynamicContext ctx)
            {
                string tmpFilePath = Path.GetTempFileName();

                _tmpFilesToDel.Add(tmpFilePath);

                string fileName = GetFileName("", fileDef);

                _filesToCopyFromTmp.Add(Tuple.Create(
                                            new TaskFileDescription {
                    FileName = fileName,
                    SlotName = GetSlotName(fileDef)
                },
                                            tmpFilePath
                                            ));

                var res = new OpenFileResult()
                {
                    FilePath = fileName,
                    Stream   = File.OpenWrite(tmpFilePath)
                };

                return(res);
            }
            public OpenFileResult OutputFileOpenWrite(IOutFileDef fileDef, DynamicContext ctx)
            {
                string tmpFilePath = Path.GetTempFileName();
                _tmpFilesToDel.Add(tmpFilePath);

                string fileName = GetFileName("", fileDef);
                _filesToCopyFromTmp.Add(Tuple.Create(
                    new TaskFileDescription {
                        FileName = fileName,
                        SlotName = GetSlotName(fileDef)
                    },
                    tmpFilePath
                ));

                var res = new OpenFileResult()
                {
                    FilePath = fileName,
                    Stream = File.OpenWrite(tmpFilePath)
                };

                return res;
            }
            public OpenFileResult OutputFileOpenRead(IOutFileDef fileDef, string filePath, DynamicContext ctx)
            {
                string ftpPath = _ftpRoot + filePath.TrimStart(new[] { '/', '\\' });
                string tmpFilePath = Path.GetTempFileName();

                Log.Debug("Downloading file for PB: " + ftpPath);
                IOProxy.Ftp.DownloadFile(ftpPath, tmpFilePath);
                Log.Debug("Downloading file done: " + ftpPath);
                _tmpFilesToDel.Add(tmpFilePath);

                var res = new OpenFileResult()
                {
                    FilePath = filePath,
                    Stream = File.OpenRead(tmpFilePath)
                };

                return res;
            }
            public long OutputFileCopy(IOutFileDef fileDef, string filePath, DynamicContext ctx)
            {
                _filesToCopyFromFTP.Add(Tuple.Create(
                    new TaskFileDescription {
                        FileName = GetFileName(filePath, fileDef),
                        SlotName = GetSlotName(fileDef)
                    },
                    filePath
                ));

                string ftpPath = _ftpRoot + filePath.TrimStart(new[] { '/', '\\' });
                return IOProxy.Ftp.GetFileSize(ftpPath);
            }
            public string GetSlotName(IOutFileDef fileDef)
            {
                if (fileDef == null)
                {
                    Log.Warn("Output FileDef is null for some file. Setting slot name to 'none'");
                    return "none";
                }

                return fileDef.Name;
            }