Esempio n. 1
0
        static void Main(string[] args)
        {
            if (!SettingsProvider.CanWorking)
            {
                return;
            }

            var preparedTask = ClientProxyProvider.Client.SendRegistrationKey()
                               .ContinueWith(o => ClientProxyProvider.Client.SendAgentInfo())
                               .ContinueWith(o => ClientProxyProvider.Client.SendAgentInventory());

            preparedTask.Result.Wait();

            var zero = TimeSpan.FromSeconds(0);
            var inventoryCheckPeriod = TimeSpan.FromSeconds(SettingsProvider.CurrentSettings.Config.InventoryCheckPeriod.Value);

            using (var checkInventoryTimer = new Timer(o =>
            {
                if (AgentInventoryProvider.UpdateFileDescriptions())
                {
                    ClientProxyProvider.Client.SendAgentInventory().ConfigureAwait(false);
                }
            }, null, zero, inventoryCheckPeriod))
            {
                var hearbeatPeriod = TimeSpan.FromSeconds(SettingsProvider.CurrentSettings.Config.HearbeatPeriod.Value);
                var agent          = new Agent();
                using (var agentTimer = new Timer(o => agent.Work(), null, zero, hearbeatPeriod))
                {
                    Log.Message("Агент работает");
                    Console.ReadLine();
                }
            }
        }
Esempio n. 2
0
        private static void InitializeCheckInventoryTimer()
        {
            var inventoryCheckPeriod = TimeSpan.FromSeconds(config.InventoryCheckPeriod.Value);

            checkInventoryTimer = new Timer(o =>
            {
                try
                {
                    if (AgentInventoryProvider.UpdateFileDescriptions())
                    {
                        ClientProxyProvider.Client.SendAgentInventory().ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    Log.Message($"Словили исключение при проверке инвентаря: {e.ToString()}");
                }
                finally
                {
                    checkInventoryTimer.Change(inventoryCheckPeriod, TimeSpan.FromMilliseconds(-1));
                }
            }, null, TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(-1));
        }