static async Task Main(string[] args)
        {
            var typeName = typeof(Program).Assembly.GetName();

            Log($"Start {typeName.Name} (v{typeName.Version})");

            var currentConfig = CurrentConfiguration.Build();

            // Create the consumer configuration
            var config = new ConsumerConfig
            {
                GroupId          = "starwars-consumer-group",
                BootstrapServers = currentConfig.BootstrapServers,
                AutoOffsetReset  = AutoOffsetReset.Earliest
            };


            Log($"Connect consumer to kafka > {currentConfig.BootstrapServers}");

            // Create the consumer
            using (var consumer = new ConsumerBuilder <Ignore, string>(config).Build())
            {
                // Subscribe to the Kafka topic
                consumer.Subscribe(new List <string>()
                {
                    currentConfig.Topic
                });

                // Handle Cancel Keypress
                var cts = new CancellationTokenSource();
                Console.CancelKeyPress += (_, e) => {
                    e.Cancel = true; // prevent the process from terminating.
                    cts.Cancel();
                };

                Log("Press Ctrl+C to exit");

                // Poll for messages
                try
                {
                    while (true)
                    {
                        try
                        {
                            var cr = consumer.Consume(cts.Token);
                            Log($"  >> Consumed message '{cr.Value}' at: '{cr.TopicPartitionOffset}'.");
                        }
                        catch (ConsumeException e)
                        {
                            Log($"  >> Error occured: {e.Error.Reason}");
                        }
                    }
                }
                catch (OperationCanceledException)
                {
                    // Ensure the consumer leaves the group cleanly and final offsets are committed.
                    consumer.Close();
                }
            }
        }
Beispiel #2
0
 private void SaveConfig(string path = null)
 {
     CurrentConfiguration.SaveToXml(path);
     lblConfigPath.Text = CurrentConfiguration.Filepath;
     Settings.Default.LastConfigFilepath = CurrentConfiguration.Filepath;
     Settings.Default.Save();
 }
Beispiel #3
0
        protected static ISessionFactory CreateSessionFactory()
        {
            ISessionFactory factory = CurrentConfiguration.BuildSessionFactory();

            if (factory == null)
            {
                string msg = "NHibernateCouldNotCreateFactoryException";
                throw new Exception(msg);
            }
            return(factory);
        }
        public void AppConfiguration_Can_Create_Template_Config_File()
        {
            //Arrange
            string templateFilePath = "Stundenlisten.AppConfiguration.template.toml";

            //Act
            CurrentConfiguration.CreateTemplateConfig(templateFilePath);

            //Assert
            Assert.IsTrue(File.Exists(templateFilePath));
        }
Beispiel #5
0
        /// <summary>
        ///     creates the apicall object needed to activate the request
        /// </summary>
        /// <returns></returns>
        protected virtual ApiCall Create()
        {
            if (HostAdress != null && CurrentConfiguration.Host == null)
            {
                CurrentConfiguration.Host = HostAdress;
            }

            var call = CurrentConfiguration.CreateCall();

            ResetCurrentConfiguration();
            return(call);
        }
Beispiel #6
0
        /// <summary>
        /// save to text file
        /// </summary>
        static public void SaveConfiguration()
        {
            string p = FullconfigFilePath;

            if (File.Exists(p))
            {
                File.Copy(p, GetOldConfigFilename());
            }

            string s = CurrentConfiguration.Serialize();

            File.WriteAllText(p, s);
        }
Beispiel #7
0
        /// <summary>
        /// Gets the instance to be used by a user to configure the selected node.
        /// </summary>
        /// <param name="descriptor">Provides identifying description of the node to be configured.</param>
        /// <returns>Returned object provides access to the instance node configuration edition functionality.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public override IInstanceConfiguration GetInstanceConfiguration(INodeDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }
            if (CurrentConfiguration == null)
            {
                return(null);
            }
            NodeDescriptorBase _nd = NodeDescriptorBase.Clone(descriptor);

            return(InstanceConfigurationFactory.GetIInstanceConfiguration(CurrentConfiguration.GetInstanceConfiguration(_nd), CurrentConfiguration.GetMessageHandlers(), TraceSource.TraceData, () => this.RaiseOnChangeEvent()));
        }
Beispiel #8
0
        /// <summary>
        ///     creates the apicall object needed to activate the request
        /// </summary>
        /// <typeparam name="T"> response will be cast to this type</typeparam>
        /// <returns></returns>
        protected virtual ApiCall <T> Create <T>()
        {
            if (HostAdress != null && CurrentConfiguration.Host == null)
            {
                CurrentConfiguration.Host = HostAdress;
            }

            if (IdentityProvider != null)
            {
                CurrentConfiguration.Identity = IdentityProvider;
            }

            var call = CurrentConfiguration.CreateCall <T>();

            ResetCurrentConfiguration();
            return(call);
        }
Beispiel #9
0
        protected ApiCall <T> Create()
        {
            if (HostAdress != null && CurrentConfiguration.Host == null)
            {
                CurrentConfiguration.Host = HostAdress;
            }

            var call = CurrentConfiguration.CreateCall <T>();

            ResetCurrentConfiguration();

            call.OnSuccess((args) =>
            {
                if (args.HasContent)
                {
                    _trackedEntities.TrackExternalEntity(args.Content);
                }
            });

            return(call);
        }
Beispiel #10
0
        static async Task Main(string[] args)
        {
            var typeName = typeof(Program).Assembly.GetName();

            Log($"Start {typeName.Name} (v{typeName.Version})");

            var currentConfig = CurrentConfiguration.Build();

            var config = new ProducerConfig
            {
                BootstrapServers = currentConfig.BootstrapServers
            };

            Log($"Connect to kafka > {currentConfig.BootstrapServers}");

            using (var producer = new ProducerBuilder <Null, string>(config).Build())
            {
                var topic = currentConfig.Topic;
                try
                {
                    for (int i = 0; i < 5; i++)
                    {
                        var message = $"May the Force be with you {i}";

                        var deliveryResult = await producer.ProduceAsync(topic, new Message <Null, string> {
                            Value = message
                        });

                        Log($"  >> Delivered '{deliveryResult.Value}' to '{deliveryResult.TopicPartitionOffset}'");
                    }

                    // wait for up to 10 seconds for any inflight messages to be delivered.
                    producer.Flush(TimeSpan.FromSeconds(10));
                }
                catch (ProduceException <Null, string> e)
                {
                    Log($"  >> Delivery failed: {e.Error.Reason}");
                }
            }
        }
Beispiel #11
0
        // init
        public Program(MainWindow mainWindow)
        {
            // init listener
            Process[] listeners = Process.GetProcessesByName("Listener");
            if (listeners.Length == 0)
            {
                //MessageBox.Show("No listener available");
                //Environment.Exit(0);
                Process.Start("Listener");
            }
            else
            {
                foreach (var listener in listeners)
                {
                    listener.Kill();
                }
                Process.Start("Listener");
            }

            // setup GUI and GUI events
            SetupGUI.setupStudyTable(mainWindow);
            SetupGUI.setupSeriesTable(mainWindow.downloadPage);
            mainWindow.queryPage.localSearch.Click    += onLocalSearchButtonClicked;
            mainWindow.queryPage.Search.Click         += onSearchButtonClicked;
            mainWindow.downloadPage.series_ClickEvent += onSeriesClicked;
            mainWindow.downloadPage.thumb_ClickEvent  += onThumbClicked;

            // watch changes in configuration
            configuration = new CurrentConfiguration();
            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.Path                = Path.GetDirectoryName("./");
            watcher.Filter              = Path.GetFileName("ServerConfig.txt");
            watcher.Changed            += new FileSystemEventHandler(onConfigurationChanged);
            watcher.EnableRaisingEvents = true;

            this.mainWindow = mainWindow;
            mainWindow.frame.Navigate(mainWindow.queryPage);
        }
Beispiel #12
0
        protected ApiCall <List <T> > CreateBulkCall()
        {
            if (HostAdress != null && CurrentConfiguration.Host == null)
            {
                CurrentConfiguration.Host = HostAdress;
            }

            var call = CurrentConfiguration.CreateCall <List <T> >();

            ResetCurrentConfiguration();

            call.OnSuccess((args) =>
            {
                if (!args.HasContent)
                {
                    return;
                }

                args.Content.ForEach(item => _trackedEntities.TrackExternalEntity(item));
            });

            return(call);
        }
Beispiel #13
0
 public void SaveChanges()
 {
     CurrentConfiguration.Save(ConfigurationSaveMode.Modified);
 }
 public CustomConfigurationSection()
 {
     Current = CurrentConfiguration.GetSection(CustomSectionName);
 }
 public void SaveChanges()
 {
     CurrentConfiguration.Save(ConfigurationSaveMode.Full);
 }
Beispiel #16
0
        private async void NewGame(Chat c)
        {
            if (c.Id != Admin)
            {
                return;
            }

            List <Chat> localMembers;

            lock (Members)
            {
                if (Members.Count > CurrentConfiguration.Sum(x => (int)x))
                {
                    Program.Bot.SendTextMessageAsync(c.Id, "Недостаточно карт. Невозможно начать новую игру.");
                    return;
                }
                if (CurrentConfiguration.Sum(x => (int)x) - Members.Count >=
                    CurrentConfiguration.Skip(2).Take(2).Sum(x => (int)x))
                {
                    Program.Bot.SendTextMessageAsync(c.Id,
                                                     "Количество оставшихся карт больше, чем количество плохих ролей. Невозможно начать новую игру.");
                    return;
                }
                localMembers = new List <Chat>(Members);
            }

            var localMembers2 = new List <Chat>(localMembers);
            var rnd           = new Random(DateTime.Now.Millisecond);

            roles = new Dictionary <long, Role>(localMembers.Count);

            var leader = rnd.Next(0, localMembers.Count);

            roles.Add(localMembers[leader].Id, Role.Ведущий);
            localMembers.RemoveAt(leader);

            var rolesBag = new List <Role>();

            for (var i = 1; i < CurrentConfiguration.Length; i++)
            {
                for (var j = 0; j < CurrentConfiguration[i]; j++)
                {
                    rolesBag.Add((Role)i);
                }
            }

            while (localMembers.Count > 0)
            {
                var x = rnd.Next(0, rolesBag.Count);
                roles.Add(localMembers[0].Id, rolesBag[x]);
                localMembers.RemoveAt(0);
                rolesBag.RemoveAt(x);
            }

            remainingRoles = rolesBag;

            var markup = new ReplyKeyboardMarkup(new KeyboardButton[] { Strings.ShowMeRole }, true);

            foreach (var chat in localMembers2)
            {
                Program.Bot.SendTextMessageAsync(chat.Id, "Новая игра началась!",
                                                 replyMarkup: markup);
            }
        }