Ejemplo n.º 1
0
        public async Task Start(string [] args)
        {
            IServiceProvider provider = StaticServiceProvider.Provider;

            SessionProvider    = provider.GetService <ISessionProvider <TUser> > ( );
            CommandProvider    = provider.GetService <ICommandProvider <TUser> > ( );
            UserProvider       = provider.GetService <ITelegramIdUserProvider <TUser> > ( );
            PermissionProvider = provider.GetService <IUserPermissionProvider <TUser> > ( );

            TaskDispatcher = provider.GetService <ITaskDispatcher> ( );

            TaskDispatcher.Start( );

            BotClient = new TelegramBotClient(BotToken, WebProxy);

            Logger.LogInformation("Connecting...");

            User me = await BotClient.GetMeAsync( );

            Logger.LogInformation("Use Bot {0}", me.Username);
            Console.Title = me.Username;

            BotClient.OnMessage       += BotClient_OnMessage;
            BotClient.OnCallbackQuery += BotClient_OnCallbackQuery;
            BotClient.OnInlineQuery   += BotClient_OnInlineQuery;

            BotClient.StartReceiving( );
        }
Ejemplo n.º 2
0
 public InstrumentProcessor(ITaskDispatcher taskDispatcher, IInstrument instrument)
 {
     _taskDispatcher       = taskDispatcher;
     _instrument           = instrument;
     _instrument.Error    += OnError;
     _instrument.Finished += OnFinished;
 }
Ejemplo n.º 3
0
        public override void Start(string [] args)
        {
            PerformanceCounterProvider provider = new PerformanceCounterProvider( );

            provider.GetPerformanceCounter("a");

            (string SourceCodeVersion, string Builder, DateTimeOffset ? BuildTime) ? a =
                typeof(ProgramBase <Program, ProgramExitCode, ProgramSetting, ProgramSettingCatalog>).Assembly.
                GetInformationalVersion( );

            Thread thread = new Thread(DoSth);

            thread.Start( );

            Dispatcher = StaticServiceProvider.Provider.GetService <ITaskDispatcher> ( );

            Dispatcher.Start( );

            OnetimeTask task1 = new OnetimeTask(PrintTime1, default);

            Dispatcher.Dispatch(task1);

            IntervalTask task2 = new IntervalTask(
                PrintTime2,
                TimeSpan.FromSeconds(1),
                priority: TaskPriority.Background);

            Dispatcher.Dispatch(task2);
        }
Ejemplo n.º 4
0
 public InstrumentProcessor(ITaskDispatcher taskDispatcher, IInstrument instrument)
 {
     this.taskDispatcher  = taskDispatcher;
     this.instrument      = instrument;
     instrument.Error    += InstrumentOnError;
     instrument.Finished += InstrumentOnFinished;
 }
Ejemplo n.º 5
0
        public void Invoke(ITaskDispatcher dispatcher)
        {
            lock (this)
            {
                IsRunning = true;

                if (NextRun != null)
                {
                    if (DateTimeOffset.Now >= NextRun)
                    {
                        LastRun = DateTime.Now;

                        try
                        {
                            NextRun = Action ? .Invoke( );
                        }
                        catch (Exception e)
                        {
                            Logger? .LogError(e, $"{nameof ( ScheduledTask )} thrown unhandled exception.");
                        }

                        RunCount++;
                    }
                }

                IsRunning = false;
            }
        }
Ejemplo n.º 6
0
        public InstrumentProcessor(ITaskDispatcher taskDispatcher, IInstrument instrument)
        {
            _taskDispatcher = taskDispatcher;
            _instrument     = instrument;

            _instrument.Finished += (sender, eventArgs) => _taskDispatcher.FinishedTask(((InstrumentEventArgs)eventArgs).Task);
        }
Ejemplo n.º 7
0
        public void Invoke(ITaskDispatcher dispatcher)
        {
            lock (this)
            {
                IsRunning = true;

                if (DateTimeOffset.Now >= NextRun)
                {
                    LastRun = DateTime.Now;

                    try
                    {
                        Action? .Invoke( );
                    }
                    catch (Exception e)
                    {
                        Logger? .LogError(e, $"{nameof ( IntervalTask )} thrown unhandled exception.");
                    }

                    RunCount++;

                    UpdateStatus( );
                }

                IsRunning = false;
            }
        }
Ejemplo n.º 8
0
        public InstrumentProcessor(ITaskDispatcher taskDispatcher, IInstrument instrument, IConsoleWriter console)
        {
            this.consoleWriter = console;
            this.dispatcher    = taskDispatcher;
            this.instrument    = instrument;

            this.instrument.Finished += this.InstrumentOnFinished;
            this.instrument.Error    += this.InstrumentOnError;
        }
 public InstrumentProcessor(ITaskDispatcher taskDispatcher, IInstrument instrument)
 {
     _taskDispatcher       = taskDispatcher;
     _instrument           = instrument;
     _instrument.Finished += (EventHandler)((sender, args) =>
     {
         var processedTask = args as TaskEventArgs;
         _taskDispatcher.FinishedTask(processedTask.Task);
     });
 }
        internal SubscriptionToken(MessageBase messageBase, ITaskDispatcher dispatcher, Func <Task> func, Func <bool> pred)
        {
            _dispatcher = dispatcher;

            _func = func;

            _pred = pred;

            _messageBaseBase = messageBase;
        }
Ejemplo n.º 11
0
 public static void ExecuteTask(this ITaskDispatcher self, Action action, int timeoutMs)
 {
     try
     {
         self.QueueTask(action).Wait(timeoutMs);
     }
     catch (AggregateException ex)
     {
         throw ex.Flatten().InnerException.PrepareForRethrow();
     }
 }
Ejemplo n.º 12
0
        public Analytics(ITaskDispatcher taskDispatcher, IServiceScopeFactory scopeFactory)
            : base(scopeFactory)
        {
            _taskDispacher  = taskDispatcher;
            TopContributors = new List <Tuple <string, int> >();

            // fire and forget
            // TODO: better?
            UpdateStatistics().Wait();

            aTimer = new Timer(async a => {
                await UpdateStatistics();
            }, null, 0, 5 * 60 * 1000); // 10 min
        }
Ejemplo n.º 13
0
        public InstrumentProcessor(IInstrument instrument, ITaskDispatcher taskDispatcher, IConsole console)
        {
            this.instrument     = instrument;
            this.taskDispatcher = taskDispatcher;
            this.console        = console;

            this.instrument.Finished += (sender, args) =>
            {
                this.taskDispatcher.FinishedTask(currentTasks.Dequeue());
            };

            this.instrument.Error += (sender, args) =>
            { this.console.WriteLine(currentTasks.Dequeue()); };
        }
        public InstrumentProcessor(IInstrument instrument, ITaskDispatcher taskDispatcher, IConsole console)
        {
            this.instrument = instrument;
            this.taskDispatcher = taskDispatcher;
            this.console = console;

            this.instrument.Finished += (sender, args) =>
                {
                    this.taskDispatcher.FinishedTask(currentTasks.Dequeue());
                };

            this.instrument.Error += (sender, args) =>
                { this.console.WriteLine(currentTasks.Dequeue()); };
        }
Ejemplo n.º 15
0
        public DashboardViewModel(IFeedServices feedServices, ITaskDispatcher dispatcher)
        {
            FeedServices = feedServices;
            Dispatcher   = dispatcher;

            ListItems = new ObservableCollection <DashboardSideItemViewModel>();

            LoadData();

            var dispatcherTimer = new System.Windows.Threading.DispatcherTimer();

            dispatcherTimer.Tick += (a, b) => {
                CycleImages();
            };
            dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
            dispatcherTimer.Start();
        }
Ejemplo n.º 16
0
 public static T ExecuteTask <T>(this ITaskDispatcher self, Func <T> action, int timeoutMs)
 {
     try
     {
         using (Task <T> task = self.QueueTask <T>(action))
         {
             if (!task.Wait(timeoutMs))
             {
                 throw new TimeoutException("Timed out waiting on task");
             }
             return(task.Result);
         }
     }
     catch (AggregateException ex)
     {
         throw ex.Flatten().InnerException.PrepareForRethrow();
     }
 }
Ejemplo n.º 17
0
        public void Setup()
        {
            mocks = new MockRepository();

            taskRepository            = mocks.DynamicMock <IRepository <Task> >();
            teamTaskStateRepository   = mocks.DynamicMock <IRepository <TeamTaskState> >();
            acceptedCodeRepository    = mocks.DynamicMock <IRepository <AcceptedCode> >();
            acceptedBadCodeRepository = mocks.DynamicMock <IRepository <AcceptedBadCode> >();
            acceptedTipRepository     = mocks.DynamicMock <IRepository <AcceptedTip> >();
            dispatcherFactory         = mocks.DynamicMock <ITaskDispatcherFactory>();
            taskDispatcher            = mocks.DynamicMock <ITaskDispatcher>();

            game = new Game {
                Name = "Game"
            };
            team = new Team {
                Name = "Team"
            };
        }
Ejemplo n.º 18
0
 public CrowdSourceController(
     ILoggerFactory loggerFactory,
     IDataLogic logic,
     ApplicationDbContext context,
     ITaskDispatcher taskDispatcher,
     ITextSanitizer textSanitizer,
     IDbConfig config,
     UserManager <ApplicationUser> userMan,
     IHttpContextAccessor httpContext
     )
 {
     _context        = context;
     _logger         = loggerFactory.CreateLogger <CrowdSourceController>();
     _logic          = logic;
     _taskDispatcher = taskDispatcher;
     _textSanitizer  = textSanitizer;
     _config         = config;
     _httpContext    = httpContext;
     _userMan        = userMan;
 }
Ejemplo n.º 19
0
        public ChatPageViewModel(
            IChatService chatService,
            IPageDialogService pageDialogService,
            IUserService userService,
            IApplicationContext applicationContext,
            ITimer timer,
            ITaskDispatcher taskDispatcher)
        {
            this._userService        = userService;
            this._pageDialogService  = pageDialogService;
            this._applicationContext = applicationContext;
            this._timer             = timer;
            this._taskDispatcher    = taskDispatcher;
            this.SendMessageCommand = new DelegateCommand(async() => { await SendMessage(); });

            OnlineUserCollection = new ObservableCollection <string>();

            if (chatService == null)
            {
                throw new ArgumentNullException(nameof(chatService));
            }
            _chatService = chatService;
        }
Ejemplo n.º 20
0
 public QueueController(ILoggerFactory loggerFactory, ITaskDispatcher taskDispatcher)
 {
     _logger         = loggerFactory.CreateLogger <QueueController>();
     _taskDispatcher = taskDispatcher;
 }
Ejemplo n.º 21
0
        public void Setup()
        {
            mocks = new MockRepository();

            taskRepository = mocks.DynamicMock<IRepository<Task>>();
            teamTaskStateRepository = mocks.DynamicMock<IRepository<TeamTaskState>>();
            acceptedCodeRepository = mocks.DynamicMock<IRepository<AcceptedCode>>();
            acceptedBadCodeRepository = mocks.DynamicMock<IRepository<AcceptedBadCode>>();
            acceptedTipRepository = mocks.DynamicMock<IRepository<AcceptedTip>>();
            dispatcherFactory = mocks.DynamicMock<ITaskDispatcherFactory>();
            taskDispatcher = mocks.DynamicMock<ITaskDispatcher>();

            game = new Game { Name = "Game" };
            team = new Team { Name = "Team" };
        }
Ejemplo n.º 22
0
        public ISubscriptionToken Subscribe(Func <Task> func, ThreadHandler runOnThread, Func <bool> shouldRunPredicate = null)
        {
            ITaskDispatcher taskDispatcher = TaskDispatchers[runOnThread];

            return(AddSubscriber(new SubscriptionToken(this, taskDispatcher, func, shouldRunPredicate)));
        }
Ejemplo n.º 23
0
 public static T ExecuteTask <T>(this ITaskDispatcher self, Func <T> action)
 {
     return(self.ExecuteTask <T>(action, -1));
 }
Ejemplo n.º 24
0
 public static void ExecuteTask(this ITaskDispatcher self, Action action)
 {
     self.ExecuteTask(action, -1);
 }
 public MainViewModel(ISnackbarMessageQueue snackbarMessageQueue, ITaskDispatcher dispatcher) : base(dispatcher)
 {
     SnackbarMessageQueue = snackbarMessageQueue;
     CurrentViewModel     = new DashboardViewModel(new FeedServices(), dispatcher);
 }
 public void RegisterTaskDispatcher(ThreadHandler threadHandler, ITaskDispatcher taskDispatcher)
 {
     _taskDispatchers.Add(threadHandler, taskDispatcher);
 }
Ejemplo n.º 27
0
 public TaskDispatcherScheduler(ITaskDispatcher dispatcher)
 {
     Invariant.ArgumentNotNull((object)dispatcher, "dispatcher");
     this.dispatcher = dispatcher;
 }
 public RootViewModel(ITaskDispatcher dispatcher)
 {
     this.dispatcher = dispatcher;
 }
Ejemplo n.º 29
0
 public TaskManager(ITaskDispatcher dispatcher)
     : this()
 {
     _dispatcher = dispatcher;
 }
Ejemplo n.º 30
0
 public TaskManager(ITaskDispatcher dispatcher, TaskMode mode)
     : this(dispatcher)
 {
     _mode = mode;
 }