Example #1
0
        void Thread_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker callingThread = (BackgroundWorker)sender;
            NetStream JobStream = null;
            string currentJob = currentThread.Next;
            if (currentJob != null)
            {
                JobStream = new NetStream(currentJob);
                byte[] data = new byte[JobStream.Length];
                int offset = 0;

                while (JobStream.HasData)
                {
                    offset += JobStream.Read(data, offset, Configuration.ChunkSize);
                    ConcurrentOperationsProgress[ConcurrentOperations.IndexOf(callingThread)] = (int)JobStream.PercentComplete;
                    ConcurrentOperationsString[ConcurrentOperations.IndexOf(callingThread)] = Util.FileSizeToString(JobStream.Position, 2) + " / " + Util.FileSizeToString(JobStream.Length, 2) + "      " + JobStream.PercentComplete + "%";
                    ConcurrentOperationsCurrentJob[ConcurrentOperations.IndexOf(callingThread)] = currentJob;
                }
                if (data.Length > 0)
                {
                    try
                    {
                        MemoryStream bitmapData = new MemoryStream(data);
                        Bitmap bmp = new Bitmap(bitmapData);
                        bmp.Save(currentThread.StoragePath + "\\" + Path.GetFileName(currentJob), MimeType.ToImageFormat(JobStream.MimeType));
                    }
                    catch { JobLog.Add("Error in job [" + currentJob + "] Bitmap Data"); }
                }
                JobLog.Add("Job completed without errors: [" + currentJob + "]");
            }
            if (JobStream != null && JobStream.LastError != null)
            {
                if (JobStream.HTTPStatusCode != System.Net.HttpStatusCode.NotFound)
                {
                    currentThread.ReQueue(currentJob);
                    JobLog.Add("Error occured in job: [" + currentJob + "] re-entering job queue.");
                    JobLog.Add(JobStream.LastError);
                }
                else
                    JobLog.Add("Image doesn't exist. Skipping.");
            }
        }
Example #2
0
        /// <summary>
        /// Scan and parse the thread for new images.
        /// </summary>
        public void Scan()
        {
            NetStream SourceStream = new NetStream(ThreadURL);

            if (SourceStream.HTTPStatusCode == HttpStatusCode.NotFound) m_isdead = true; //404

            if (SourceStream.Exists)
                Source = SourceStream.Encoding.GetString(SourceStream.GetAllData());
            else
                return;
            if (board == null) return;
            System.Text.RegularExpressions.Regex ImageRegex = new System.Text.RegularExpressions.Regex(board.ImageRegex);
            System.Text.RegularExpressions.Match ImageMatch = ImageRegex.Match(Source);

            while (ImageMatch.Success)
            {
                if (!m_DownloadedFiles.Contains(ImageMatch.Value) && !m_QueuedFiles.Contains(ImageMatch.Value))
                {
                    m_QueuedFiles.Enqueue(ImageMatch.Value);
                    m_imageCount++;
                }
                ImageMatch = ImageMatch.NextMatch();
            }
            SaveHTML();
            OnScanComplete(EventArgs.Empty);
        }