public DateTime UpdateMediaFiles(DirectoryInfo diMedia, DirectoryInfo diVeg, string subMedia, RenderStatusManager rsm, object dr)
        {
            DirectoryInfo mediaDirectory         = null;
            string        mediaDirectoryFullName = Path.Combine(diVeg.FullName, subMedia);

            mediaDirectory = new DirectoryInfo(mediaDirectoryFullName);

            DateTime lastFileModified = DateTime.MinValue;
            int      filesCopied      = 0;

            foreach (FileInfo fiMedia in diMedia.GetFiles())
            {
                switch (fiMedia.Extension.ToLower())
                {
                // List of file types to copy
                case ".jpg":
                case ".gif":
                case ".png":
                case ".psd":
                case ".tif":
                    if (mediaDirectory.Exists)
                    {
                        string   targetName = Path.Combine(mediaDirectory.FullName, fiMedia.Name);
                        FileInfo fiTarget   = new FileInfo(targetName);
                        if (!fiTarget.Exists ||
                            fiTarget.LastWriteTimeUtc < fiMedia.LastWriteTimeUtc ||
                            fiTarget.Length == 0)
                        {
                            System.Diagnostics.Debug.WriteLine("Copying {0} to {1}", fiMedia.Name, mediaDirectory.FullName);
                            fiMedia.CopyTo(targetName, true);
                            filesCopied++;
                        }
                    }
                    break;

                default:
                    // Do nothing
                    break;
                }
            }
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.MediaFilesCopied, filesCopied);

            // Find the last modified tile for the media directory (if it exists)
            if (mediaDirectory.Exists)
            {
                foreach (FileInfo fi in mediaDirectory.GetFiles())
                {
                    if (fi.LastWriteTimeUtc > lastFileModified)
                    {
                        lastFileModified = fi.LastWriteTimeUtc;
                    }
                }
            }
            return(lastFileModified);
        }
        public bool ProcessFile(FileInfo fiVeg, DirectoryInfo diMedia, string subMedia, string subRender,
                                RenderTemplate renderTemplate, RenderStatusManager rsm)
        {
            object   dr           = rsm.StartProjectProcessing(fiVeg);
            DateTime lastMedia    = UpdateMediaFiles(diMedia, fiVeg.Directory, subMedia, rsm, dr);
            FileInfo renderedFile = GetRenderedFile(fiVeg, subRender);

            if ((!renderedFile.Exists ||
                 renderedFile.LastWriteTimeUtc < fiVeg.LastWriteTimeUtc ||
                 renderedFile.LastWriteTimeUtc < lastMedia ||
                 renderedFile.Length == 0) && renderedFile.Directory.Exists)
            {
                return(RenderFile(fiVeg, renderedFile, renderTemplate, rsm, dr));
            }
            else
            {
                rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStatus, "Skipped");
            }
            return(false);
        }
        public bool RenderFile(FileInfo fiVeg, FileInfo fiRendered, RenderTemplate renderTemplate, RenderStatusManager rsm, object dr)
        {
            DateTime renderStart = DateTime.Now;
            DateTime renderEnd;
            TimeSpan renderTime;

            rsm.Dialog.Hide(); // Temporarily hide because during load the UX kills it.
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStart, renderStart);
            if (myVegas.Project != null)
            {
                // No close method so create a clean new project without the ability to prompt for save of existing
                // and then open after that.
                myVegas.NewProject(false, false);
            }
            myVegas.UpdateUI();
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStatus, "Loading");
            myVegas.OpenFile(fiVeg.FullName);
            myVegas.UpdateUI();
            myVegas.WaitForIdle();
            rsm.Dialog.Show();

            // Render
            RenderArgs ra = new RenderArgs();

            ra.OutputFile     = fiRendered.FullName;
            ra.RenderTemplate = renderTemplate;
            Timecode projectLength = GetProjectLength();

            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.ProjectLength, projectLength);
            ra.Length     = projectLength;
            ra.StartNanos = 0;

            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStatus, "Rendering");
            RenderStatus status = myVegas.Render(ra);

            renderEnd  = DateTime.Now;
            renderTime = renderEnd - renderStart;
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderEnd, renderEnd);
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderTime, renderTime);
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStatus, status.ToString());
            return(status == RenderStatus.Complete);
        }