Beispiel #1
0
        private void MenuOptionsClick(object sender, EventArgs e)
        {
            bool needToReset = false;

            SetupWin dlg = new SetupWin(_masterServer, true);
            dlg.Port = _masterServer.Port;
            dlg.AutoPort = _masterServer.AutoOfferPort;
            dlg.Configs = _masterServer.GetConfigs();
            dlg.LogFile = _masterServer.LogFile;
            dlg.LogEnabled = _masterServer.LogEnabled;
            dlg.EmailFrom = _masterServer.EmailFrom;
            dlg.SmtpServer = _masterServer.SmtpServer;
            dlg.SmtpUsername = _masterServer.SmtpUsername;
            dlg.SmtpPassword = _masterServer.SmtpPassword;
            dlg.OfferWeb = _masterServer.OfferWeb;
            dlg.OfferWebPort = _masterServer.OfferWebPort;
            dlg.RenderBlocks = _masterServer.RenderBlocks;
            dlg.MappedDrives = _masterServer.GetMappedDrives();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (_masterServer.Port != dlg.Port && dlg.AutoPort == false)
                    needToReset = true;
                _masterServer.Port = dlg.Port;
                _masterServer.AutoOfferPort = dlg.AutoPort;
                _masterServer.ReplaceConfigs(dlg.Configs);
                _masterServer.LogFile = dlg.LogFile;
                _masterServer.LogEnabled = dlg.LogEnabled;
                _masterServer.EmailFrom = dlg.EmailFrom;
                _masterServer.SmtpServer = dlg.SmtpServer;
                _masterServer.SmtpUsername = dlg.SmtpUsername;
                _masterServer.SmtpPassword = dlg.SmtpPassword;
                _masterServer.OfferWeb = dlg.OfferWeb;
                _masterServer.OfferWebPort = dlg.OfferWebPort;
                _masterServer.RenderBlocks = dlg.RenderBlocks;
                string res = _masterServer.SetMappedDrives(dlg.MappedDrives);
                if (res != "")
                    MessageBox.Show(res);

                _masterServer.LoadFileFormats();
                _masterServer.SaveSettings();
                RepaintClientList();
            }
            dlg.Dispose();

            if (needToReset)
            {
                _masterServer.ResetPort(_masterServer.AutoOfferPort, _masterServer.Port);
            }
        }
Beispiel #2
0
        private void ServerWin_Shown(object sender, EventArgs e)
        {
            string version = Assembly.GetExecutingAssembly().GetName().Version.Major.ToString();
            version = version + "." + Assembly.GetExecutingAssembly().GetName().Version.Minor;
            version = version + "." + Assembly.GetExecutingAssembly().GetName().Version.Build;

            Text = "Amleto Server " + version;

            BroadcastFinder findMaster = new BroadcastFinder();
            if (findMaster.Server != "") // Let's connect to the master
            {
                _isMaster = false;
                try
                {
                    // Find a free port for the callback...
                    for (int i = 10000; i < 60000; i++)
                    {
                        try
                        {
                            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                            IDictionary props = new Hashtable();

                            props["port"] = i;
                            _channel = new TcpChannel(props, clientProv, serverProv);
                            break;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex, "Error creating TCP channel");
                        }
                    }

                    ChannelServices.RegisterChannel(_channel, false);
                    _masterServer = (MasterServer)Activator.CreateInstance(typeof(MasterServer),
                                                                            new object[] { Environment.UserName },
                                                                            new object[]
                                                                                {
                                                                                    new UrlAttribute("tcp://" +
                                                                                                     findMaster.Server +
                                                                                                     ":" +
                                                                                                     findMaster.Port)
                                                                                });

                    List<string> oldMessages = _masterServer.GetOldMessages();
                    foreach (string s in oldMessages)
                        DoConsumeMessage(s);
                    List<FinishedFrame> oldFrames = _masterServer.GetOldFrames();
                    DoAddFrames(oldFrames);

                    RepaintClientList();
                    RepaintProjectList();

                    Text = Text + " - Terminal";

                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error initialising server");
                }
            }
            else // We should be master
            {
                _masterServer = new MasterServer(Environment.UserName);
                _isMaster = true;
                Text = Text + " - Master";
            }

            if (_masterServer.RestoreSettings() == false || _masterServer.NbConfigs == 0)
            {
                SetupWin dlg = new SetupWin(_masterServer, false);
                dlg.ScanAllConfigs();
                if (dlg.ShowDialog() != DialogResult.OK)
                    Application.Exit();
                _masterServer.Port = dlg.Port;
                _masterServer.AutoOfferPort = dlg.AutoPort;
                _masterServer.ReplaceConfigs(dlg.Configs);
                _masterServer.LogFile = dlg.LogFile;
                _masterServer.EmailFrom = dlg.EmailFrom;
                _masterServer.SmtpServer = dlg.SmtpServer;
                _masterServer.SmtpUsername = dlg.SmtpUsername;
                _masterServer.SmtpPassword = dlg.SmtpPassword;
                _masterServer.OfferWeb = dlg.OfferWeb;
                _masterServer.OfferWebPort = dlg.OfferWebPort;
                _masterServer.RenderBlocks = dlg.RenderBlocks;
                string res = _masterServer.SetMappedDrives(dlg.MappedDrives);
                if (res != "")
                    MessageBox.Show(res);
                _masterServer.SaveSettings();
            }

            _eventBridge = new EventBridge(RefreshClientList, RefreshProjectList, RefreshFinishedList, ShowImage, ConsumeMessage, ShowClientLog);

            _masterServer.AddClientStatus(_eventBridge.ClientRefresh);
            _masterServer.AddProjectStatus(_eventBridge.ProjectRefresh);
            _masterServer.AddFinishedStatus(_eventBridge.FinishedRefresh);
            _masterServer.AddImagePreview(_eventBridge.ImagePreview);
            _masterServer.AddMessageConsumer(_eventBridge.MessageConsume);

            if (_isMaster)
            {
                _masterServer.Startup();

                // Restore previously saved jobs
                string loadPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Amleto");
                loadPath = Path.Combine(loadPath, "RenderJobs");
                if (Directory.Exists(loadPath))
                {
                    DirectoryInfo bufferPath = new DirectoryInfo(loadPath);
                    foreach (FileInfo file in bufferPath.GetFiles("*.xml"))
                    {
                        RenderProject project = new RenderProject();
                        project = project.Load(file.FullName);
                        _masterServer.AddProject(project);
                    }
                }
            }

            DoConsumeMessage("Clearing thumbnail cache");
            string thumbnailPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Amleto");
            thumbnailPath = Path.Combine(thumbnailPath, @"Cache\thumbnails");
            try
            {
                if (Directory.Exists(thumbnailPath))
                    Directory.Delete(thumbnailPath, true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error clearing thumbnail cache");
            }
        }