示例#1
0
文件: Steam.cs 项目: gamedb/updater
        private static async void CheckForChanges(Object obj, EventArgs args)
        {
            timer2.Stop();
            try
            {
                // Check logged in
                if (steamClient.IsConnected && isLoggedOn)
                {
                    // Get the last change ID
                    if (previousChangeNumber == 0 && File.Exists(LastChangeFile))
                    {
                        var contents = File.ReadAllText(LastChangeFile);
                        previousChangeNumber = contents == "" ? 0 : UInt32.Parse(contents);
                    }

                    // Get latest changes. If more than 5000, returns 0
                    var JobID    = steamApps.PICSGetChangesSince(previousChangeNumber, true, true);
                    var callback = await JobID;

                    if (previousChangeNumber < callback.CurrentChangeNumber)
                    {
                        Log.Info(
                            $"{callback.CurrentChangeNumber - callback.LastChangeNumber:N0} changes, {callback.AppChanges.Count} apps, {callback.PackageChanges.Count} packages"
                            );

                        // Save apps
                        foreach (var appID in callback.AppChanges.Keys)
                        {
                            var appPayload = AppMessage.create(appID);
                            AbstractConsumer.Produce(AbstractConsumer.queue_cs_apps, appPayload);
                        }

                        // Save packages
                        foreach (var packageID in callback.PackageChanges.Keys)
                        {
                            var packagePayload = PackageMessage.create(packageID);
                            AbstractConsumer.Produce(AbstractConsumer.queue_cs_packages, packagePayload);
                        }

                        // Save changes
                        var changePayload = ChangeMessage.create(callback.CurrentChangeNumber, callback);
                        AbstractConsumer.Produce(AbstractConsumer.queue_go_changes, changePayload);

                        // Update change number
                        previousChangeNumber = callback.CurrentChangeNumber;
                        File.WriteAllText(LastChangeFile, previousChangeNumber.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Failed checking for changes - " + ex.Message);
            }
            finally
            {
                timer2.Start();
            }
        }
示例#2
0
        internal override void RegisterChannel <T>(IBasicProperties basicProperties, AbstractConsumer <T> consumer, string queue, string errorQueue, string exchange, string routingKey)
        {
            Logger.Info("Consumer has been registering. Consumer: " + consumer + ", queue: " + queue + ", errorRoute: " + errorQueue);
            ConsumerResolver <T> resolver = (int eventId, string eventName, string contractVersion) =>
            {
                return(consumer);
            };

            this.ChannelRegistration(basicProperties, queue, errorQueue, exchange, routingKey, resolver);
        }
示例#3
0
        private void view_StopBenchmark(object sender, EventArgs e)
        {
            foreach (IFrameConsumer consumer in consumers)
            {
                consumer.Deactivate();
                while (consumer.Active)
                {
                    // Busy spin while the consumer thread reach a clean break.
                }
            }

            grabber.Stop();

            Dictionary <string, IBenchmarkCounter> counters = pipeline.StopBenchmark();

            foreach (IFrameConsumer consumer in consumers)
            {
                AbstractConsumer c = consumer as AbstractConsumer;
                if (c == null)
                {
                    continue;
                }

                var counter = c.BenchmarkCounter;
                if (counter != null)
                {
                    counters.Add(consumer.GetType().Name, counter);
                }
            }

            List <string> extraBefore = new List <string>();

            AddSessionInformation(extraBefore);

            List <string> extraAfter = new List <string>();

            AddMachineInformation(extraAfter);

            BenchmarkReport br = new BenchmarkReport(extraBefore, extraAfter, counters);

            br.ShowDialog();
            br.Dispose();
        }
示例#4
0
文件: Program.cs 项目: gamedb/updater
        private static void Main(String[] args)
        {
            Console.Title = "GameDB Updater";

            // Config
            Config.init();

            // Wait for Rabbit
            AbstractConsumer.waitForConnections();

            // Poll for new changes
            Steam.startSteam(!args.Contains("--nopics"), false);
            while (true)
            {
                Thread.Sleep(TimeSpan.FromSeconds(1));

                if (Steam.steamClient.IsConnected && Steam.isLoggedOn)
                {
                    break;
                }

                Log.Info("Waiting for Steam.. ");
            }

            // Consumers
            AbstractConsumer.startConsumers();

            // On quit
            Console.CancelKeyPress += delegate
            {
                Steam.quitOnDisconnect = true;
                Steam.steamUser.LogOff();
            };

            // Block thread
            Thread.Sleep(Timeout.Infinite);
        }
 internal abstract void RegisterChannel <T>(IBasicProperties basicProperties, AbstractConsumer <T> consumer, string queue, string errorQueue, string exchange, string routingKey);
示例#6
0
 public void Consume <T>(IBasicProperties basicProperties, AbstractConsumer <T> consumer, string queue, string errorQueue, string exchange, string routingKey)
 {
     this.channelManager.RegisterChannel(basicProperties, consumer, queue, errorQueue, exchange, routingKey);
 }
示例#7
0
        private void ChannelRegistration <T>(IBasicProperties basicProperties, string queue, string errorQueue, string exchange, string routingKey, ConsumerResolver <T> resolver)
        {
            var rabbitConsumer = new EventingBasicConsumer(channel);

            rabbitConsumer.Received += (model, ea) =>
            {
                var serializer = RabbitMQWrapperConnection.DefaultAdapter;
                try
                {
                    var message = serializer.DeserializeBytes <RabbitMQWrapperMessage <T> >(ea.Body);

                    AbstractConsumer <T> consumer = null;
                    try
                    {
                        consumer = resolver(message.EventID, message.Event, message.ContractVersion);

                        if (message.Event == "")
                        {
                            consumer.Consume(message.EventID, message.Content, message.ContractVersion);
                        }
                        consumer.Consume(message.Event, message.Content, message.ContractVersion);
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Consumer: " + consumer + " has unexpected error", e);
                        channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: true);
                        return;
                    }

                    try
                    {
                        channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Connection lost", e);
                        throw e;
                    }
                }
                catch (JsonException e)
                {
                    var customError = new UnexpectedException(e);
                    Logger.Error("Could not deserialize the object: " + ea.Body, customError);
                    try
                    {
                        Logger.Warn("Creating error queue...");
                        this.EnsureRoute(errorQueue, exchange, routingKey);
                        this.channel.BasicPublish(exchange: exchange, routingKey: routingKey, basicProperties: basicProperties, body: ea.Body);
                        channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: false);
                    }
                    catch (Exception ex)
                    {
                        var custom = new UnexpectedException(ex);
                        Logger.Fatal("Unexpected error occured while publishing items to error queue", custom);
                        throw custom;
                    }
                }
                catch (Exception e)
                {
                    var custom = new UnexpectedException(e);
                    Logger.Fatal("Unexpected error occured while consumer received a message", custom);
                    throw custom;
                }
            };

            try
            {
                channel.BasicConsume(queue: queue, noAck: false, consumer: rabbitConsumer, consumerTag: appKey);
            }
            catch (IOException e)
            {
                if (channel.IsOpen == false)
                {
                    var custom = new ConnectionClosedException(e);
                    Logger.Info("Trying to reconnect again... Queue:" + queue, custom);
                    Thread.Sleep(200);
                    channel.BasicConsume(queue: queue, noAck: false, consumer: rabbitConsumer, consumerTag: appKey);
                }
                else
                {
                    var custom = new AccessDeniedException(e);
                    Logger.Fatal("Access denied. Queue: " + queue, custom);
                    throw custom;
                }
            }
        }