Task IReliableDispatcher <T> .RunAsync(DispatcherTask <T> dispatcherTask, CancellationToken cancellationToken) { Requires.IsNotNull(dispatcherTask, nameof(dispatcherTask)); cancellationToken.Register(StopDispatcher, false); return(StartDispatcherAsync(dispatcherTask)); }
/// <summary> /// Permet de déconnecter le client /// </summary> public void Dispose() { Client.Stop(); m_Dispatcher = null; m_dispatcherTask = null; }
/// <summary> /// Executa um delegate de forma assincrona. /// </summary> /// <param name="method">Delegate do método que será executado.</param> /// <param name="args">Parametros do método que será executado.</param> /// <returns> /// O valor de retorno do delegate que está sendo /// chamado ou nulo se o delegate não tem valor de retorno. /// </returns> public virtual object Invoke(Delegate method, params object[] args) { if (method == null) { throw new ArgumentNullException("method"); } if (_thread == null) { throw new ObjectDisposedException("this"); } var task = new DispatcherTask { Method = method, Arguments = args }; if (_thread == System.Threading.Thread.CurrentThread) { task.Execute(); } else { lock (_tasks) { _tasks.Enqueue(task); _allDone.Set(); } } return(task.GetResult()); }
private static void Stop() { if (!Running) { return; } Running = false; if (Config != null) { Config.Save(); } if (MITM != null) { MITM.Stop(); } if (DispatcherTask != null) { DispatcherTask.Stop(); } PluginManager.Instance.UnLoadAllPlugins(); }
/// <summary> /// Método do robo. /// </summary> private void Robot() { try { System.Threading.Thread.CurrentThread.Name = "DP " + Name; DispatcherTask task = null; while (true) { lock (_tasks) task = _tasks.Count > 0 ? _tasks.Dequeue() : null; if (task != null) { task.Execute(); } var count = 0; lock (_tasks) count = _tasks.Count; if (count == 0) { _allDone.WaitOne(); } lock (_tasks) if (_tasks.Count == 0) { _allDone.Reset(); } } } catch (System.Threading.ThreadAbortException) { } }
/// <summary> /// Invokes specified delegate with parameters on the dispatcher thread synchronously. /// </summary> /// <param name="method">delegate to run on the thread</param> /// <param name="args">arguments to supply to the delegate</param> /// <returns>result of an action</returns> public object Invoke(Delegate method, object[] args) { // create the task DispatcherTask task = new DispatcherTask { Task = method, Params = args }; // we don't want the task to be completed before we start waiting for that, so the outer lock lock (task) { lock (_sync) { _taskQueue.Enqueue(task); Monitor.PulseAll(_sync); } // until this point, evaluation could not start //Monitor.Wait(task); Monitor.Wait(task, 1000); // and when we're done waiting, we know that the result was already set return(task.Result); } }
private static void Stop() { if (!Running) { return; } Running = false; BotManager.Instance.RemoveAll(); if (Config != null) { Config.Save(); } if (MITM != null) { MITM.Stop(); } if (DispatcherTask != null) { DispatcherTask.Stop(); } PluginManager.Instance.UnLoadAllPlugins(); RedisServerHost.Instance.Shutdown(); }
private void MainForm_Load(object sender, EventArgs e) { try { GlobalConfiguration.Instance.Initialize(); AccountConfiguration accountToConnect; using (var af = new AccountsForm()) { if (af.ShowDialog() != DialogResult.OK) { Environment.Exit(-1); } accountToConnect = af.AccountToConnect; } Task.Factory.StartNew(() => { UserData.RegisterAssembly(); CommandManager.Build(); ProtocolTypeManager.Initialize(); Logger.Default.OnLog += Logger_OnLog; Settings.Default.DofusPath = GlobalConfiguration.Instance.DofusPath; Settings.Default.Save(); MapsManager.Init(Settings.Default.DofusPath + @"\app\content\maps"); IconsManager.Instance.Initialize(Settings.Default.DofusPath + @"\app\content\gfx\items"); ObjectDataManager.Instance.AddReaders(Settings.Default.DofusPath + @"\app\data\common"); FastD2IReader.Instance.Init(Settings.Default.DofusPath + @"\app\data\i18n" + "\\i18n_fr.d2i"); ImageManager.Init(Settings.Default.DofusPath); }).ContinueWith(p => { var fullSocketConfiguration = new FullSocketConfiguration { RealAuthHost = "213.248.126.40", RealAuthPort = 443 }; var messageReceiver = new MessageReceiver(); messageReceiver.Initialize(); _fullSocket = new FullSocket.FullSocket(fullSocketConfiguration, messageReceiver); var dispatcherTask = new DispatcherTask(new MessageDispatcher(), _fullSocket); _account = _fullSocket.Connect(accountToConnect.Username, accountToConnect.Password, this); LogWelcomeMessage(); }); } catch (Exception exception) { MessageBox.Show(exception.Message); Environment.Exit(-1); } }
private async Task <bool> TryDispatchTaskAsync(DispatcherTask <T> dispatcherTask, ITransaction transaction, T item) { var success = true; try { await dispatcherTask(transaction, item, _tokenSource.Token).ConfigureAwait(false); await transaction.CommitAsync().ConfigureAwait(false); } catch { transaction.Abort(); success = false; } return(success); }
private async Task StartDispatcherAsync(DispatcherTask <T> dispatcherTask) { while (true) { await MessageIsEnqueuedAsync().ConfigureAwait(false); _tokenSource.Token.ThrowIfCancellationRequested(); bool taskDispatched; using (var transaction = _transactionFactory.Create()) { var item = await GetNextItem(transaction).ConfigureAwait(false); taskDispatched = await TryDispatchTaskAsync(dispatcherTask, transaction, item).ConfigureAwait(false); } if (!taskDispatched) { await DequeueItemAsync().ConfigureAwait(false); } } }
/// <summary> /// Invokes specified delegate with parameters on the dispatcher thread synchronously. /// </summary> /// <param name="method">delegate to run on the thread</param> /// <param name="args">arguments to supply to the delegate</param> /// <returns>result of an action</returns> public object Invoke(Delegate method, object[] args) { // create the task DispatcherTask task = new DispatcherTask{Task = method, Params = args}; // we don't want the task to be completed before we start waiting for that, so the outer lock lock (task) { lock (_sync) { _taskQueue.Enqueue(task); Monitor.PulseAll(_sync); } // until this point, evaluation could not start Monitor.Wait(task); // and when we're done waiting, we know that the result was already set return task.Result; } }
public ClientHost(SimpleClient client) { Activity = PacketActivityEnum.None; Client = client; logger = true; m_Dispatcher = new MessageDispatcher(); m_dispatcherTask = new DispatcherTask(m_Dispatcher); m_dispatcherTask.Start(); m_floods = new List <NetworkMessage>(); m_flood_timer = new System.Timers.Timer(); m_flood_timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); m_flood_timer.Interval = 1000; if (FloodQuit) { m_flood_timer.Start(); } if (client != null) { Client.DataReceived += this.ClientDataReceive; Client.Disconnected += this.ClientDisconnected; } }
public void Initialize() { InterBotDispatcher = new MessageDispatcher(); DispatcherTask = new DispatcherTask(InterBotDispatcher, this); DispatcherTask.Start(); }
public static void Initialize() { if (Initialized) { return; } if (!Debugger.IsAttached) // the debugger handle the unhandled exceptions { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; } AppDomain.CurrentDomain.ProcessExit += OnProcessExit; Config = new Config(ConfigPath); foreach (var assembly in m_hierarchy) { Config.BindAssembly(assembly); Config.RegisterAttributes(assembly); } Config.Load(); logger.Info("{0} loaded", Path.GetFileName(Config.FilePath)); var d2oSource = new D2OSource(); d2oSource.AddReaders(DofusDataPath); DataProvider.Instance.AddSource(d2oSource); var maps = new D2PSource(new D2pFile(DofusMapsD2P)); DataProvider.Instance.AddSource(maps); // todo : langs var d2iSource = new D2ISource(Languages.English); d2iSource.AddReaders(DofusI18NPath); DataProvider.Instance.AddSource(d2iSource); MITM = new MITM.MITM(new MITMConfiguration { FakeAuthHost = BotAuthHost, FakeAuthPort = BotAuthPort, FakeWorldHost = BotWorldHost, FakeWorldPort = BotWorldPort, RealAuthHost = RealAuthHost, RealAuthPort = RealAuthPort }); MessageDispatcher.DefineHierarchy(m_hierarchy); foreach (var assembly in m_hierarchy) { MessageDispatcher.RegisterSharedAssembly(assembly); } PluginManager.Instance.LoadAllPlugins(); DispatcherTask = new DispatcherTask(new MessageDispatcher(), MITM); DispatcherTask.Start(); // we have to start it now to dispatch the initialization msg var msg = new HostInitializationMessage(); DispatcherTask.Dispatcher.Enqueue(msg, MITM); msg.Wait(); Initialized = true; }
public static void Initialize() { if (Initialized) { return; } UIManager.Instance.SetBusy(true); try { if (!Debugger.IsAttached) // the debugger handle the unhandled exceptions { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; } AppDomain.CurrentDomain.ProcessExit += OnProcessExit; UIManager.Instance.BusyMessage = "Load config ..."; Config = new Config(ConfigPath); foreach (Assembly assembly in m_hierarchy) { Config.BindAssembly(assembly); Config.RegisterAttributes(assembly); } Config.Load(); logger.Info("{0} loaded", Path.GetFileName(Config.FilePath)); UIManager.Instance.BusyMessage = "Loading D2O files ..."; ObjectDataManager.Instance.AddReaders(Path.Combine(GetDofusPath(), DofusDataPath)); I18NDataManager.Instance.DefaultLanguage = Languages.English; I18NDataManager.Instance.AddReaders(Path.Combine(GetDofusPath(), DofusI18NPath)); IconsManager.Instance.Initialize(Path.Combine(GetDofusPath(), DofusItemIconPath)); UIManager.Instance.BusyMessage = "Starting redis server ..."; logger.Info("Starting redis server ..."); RedisServerHost.Instance.ExecutablePath = RedisServerExe; RedisServerHost.Instance.StartOrFindProcess(); UIManager.Instance.BusyMessage = string.Format("Loading {0}...", MapsManager.MapsDataFile); logger.Info("Loading {0}...", MapsManager.MapsDataFile); ProgressionCounter progression = MapsManager.Instance.Initialize(Path.Combine(GetDofusPath(), DofusMapsD2P)); if (progression != null) { ExecuteProgress(progression); } UIManager.Instance.BusyMessage = "Loading maps positions ..."; logger.Info("Loading maps positions ..."); progression = MapsPositionManager.Instance.Initialize(); if (progression != null) { ExecuteProgress(progression); } UIManager.Instance.BusyMessage = "Loading submaps ..."; logger.Info("Loading submaps ..."); progression = SubMapsManager.Instance.Initialize(); if (progression != null) { ExecuteProgress(progression); } MITM = new MITM.MITM(new MITMConfiguration { FakeAuthHost = BotAuthHost, FakeAuthPort = BotAuthPort, FakeWorldHost = BotWorldHost, FakeWorldPort = BotWorldPort, RealAuthHost = RealAuthHost, RealAuthPort = RealAuthPort }); MessageDispatcher.DefineHierarchy(m_hierarchy); foreach (Assembly assembly in m_hierarchy) { MessageDispatcher.RegisterSharedAssembly(assembly); } UIManager.Instance.BusyMessage = "Loading plugins ..."; PluginManager.Instance.LoadAllPlugins(); DispatcherTask = new DispatcherTask(new MessageDispatcher(), MITM); DispatcherTask.Start(); // we have to start it now to dispatch the initialization msg BotManager.Instance.Initialize(); var msg = new HostInitializationMessage(); DispatcherTask.Dispatcher.Enqueue(msg, MITM); msg.Wait(); } finally { UIManager.Instance.SetBusy(false); } Initialized = true; }