Пример #1
0
        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();
            }
        }