示例#1
0
        private void SearchServer(object obj)
        {
            BroadcastFinder finder = new BroadcastFinder();

            Settings.ServerPort = finder.Port;
            Settings.ServerHost = finder.Server;
            if (Settings.ServerHost == "")
            {
                AddMessage(1, "Amleto server has not been found.");
                AddMessage(1, "Check that your firewall allows access to port 61111 on the server");
                AddMessage(1, "and the server is currently running");
            }
            else
            {
                AddMessage(0, "Found Amleto server at " + Settings.ServerHost + " on port " + Settings.ServerPort);
            }

            AddMessage(0, "Attempting to connect to the Server.");
            ThreadPool.QueueUserWorkItem(ConnectToServer);
        }
示例#2
0
        private void ConnectToServer(object obj)
        {
            if (Settings.ServerHost == "" || Settings.AutoServerFinder)
            {
                BroadcastFinder finder = new BroadcastFinder();
                Settings.ServerPort = finder.Port;
                Settings.ServerHost = finder.Server;
            }

            if (_channel == null)
            {
                _channel = new TcpChannel();
                ChannelServices.RegisterChannel(_channel, false);
            }

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    _server = (ServerServices)Activator.CreateInstance(typeof(ServerServices), null,
                                                                       new object[]
                    {
                        new UrlAttribute("tcp://" + Settings.ServerHost + ":" +
                                         Settings.ServerPort)
                    });
                    if (_server.IsWorking())
                    {
                        break;
                    }
                    Thread.Sleep(100);
                }
                catch (Exception)
                {
                    _server = null;
                    // Don't log this error as this is expected if the server isn't runningB
                }
            }

            if (_server == null)
            {
                if (_setupToDo)
                {
                    AddMessage(1, "Cannot connect to the server. Will retry in 5 seconds.");
                }

                Thread.Sleep(5000);
                ThreadPool.QueueUserWorkItem(ConnectToServer);
            }
            else
            {
                lock (_lock)
                {
                    int bitsize = Environment.Is64BitOperatingSystem ? 64 : 32;
                    _server.RegisterClient(Environment.MachineName, GetIP(), Settings.RenderPriority, bitsize);
                }
                AddMessage(0, "Connected to the server " + Settings.ServerHost + " on port " + Settings.ServerPort + ".");
                try
                {
                    if (_setupToDo)
                    {
                        _server.SetCurrentJob("Starting up");
                    }
                }
                catch (Exception ex)
                {
                    _server = null;
                    if (_setupToDo)
                    {
                        AddMessage(1, "Cannot connect to the server. Will retry in 5 seconds.");
                    }
                    Thread.Sleep(5000);
                    ThreadPool.QueueUserWorkItem(ConnectToServer);
                    logger.Error(ex, "Error connecting to the server");
                }
            }
        }
示例#3
0
        private void SearchServer(object obj)
        {
            BroadcastFinder finder = new BroadcastFinder();
            Settings.ServerPort = finder.Port;
            Settings.ServerHost = finder.Server;
            if (Settings.ServerHost == "")
            {
                AddMessage(1, "Amleto server has not been found.");
                AddMessage(1, "Check that your firewall allows access to port 61111 on the server");
                AddMessage(1, "and the server is currently running");
            }
            else
            {
                AddMessage(0, "Found Amleto server at " + Settings.ServerHost + " on port " + Settings.ServerPort);
            }

            AddMessage(0, "Attempting to connect to the Server.");
            ThreadPool.QueueUserWorkItem(ConnectToServer);
        }
示例#4
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");
            }
        }
示例#5
0
        private void ConnectToServer(object obj)
        {
            if (Settings.ServerHost == "" || Settings.AutoServerFinder)
            {
                BroadcastFinder finder = new BroadcastFinder();
                Settings.ServerPort = finder.Port;
                Settings.ServerHost = finder.Server;
            }

            if (_channel == null)
            {
                _channel = new TcpChannel();
                ChannelServices.RegisterChannel(_channel, false);
            }

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    _server = (ServerServices)Activator.CreateInstance(typeof(ServerServices), null,
                                                 new object[]
                                                     {
                                                         new UrlAttribute("tcp://" + Settings.ServerHost + ":" +
                                                                          Settings.ServerPort)
                                                     });
                    if (_server.IsWorking())
                        break;
                    Thread.Sleep(100);
                }
                catch (Exception)
                {
                    _server = null;
                    // Don't log this error as this is expected if the server isn't runningB
                }
            }

            if (_server == null)
            {
                if (_setupToDo)
                    AddMessage(1, "Cannot connect to the server. Will retry in 5 seconds.");

                Thread.Sleep(5000);
                ThreadPool.QueueUserWorkItem(ConnectToServer);
            }
            else
            {
                lock (_lock)
                {
                    int bitsize = Environment.Is64BitOperatingSystem ? 64 : 32;
                    _server.RegisterClient(Environment.MachineName, GetIP(), Settings.RenderPriority, bitsize);
                }
                AddMessage(0, "Connected to the server " + Settings.ServerHost + " on port " + Settings.ServerPort + ".");
                try
                {
                    if (_setupToDo)
                        _server.SetCurrentJob("Starting up");
                }
                catch (Exception ex)
                {
                    _server = null;
                    if (_setupToDo)
                        AddMessage(1, "Cannot connect to the server. Will retry in 5 seconds.");
                    Thread.Sleep(5000);
                    ThreadPool.QueueUserWorkItem(ConnectToServer);
                    logger.Error(ex, "Error connecting to the server");
                }
            }
        }