Exemplo n.º 1
0
        private List <ExecutableAction> CreateActionsForFile(FileInfo fileInfo)
        {
            var actions = new List <ExecutableAction>();

            foreach (string profile in AppSettings.Default.TranscodingProfiles)
            {
                var    profileParts   = profile.Split('|');
                string profileName    = profileParts[0].Trim();
                string profileCommand = profileParts[1].Trim();

                string outputFileNameShort =
                    Path.GetFileNameWithoutExtension(fileInfo.Name) +
                    "-" + profileName + ".mp4";
                string outputFileNameFull = this.workDir + "\\" + outputFileNameShort;

                TranscodeAction transcodeAction = new TranscodeAction()
                {
                    Description        = $"Transcoding {fileInfo.Name} to {profileName}",
                    InputFile          = fileInfo.FullName,
                    TranscodingCommand = profileCommand
                                         .Replace("{input}", '"' + fileInfo.FullName + '"')
                                         .Replace("{output}", '"' + outputFileNameFull + '"'),
                    OutputFile = outputFileNameFull
                };
                transcodeAction.ExecutionStateChanged += TranscodeAction_ExecutionStateChanged;
                transcodeAction.ErrorOccurred         += TranscodeAction_ErrorOccurred;
                actions.Add(transcodeAction);

                string ftpPath = this.textBoxFTPPath.Text;
                if (!ftpPath.EndsWith("/"))
                {
                    ftpPath = ftpPath + "/";
                }
                UploadAction uploadAction = new UploadAction()
                {
                    Description = $"Uploading {outputFileNameShort} to FTP folder {ftpPath}",
                    InputFile   = outputFileNameFull,
                    FtpClient   = new FtpClient(
                        this.ftpClient.Host,
                        this.ftpClient.Credentials
                        ),
                    PathAtFTP       = ftpPath + outputFileNameShort,
                    DependsOnAction = transcodeAction
                };
                uploadAction.FtpClient.DataConnectionType = this.ftpClient.DataConnectionType;
                uploadAction.FtpClient.SocketKeepAlive    = this.ftpClient.SocketKeepAlive;
                uploadAction.ExecutionStateChanged       += UploadAction_ExecutionStateChanged;
                uploadAction.ErrorOccurred += UploadAction_ErrorOccurred;
                actions.Add(uploadAction);
            }

            return(actions);
        }
Exemplo n.º 2
0
        private void TranscodeAction_ExecutionStateChanged(object sender, EventArgs e)
        {
            TranscodeAction action = sender as TranscodeAction;

            if (action.ExecutionState == ExecutionState.Running)
            {
                this.Log($"Transcoding <b>started</b>: <code>{action.Description}</code>", indentTabs: 1);
            }
            else if (action.ExecutionState == ExecutionState.CompletedSuccessfully)
            {
                this.Log($"Transcoding <b>successful</b>: <code>{action.Description}</code>", indentTabs: 1);
            }
            else if (action.ExecutionState == ExecutionState.Failed)
            {
                this.Log($"Transcoding <b>failed</b>: <code>{action.Description}</code>", indentTabs: 1);
            }
            else if (action.ExecutionState == ExecutionState.Canceled)
            {
                this.Log($"Transcoding <b>canceled</b>: <code>{action.Description}</code>", indentTabs: 1);
            }
        }