コード例 #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);
            }
        }
コード例 #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);
            }
        }