Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
 public static bool AddChunk(UsenetChunk chunk)
 {
     try
     {
         _queueOfChunks.Enqueue(chunk);
         return(true);
     }
     catch (Exception ex)
     {
         Logger.Error(LOGNAME, ex.Message, ex);
     }
     return(false);
 }
Example #4
0
        public bool Upload(UsenetChunk chunk, string posterEmail)
        {
            if (CheckConnexion() == false)
            {
                return(false);
            }

            ArticleHeadersDictionary headers = CreateHeader(chunk.Id, chunk.Subject, posterEmail);

            Rfc977NntpClientWithExtensions nntpClient = client;

            var rawData = chunk.Data;

            try
            {
                try
                {
                    nntpClient.PostArticle(new ArticleHeadersDictionaryEnumerator(headers), Upload(rawData).ToList());
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    if (nntpClient.LastNntpResponse.StartsWith("441 "))
                    {
                        return(false);
                    }
                    //throw ex;
                }

                //if (!nntpClient.LastNntpResponse.StartsWith("240 ") && nntpClient.LastNntpResponse.Split('<')[1].Split('>')[0] == null)
                //{
                //    throw new Exception(nntpClient.LastNntpResponse);
                //}
                if (nntpClient.LastNntpResponse.StartsWith("240 "))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                //nothing todo
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return(false);
        }
Example #5
0
        public byte[] Download(UsenetChunk chunk)
        {
            if (CheckConnexion() == false)
            {
                return(null);
            }

            try
            {
                return(Download(client.RetrieveArticleBody(IdToMessageId(chunk.Id))));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                //if (nntpClient.LastNntpResponse.StartsWith("430 No Such Article"))
                //{
                //    return null;
                //}
            }
            return(null);
        }