public static dlData getAndRemoveFromDownloadList() { if (downloadList.Count > 0) { while (true) { try { //Debug.WriteLine("SHAREDDATA-DEBUG: returning: " + downloadList[0].dlPack + " from first index "); dlData toreturn = downloadList[0]; downloadList.RemoveAt(0); return(toreturn); // this should prevent from reading non existent downloads, if there is no available next time will be. } catch (Exception e) { Debug.WriteLine("SHAREDDATA-DEBUG: Could not return and remove downloaditem, retrying until it can"); } } } else { //Debug.WriteLine("SHAREDDATA-DEBUG: could not return latestdownloadadded, returning: null"); return(null); } }
public static void AddToDownloadList(dlData data) { while (true) { if (!downloadList.Contains(data)) { downloadList.Add(data); break; } } // Debug.WriteLine("SHAREDDATA-DEBUG: added download: " + data.dlPack + " at index: " + (downloadList.Count - 1)); }
private void downloaderLogic() { Debug.WriteLine("DEBUG-IRCHANDLER: DOWNLOADER LOGIC STARTED"); while (!SharedData.closeBackend) { Thread.Sleep(1); if (irc.isClientRunning() && !isBussyConnecting && SharedData.joinedChannel) { Thread.Sleep(1000); if (!irc.checkIfDownload() && !SharedData.currentlyDownloading) { Thread.Sleep(500); if (!irc.didErrorHappen) { //Debug.WriteLine("DEBUG-IRCHANDLER: QUEU LENGTH BEFORE TAKING: " + SharedData.downloadList.Count); dlData data = SharedData.getAndRemoveFromDownloadList(); if (data != null) { SharedData.currentDownloadId = data.dlId; bool succes = false; try { if (data.dlBot != "undefined" && data.dlPack != "undefined") { irc.sendMessage("/msg " + data.dlBot + " xdcc send " + data.dlPack); succes = true; } } catch { Debug.WriteLine("DEBUG-IRCHANDLER: ERROR: NOT CONNECTED TO IRC, CAN'T DOWNLOAD FILE :("); } if (succes) { //SharedData.AddToMessageList("DOWNLOADSTARTED"); Debug.WriteLine("DEBUG-IRCHANDLER: Started a download: " + "/msg " + data.dlBot + " xdcc send " + data.dlPack); Console.WriteLine("Started a download: " + "/msg " + data.dlBot + " xdcc send " + data.dlPack); SharedData.currentlyDownloading = true; } } // Debug.WriteLine("DEBUG-IRCHANDLER: QUEU LENGTH AFTER TAKING: " + SharedData.downloadList.Count); } } } } }
private void addDownload(dynamic download) { try { string dlId = download.id.ToString(); string dlPack = download.pack.ToString(); string dlBot = download.bot.ToString(); dlData d = new dlData(); d.dlId = dlId; d.dlBot = dlBot; d.dlPack = dlPack; d.dlIndex = SharedData.downloadList.Count; SharedData.AddToDownloadList(d); //Debug.WriteLine("DEBUG-WEBSOCKETHANDLER:DONE ADDING BATCH TO DOWLOADS: ID:" + dlId + " XDCC: /msg " + dlBot + " xdcc send #" + dlPack); } catch (Exception ex) { Debug.WriteLine("DEBUG-WEBSOCKETHANDLER:ERROR: " + ex.ToString()); } }