Exemple #1
0
 /// <summary>
 /// Executes the Configuration task
 /// </summary>
 /// <param name="messageBack">Message sent back to the server</param>
 /// <param name="jobs">List of Jobs</param>
 public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
 {
     messageBack(0, "Set config to: " + _configName);
     Server.SetCurrentJob("Setting up new config");
     ClientServices.ConfigName = _configName;
     ClientServices.ReDoSetup();
 }
Exemple #2
0
        public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
        {
            messageBack(0, "Checking the LightWave setup on the Client");
            Server.SetCurrentJob("Setting up client");

            List<string> progs = Server.GetSetupFileList();
            List<string> support = Server.GetSupportFileList();
            List<string> plugins = Server.GetPluginFileList();
            List<string> config = Server.GetConfigFileList();
            List<string> extPlugins = Server.GetExtPluginFileList();

            lock (jobs)
            {
                foreach (string s in progs)
                    jobs.Enqueue(new DownloadProgJob(s, _forceDownload));

                foreach (string s in support)
                    jobs.Enqueue(new DownloadSupportJob(s, _forceDownload));

                foreach (string s in plugins)
                    jobs.Enqueue(new DownloadPluginJob(s, _forceDownload));

                foreach (string s in extPlugins)
                    jobs.Enqueue(new DownloadExtraPluginsJob(s, _forceDownload));

                foreach (string s in config)
                    jobs.Enqueue(new DownloadConfigJob(s));

                jobs.Enqueue(new ClientReadyJob());
            }
        }
 /// <summary>
 /// Executes the Configuration task
 /// </summary>
 /// <param name="messageBack">Message sent back to the server</param>
 /// <param name="jobs">List of Jobs</param>
 public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
 {
     messageBack(0, "Set config to: " + _configName);
     Server.SetCurrentJob("Setting up new config");
     ClientServices.ConfigName = _configName;
     ClientServices.ReDoSetup();
 }
Exemple #4
0
        public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
        {
            string localPath = Path.Combine(Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName), "Plugins");
            string localFile = Path.Combine(localPath, _file);

            Directory.CreateDirectory(localPath);

            try
            {
                FileInfo remote = Server.GetFileInfo(FileType.Plugin, _file);

                bool needToDownload = false;
                if (!File.Exists(localFile) || _force)
                {
                    needToDownload = true;
                }
                else
                {
                    FileInfo local = new FileInfo(localFile);
                    if (remote.LastWriteTimeUtc != local.LastWriteTimeUtc || remote.Length != local.Length)
                    {
                        needToDownload = true;
                    }
                }

                if (needToDownload)
                {
                    messageBack(0, "Downloading plugin " + _file);
                    byte[] res = Server.GetFile(FileType.Plugin, _file);
                    Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                    if (res.Length > 0)
                    {
                        FileStream stream = File.Create(localFile, res.Length);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        // Create empty file
                        FileStream stream = File.Create(localFile);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }

                    FileInfo local = new FileInfo(localFile);
                    local.LastWriteTimeUtc = remote.LastWriteTimeUtc;
                    messageBack(0, "Saved at " + _file);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unable to download plugin: " + _file);
            }
        }
        public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
        {
            string localFolder = Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName);
            localFolder = Path.Combine(localFolder, "Program");
            string localFile = Path.Combine(localFolder, _file);
            string destinationFolder = Path.GetDirectoryName(localFile);

            try
            {
                Directory.CreateDirectory(localFolder);
                if (destinationFolder != null)
                    Directory.CreateDirectory(destinationFolder);

                FileInfo remote = Server.GetFileInfo(FileType.Program, _file);

                bool needToDownload = false;
                if (!File.Exists(localFile) || _force)
                    needToDownload = true;
                else
                {
                    FileInfo local = new FileInfo(localFile);
                    if (remote.LastWriteTimeUtc != local.LastWriteTimeUtc || remote.Length != local.Length)
                        needToDownload = true;
                }

                if (needToDownload)
                {
                    messageBack(0, "Downloading setup prog " + _file);
                    byte[] res = Server.GetFile(FileType.Program, _file);
                    Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                    if (res.Length > 0)
                    {
                        FileStream stream = File.Create(localFile, res.Length);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        // Create empty file
                        FileStream stream = File.Create(localFile);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    FileInfo local = new FileInfo(localFile);
                    local.LastWriteTimeUtc = remote.LastWriteTimeUtc;
                    messageBack(0, "Saved at " + _file);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unable to download file: " + _file);
            }
        }
Exemple #6
0
        public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
        {
            string localPath = Path.Combine(ClientServices.GetClientDir(), "Content");
            string localFile = Path.Combine(localPath, _localFile);

            Directory.CreateDirectory(localPath);

            bool needToDownload = false;

            if (!File.Exists(localFile))
            {
                needToDownload = true;
            }
            else
            {
                FileInfo f = new FileInfo(localFile);
                if (f.LastWriteTimeUtc != _modDate || f.Length != _size)
                {
                    needToDownload = true;
                }
            }

            if (needToDownload)
            {
                try
                {
                    messageBack(0, "Downloading " + _remoteFile);
                    byte[] res = Server.GetFile(FileType.Absolute, _remoteFile);
                    Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                    if (res.Length > 0)
                    {
                        FileStream stream = File.Create(localFile, res.Length);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        // Create empty file
                        FileStream stream = File.Create(localFile);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }

                    FileInfo f = new FileInfo(localFile);
                    f.LastWriteTimeUtc = _modDate;
                    messageBack(0, "Saved at " + _localFile);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Unable to download job: " + _remoteFile);
                }
            }
        }
        public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
        {
            try
            {
                string remoteFileName = Path.GetFileName(_file);
                string localPath = Path.Combine(Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName), "ExtPlugins");
                string localFile = Path.Combine(localPath, remoteFileName);
                Directory.CreateDirectory(localPath);

                FileInfo remote = Server.GetFileInfo(FileType.Absolute, _file);

                bool needToDownload = false;
                if (!File.Exists(localFile) || _force)
                    needToDownload = true;
                else
                {
                    FileInfo local = new FileInfo(localFile);
                    if (remote.LastWriteTimeUtc != local.LastWriteTimeUtc || remote.Length != local.Length)
                        needToDownload = true;
                }

                if (needToDownload)
                {
                    messageBack(0, "Downloading plugin " + Path.GetFileName(_file));
                    byte[] res = Server.GetFile(FileType.Absolute, _file);
                    Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                    if (res.Length > 0)
                    {
                        FileStream stream = File.Create(localFile, res.Length);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        // Create empty file
                        FileStream stream = File.Create(localFile);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    FileInfo local = new FileInfo(localFile);
                    local.LastWriteTimeUtc = remote.LastWriteTimeUtc;
                    messageBack(0, "Saved at " + remoteFileName);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unable to download plugin: " + _file);
            }
        }
Exemple #8
0
        public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
        {
            string localPath = Path.Combine(ClientServices.GetClientDir(), "Content");
            string localFile = Path.Combine(localPath, _localFile);
            Directory.CreateDirectory(localPath);

            bool needToDownload = false;
            if (!File.Exists(localFile))
                needToDownload = true;
            else
            {
                FileInfo f = new FileInfo(localFile);
                if (f.LastWriteTimeUtc != _modDate || f.Length != _size)
                    needToDownload = true;
            }

            if (needToDownload)
            {
                try
                {
                    messageBack(0, "Downloading " + _remoteFile);
                    byte[] res = Server.GetFile(FileType.Absolute, _remoteFile);
                    Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                    if (res.Length > 0)
                    {
                        FileStream stream = File.Create(localFile, res.Length);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        // Create empty file
                        FileStream stream = File.Create(localFile);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }

                    FileInfo f = new FileInfo(localFile);
                    f.LastWriteTimeUtc = _modDate;
                    messageBack(0, "Saved at " + _localFile);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Unable to download job: " + _remoteFile);
                }
            }
        }
Exemple #9
0
        public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
        {
            messageBack(0,"Waiting for first node to be ready...");

            while (Server.IsFirstClientReady() == false)
            {
                if (ClientServices.IsRunning == false)
                {
                    messageBack(0,"Need to quit.");
                    return;
                }
                System.Threading.Thread.Sleep(100);
            }

            messageBack(0,"Done, let's continue then.");
        }
Exemple #10
0
        public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
        {
            messageBack(0, "Waiting for first node to be ready...");

            while (Server.IsFirstClientReady() == false)
            {
                if (ClientServices.IsRunning == false)
                {
                    messageBack(0, "Need to quit.");
                    return;
                }
                System.Threading.Thread.Sleep(100);
            }

            messageBack(0, "Done, let's continue then.");
        }
Exemple #11
0
        public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
        {
            messageBack(0, "Checking the LightWave setup on the Client");
            Server.SetCurrentJob("Setting up client");

            List <string> progs      = Server.GetSetupFileList();
            List <string> support    = Server.GetSupportFileList();
            List <string> plugins    = Server.GetPluginFileList();
            List <string> config     = Server.GetConfigFileList();
            List <string> extPlugins = Server.GetExtPluginFileList();

            lock (jobs)
            {
                foreach (string s in progs)
                {
                    jobs.Enqueue(new DownloadProgJob(s, _forceDownload));
                }

                foreach (string s in support)
                {
                    jobs.Enqueue(new DownloadSupportJob(s, _forceDownload));
                }

                foreach (string s in plugins)
                {
                    jobs.Enqueue(new DownloadPluginJob(s, _forceDownload));
                }

                foreach (string s in extPlugins)
                {
                    jobs.Enqueue(new DownloadExtraPluginsJob(s, _forceDownload));
                }

                foreach (string s in config)
                {
                    jobs.Enqueue(new DownloadConfigJob(s));
                }

                jobs.Enqueue(new ClientReadyJob());
            }
        }
Exemple #12
0
        public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
        {
            string baseDir = Path.Combine(ClientServices.GetClientDir(), "Output");

            try
            {
                Directory.Delete(baseDir, true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unable to delete output directory");
            }

            try
            {
                Directory.CreateDirectory(baseDir);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unable to create output directory");
            }
        }
        public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
        {
            string baseDir = Path.Combine(ClientServices.GetClientDir(), "Output");

            try
            {
                Directory.Delete(baseDir,true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unable to delete output directory");
            }

            try
            {
                Directory.CreateDirectory(baseDir);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unable to create output directory");
            }
        }
Exemple #14
0
 public ArchiveExtract(MessageBack messageCallBack)
 {
     MessageCallBack = messageCallBack;
 }
Exemple #15
0
 public abstract void ExecuteJob(MessageBack messageBack, Queue <Job> jobs);
Exemple #16
0
 public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
 {
     messageBack(0, "Should kill render process");
     ClientServices.KillRenderProcess();
 }
Exemple #17
0
 public abstract void ExecuteJob(MessageBack messageBack, Queue<Job> jobs);
Exemple #18
0
 public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
 {
     messageBack(0, "Sending log back to server");
     ReceiverLog(ClientServices.OldMessages);
 }
Exemple #19
0
 public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
 {
     messageBack(0, "Changed priority: " + _priority);
     ClientServices.SetRenderProcessPriority(_priority);
 }
Exemple #20
0
 public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
 {
     messageBack(0,"Should kill render process");
     ClientServices.KillRenderProcess();
 }
Exemple #21
0
 public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
 {
     messageBack(0,"Changed priority: " + _priority);
     ClientServices.SetRenderProcessPriority(_priority);
 }
Exemple #22
0
        public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
        {
            string localPath = Path.Combine(Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName), "Config");
            string localFile = Path.Combine(localPath, _file);

            Directory.CreateDirectory(localPath);
            FileInfo remote = Server.GetFileInfo(FileType.Config, _file);

            bool needToDownload = false;

            if (!File.Exists(localFile))
            {
                needToDownload = true;
            }
            else
            {
                FileInfo local = new FileInfo(localFile);
                if (remote.LastWriteTimeUtc != local.LastWriteTimeUtc || remote.Length != local.Length)
                {
                    needToDownload = true;
                }
            }

            if (needToDownload)
            {
                try
                {
                    messageBack(0, "Downloading config " + _file);

                    byte[] res = Server.GetFile(FileType.Config, _file);
                    Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                    if (res.Length > 0)
                    {
                        FileStream stream = File.Create(localFile, res.Length);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        // Create empty file
                        FileStream stream = File.Create(localFile);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }

                    if (ClientServices.IsMainConfig(localFile))
                    {
                        string[]     lines  = File.ReadAllLines(localFile);
                        StreamWriter writer = new StreamWriter(localFile);
                        foreach (string line in lines)
                        {
                            if (line.StartsWith("DefaultSegmentMemory"))
                            {
                                writer.WriteLine("DefaultSegmentMemory " + (ClientServices.Settings.MemorySegment * 1024 * 1024));
                            }
                            else if (line.StartsWith("RenderThreads"))
                            {
                                writer.WriteLine("RenderThreads " + ClientServices.Settings.NumThreads);
                            }
                            else
                            {
                                writer.WriteLine(line);
                            }
                        }
                        writer.Close();
                        writer.Dispose();
                    }
                    else if (localFile.ToUpper().Contains("LWEXT"))
                    {
                        string[]     lines  = File.ReadAllLines(localFile);
                        StreamWriter writer = new StreamWriter(localFile);
                        foreach (string line in lines)
                        {
                            if (line.ToUpper().Contains("MODULE \"") || line.StartsWith("  Module \""))
                            {
                                // Get the original plugin filename path and replace it with the new path
                                string originalPlugin = line.Replace(@"\\", @"\").Trim();
                                originalPlugin = originalPlugin.Substring(originalPlugin.IndexOf("\"") + 1);
                                originalPlugin = originalPlugin.Replace('\"', ' ').Trim();
                                string name      = Path.GetFileName(originalPlugin);
                                string newPlugin = Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName);
                                newPlugin = Path.Combine(Path.Combine(newPlugin, "ExtPlugins"), name);
                                writer.WriteLine("  Module \"" + newPlugin.Replace(@"\", @"\\") + "\"");
                            }
                            else
                            {
                                writer.WriteLine(line);
                            }
                        }
                        writer.Close();
                        writer.Dispose();
                    }
                    FileInfo local = new FileInfo(localFile);
                    local.LastWriteTimeUtc = remote.LastWriteTimeUtc;
                    messageBack(0, "Saved at " + _file);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Unable to save config file: " + _file);
                }
            }
        }
        public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
        {
            string localPath = Path.Combine(Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName), "Config");
            string localFile = Path.Combine(localPath, _file);

            Directory.CreateDirectory(localPath);
            FileInfo remote = Server.GetFileInfo(FileType.Config, _file);

            bool needToDownload = false;
            if (!File.Exists(localFile))
                needToDownload = true;
            else
            {
                FileInfo local = new FileInfo(localFile);
                if (remote.LastWriteTimeUtc != local.LastWriteTimeUtc || remote.Length != local.Length)
                    needToDownload = true;
            }

            if (needToDownload)
            {
                try
                {
                    messageBack(0, "Downloading config " + _file);

                    byte[] res = Server.GetFile(FileType.Config, _file);
                    Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                    if (res.Length > 0)
                    {
                        FileStream stream = File.Create(localFile, res.Length);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        // Create empty file
                        FileStream stream = File.Create(localFile);
                        stream.Write(res, 0, res.Length);
                        stream.Close();
                        stream.Dispose();
                    }

                    if (ClientServices.IsMainConfig(localFile))
                    {
                        string[] lines = File.ReadAllLines(localFile);
                        StreamWriter writer = new StreamWriter(localFile);
                        foreach (string line in lines)
                        {
                            if (line.StartsWith("DefaultSegmentMemory"))
                                writer.WriteLine("DefaultSegmentMemory " + (ClientServices.Settings.MemorySegment * 1024 * 1024));
                            else if (line.StartsWith("RenderThreads"))
                                writer.WriteLine("RenderThreads " + ClientServices.Settings.NumThreads);
                            else
                                writer.WriteLine(line);
                        }
                        writer.Close();
                        writer.Dispose();
                    }
                    else if (localFile.ToUpper().Contains("LWEXT"))
                    {
                        string[] lines = File.ReadAllLines(localFile);
                        StreamWriter writer = new StreamWriter(localFile);
                        foreach (string line in lines)
                        {
                            if (line.ToUpper().Contains("MODULE \"") || line.StartsWith("  Module \""))
                            {
                                // Get the original plugin filename path and replace it with the new path
                                string originalPlugin = line.Replace(@"\\", @"\").Trim();
                                originalPlugin = originalPlugin.Substring(originalPlugin.IndexOf("\"") + 1);
                                originalPlugin = originalPlugin.Replace('\"', ' ').Trim();
                                string name = Path.GetFileName(originalPlugin);
                                string newPlugin = Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName);
                                newPlugin = Path.Combine(Path.Combine(newPlugin, "ExtPlugins"), name);
                                writer.WriteLine("  Module \"" + newPlugin.Replace(@"\", @"\\") + "\"");
                            }
                            else
                                writer.WriteLine(line);
                        }
                        writer.Close();
                        writer.Dispose();
                    }
                    FileInfo local = new FileInfo(localFile);
                    local.LastWriteTimeUtc = remote.LastWriteTimeUtc;
                    messageBack(0, "Saved at " + _file);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Unable to save config file: " + _file);
                }
            }
        }
Exemple #24
0
        public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
        {
            _messageBack = messageBack;
            Server.SetCurrentJob("Render " + _file + " frame(s) " + StartFrame + " to " + EndFrame);

            string ext = ImageFormat.Substring(ImageFormat.IndexOf('(') + 1, (ImageFormat.IndexOf(')') - ImageFormat.IndexOf('(')) - 1);

            try
            {
                for (int i = StartFrame; i <= EndFrame; i += Step)
                {
                    string outputPath = Path.Combine(ClientServices.GetClientDir(), "Output");
                    string fname      = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_{1:0000}{2}", Instance, i, ext);

                    if (File.Exists(fname))
                    {
                        File.Delete(fname);
                    }

                    if (SaveAlpha)
                    {
                        ext = AlphaImageFormat.Substring(AlphaImageFormat.IndexOf('(') + 1,
                                                         (AlphaImageFormat.IndexOf(')') - AlphaImageFormat.IndexOf('(')) -
                                                         1);
                        fname = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_a{1:0000}{2}", Instance, i, ext);
                        if (File.Exists(fname))
                        {
                            File.Delete(fname);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error deleting existing images");
            }

            try
            {
                messageBack(0, "Rendering file " + _file + " frame(s) " + StartFrame + " to " + EndFrame);
                string contentPath = Path.Combine(ClientServices.GetClientDir(), "Content");
                string outputPath  = Path.Combine(ClientServices.GetClientDir(), "Output");

                Directory.CreateDirectory(outputPath);
                string[]     lines  = File.ReadAllLines(Path.Combine(contentPath, _file));
                StreamWriter writer = new StreamWriter(Path.Combine(contentPath, "render_" + Instance + ".aml"));
                writer.WriteLine("LWSC");
                writer.WriteLine(lines[1]);
                writer.WriteLine("");
                writer.WriteLine("RenderRangeType 0");
                writer.WriteLine("FirstFrame " + StartFrame);
                writer.WriteLine("LastFrame " + EndFrame);
                writer.WriteLine("FrameStep " + Step);

                if (SaveAlpha)
                {
                    writer.WriteLine("SaveAlpha 1");
                }
                else
                {
                    writer.WriteLine("SaveAlpha 0");
                }

                writer.WriteLine("SaveRGB 1");
                writer.WriteLine("OutputFilenameFormat 3");
                writer.WriteLine("SaveRGBImagesPrefix " + Path.Combine(outputPath, Instance + "_"));
                writer.WriteLine("SaveAlphaImagesPrefix " + Path.Combine(outputPath, Instance + "_a"));
                writer.WriteLine("RGBImageSaver " + ImageFormat);
                writer.WriteLine("AlphaImageSaver " + AlphaImageFormat);

                bool   inMaster   = false;
                int    lineNumber = 0;
                bool   inPlugin   = false;
                string prevLine   = "";

                foreach (string line in lines)
                {
                    // Skip the header
                    lineNumber++;
                    if (lineNumber < 4)
                    {
                        continue;
                    }

                    if (inPlugin)
                    {
                        if (prevLine.Contains("{ Options"))
                        {
                            OutputPlugins plugin = Plugins[Plugins.Count - 1];
                            if (plugin.PluginType == "BufferExport")
                            {
                                // current line should be the path
                                string baseName = line.Replace('\"', ' ').Trim();
                                baseName = baseName.Replace(@"\\", @"\");
                                string filename  = Path.GetFileNameWithoutExtension(baseName);
                                string output    = Path.GetDirectoryName(baseName);
                                string extension = Path.GetExtension(baseName);
                                if (output == null)
                                {
                                    output = "";
                                }
                                plugin.BaseFilename  = filename;
                                plugin.BasePath      = output;
                                plugin.FileExtension = extension;

                                // write the new path
                                string newfile = Path.Combine(outputPath, filename + extension);
                                writer.WriteLine("    \"" + newfile.Replace(@"\", @"\\") + "\"");
                            }
                        }
                        else
                        {
                            if (line.Contains("EndPlugin"))
                            {
                                inPlugin = false;
                            }
                            writer.WriteLine(line);
                        }
                    }
                    else
                    {
                        if (line.StartsWith("Plugin "))
                        {
                            if (line.Contains("LW_CompositeBuffer"))
                            {
                                OutputPlugins plugin = new OutputPlugins();
                                plugin.PluginType = "BufferExport";
                                Plugins.Add(plugin);
                                inPlugin = true;
                                writer.WriteLine();
                            }
                        }
                        // Skip the render range / format definition
                        if (line.StartsWith("FirstFrame "))
                        {
                            continue;
                        }
                        if (line.StartsWith("LastFrame "))
                        {
                            continue;
                        }
                        if (line.StartsWith("FrameStep "))
                        {
                            continue;
                        }
                        if (line.StartsWith("RenderRangeType "))
                        {
                            continue;
                        }
                        if (line.StartsWith("RenderRangeArbitrary "))
                        {
                            continue;
                        }
                        if (line.StartsWith("Plugin MasterHandler") && StrippedMaster.Count > 0)
                        {
                            string[] p = line.Split(' ');
                            if (StrippedMaster.Exists(delegate(string x) { return(x == p[3]); }))
                            {
                                inMaster = true;
                                continue;
                            }
                        }
                        if (inMaster && line == "EndPlugin") // Strip until EndPlugin
                        {
                            inMaster = false;
                            continue;
                        }
                        if (inMaster) // We are in a master plugin
                        {
                            continue;
                        }
                        if (line.StartsWith("OutputFilenameFormat "))
                        {
                            continue;
                        }
                        if (line.StartsWith("SaveRGB "))
                        {
                            continue;
                        }
                        if (line.StartsWith("SaveRGBImagesPrefix "))
                        {
                            continue;
                        }
                        if (line.StartsWith("RGBImageSaver "))
                        {
                            continue;
                        }
                        if (line.StartsWith("SaveAlphaImagesPrefix "))
                        {
                            continue;
                        }
                        if (line.StartsWith("AlphaImageSaver "))
                        {
                            continue;
                        }
                        if (line.StartsWith("SaveAlpha "))
                        {
                            continue;
                        }

                        if (line.StartsWith("LimitedRegion "))
                        {
                            // If not split rendering, leave the current settings
                            if (SlicesDown == 1 && SlicesAcross == 1)
                            {
                                writer.WriteLine(line);
                            }

                            continue;
                        }
                        if (line.StartsWith("RegionLimits "))
                        {
                            if (SlicesDown == 1 && SlicesAcross == 1)
                            {
                                writer.WriteLine(line);
                            }

                            continue;
                        }

                        if (line.StartsWith("Antialiasing "))
                        {
                            if (SlicesDown > 1 || SlicesAcross > 1)
                            {
                                writer.WriteLine("LimitedRegion 2");

                                int posX;
                                int posY;

                                if (SlicesDown > 1 && SlicesAcross > 1)
                                {
                                    posX = SliceNumber % SlicesAcross;
                                    posY = SliceNumber / SlicesAcross;
                                }
                                else if (SlicesDown == 1)
                                {
                                    posX = SliceNumber;
                                    posY = 0;
                                }
                                else
                                {
                                    posX = 0;
                                    posY = SliceNumber;
                                }

                                double sizeV    = 1.0 / SlicesDown;
                                double sizeH    = 1.0 / SlicesAcross;
                                double overlapV = sizeV * (Overlap / 100.0);
                                double overlapH = sizeH * (Overlap / 100.0);

                                double sliceLeft   = sizeH * posX - overlapH;
                                double sliceRight  = sizeH * posX + sizeH + overlapH;
                                double sliceTop    = sizeV * posY - overlapV;
                                double sliceBottom = sizeV * posY + sizeV + overlapV;

                                sliceTop    = Math.Max(0.0, sliceTop);
                                sliceBottom = Math.Min(1.0, sliceBottom);
                                sliceLeft   = Math.Max(0.0, sliceLeft);
                                sliceRight  = Math.Min(1.0, sliceRight);

                                writer.WriteLine("RegionLimits " +
                                                 sliceLeft.ToString("F3") + " " +
                                                 sliceRight.ToString("F3") + " " +
                                                 sliceTop.ToString("F3") + " " +
                                                 sliceBottom.ToString("F3"));
                                Debug.WriteLine("RegionLimits " + SliceNumber + " " + posX + "," + posY + " " +
                                                sliceLeft.ToString("F3") + " " +
                                                sliceRight.ToString("F3") + " " +
                                                sliceTop.ToString("F3") + " " +
                                                sliceBottom.ToString("F3"));
                            }
                        }

                        if (OverrideSettings)
                        {
                            if (line.StartsWith("RenderMode "))
                            {
                                writer.WriteLine("RenderMode " + RenderMode);
                            }
                            else if (line.StartsWith("RayTraceEffects "))
                            {
                                writer.WriteLine("RayTraceEffects " + RenderEffect);
                            }
                            else if (line.StartsWith("EnableRadiosity"))
                            {
                                writer.WriteLine("EnableRadiosity " + Radiosity);
                                writer.WriteLine("RadiosityType " + RadiosityType);
                                writer.WriteLine("RadiosityInterpolated " + InterpolatedGI);
                                writer.WriteLine("RadiosityTransparency " + BackdropTranspGI);
                                writer.WriteLine("CacheRadiosity " + CachedGI);
                                writer.WriteLine("RadiosityIntensity " + IntensityGI);
                                writer.WriteLine("RadiosityTolerance " + ToleranceGI);
                                writer.WriteLine("RadiosityRays " + RayGI);
                                writer.WriteLine("RadiosityMinSpacing " + MinEvalGI);
                                writer.WriteLine("RadiosityMinPixelSpacing " + MinPixelGI);
                                writer.WriteLine("IndirectBounces " + IndirectGI);
                                writer.WriteLine("RadiosityUseAmbient " + UseAmbientGI);
                                writer.WriteLine("VolumetricRadiosity " + VolumetricGI);
                                writer.WriteLine("RadiosityDirectionalRays " + DirectionalGI);
                            }
                            else if (line.StartsWith("RadiosityType "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityInterpolated "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityTransparency "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("CacheRadiosity "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityIntensity "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityTolerance "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityRays "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityMinSpacing "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityMinPixelSpacing "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("IndirectBounces "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityUseAmbient "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("VolumetricRadiosity "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("RadiosityDirectionalRays "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("GlobalFrameSize "))
                            {
                                writer.WriteLine("GlobalFrameSize " + Width + " " + Height);
                            }
                            else if (line.StartsWith("FrameSize "))
                            {
                                writer.WriteLine("FrameSize " + Width + " " + Height);
                            }
                            else if (line.StartsWith("GlobalPixelAspect "))
                            {
                                writer.WriteLine("GlobalPixelAspect " + Aspect);
                            }
                            else if (line.StartsWith("PixelAspect "))
                            {
                                writer.WriteLine("PixelAspect " + Aspect);
                            }
                            else if (line.StartsWith("RayRecursionLimit "))
                            {
                                writer.WriteLine("RayRecursionLimit " + RecursionLimit);
                            }
                            else if (line.StartsWith("RenderLines "))
                            {
                                writer.WriteLine("RenderLines " + RenderLine);
                            }
                            else if (line.StartsWith("Antialiasing ")) // Antialiasing block
                            {
                                writer.WriteLine("Antialiasing " + Antialias);
                                writer.WriteLine("AntiAliasingLevel " + AntialiasLevel);
                                writer.WriteLine("EnhancedAA " + EnhanceAA);
                                writer.WriteLine("AdaptiveSampling " + AdaptiveSampling);
                                writer.WriteLine("AdaptiveThreshold " + AdaptiveThreshold);
                                writer.WriteLine("FilterType " + FilterType);
                                writer.WriteLine("ReconstructionFilter " + EnhanceAA);
                            }
                            else if (line.StartsWith("AdaptiveSampling "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("AdaptiveThreshold "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("FilterType "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("EnhancedAA "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("AntiAliasingLevel "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("ReconstructionFilter "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("CurrentCamera "))
                            {
                                writer.WriteLine("CurrentCamera " + Camera);
                            }
                            else if (line.StartsWith("CameraName "))
                            {
                                writer.WriteLine(line);
                                writer.WriteLine("AASamples " + CameraAntialias);
                                writer.WriteLine("Sampler " + SamplingPattern);
                            }
                            else if (line.StartsWith("AASamples "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("Sampler "))
                            {
                                continue;
                            }
                            else if (line.StartsWith("MinimumSamples "))
                            {
                                writer.WriteLine("MinimumSamples " + MinSamples);
                            }
                            else if (line.StartsWith("MaximumSamples "))
                            {
                                writer.WriteLine("MaximumSamples " + MaxSamples);
                            }
                            else
                            {
                                writer.WriteLine(line);
                            }
                        }
                        else
                        {
                            writer.WriteLine(line);
                        }
                    }
                    prevLine = line;
                }

                writer.Close();
                writer.Dispose();

                TimeSpent = new Stopwatch();
                TimeSpent.Start();

                Process process     = new Process();
                string  configPath  = Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName);
                string  programPath = Path.Combine(configPath, "Program");

                process.StartInfo.FileName  = Path.Combine(programPath, "lwsn.exe");
                process.StartInfo.Arguments = "-3 \"-c" + configPath + "\" \"-d" + contentPath + "\" \"" +
                                              Path.Combine(contentPath, "render_" + Instance + ".aml") + "\" " +
                                              StartFrame + " " + EndFrame + " " + Step;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.WorkingDirectory       = programPath;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.CreateNoWindow         = true;
                process.OutputDataReceived += ProcessOutputDataReceived;
                ClientServices.SetRenderProcess(process);
                process.Start();
                process.PriorityClass = ClientServices.Settings.RenderPriority;
                process.BeginOutputReadLine();
                process.WaitForExit();
                ClientServices.SetRenderProcess(null);
                process.Close();
                process.Dispose();

                TimeSpent.Stop();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error rendering scene file");
            }

            Server.SetCurrentJob("Uploading back images");

            for (int i = StartFrame; i <= EndFrame; i += Step)
            {
                bool uploadError = false;

                string outputPath = Path.Combine(ClientServices.GetClientDir(), "Output");
                string fname;
                string afname;

                if (i < 0)
                {
                    fname  = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_{1:000}{2}", Instance, i, ext);
                    afname = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_a{1:000}{2}", Instance, i, ext);
                }
                else
                {
                    fname  = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_{1:0000}{2}", Instance, i, ext);
                    afname = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_a{1:0000}{2}", Instance, i, ext);
                }

                if (File.Exists(fname))
                {
                    try
                    {
                        messageBack(0, "Frame " + i + " rendered successfully");
                        Server.SendImage(i, SliceNumber, File.ReadAllBytes(fname));
                        File.Delete(fname);
                    }
                    catch (Exception ex)
                    {
                        messageBack(1, "Error while uploading frame " + i);
                        uploadError = true;
                        logger.Error(ex, "Error sending file: " + fname);
                    }
                }
                else
                {
                    messageBack(1, "Frame " + i + " failed to render");
                    Server.FrameLost(i, SliceNumber);
                    logger.Log(LogLevel.Info, "Image file not found: " + fname);
                }

                if (SaveAlpha && File.Exists(afname))
                {
                    try
                    {
                        messageBack(0, "Frame " + i + " alpha rendered successfully");
                        Server.SendImageAlpha(i, SliceNumber, File.ReadAllBytes(afname));
                        File.Delete(afname);
                    }
                    catch (Exception ex)
                    {
                        messageBack(1, "Error while uploading frame " + i + " Alpha");
                        uploadError = true;
                        logger.Error(ex, "Error sending file: " + fname);
                    }
                }
                else if (!File.Exists(fname))
                {
                    logger.Log(LogLevel.Info, "Image file not found: " + fname);
                }


                // Process any files from image saver plugins
                foreach (OutputPlugins plugin in Plugins)
                {
                    if (plugin.PluginType == "BufferExport")
                    {
                        DirectoryInfo bufferPath = new DirectoryInfo(outputPath);
                        foreach (FileInfo file in bufferPath.GetFiles(plugin.BaseFilename + "*"))
                        {
                            string nameFormat    = FilenameFormat.Substring(FilenameFormat.IndexOf("\\") + 1);
                            string fileNumber    = string.Format(nameFormat, "", "", i, plugin.FileExtension);
                            string fileNumberAlt = i.ToString("D3");
                            if (file.FullName.Contains(fileNumber) || file.FullName.Contains(fileNumberAlt))
                            {
                                try
                                {
                                    // rename the file instance name to the basename
                                    Server.SendFile(plugin.BasePath, Path.GetFileName(file.FullName), File.ReadAllBytes(file.FullName));
                                    messageBack(0, "Frame " + i + " buffer " + Path.GetFileName(file.FullName) + " rendered successfully");
                                    File.Delete(file.FullName);
                                }
                                catch (Exception ex)
                                {
                                    messageBack(1, "Error while uploading frame " + i);
                                    uploadError = true;
                                    logger.Error(ex, "Error uploading image file: " + file.FullName);
                                }
                            }
                        }
                    }
                }

                // Process any files from image saver plugins (LW11.6.3 with "User RGB Render Path" selected)
                foreach (OutputPlugins plugin in Plugins)
                {
                    if (plugin.PluginType == "BufferExport")
                    {
                        DirectoryInfo bufferPath = new DirectoryInfo(outputPath);
                        foreach (FileInfo file in bufferPath.GetFiles(Instance + "_*"))
                        {
                            string fileNumber = i.ToString("D3");
                            if (file.FullName.Contains(fileNumber))
                            {
                                try
                                {
                                    int    strPos  = file.FullName.IndexOf('_');
                                    string newName = Path.Combine(outputPath, plugin.BaseFilename + file.FullName.Substring(strPos));
                                    if (File.Exists(newName))
                                    {
                                        File.Delete(newName);
                                    }
                                    File.Move(file.FullName, newName);
                                    Server.SendFile(plugin.BasePath, Path.GetFileName(newName), File.ReadAllBytes(newName));
                                    messageBack(0, "Frame " + i + " buffer " + Path.GetFileName(newName) + " rendered successfully");
                                    File.Delete(newName);
                                }
                                catch (Exception ex)
                                {
                                    messageBack(1, "Error while uploading frame " + i);
                                    uploadError = true;
                                    logger.Error(ex, "Error uploading image file: " + file.FullName);
                                }
                            }
                        }
                    }
                }

                if (uploadError)
                {
                    Server.FrameLost(i, SliceNumber);
                }
                else
                {
                    Server.FrameFinished(i, SliceNumber);
                }
            }
            Server.SetCurrentJob("");
            Server.SetLastRenderTime(TimeSpent.Elapsed);
            GC.Collect();
        }
Exemple #25
0
 public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
 {
     messageBack(0, "Controller asked to quit.");
     ClientServices.Shutdown();
     Environment.Exit(0);
 }
Exemple #26
0
 public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
 {
     messageBack(0, "Sending log back to server");
     ReceiverLog(ClientServices.OldMessages);
 }
Exemple #27
0
        public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
        {
            _messageBack = messageBack;
            Server.SetCurrentJob("Render " + _file + " frame(s) " + StartFrame + " to " + EndFrame);

            string ext = ImageFormat.Substring(ImageFormat.IndexOf('(') + 1, (ImageFormat.IndexOf(')') - ImageFormat.IndexOf('(')) - 1);

            try
            {
                for (int i = StartFrame; i <= EndFrame; i += Step)
                {
                    string outputPath = Path.Combine(ClientServices.GetClientDir(), "Output");
                    string fname = string.Format( outputPath + Path.DirectorySeparatorChar + "{0}_{1:0000}{2}", Instance, i, ext);

                    if (File.Exists(fname))
                        File.Delete(fname);

                    if (SaveAlpha)
                    {
                        ext = AlphaImageFormat.Substring(AlphaImageFormat.IndexOf('(') + 1,
                                                         (AlphaImageFormat.IndexOf(')') - AlphaImageFormat.IndexOf('(')) -
                                                         1);
                        fname = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_a{1:0000}{2}", Instance, i, ext);
                        if (File.Exists(fname))
                            File.Delete(fname);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error deleting existing images");
            }

            try
            {
                messageBack(0,"Rendering file " + _file + " frame(s) " + StartFrame + " to " + EndFrame);
                string contentPath = Path.Combine(ClientServices.GetClientDir(), "Content");
                string outputPath = Path.Combine(ClientServices.GetClientDir(), "Output");

                Directory.CreateDirectory(outputPath);
                string[] lines = File.ReadAllLines(Path.Combine(contentPath, _file));
                StreamWriter writer = new StreamWriter(Path.Combine(contentPath, "render_" + Instance + ".aml"));
                writer.WriteLine("LWSC");
                writer.WriteLine(lines[1]);
                writer.WriteLine("");
                writer.WriteLine("RenderRangeType 0");
                writer.WriteLine("FirstFrame " + StartFrame);
                writer.WriteLine("LastFrame " + EndFrame);
                writer.WriteLine("FrameStep " + Step);

                if (SaveAlpha)
                    writer.WriteLine("SaveAlpha 1");
                else
                    writer.WriteLine("SaveAlpha 0");

                writer.WriteLine("SaveRGB 1");
                writer.WriteLine("OutputFilenameFormat 3");
                writer.WriteLine("SaveRGBImagesPrefix " + Path.Combine(outputPath, Instance + "_"));
                writer.WriteLine("SaveAlphaImagesPrefix " + Path.Combine(outputPath, Instance + "_a"));
                writer.WriteLine("RGBImageSaver " + ImageFormat);
                writer.WriteLine("AlphaImageSaver " + AlphaImageFormat);

                bool inMaster = false;
                int lineNumber = 0;
                bool inPlugin = false;
                string prevLine = "";

                foreach (string line in lines)
                {
                    // Skip the header
                    lineNumber++;
                    if (lineNumber < 4)
                        continue;

                    if (inPlugin)
                    {
                        if (prevLine.Contains("{ Options"))
                        {

                            OutputPlugins plugin = Plugins[Plugins.Count - 1];
                            if (plugin.PluginType == "BufferExport")
                            {
                                // current line should be the path
                                string baseName = line.Replace('\"', ' ').Trim();
                                baseName = baseName.Replace(@"\\", @"\");
                                string filename = Path.GetFileNameWithoutExtension(baseName);
                                string output = Path.GetDirectoryName(baseName);
                                string extension = Path.GetExtension(baseName);
                                if (output == null)
                                    output = "";
                                plugin.BaseFilename = filename;
                                plugin.BasePath = output;
                                plugin.FileExtension = extension;

                                // write the new path
                                string newfile = Path.Combine(outputPath, filename + extension);
                                writer.WriteLine("    \"" + newfile.Replace(@"\", @"\\") + "\"");
                            }
                        }
                        else
                        {
                            if (line.Contains("EndPlugin"))
                                inPlugin = false;
                            writer.WriteLine(line);
                        }
                    }
                    else
                    {
                        if (line.StartsWith("Plugin "))
                        {
                            if (line.Contains("LW_CompositeBuffer"))
                            {
                                OutputPlugins plugin = new OutputPlugins();
                                plugin.PluginType = "BufferExport";
                                Plugins.Add(plugin);
                                inPlugin = true;
                                writer.WriteLine();
                            }
                        }
                        // Skip the render range / format definition
                        if (line.StartsWith("FirstFrame "))
                            continue;
                        if (line.StartsWith("LastFrame "))
                            continue;
                        if (line.StartsWith("FrameStep "))
                            continue;
                        if (line.StartsWith("RenderRangeType "))
                            continue;
                        if (line.StartsWith("RenderRangeArbitrary "))
                            continue;
                        if (line.StartsWith("Plugin MasterHandler") && StrippedMaster.Count > 0)
                        {
                            string[] p = line.Split(' ');
                            if (StrippedMaster.Exists(delegate(string x) { return x == p[3]; }))
                            {
                                inMaster = true;
                                continue;
                            }
                        }
                        if (inMaster && line == "EndPlugin") // Strip until EndPlugin
                        {
                            inMaster = false;
                            continue;
                        }
                        if (inMaster) // We are in a master plugin
                            continue;
                        if (line.StartsWith("OutputFilenameFormat "))
                            continue;
                        if (line.StartsWith("SaveRGB "))
                            continue;
                        if (line.StartsWith("SaveRGBImagesPrefix "))
                            continue;
                        if (line.StartsWith("RGBImageSaver "))
                            continue;
                        if (line.StartsWith("SaveAlphaImagesPrefix "))
                            continue;
                        if (line.StartsWith("AlphaImageSaver "))
                            continue;
                        if (line.StartsWith("SaveAlpha "))
                            continue;

                        if (line.StartsWith("LimitedRegion "))
                        {
                            // If not split rendering, leave the current settings
                            if (SlicesDown == 1 && SlicesAcross == 1)
                                writer.WriteLine(line);

                            continue;
                        }
                        if (line.StartsWith("RegionLimits "))
                        {
                            if (SlicesDown == 1 && SlicesAcross == 1)
                                writer.WriteLine(line);

                            continue;
                        }

                        if (line.StartsWith("Antialiasing "))
                        {
                            if (SlicesDown > 1 || SlicesAcross > 1)
                            {
                                writer.WriteLine("LimitedRegion 2");

                                int posX;
                                int posY;

                                if (SlicesDown > 1 && SlicesAcross > 1)
                                {
                                    posX = SliceNumber%SlicesAcross;
                                    posY = SliceNumber/SlicesAcross;
                                }
                                else if (SlicesDown == 1)
                                {
                                    posX = SliceNumber;
                                    posY = 0;
                                }
                                else
                                {
                                    posX = 0;
                                    posY = SliceNumber;
                                }

                                double sizeV = 1.0/SlicesDown;
                                double sizeH = 1.0/SlicesAcross;
                                double overlapV = sizeV*(Overlap/100.0);
                                double overlapH = sizeH*(Overlap/100.0);

                                double sliceLeft = sizeH*posX - overlapH;
                                double sliceRight = sizeH*posX + sizeH + overlapH;
                                double sliceTop = sizeV*posY - overlapV;
                                double sliceBottom = sizeV*posY + sizeV + overlapV;

                                sliceTop = Math.Max(0.0, sliceTop);
                                sliceBottom = Math.Min(1.0, sliceBottom);
                                sliceLeft = Math.Max(0.0, sliceLeft);
                                sliceRight = Math.Min(1.0, sliceRight);

                                writer.WriteLine("RegionLimits " +
                                                 sliceLeft.ToString("F3") + " " +
                                                 sliceRight.ToString("F3") + " " +
                                                 sliceTop.ToString("F3") + " " +
                                                 sliceBottom.ToString("F3"));
                                Debug.WriteLine("RegionLimits " + SliceNumber + " " + posX + "," + posY + " " +
                                                sliceLeft.ToString("F3") + " " +
                                                sliceRight.ToString("F3") + " " +
                                                sliceTop.ToString("F3") + " " +
                                                sliceBottom.ToString("F3"));
                            }
                        }

                        if (OverrideSettings)
                        {
                            if (line.StartsWith("RenderMode "))
                                writer.WriteLine("RenderMode " + RenderMode);
                            else if (line.StartsWith("RayTraceEffects "))
                                writer.WriteLine("RayTraceEffects " + RenderEffect);
                            else if (line.StartsWith("EnableRadiosity"))
                            {
                                writer.WriteLine("EnableRadiosity " + Radiosity);
                                writer.WriteLine("RadiosityType " + RadiosityType);
                                writer.WriteLine("RadiosityInterpolated " + InterpolatedGI);
                                writer.WriteLine("RadiosityTransparency " + BackdropTranspGI);
                                writer.WriteLine("CacheRadiosity " + CachedGI);
                                writer.WriteLine("RadiosityIntensity " + IntensityGI);
                                writer.WriteLine("RadiosityTolerance " + ToleranceGI);
                                writer.WriteLine("RadiosityRays " + RayGI);
                                writer.WriteLine("RadiosityMinSpacing " + MinEvalGI);
                                writer.WriteLine("RadiosityMinPixelSpacing " + MinPixelGI);
                                writer.WriteLine("IndirectBounces " + IndirectGI);
                                writer.WriteLine("RadiosityUseAmbient " + UseAmbientGI);
                                writer.WriteLine("VolumetricRadiosity " + VolumetricGI);
                                writer.WriteLine("RadiosityDirectionalRays " + DirectionalGI);
                            }
                            else if (line.StartsWith("RadiosityType "))
                                continue;
                            else if (line.StartsWith("RadiosityInterpolated "))
                                continue;
                            else if (line.StartsWith("RadiosityTransparency "))
                                continue;
                            else if (line.StartsWith("CacheRadiosity "))
                                continue;
                            else if (line.StartsWith("RadiosityIntensity "))
                                continue;
                            else if (line.StartsWith("RadiosityTolerance "))
                                continue;
                            else if (line.StartsWith("RadiosityRays "))
                                continue;
                            else if (line.StartsWith("RadiosityMinSpacing "))
                                continue;
                            else if (line.StartsWith("RadiosityMinPixelSpacing "))
                                continue;
                            else if (line.StartsWith("IndirectBounces "))
                                continue;
                            else if (line.StartsWith("RadiosityUseAmbient "))
                                continue;
                            else if (line.StartsWith("VolumetricRadiosity "))
                                continue;
                            else if (line.StartsWith("RadiosityDirectionalRays "))
                                continue;
                            else if (line.StartsWith("GlobalFrameSize "))
                                writer.WriteLine("GlobalFrameSize " + Width + " " + Height);
                            else if (line.StartsWith("FrameSize "))
                                writer.WriteLine("FrameSize " + Width + " " + Height);
                            else if (line.StartsWith("GlobalPixelAspect "))
                                writer.WriteLine("GlobalPixelAspect " + Aspect);
                            else if (line.StartsWith("PixelAspect "))
                                writer.WriteLine("PixelAspect " + Aspect);
                            else if (line.StartsWith("RayRecursionLimit "))
                                writer.WriteLine("RayRecursionLimit " + RecursionLimit);
                            else if (line.StartsWith("RenderLines "))
                                writer.WriteLine("RenderLines " + RenderLine);
                            else if (line.StartsWith("Antialiasing ")) // Antialiasing block
                            {
                                writer.WriteLine("Antialiasing " + Antialias);
                                writer.WriteLine("AntiAliasingLevel " + AntialiasLevel);
                                writer.WriteLine("EnhancedAA " + EnhanceAA);
                                writer.WriteLine("AdaptiveSampling " + AdaptiveSampling);
                                writer.WriteLine("AdaptiveThreshold " + AdaptiveThreshold);
                                writer.WriteLine("FilterType " + FilterType);
                                writer.WriteLine("ReconstructionFilter " + EnhanceAA);
                            }
                            else if (line.StartsWith("AdaptiveSampling "))
                                continue;
                            else if (line.StartsWith("AdaptiveThreshold "))
                                continue;
                            else if (line.StartsWith("FilterType "))
                                continue;
                            else if (line.StartsWith("EnhancedAA "))
                                continue;
                            else if (line.StartsWith("AntiAliasingLevel "))
                                continue;
                            else if (line.StartsWith("ReconstructionFilter "))
                                continue;
                            else if (line.StartsWith("CurrentCamera "))
                                writer.WriteLine("CurrentCamera " + Camera);
                            else if (line.StartsWith("CameraName "))
                            {
                                writer.WriteLine(line);
                                writer.WriteLine("AASamples " + CameraAntialias);
                                writer.WriteLine("Sampler " + SamplingPattern);
                            }
                            else if (line.StartsWith("AASamples "))
                                continue;
                            else if (line.StartsWith("Sampler "))
                                continue;
                            else if (line.StartsWith("MinimumSamples "))
                                writer.WriteLine("MinimumSamples " + MinSamples);
                            else if (line.StartsWith("MaximumSamples "))
                                writer.WriteLine("MaximumSamples " + MaxSamples);
                            else
                                writer.WriteLine(line);
                        }
                        else
                            writer.WriteLine(line);

                    }
                    prevLine = line;
                }

                writer.Close();
                writer.Dispose();

                TimeSpent = new Stopwatch();
                TimeSpent.Start();

                Process process = new Process();
                string configPath = Path.Combine(ClientServices.GetClientDir(), ClientServices.ConfigName);
                string programPath = Path.Combine(configPath, "Program");

                process.StartInfo.FileName = Path.Combine(programPath, "lwsn.exe");
                process.StartInfo.Arguments = "-3 \"-c" + configPath + "\" \"-d" + contentPath + "\" \"" +
                                              Path.Combine(contentPath, "render_" + Instance + ".aml") + "\" " +
                                              StartFrame + " " + EndFrame + " " + Step;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.WorkingDirectory = programPath;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.CreateNoWindow = true;
                process.OutputDataReceived += ProcessOutputDataReceived;
                ClientServices.SetRenderProcess(process);
                process.Start();
                process.PriorityClass = ClientServices.Settings.RenderPriority;
                process.BeginOutputReadLine();
                process.WaitForExit();
                ClientServices.SetRenderProcess(null);
                process.Close();
                process.Dispose();

                TimeSpent.Stop();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error rendering scene file");
            }

            Server.SetCurrentJob("Uploading back images");

            for (int i = StartFrame; i <= EndFrame; i += Step)
            {
                bool uploadError = false;

                string outputPath = Path.Combine(ClientServices.GetClientDir(), "Output");
                string fname;
                string afname;

                if (i < 0)
                {
                    fname = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_{1:000}{2}", Instance, i, ext);
                    afname = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_a{1:000}{2}", Instance, i, ext);
                }
                else
                {
                    fname = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_{1:0000}{2}", Instance, i, ext);
                    afname = string.Format(outputPath + Path.DirectorySeparatorChar + "{0}_a{1:0000}{2}", Instance, i, ext);
                }

                if (File.Exists(fname))
                {
                    try
                    {
                        messageBack(0,"Frame " + i + " rendered successfully");
                        Server.SendImage(i, SliceNumber, File.ReadAllBytes(fname));
                        File.Delete(fname);
                    }
                    catch (Exception ex)
                    {
                        messageBack(1, "Error while uploading frame " + i);
                        uploadError = true;
                        logger.Error(ex, "Error sending file: " + fname);
                    }
                }
                else
                {
                    messageBack(1, "Frame " + i + " failed to render");
                    Server.FrameLost(i, SliceNumber);
                    logger.Log(LogLevel.Info, "Image file not found: " + fname);
                }

                if (SaveAlpha && File.Exists(afname))
                {
                    try
                    {
                        messageBack(0, "Frame " + i + " alpha rendered successfully");
                        Server.SendImageAlpha(i, SliceNumber, File.ReadAllBytes(afname));
                        File.Delete(afname);
                    }
                    catch (Exception ex)
                    {
                        messageBack(1, "Error while uploading frame " + i + " Alpha");
                        uploadError = true;
                        logger.Error(ex, "Error sending file: " + fname);
                    }
                }
                else if (!File.Exists(fname))
                {
                    logger.Log(LogLevel.Info, "Image file not found: " + fname);
                }

                // Process any files from image saver plugins
                foreach (OutputPlugins plugin in Plugins)
                {
                    if (plugin.PluginType == "BufferExport")
                    {
                        DirectoryInfo bufferPath = new DirectoryInfo(outputPath);
                        foreach (FileInfo file in bufferPath.GetFiles(plugin.BaseFilename + "*"))
                        {
                            string nameFormat = FilenameFormat.Substring(FilenameFormat.IndexOf("\\") + 1);
                            string fileNumber = string.Format(nameFormat, "", "", i, plugin.FileExtension);
                            string fileNumberAlt = i.ToString("D3");
                            if (file.FullName.Contains(fileNumber) || file.FullName.Contains(fileNumberAlt))
                            {
                                try
                                {
                                    // rename the file instance name to the basename
                                    Server.SendFile(plugin.BasePath, Path.GetFileName(file.FullName), File.ReadAllBytes(file.FullName));
                                    messageBack(0, "Frame " + i + " buffer " + Path.GetFileName(file.FullName) + " rendered successfully");
                                    File.Delete(file.FullName);
                                }
                                catch (Exception ex)
                                {
                                    messageBack(1, "Error while uploading frame " + i);
                                    uploadError = true;
                                    logger.Error(ex, "Error uploading image file: " + file.FullName);
                                }
                            }
                        }
                    }
                }

                // Process any files from image saver plugins (LW11.6.3 with "User RGB Render Path" selected)
                foreach (OutputPlugins plugin in Plugins)
                {
                    if (plugin.PluginType == "BufferExport")
                    {
                        DirectoryInfo bufferPath = new DirectoryInfo(outputPath);
                        foreach (FileInfo file in bufferPath.GetFiles(Instance + "_*"))
                        {
                            string fileNumber = i.ToString("D3");
                            if (file.FullName.Contains(fileNumber))
                            {
                                try
                                {
                                    int strPos = file.FullName.IndexOf('_');
                                    string newName = Path.Combine(outputPath, plugin.BaseFilename + file.FullName.Substring(strPos));
                                    if (File.Exists(newName))
                                        File.Delete(newName);
                                    File.Move(file.FullName, newName);
                                    Server.SendFile(plugin.BasePath, Path.GetFileName(newName), File.ReadAllBytes(newName));
                                    messageBack(0, "Frame " + i + " buffer " + Path.GetFileName(newName) + " rendered successfully");
                                    File.Delete(newName);
                                }
                                catch (Exception ex)
                                {
                                    messageBack(1, "Error while uploading frame " + i);
                                    uploadError = true;
                                    logger.Error(ex, "Error uploading image file: " + file.FullName);
                                }
                            }
                        }
                    }
                }

                if (uploadError)
                    Server.FrameLost(i, SliceNumber);
                else
                    Server.FrameFinished(i, SliceNumber);
            }
            Server.SetCurrentJob("");
            Server.SetLastRenderTime(TimeSpent.Elapsed);
            GC.Collect();
        }
Exemple #28
0
 public override void ExecuteJob(MessageBack messageBack, Queue <Job> jobs)
 {
     messageBack(0, "Batch finished...");
     Server.SetReady();
 }
Exemple #29
0
 public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
 {
     messageBack(0, "Controller asked to quit.");
     ClientServices.Shutdown();
     Environment.Exit(0);
 }
Exemple #30
0
 public override void ExecuteJob(MessageBack messageBack, Queue<Job> jobs)
 {
     messageBack(0,"Batch finished...");
     Server.SetReady();
 }