public AddBotToQueue ( |
||
aBot | ||
aInt | int | |
리턴 | void |
void BotDisconnected(object aSender, EventArgs <Packet> aEventArgs) { var download = _botDownloads.SingleOrDefault(c => c.Packet == aEventArgs.Value1); if (download != null) { download.Packet = null; download.OnDisconnected -= BotDisconnected; download.OnNotificationAdded -= AddNotification; _botDownloads.Remove(download); if (!AllowRunning) { return; } try { // if the connection never connected, there will be no file // and if we manually stopped the packet there will be file also // the missing size is negative?! if (download.File != null && download.File.MissingSize <= 0) { // do this here because the bothandler sets the file state FileActions.FinishFile(download.File); } } catch (Exception ex) { _log.Fatal("BotDisconnected()", ex); } try { IrcConnection connection = _connections.SingleOrDefault(c => c.Server == aEventArgs.Value1.Parent.Parent.Parent); if (connection != null) { connection.AddBotToQueue(aEventArgs.Value1.Parent, Settings.Default.CommandWaitTime); } } catch (Exception ex) { _log.Fatal("BotDisconnected() request", ex); } } }
void BotConnect(object aSender, EventArgs <Packet, Int64, IPAddress, int> aEventArgs) { int currentDownloadCount = (from file in Files.All where file.Connected select file).Count(); if (Settings.Default.MaxDownloads > 0 && currentDownloadCount >= Settings.Default.MaxDownloads) { _log.Error("BotConnect(" + aEventArgs.Value1 + ") skipping, because already " + Settings.Default.MaxDownloads + " packets are downloading"); IrcConnection connection = _connections.SingleOrDefault(c => c.Server == aEventArgs.Value1.Parent.Parent.Parent); if (connection != null) { connection.AddBotToQueue(aEventArgs.Value1.Parent, Settings.Default.BotWaitTime); } return; } var download = _botDownloads.SingleOrDefault(c => c.Packet == aEventArgs.Value1); if (download == null) { download = new BotDownload { Files = Files, Packet = aEventArgs.Value1, StartSize = aEventArgs.Value2, IP = aEventArgs.Value3, Port = aEventArgs.Value4, MaxData = aEventArgs.Value1.RealSize - aEventArgs.Value2, Scheduler = Scheduler }; download.OnDisconnected += BotDisconnected; download.OnNotificationAdded += AddNotification; _botDownloads.Add(download); download.Start(aEventArgs.Value3 + ":" + aEventArgs.Value4); } else { // uhh - that should not happen _log.Error("BotConnect(" + aEventArgs.Value1 + ") is already downloading"); } }