private static void Process(object connNumber) { try { UsenetServer us = UsenetConns.ListOfConns[(int)connNumber]; while (_queueOfChunks.IsEmpty == false) { try { UsenetChunk chunk = null; if (_queueOfChunks.TryDequeue(out chunk)) { chunk.SetDataFromBr(_encKey); chunk.SetSubject(); bool isUploaded = false; for (byte passNumber = 0; passNumber < UsenetServer.MAX_PASS; passNumber++) { chunk.SetId(passNumber); //DEBUG ONLY START //string chunkPath = Path.Combine(Utilities.ExecutableFolder, "chunks"); //if (Directory.Exists(chunkPath) == false) //{ // Directory.CreateDirectory(chunkPath); //} //chunkPath = Path.Combine(chunkPath, chunk.ChunkExt + "_" + chunk.ChunkNumber + "_" + chunk.Id); //File.WriteAllBytes(chunkPath, chunk.Data); //isUploaded = true; //break; //DEBUG ONLY END isUploaded = us.Upload(chunk, _poster); if (isUploaded == true) { break; } } if (isUploaded == false) { chunk.SetId(UsenetServer.MAX_PASS); Logger.Warn(LOGNAME, "Cannot upload chunk " + chunk.Filename + " (#" + chunk.ChunkNumber + ")"); } chunk.DataRaz();//free memory } } catch (Exception ex) { Logger.Error(LOGNAME, ex.Message, ex); } Interlocked.Decrement(ref _remainingChunks); } } catch (Exception ex) { Logger.Error(LOGNAME, ex.Message, ex); } }
private static void Process(object connNumber) { try { UsenetServer us = UsenetConns.ListOfConns[(int)connNumber]; while (_queueOfChunks.IsEmpty == false) { try { UsenetChunk chunk = null; if (_queueOfChunks.TryDequeue(out chunk)) { chunk.SetId(chunk.PassNumber); for (int i = 0; i < MAX_RETRY; i++) { byte[] rawdata = null; ////DEBUG ONLY START //string chunkPath = Path.Combine(Utilities.ExecutableFolder, "chunks", chunk.ChunkExt + "_" + chunk.ChunkNumber + "_" + chunk.Id); //if (File.Exists(chunkPath)) //{ // rawdata = File.ReadAllBytes(chunkPath); // chunk.DataSet(rawdata, _encKey); // chunk.WriteDataToBw(); //} //break; ////DEBUG ONLY END rawdata = us.Download(chunk); if (rawdata == null || rawdata.Length == 0) { if (i == MAX_RETRY - 1) { Logger.Warn(LOGNAME, "Cannot download chunk " + chunk.Filename + " (#" + chunk.ChunkNumber + ")"); } continue; } chunk.DataSet(rawdata, _encKey); chunk.WriteDataToBw(); } chunk.DataRaz();//free memory } } catch (Exception ex) { Logger.Error(LOGNAME, ex.Message, ex); } Interlocked.Decrement(ref _remainingChunks); } } catch (Exception ex) { Logger.Error(LOGNAME, ex.Message, ex); } }
public static bool Start() { try { for (int i = 0; i < Settings.Settings.Current.UsenetSlots; i++) { IProxyClient proxyClient = GetProxy(); if (i == 0 && proxyClient != null) { Logger.Info(LOGNAME, "Proxy enabled (" + Settings.Settings.Current.ProxyType + "): " + Settings.Settings.Current.ProxyServer + ":" + Settings.Settings.Current.ProxyPort); } UsenetServer us = new UsenetServer(Settings.Settings.Current.UsenetServer, Settings.Settings.Current.UsenetPort, Settings.Settings.Current.UsenetUseSSL, Settings.Settings.Current.UsenetUsername, Settings.Settings.Current.UsenetPassword, Settings.Settings.Current.UsenetNewsgroup, proxyClient); ListOfConns.Add(us); } Logger.Info(LOGNAME, "UsenetConns loaded"); return(true); } catch (Exception ex) { Logger.Error(LOGNAME, ex.Message, ex); } return(false); }