Beispiel #1
0
        private static void CheckFileExists(string buildName,
                                            Action <BuildInfo> successHandler, Action <BuildInfo> failHandler, Action onReady)
        {
            var buildInfo = RemoteBuildManager.GetBuild(buildName);

            if (!buildInfo.Ready)
            {
                // Save memory by unloading old data.
                RemoteBuildManager.ClearExpiredBuilds();

                failHandler(buildInfo);
                buildInfo.OnReady += onReady;
                if (!buildInfo.Loading)
                {
                    buildInfo.Prepare();
                }
            }
            else
            {
                successHandler(buildInfo);
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
#if !UNIX && !DEBUG
            if (args.Length == 0)
            {
                Console.WriteLine("Arguments:");
                Console.WriteLine("--conf, -c           Path the xml configuration file.");
                return;
            }
#endif

#if !UNIX
            // Setup console
            _styleSheet = new StyleSheet(Color.White);
            _styleSheet.AddStyle(@"[0-9\/]+ [0-9:]+ (?:A|P)M", Color.SlateBlue);
            _styleSheet.AddStyle(@"\[[A-Z]+\]", Color.Gold);
            _styleSheet.AddStyle(@"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)", Color.Purple);
            _styleSheet.AddStyle(@"#[-az0-9_-]", Color.DarkGreen);
            _styleSheet.AddStyle(@"[a-f0-9]{32}", Color.Orange);
            _styleSheet.AddStyle(@"[a-z_-]+\-[0-9]{5}patch[0-9]\.[0-9]\.[0-9]_[A-Za-z]+", Color.Firebrick);
#endif

            _startupArguments = args;

            Console.CancelKeyPress += (s, ea) => {
                WriteLine("[ERROR] Aborting ...");
                foreach (var knownServer in _ircClients)
                {
                    knownServer.Value.Disconnect();
                }

                Proxy?.Stop();

                _token.Cancel();
            };

            #region Load XML configuration file
            var configurationFileName = GetStringParam("--conf", "-c", "conf.xml");
            var serializer            = new XmlSerializer(typeof(Configuration));
            using (var reader = new StreamReader(configurationFileName))
                Configuration = (Configuration)serializer.Deserialize(reader);
            #endregion

            // Read channels from XML
            foreach (var channelInfo in Configuration.Branches)
            {
                var newChannel = new Channel()
                {
                    ChannelName = channelInfo.Name, DisplayName = channelInfo.Description
                };
                newChannel.BuildDeployed += OnBuildDeployed;

                Channels.Add(newChannel);
            }

            #region HTTP Proxy setup

            if (Configuration.Proxy.Enabled)
            {
                WriteLine("[HTTP] Listening on http://{1}:{0}", Configuration.Proxy.PublicDomainName, Configuration.Proxy.BindPort);

                Proxy = new HttpServer(Configuration.Proxy.Endpoint, Configuration.Proxy.PublicDomainName);
                Proxy.Listen(Configuration.Proxy.BindPort, _token);
            }
            #endregion

            // Setup IRC clients
            foreach (var serverInfo in Configuration.Servers)
            {
                WriteLine("[IRC] Connecting to {0}:{1}", serverInfo.Address, serverInfo.Port);

                var client = new IrcClient()
                {
                    SupportNonRfc        = true,
                    ActiveChannelSyncing = true
                };

                client.OnConnected += (sender, eventArgs) => StartThreads();

                client.OnChannelMessage += (sender, eventArgs) => {
                    Dispatcher.Dispatch(eventArgs.Data, client);
                };

                client.Connect(serverInfo.Address, serverInfo.Port);
                client.Login(serverInfo.Username, serverInfo.Username, 0, serverInfo.Username);
                foreach (var channelInfo in serverInfo.Channels)
                {
                    if (string.IsNullOrEmpty(channelInfo.Key))
                    {
                        client.RfcJoin("#" + channelInfo.Name);
                    }
                    else
                    {
                        client.RfcJoin("#" + channelInfo.Name, channelInfo.Key);
                    }
                }

                Task.Run(() => { client.Listen(); });

                _ircClients[serverInfo.Address] = client;
            }

            while (!_token.IsCancellationRequested)
            {
                if (_token.Token.WaitHandle.WaitOne(10000))
                {
                    break;
                }

                RemoteBuildManager.ClearExpiredBuilds();
            }

            RemoteBuildManager.ClearExpiredBuilds();
        }